From f7c88a8e06ae639f5d8f2ac46928a1346b8bc9f2 Mon Sep 17 00:00:00 2001 From: jakubs <jakubs> Date: Tue, 17 Mar 2015 15:25:07 +0000 Subject: [PATCH] SSDM-1626 create materials & test scaffolding SVN: 33679 --- .../server/api/v3/ApplicationServerApi.java | 24 ++- .../api/v3/ApplicationServerApiLogger.java | 9 + .../entity/AbstractCreateEntityExecutor.java | 9 +- .../material/CreateMaterialExecutor.java | 159 ++++++++++++++++++ .../material/ICreateMaterialExecutor.java | 29 ++++ .../material/ISetMaterialTypeExecutor.java | 29 ++++ .../material/IVerifyMaterialExecutor.java | 32 ++++ .../material/SetMaterialTypeExecutor.java | 73 ++++++++ .../material/VerifyMaterialExecutor.java | 54 ++++++ .../server/dataaccess/IMaterialDAO.java | 2 +- .../server/dataaccess/db/MaterialDAO.java | 2 +- .../systemtest/api/v3/CreateMaterialTest.java | 84 +++++++++ 12 files changed, 499 insertions(+), 7 deletions(-) create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/CreateMaterialExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/ICreateMaterialExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/ISetMaterialTypeExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/IVerifyMaterialExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/SetMaterialTypeExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/VerifyMaterialExecutor.java create mode 100644 openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateMaterialTest.java diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApi.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApi.java index eaf387680b7..77553434f37 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApi.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApi.java @@ -39,6 +39,7 @@ import ch.ethz.sis.openbis.generic.server.api.v3.executor.experiment.IDeleteExpe import ch.ethz.sis.openbis.generic.server.api.v3.executor.experiment.IMapExperimentByIdExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.experiment.ISearchExperimentExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.experiment.IUpdateExperimentExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.executor.material.ICreateMaterialExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.material.IDeleteMaterialExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.material.IMapMaterialByIdExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.project.ICreateProjectExecutor; @@ -75,6 +76,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experimen import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentCreation; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentUpdate; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.Material; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.MaterialCreation; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.ProjectCreation; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.Sample; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.SampleCreation; @@ -93,6 +95,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.IDeletionId; 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.material.IMaterialId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.MaterialPermId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.ProjectPermId; 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.SamplePermId; @@ -179,11 +182,14 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> @Autowired private IMapMaterialByIdExecutor mapMaterialByIdExecutor; + @Autowired + private ICreateMaterialExecutor createMaterialExecutor; + @Autowired private ISearchSpaceExecutor searchSpaceExecutor; @Autowired - private IDeleteMaterialExecutor deleteMaterialsExecutor; + private IDeleteMaterialExecutor deleteMaterialExecutor; @Autowired private ISearchExperimentExecutor searchExperimentExecutor; @@ -272,6 +278,20 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> } } + @Override + public List<MaterialPermId> createMaterials(String sessionToken, List<MaterialCreation> newMaterials) + { + Session session = getSession(sessionToken); + OperationContext context = new OperationContext(session); + try + { + return createMaterialExecutor.create(context, newMaterials); + } catch (Throwable t) + { + throw ExceptionUtils.create(context, t); + } + } + @Override @Transactional @RolesAllowed({ RoleWithHierarchy.SPACE_POWER_USER, RoleWithHierarchy.SPACE_ETL_SERVER }) @@ -659,7 +679,7 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> OperationContext context = new OperationContext(session); try { - deleteMaterialsExecutor.delete(context, materialIds, deletionOptions); + deleteMaterialExecutor.delete(context, materialIds, deletionOptions); } catch (Throwable t) { throw ExceptionUtils.create(context, t); diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApiLogger.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApiLogger.java index 96c27574bdc..9b9bf0108fc 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApiLogger.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApiLogger.java @@ -32,6 +32,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experimen import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentCreation; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentUpdate; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.Material; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.MaterialCreation; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.ProjectCreation; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.Sample; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.SampleCreation; @@ -50,6 +51,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.IDeletionId; 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.material.IMaterialId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.MaterialPermId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.ProjectPermId; 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.SamplePermId; @@ -123,6 +125,13 @@ public class ApplicationServerApiLogger extends AbstractServerLogger implements return null; } + @Override + public List<MaterialPermId> createMaterials(String sessionToken, List<MaterialCreation> newMaterials) + { + logAccess(sessionToken, "create-materials", "NEW_MATERIALS(%s)", newMaterials); + return null; + } + @Override public List<ExperimentPermId> createExperiments(String sessionToken, List<ExperimentCreation> newExperiments) { diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/entity/AbstractCreateEntityExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/entity/AbstractCreateEntityExecutor.java index d3a0bba7aee..b288c1fd876 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/entity/AbstractCreateEntityExecutor.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/entity/AbstractCreateEntityExecutor.java @@ -85,9 +85,6 @@ public abstract class AbstractCreateEntityExecutor<CREATION, PE, PERM_ID> implem checkData(context, creation); PE entity = create(context, creation); - PERM_ID permId = createPermId(context, entity); - - permIdsAll.add(permId); entitiesAll.put(creation, entity); batchMap.put(creation, entity); } @@ -99,6 +96,12 @@ public abstract class AbstractCreateEntityExecutor<CREATION, PE, PERM_ID> implem checkAccess(context, entity); } + for (PE entity : entitiesAll.values()) + { + PERM_ID permId = createPermId(context, entity); + permIdsAll.add(permId); + } + save(context, new ArrayList<PE>(batchMap.values()), false); daoFactory.setBatchUpdateMode(false); diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/CreateMaterialExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/CreateMaterialExecutor.java new file mode 100644 index 00000000000..2ccc0499a40 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/CreateMaterialExecutor.java @@ -0,0 +1,159 @@ +/* + * Copyright 2014 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.material; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; + +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataAccessException; +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.AbstractCreateEntityExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.executor.property.IUpdateEntityPropertyExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.executor.tag.IAddTagToEntityExecutor; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.MaterialCreation; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.MaterialPermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.tag.ITagId; +import ch.systemsx.cisd.common.exceptions.UserFailureException; +import ch.systemsx.cisd.openbis.generic.server.ComponentNames; +import ch.systemsx.cisd.openbis.generic.server.business.bo.DataAccessExceptionTranslator; +import ch.systemsx.cisd.openbis.generic.server.business.bo.ICommonBusinessObjectFactory; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; +import ch.systemsx.cisd.openbis.generic.shared.dto.IEntityPropertiesHolder; +import ch.systemsx.cisd.openbis.generic.shared.dto.IEntityWithMetaprojects; +import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SpaceIdentifierFactory; +import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind; + +/** + * @author Jakub Straszewski + */ +@Component +public class CreateMaterialExecutor extends AbstractCreateEntityExecutor<MaterialCreation, MaterialPE, MaterialPermId> implements + ICreateMaterialExecutor +{ + + @Resource(name = ComponentNames.COMMON_BUSINESS_OBJECT_FACTORY) + ICommonBusinessObjectFactory businessObjectFactory; + + @Autowired + private IDAOFactory daoFactory; + + @Autowired + private ISetMaterialTypeExecutor setMaterialTypeExecutor; + + @Autowired + private IUpdateEntityPropertyExecutor updateEntityPropertyExecutor; + + @Autowired + private IAddTagToEntityExecutor addTagToEntityExecutor; + + @Autowired + private IVerifyMaterialExecutor verifyMaterialExecutor; + + @Override + protected MaterialPE create(IOperationContext context, MaterialCreation creation) + { + MaterialPE material = new MaterialPE(); + material.setCode(creation.getCode()); + material.setRegistrator(context.getSession().tryGetPerson()); + return material; + } + + @Override + protected MaterialPermId createPermId(IOperationContext context, MaterialPE entity) + { + return new MaterialPermId(entity.getCode(), entity.getEntityType().getCode()); + } + + @Override + protected void checkData(IOperationContext context, MaterialCreation creation) + { + if (StringUtils.isEmpty(creation.getCode())) + { + throw new UserFailureException("Code cannot be empty."); + } + + SpaceIdentifierFactory.assertValidCode(creation.getCode()); + } + + @Override + protected void checkAccess(IOperationContext context, MaterialPE entity) + { + // nothing to do + } + + @Override + protected void checkBusinessRules(IOperationContext context, Collection<MaterialPE> entities) + { + verifyMaterialExecutor.verify(context, entities); + } + + @Override + protected void updateBatch(IOperationContext context, Map<MaterialCreation, MaterialPE> entitiesMap) + { + setMaterialTypeExecutor.set(context, entitiesMap); + + Map<IEntityPropertiesHolder, Map<String, String>> propertyMap = new HashMap<IEntityPropertiesHolder, Map<String, String>>(); + for (Map.Entry<MaterialCreation, MaterialPE> entry : entitiesMap.entrySet()) + { + propertyMap.put(entry.getValue(), entry.getKey().getProperties()); + } + updateEntityPropertyExecutor.update(context, propertyMap); + } + + @Override + protected void updateAll(IOperationContext context, Map<MaterialCreation, MaterialPE> entitiesMap) + { + Map<IEntityWithMetaprojects, Collection<? extends ITagId>> tagMap = new HashMap<IEntityWithMetaprojects, Collection<? extends ITagId>>(); + + for (Map.Entry<MaterialCreation, MaterialPE> entry : entitiesMap.entrySet()) + { + MaterialCreation creation = entry.getKey(); + MaterialPE entity = entry.getValue(); + tagMap.put(entity, creation.getTagIds()); + } + + addTagToEntityExecutor.add(context, tagMap); + } + + @Override + protected List<MaterialPE> list(IOperationContext context, Collection<Long> ids) + { + return daoFactory.getMaterialDAO().listMaterialsById(ids); + } + + @Override + protected void save(IOperationContext context, List<MaterialPE> entities, boolean clearCache) + { + daoFactory.getMaterialDAO().createOrUpdateMaterials(entities); + } + + @Override + protected void handleException(DataAccessException e) + { + DataAccessExceptionTranslator.throwException(e, EntityKind.MATERIAL.getLabel(), EntityKind.MATERIAL); + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/ICreateMaterialExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/ICreateMaterialExecutor.java new file mode 100644 index 00000000000..792eb823a06 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/ICreateMaterialExecutor.java @@ -0,0 +1,29 @@ +/* + * 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.material; + +import ch.ethz.sis.openbis.generic.server.api.v3.executor.entity.ICreateEntityExecutor; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.MaterialCreation; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.MaterialPermId; + +/** + * @author Jakub Straszewski + */ +public interface ICreateMaterialExecutor extends ICreateEntityExecutor<MaterialCreation, MaterialPermId> +{ + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/ISetMaterialTypeExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/ISetMaterialTypeExecutor.java new file mode 100644 index 00000000000..0fc246ac1d5 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/ISetMaterialTypeExecutor.java @@ -0,0 +1,29 @@ +/* + * Copyright 2014 ETH Zuerich, Scientific IT Services + * + * 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.material; + +import ch.ethz.sis.openbis.generic.server.api.v3.executor.entity.ISetEntityRelationsExecutor; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.MaterialCreation; +import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE; + +/** + * @author Jakub Straszewski + */ +public interface ISetMaterialTypeExecutor extends ISetEntityRelationsExecutor<MaterialCreation, MaterialPE> +{ + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/IVerifyMaterialExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/IVerifyMaterialExecutor.java new file mode 100644 index 00000000000..e1f77689cad --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/IVerifyMaterialExecutor.java @@ -0,0 +1,32 @@ +/* + * Copyright 2014 ETH Zuerich, Scientific IT Services + * + * 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.material; + +import java.util.Collection; + +import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext; +import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE; + +/** + * @author Jakub Straszewski + */ +public interface IVerifyMaterialExecutor +{ + + public void verify(IOperationContext context, Collection<MaterialPE> materials); + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/SetMaterialTypeExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/SetMaterialTypeExecutor.java new file mode 100644 index 00000000000..cfd989868a9 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/SetMaterialTypeExecutor.java @@ -0,0 +1,73 @@ +/* + * Copyright 2014 ETH Zuerich, Scientific IT Services + * + * 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.material; + +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.AbstractSetEntityRelationExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.executor.entity.IMapEntityTypeByIdExecutor; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.MaterialCreation; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.entitytype.IEntityTypeId; +import ch.systemsx.cisd.common.exceptions.UserFailureException; +import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialTypePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind; + +/** + * @author Jakub Straszewski + */ +@Component +public class SetMaterialTypeExecutor extends AbstractSetEntityRelationExecutor<MaterialCreation, MaterialPE, IEntityTypeId, EntityTypePE> implements + ISetMaterialTypeExecutor +{ + + @Autowired + private IMapEntityTypeByIdExecutor mapEntityTypeByIdExecutor; + + @Override + protected IEntityTypeId getRelatedId(MaterialCreation creation) + { + return creation.getTypeId(); + } + + @Override + protected Map<IEntityTypeId, EntityTypePE> map(IOperationContext context, List<IEntityTypeId> relatedIds) + { + return mapEntityTypeByIdExecutor.map(context, EntityKind.MATERIAL, relatedIds); + } + + @Override + protected void check(IOperationContext context, MaterialPE entity, IEntityTypeId relatedId, EntityTypePE related) + { + if (relatedId == null) + { + throw new UserFailureException("Type id cannot be null."); + } + } + + @Override + protected void set(IOperationContext context, MaterialPE entity, EntityTypePE related) + { + entity.setMaterialType((MaterialTypePE) related); + } +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/VerifyMaterialExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/VerifyMaterialExecutor.java new file mode 100644 index 00000000000..babf3f12785 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/material/VerifyMaterialExecutor.java @@ -0,0 +1,54 @@ +/* + * Copyright 2014 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.material; + +import java.util.Collection; + +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.property.IVerifyEntityPropertyExecutor; +import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE; + +/** + * @author Jakub Straszewski + */ +@Component +public class VerifyMaterialExecutor implements IVerifyMaterialExecutor +{ + + @Autowired + private IVerifyEntityPropertyExecutor verifyEntityPropertyExecutor; + + @SuppressWarnings("unused") + private VerifyMaterialExecutor() + { + } + + public VerifyMaterialExecutor(IVerifyEntityPropertyExecutor verifyEntityPropertyExecutor) + { + this.verifyEntityPropertyExecutor = verifyEntityPropertyExecutor; + } + + @Override + public void verify(IOperationContext context, Collection<MaterialPE> materials) + { + verifyEntityPropertyExecutor.verify(context, materials); + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IMaterialDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IMaterialDAO.java index 5252b1ff5df..c52989bb43a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IMaterialDAO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IMaterialDAO.java @@ -54,7 +54,7 @@ public interface IMaterialDAO extends IGenericDAO<MaterialPE> /** same as {@link #tryFindMaterial(MaterialIdentifier)} but works with given session */ public MaterialPE tryFindMaterial(Session session, MaterialIdentifier identifier); - public List<MaterialPE> listMaterialsById(final List<Long> ids); + public List<MaterialPE> listMaterialsById(final Collection<Long> ids); public List<MaterialPE> listMaterialsByMaterialIdentifier(final Collection<MaterialIdentifier> ids); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/MaterialDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/MaterialDAO.java index 379d85dce55..e979defa833 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/MaterialDAO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/MaterialDAO.java @@ -212,7 +212,7 @@ public class MaterialDAO extends AbstractGenericEntityWithPropertiesDAO<Material } @Override - public List<MaterialPE> listMaterialsById(final List<Long> ids) + public List<MaterialPE> listMaterialsById(final Collection<Long> ids) { if (ids == null || ids.isEmpty()) { diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateMaterialTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateMaterialTest.java new file mode 100644 index 00000000000..2781aafbc44 --- /dev/null +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateMaterialTest.java @@ -0,0 +1,84 @@ +/* + * Copyright 2014 ETH Zuerich, Scientific IT Services + * + * 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.systemtest.api.v3; + +import static org.testng.Assert.assertEquals; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.testng.annotations.Test; + +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.Material; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.MaterialCreation; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.material.MaterialFetchOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.CreationId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.entitytype.EntityTypePermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.IMaterialId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.MaterialPermId; +import ch.systemsx.cisd.common.test.AssertionUtil; + +/** + * @author pkupczyk + */ +public class CreateMaterialTest extends AbstractSampleTest +{ + + @Test + public void testSimpleMaterialCreation() + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + + MaterialCreation m1 = geneCreation("1982"); + MaterialCreation m2 = geneCreation("1984"); + + List<MaterialPermId> materialIds = v3api.createMaterials(sessionToken, Arrays.asList(m1, m2)); + + MaterialFetchOptions fetchOptions = new MaterialFetchOptions(); + + Map<IMaterialId, Material> map = v3api.mapMaterials(sessionToken, materialIds, fetchOptions); + + AssertionUtil.assertCollectionSize(map.values(), 2); + + Material material = map.get(new MaterialPermId("1982", "GENE")); + + assertEquals(material.getCode(), "1982"); + assertEquals(material.getPermId().getTypeCode(), "GENE"); + } + + // all potential error scenarios + + // create mateiral with mateiral properties + + private MaterialCreation geneCreation(String code) + { + MaterialCreation materialCreation = new MaterialCreation(); + materialCreation.setCode(code); + materialCreation.setTypeId(new EntityTypePermId("GENE")); + materialCreation.setCreationId(new CreationId("creation " + code)); + materialCreation.setDescription("Material with code " + code); + + HashMap<String, String> properties = new HashMap<String, String>(); + properties.put("GENE_SYMBOL", "SYMBOL " + code); + + materialCreation.setProperties(properties); + + return materialCreation; + } +} -- GitLab