diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/CreateDataSetExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/CreateDataSetExecutor.java index 16a766b65f6341e5276bfce4b7bb9c93a3922eba..e9478d05513ede752497e7cab9d4fa7e19021aa0 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/CreateDataSetExecutor.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/CreateDataSetExecutor.java @@ -85,6 +85,9 @@ public class CreateDataSetExecutor extends AbstractCreateEntityExecutor<DataSetC @Autowired private ISetDataSetRelatedDataSetsExecutor setDataSetRelatedDataSetsExecutor; + @Autowired + private ISetDataSetRegistratorExecutor setDataSetRegistratorExecutor; + @Autowired private IUpdateEntityPropertyExecutor updateEntityPropertyExecutor; @@ -153,7 +156,6 @@ public class CreateDataSetExecutor extends AbstractCreateEntityExecutor<DataSetC dataSet.setCode(creation.getCode()); dataSet.setDataSetType(type); dataSet.setDerived(false == creation.isMeasured()); - dataSet.setRegistrator(context.getSession().tryGetPerson()); RelationshipUtils.updateModificationDateAndModifier(dataSet, context.getSession().tryGetPerson()); dataSets.add(dataSet); @@ -171,7 +173,7 @@ public class CreateDataSetExecutor extends AbstractCreateEntityExecutor<DataSetC @Override protected void checkAccess(IOperationContext context, DataPE entity) { - if (false == new DataSetPEByExperimentOrSampleIdentifierValidator().doValidation(context.getSession().tryGetPerson(), entity)) + if (false == new DataSetPEByExperimentOrSampleIdentifierValidator().doValidation(entity.getRegistrator(), entity)) { throw new UnauthorizedObjectAccessException(new DataSetPermId(entity.getPermId())); } @@ -191,6 +193,7 @@ public class CreateDataSetExecutor extends AbstractCreateEntityExecutor<DataSetC setDataSetDataStoreExecutor.set(context, entitiesMap); setDataSetExperimentExecutor.set(context, entitiesMap); setDataSetSampleExecutor.set(context, entitiesMap); + setDataSetRegistratorExecutor.set(context, entitiesMap); Map<IEntityPropertiesHolder, Map<String, String>> propertyMap = new HashMap<IEntityPropertiesHolder, Map<String, String>>(); for (Map.Entry<DataSetCreation, DataPE> entry : entitiesMap.entrySet()) diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/ISetDataSetRegistratorExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/ISetDataSetRegistratorExecutor.java new file mode 100644 index 0000000000000000000000000000000000000000..22900f3a7bd57e28e2a48cc1ae0188775370b1e9 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/ISetDataSetRegistratorExecutor.java @@ -0,0 +1,33 @@ +/* + * Copyright 2015 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.ethz.sis.openbis.generic.server.api.v3.executor.dataset; + +import java.util.Map; + +import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.dataset.DataSetCreation; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; + +/** + * @author pkupczyk + */ +public interface ISetDataSetRegistratorExecutor +{ + + void set(IOperationContext context, Map<DataSetCreation, DataPE> entitiesMap); + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/SetDataSetRegistratorExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/SetDataSetRegistratorExecutor.java new file mode 100644 index 0000000000000000000000000000000000000000..34575a77f648c627ad3445e9e91084f40e1d20bf --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/SetDataSetRegistratorExecutor.java @@ -0,0 +1,73 @@ +/* + * Copyright 2015 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.ethz.sis.openbis.generic.server.api.v3.executor.dataset; + +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext; +import ch.ethz.sis.openbis.generic.server.api.v3.executor.entity.AbstractSetEntityToOneRelationExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.executor.person.IMapPersonByIdExecutor; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.dataset.DataSetCreation; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.person.IPersonId; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; + +/** + * @author pkupczyk + */ +@Component +public class SetDataSetRegistratorExecutor extends AbstractSetEntityToOneRelationExecutor<DataSetCreation, DataPE, IPersonId, PersonPE> implements + ISetDataSetRegistratorExecutor +{ + + @Autowired + private IMapPersonByIdExecutor mapPersonByIdExecutor; + + @Override + protected IPersonId getRelatedId(DataSetCreation creation) + { + return creation.getRegistratorId(); + } + + @Override + protected Map<IPersonId, PersonPE> map(IOperationContext context, List<IPersonId> relatedIds) + { + return mapPersonByIdExecutor.map(context, relatedIds); + } + + @Override + protected void check(IOperationContext context, DataPE entity, IPersonId relatedId, PersonPE related) + { + } + + @Override + protected void set(IOperationContext context, DataPE entity, PersonPE related) + { + if (related == null) + { + entity.setRegistrator(context.getSession().tryGetPerson()); + } else + { + entity.setRegistrator(related); + } + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/entity/AbstractSetEntityToOneRelationExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/entity/AbstractSetEntityToOneRelationExecutor.java index 4fa3ab981c6a98963eae797ad0dad18e61806e31..07b8e746136d59405c4c12d56779fd560f7a8df3 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/entity/AbstractSetEntityToOneRelationExecutor.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/entity/AbstractSetEntityToOneRelationExecutor.java @@ -60,6 +60,7 @@ public abstract class AbstractSetEntityToOneRelationExecutor<ENTITY_CREATION, EN if (relatedId == null) { check(context, entity, null, null); + set(context, entity, null); } else { RELATED_PE related = relatedMap.get(relatedId); diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateDataSetTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateDataSetTest.java index 11cc5666318ac509bf72a92355819384bd5e9ad9..3e34720792aaeeb5f44ff07dc5237ac787f8953f 100644 --- a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateDataSetTest.java +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateDataSetTest.java @@ -43,7 +43,10 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.entitytype.EntityTypePer import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.entitytype.IEntityTypeId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.ExperimentIdentifier; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.ExperimentPermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.IExperimentId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.person.PersonPermId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.ProjectIdentifier; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.ISampleId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.SampleIdentifier; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.SamplePermId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.space.SpacePermId; @@ -400,6 +403,27 @@ public class CreateDataSetTest extends AbstractDataSetTest }, experimentIds.get(0)); } + @Test + public void testCreateWithExperimentUnauthorized() + { + final String sessionToken = v3api.login(TEST_USER, PASSWORD); + + final IExperimentId experimentId = new ExperimentIdentifier("/CISD/NEMO/EXP1"); + final DataSetCreation creation = dataSetCreation(); + creation.setExperimentId(experimentId); + creation.setSampleId(null); + creation.setRegistratorId(new PersonPermId(TEST_SPACE_USER)); + + assertUnauthorizedObjectAccessException(new IDelegatedAction() + { + @Override + public void execute() + { + v3api.createDataSets(sessionToken, Arrays.asList(creation)); + } + }, new DataSetPermId(creation.getCode())); + } + @Test public void testCreateWithSampleInTrash() { @@ -424,6 +448,27 @@ public class CreateDataSetTest extends AbstractDataSetTest }, sampleIds.get(0)); } + @Test + public void testCreateWithSampleUnauthorized() + { + final String sessionToken = v3api.login(TEST_USER, PASSWORD); + + final ISampleId sampleId = new SampleIdentifier("/CISD/CP-TEST-1"); + final DataSetCreation creation = dataSetCreation(); + creation.setExperimentId(null); + creation.setSampleId(sampleId); + creation.setRegistratorId(new PersonPermId(TEST_SPACE_USER)); + + assertUnauthorizedObjectAccessException(new IDelegatedAction() + { + @Override + public void execute() + { + v3api.createDataSets(sessionToken, Arrays.asList(creation)); + } + }, new DataSetPermId(creation.getCode())); + } + @Test public void testCreateWithSampleShared() { @@ -554,9 +599,4 @@ public class CreateDataSetTest extends AbstractDataSetTest return creation; } - public static void main(String[] args) - { - System.out.println("REQUIRES_EXPERIMENT".matches("(?!REQUIRES\\_EXPERIMENT).*")); - } - } diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/entity/dataset/DataSetCreation.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/entity/dataset/DataSetCreation.java index 6af6cf91521f5f41c1b709b82d87422d6f3ba522..60d60a4eebdd93d8ce4c172af2911f8ebdfab3d2 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/entity/dataset/DataSetCreation.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/entity/dataset/DataSetCreation.java @@ -27,6 +27,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.IDataSetId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.datastore.IDataStoreId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.entitytype.IEntityTypeId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.IExperimentId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.person.IPersonId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.ISampleId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.tag.ITagId; import ch.systemsx.cisd.base.annotation.JsonObject; @@ -67,6 +68,8 @@ public class DataSetCreation implements Serializable, ICreationIdHolder private List<? extends IDataSetId> childIds; + private IPersonId registratorId; + private CreationId creationId; public IEntityTypeId getTypeId() @@ -210,6 +213,16 @@ public class DataSetCreation implements Serializable, ICreationIdHolder return properties; } + public IPersonId getRegistratorId() + { + return registratorId; + } + + public void setRegistratorId(IPersonId registratorId) + { + this.registratorId = registratorId; + } + @Override public CreationId getCreationId() {