From 2804cc64e521fa8a718b620a0a0cb029e56f9792 Mon Sep 17 00:00:00 2001 From: jakubs <jakubs> Date: Wed, 7 Nov 2012 09:26:28 +0000 Subject: [PATCH] BIS-190 SP-295 add metaproject registrations to perform entity operations SVN: 27519 --- .../openbis/generic/server/ETLService.java | 56 ++++++++++++ .../server/business/bo/IMetaprojectBO.java | 3 + .../server/business/bo/MetaprojectBO.java | 8 ++ .../shared/basic/dto/NewMetaproject.java | 85 +++++++++++++++++++ .../dto/AtomicEntityOperationDetails.java | 19 ++++- 5 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewMetaproject.java diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java index ed907746413..6c09901784a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java @@ -80,6 +80,7 @@ import ch.systemsx.cisd.openbis.generic.server.business.bo.IDataSetTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.IExperimentBO; import ch.systemsx.cisd.openbis.generic.server.business.bo.IExperimentTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.IMaterialBO; +import ch.systemsx.cisd.openbis.generic.server.business.bo.IMetaprojectBO; import ch.systemsx.cisd.openbis.generic.server.business.bo.IProjectBO; import ch.systemsx.cisd.openbis.generic.server.business.bo.IRoleAssignmentTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleBO; @@ -129,6 +130,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Metaproject; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterial; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMetaproject; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSamplesWithTypes; @@ -1514,6 +1516,14 @@ public class ETLService extends AbstractCommonServer<IETLLIMSService> implements updateMaterials(sessionForEntityOperation, operationDetails, progressListener, authorize); + long metaprojectsCreated = + createMetaprojects(sessionForEntityOperation, operationDetails, + progressListener, authorize); + + // long metaprojectsUpdates = + // updateMetaProjects(sessionForEntityOperation, operationDetails, + // progressListener, authorize); + // If the id is not null, the caller wants to persist the fact that the operation was // invoked and completed; // if the id is null, the caller does not care. @@ -1651,6 +1661,52 @@ public class ETLService extends AbstractCommonServer<IETLLIMSService> implements } } + // TODO: more metaprojects methods + + // private long updateMetaprojects(Session session, AtomicEntityOperationDetails + // operationDetails, + // IServiceConversationProgressListener progress, boolean authorize) + // { + // // MaterialHelper materialHelper = + // // new MaterialHelper(session, businessObjectFactory, getDAOFactory(), + // // getPropertiesBatchManager()); + // + // List<MetaprojectUpdateDTO> allMetaprojectUpdates = operationDetails.getMetaprojectUpdates(); + // + // if (authorize) + // { + // checkMaterialUpdateAllowed(session, allMaterialUpdates); + // } + // + // materialHelper.updateMaterials(allMaterialUpdates); + // + // // in material helper call the update of materials - but this has to wait fo change of the + // // material updates to a map + // return allMaterialUpdates.size(); + // } + + private long createMetaprojects(Session session, AtomicEntityOperationDetails operationDetails, + IServiceConversationProgressListener progress, boolean authorize) + { + final List<NewMetaproject> metaprojectRegistrations = + operationDetails.getMetaprojectRegistrations(); + int index = 0; + for (NewMetaproject experiment : metaprojectRegistrations) + { + registerMetaproject(session, experiment); + progress.update("createMetaProjects", metaprojectRegistrations.size(), ++index); + } + return index; + } + + private MetaprojectPE registerMetaproject(final Session session, NewMetaproject metaproject) + { + IMetaprojectBO metaprojectBO = businessObjectFactory.createMetaprojectBO(session); + metaprojectBO.define(metaproject); + metaprojectBO.save(); + return metaprojectBO.getMetaproject(); + } + private SpacePE registerSpaceInternal(Session session, NewSpace newSpace, String registratorUserIdOrNull) { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IMetaprojectBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IMetaprojectBO.java index a02471d5a4c..251542888b0 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IMetaprojectBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IMetaprojectBO.java @@ -24,6 +24,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.experiment.IExperim import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.material.IMaterialId; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.metaproject.IMetaprojectId; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.sample.ISampleId; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMetaproject; import ch.systemsx.cisd.openbis.generic.shared.dto.MetaprojectPE; /** @@ -33,6 +34,8 @@ public interface IMetaprojectBO extends IEntityBusinessObject { MetaprojectPE tryFindByMetaprojectId(final IMetaprojectId metaprojectId); + void define(NewMetaproject newMetaproject); + void loadByMetaprojectId(IMetaprojectId metaprojectId); void addExperiments(List<IExperimentId> experiments); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MetaprojectBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MetaprojectBO.java index ac47f87682d..5f0630791db 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MetaprojectBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MetaprojectBO.java @@ -38,6 +38,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.metaproject.Metapro import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.sample.ISampleId; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MetaprojectIdentifier; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMetaproject; import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; import ch.systemsx.cisd.openbis.generic.shared.dto.EventPE; import ch.systemsx.cisd.openbis.generic.shared.dto.EventPE.EntityType; @@ -178,6 +179,13 @@ public class MetaprojectBO extends AbstractBusinessObject implements IMetaprojec } } + @Override + public void define(NewMetaproject newMetaproject) + { + define(newMetaproject.getName(), newMetaproject.getDescription(), + newMetaproject.getOwnerId()); + } + public void define(final String metaprojectName, final String description, final String ownerId) throws UserFailureException { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewMetaproject.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewMetaproject.java new file mode 100644 index 00000000000..04003b1769c --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewMetaproject.java @@ -0,0 +1,85 @@ +/* + * Copyright 2012 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.systemsx.cisd.openbis.generic.shared.basic.dto; + +import java.io.Serializable; + +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +/** + * A metaproject to register. + * + * @author Jakub Straszewski + */ +public class NewMetaproject implements Serializable +{ + private static final long serialVersionUID = ServiceVersionHolder.VERSION; + + private String name; + + private String description; + + private String ownerId; + + public NewMetaproject(String name, String descriptionOrNull, String ownerId) + { + this.name = name; + this.description = descriptionOrNull; + this.ownerId = ownerId; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public String getOwnerId() + { + return ownerId; + } + + public void setOwnerId(String ownerId) + { + this.ownerId = ownerId; + } + + @Override + public String toString() + { + ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); + builder.append("name", getName()); + builder.append("description", getDescription()); + builder.append("ownerId", getOwnerId()); + return builder.toString(); + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AtomicEntityOperationDetails.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AtomicEntityOperationDetails.java index e3c700df627..f3cedbcecf6 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AtomicEntityOperationDetails.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/AtomicEntityOperationDetails.java @@ -28,6 +28,7 @@ import org.apache.commons.lang.builder.ToStringStyle; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterial; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMetaproject; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewProject; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSpace; @@ -61,6 +62,8 @@ public class AtomicEntityOperationDetails implements Serializable private final List<NewSample> sampleRegistrations; + private final List<NewMetaproject> metaprojectRegistrations; + private final Map<String /* material type */, List<NewMaterial>> materialRegistrations; private final List<MaterialUpdateDTO> materialUpdates; @@ -79,7 +82,8 @@ public class AtomicEntityOperationDetails implements Serializable Map<String, List<NewMaterial>> materialRegistrations, List<MaterialUpdateDTO> materialUpdates, List<? extends NewExternalData> dataSetRegistrations, - List<DataSetBatchUpdatesDTO> dataSetUpdates) + List<DataSetBatchUpdatesDTO> dataSetUpdates, + List<NewMetaproject> metaprojectRegistrations) { this.registrationIdOrNull = registrationId; this.userIdOrNull = userIdOrNull; @@ -93,6 +97,7 @@ public class AtomicEntityOperationDetails implements Serializable this.materialUpdates = new ArrayList<MaterialUpdateDTO>(materialUpdates); this.dataSetRegistrations = new ArrayList<NewExternalData>(dataSetRegistrations); this.dataSetUpdates = new ArrayList<DataSetBatchUpdatesDTO>(dataSetUpdates); + this.metaprojectRegistrations = new ArrayList<NewMetaproject>(metaprojectRegistrations); } public AtomicEntityOperationDetails(TechId registrationId, String userIdOrNull, @@ -103,11 +108,13 @@ public class AtomicEntityOperationDetails implements Serializable Map<String, List<NewMaterial>> materialRegistrations, List<MaterialUpdateDTO> materialUpdates, List<? extends NewExternalData> dataSetRegistrations, - List<DataSetBatchUpdatesDTO> dataSetUpdates, Integer batchSizeOrNull) + List<DataSetBatchUpdatesDTO> dataSetUpdates, + List<NewMetaproject> metaprojectRegistrations, Integer batchSizeOrNull) { this(registrationId, userIdOrNull, spaceRegistrations, projectRegistrations, experimentRegistrations, experimentUpdates, sampleUpdates, sampleRegistrations, - materialRegistrations, materialUpdates, dataSetRegistrations, dataSetUpdates); + materialRegistrations, materialUpdates, dataSetRegistrations, dataSetUpdates, + metaprojectRegistrations); this.batchSizeOrNull = batchSizeOrNull; } @@ -141,6 +148,11 @@ public class AtomicEntityOperationDetails implements Serializable return sampleRegistrations; } + public List<NewMetaproject> getMetaprojectRegistrations() + { + return metaprojectRegistrations; + } + public List<? extends NewExternalData> getDataSetRegistrations() { return dataSetRegistrations; @@ -191,6 +203,7 @@ public class AtomicEntityOperationDetails implements Serializable sb.append("materialRegistrations", materialRegistrations); sb.append("dataSetRegistrations", dataSetRegistrations); sb.append("dataSetUpdates", dataSetUpdates); + sb.append("metaprojectRegistrations", metaprojectRegistrations); return sb.toString(); } -- GitLab