From ac9c105a4853750dd0ced2627e1475bba81da53b Mon Sep 17 00:00:00 2001 From: pkupczyk <pkupczyk> Date: Wed, 29 Oct 2014 07:41:53 +0000 Subject: [PATCH] SSDM-1109 : V3 AS API - deleteExperiment and deleteSample methods SVN: 32683 --- .../server/api/v3/ApplicationServerApi.java | 56 ++++- .../dataset/DeleteDataSetExecutor.java | 147 +++++++++++ .../dataset/IDeleteDataSetExecutor.java | 34 +++ .../dataset/IMapDataSetByIdExecutor.java | 29 +++ .../dataset/MapDataSetByIdExecutor.java | 68 +++++ .../deletion/ConfirmDeletionExecutor.java | 141 +++++++++++ .../deletion/IConfirmDeletionExecutor.java | 32 +++ .../deletion/IListDeletionExecutor.java | 33 +++ .../deletion/IMapDeletionByIdExecutor.java | 29 +++ .../deletion/IRevertDeletionExecutor.java | 32 +++ .../deletion/ListDeletionExecutor.java | 97 ++++++++ .../deletion/MapDeletionByIdExecutor.java | 68 +++++ .../deletion/RevertDeletionExecutor.java | 233 ++++++++++++++++++ .../experiment/DeleteExperimentExecutor.java | 35 +-- .../executor/sample/DeleteSampleExecutor.java | 35 +-- .../helper/dataset/ListDataSetByPermId.java | 66 +++++ .../helper/deletion/ListDeletionByTechId.java | 65 +++++ .../entity/deletion/DeletionTranslator.java | 111 +++++++++ .../openbis/generic/server/CommonServer.java | 4 +- .../server/business/bo/DeletionTable.java | 23 +- .../server/business/bo/IDeletionTable.java | 7 +- .../api/v3/AbstractDeletionTest.java | 142 +++++++++++ .../api/v3/ConfirmDeletionTest.java | 97 ++++++++ .../api/v3/DeleteExperimentTest.java | 5 +- .../systemtest/api/v3/DeleteSampleTest.java | 5 +- .../systemtest/api/v3/ListDeletionTest.java | 122 +++++++++ .../systemtest/api/v3/RevertDeletionTest.java | 97 ++++++++ .../shared/api/v3/dto/deletion/Deletion.java | 34 ++- .../DataSetDeletionOptions.java} | 20 +- .../experiment/ExperimentDeletionOptions.java | 4 +- .../sample/SampleDeletionOptions.java | 4 +- .../deletion/DeletionFetchOptions.java | 30 +-- 32 files changed, 1809 insertions(+), 96 deletions(-) create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/DeleteDataSetExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/IDeleteDataSetExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/IMapDataSetByIdExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/MapDataSetByIdExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/ConfirmDeletionExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IConfirmDeletionExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IListDeletionExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IMapDeletionByIdExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IRevertDeletionExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/ListDeletionExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/MapDeletionByIdExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/RevertDeletionExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/dataset/ListDataSetByPermId.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/deletion/ListDeletionByTechId.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/entity/deletion/DeletionTranslator.java create mode 100644 openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/AbstractDeletionTest.java create mode 100644 openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/ConfirmDeletionTest.java create mode 100644 openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/ListDeletionTest.java create mode 100644 openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/RevertDeletionTest.java rename openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/{AbstractTrashableObjectDeletionOptions.java => dataset/DataSetDeletionOptions.java} (63%) 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 d1ae2322934..755eacafe4e 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 @@ -27,6 +27,9 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import ch.ethz.sis.openbis.generic.server.api.v3.executor.OperationContext; +import ch.ethz.sis.openbis.generic.server.api.v3.executor.deletion.IConfirmDeletionExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.executor.deletion.IListDeletionExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.executor.deletion.IRevertDeletionExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.experiment.ICreateExperimentExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.experiment.IDeleteExperimentExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.experiment.IListExperimentByIdExecutor; @@ -36,6 +39,7 @@ import ch.ethz.sis.openbis.generic.server.api.v3.executor.sample.IDeleteSampleEx import ch.ethz.sis.openbis.generic.server.api.v3.executor.sample.IListSampleByIdExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.sample.IUpdateSampleExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext; +import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.deletion.DeletionTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.experiment.ExperimentTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.sample.SampleTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.search.EntityAttributeProviderFactory; @@ -130,6 +134,15 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> @Autowired private IDeleteSampleExecutor deleteSampleExecutor; + @Autowired + private IListDeletionExecutor listDeletionExecutor; + + @Autowired + private IRevertDeletionExecutor revertDeletionExecutor; + + @Autowired + private IConfirmDeletionExecutor confirmDeletionExecutor; + // Default constructor needed by Spring public ApplicationServerApi() { @@ -410,8 +423,19 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> @RolesAllowed({ RoleWithHierarchy.SPACE_USER, RoleWithHierarchy.SPACE_ETL_SERVER }) public List<Deletion> listDeletions(String sessionToken, DeletionFetchOptions fetchOptions) { - // TODO Auto-generated method stub - return null; + Session session = getSession(sessionToken); + OperationContext context = new OperationContext(session); + + try + { + List<ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion> deletions = listDeletionExecutor.list(context, fetchOptions); + + return new ArrayList<Deletion>( + new DeletionTranslator(new TranslationContext(session), fetchOptions, getDAOFactory()).translate(deletions)); + } catch (Throwable t) + { + throw ExceptionUtils.create(context, t); + } } @Override @@ -422,7 +446,19 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> @Capability("RESTORE") public void revertDeletions(String sessionToken, List<? extends IDeletionId> deletionIds) { - // TODO Auto-generated method stub + Session session = getSession(sessionToken); + OperationContext context = new OperationContext(session); + + try + { + revertDeletionExecutor.revert(context, deletionIds); + } catch (Throwable t) + { + throw ExceptionUtils.create(context, t); + } finally + { + getDAOFactory().getSessionFactory().getCurrentSession().clear(); + } } @Override @@ -432,7 +468,19 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> @Capability("PURGE") public void confirmDeletions(String sessionToken, List<? extends IDeletionId> deletionIds) { - // TODO Auto-generated method stub + Session session = getSession(sessionToken); + OperationContext context = new OperationContext(session); + + try + { + confirmDeletionExecutor.confirm(context, deletionIds); + } catch (Throwable t) + { + throw ExceptionUtils.create(context, t); + } finally + { + getDAOFactory().getSessionFactory().getCurrentSession().clear(); + } } @Override diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/DeleteDataSetExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/DeleteDataSetExecutor.java new file mode 100644 index 00000000000..4e55a6c60dd --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/DeleteDataSetExecutor.java @@ -0,0 +1,147 @@ +/* + * 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.dataset; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.annotation.Resource; + +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.shared.api.v3.dto.deletion.dataset.DataSetDeletionOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.IDataSetId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.DeletionTechId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.IDeletionId; +import ch.ethz.sis.openbis.generic.shared.api.v3.exceptions.UnauthorizedObjectAccessException; +import ch.systemsx.cisd.openbis.generic.server.ComponentNames; +import ch.systemsx.cisd.openbis.generic.server.authorization.validator.ExperimentByIdentiferValidator; +import ch.systemsx.cisd.openbis.generic.server.business.bo.ICommonBusinessObjectFactory; +import ch.systemsx.cisd.openbis.generic.server.business.bo.ITrashBO; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; +import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetRelationshipPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.DeletionPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; +import ch.systemsx.cisd.openbis.generic.shared.util.RelationshipUtils; + +/** + * @author pkupczyk + */ +@Component +public class DeleteDataSetExecutor implements IDeleteDataSetExecutor +{ + + @Autowired + private IMapDataSetByIdExecutor mapDataSetByIdExecutor; + + @Autowired + private IDAOFactory daoFactory; + + @Resource(name = ComponentNames.COMMON_BUSINESS_OBJECT_FACTORY) + ICommonBusinessObjectFactory businessObjectFactory; + + @Override + public IDeletionId delete(IOperationContext context, List<? extends IDataSetId> dataSetIds, DataSetDeletionOptions deletionOptions) + { + if (context == null) + { + throw new IllegalArgumentException("Context cannot be null"); + } + if (dataSetIds == null) + { + throw new IllegalArgumentException("Data set ids cannot be null"); + } + if (deletionOptions == null) + { + throw new IllegalArgumentException("Deletion options cannot be null"); + } + if (deletionOptions.getReason() == null) + { + throw new IllegalArgumentException("Deletion reason cannot be null"); + } + + Map<IDataSetId, DataPE> dataSetMap = mapDataSetByIdExecutor.map(context, dataSetIds); + + for (Map.Entry<IDataSetId, DataPE> entry : dataSetMap.entrySet()) + { + IDataSetId dataSetId = entry.getKey(); + DataPE dataSet = entry.getValue(); + + if (false == new ExperimentByIdentiferValidator().doValidation(context.getSession().tryGetPerson(), dataSet.getExperiment())) + { + throw new UnauthorizedObjectAccessException(dataSetId); + } + + updateModificationDateAndModifierOfRelatedEntities(context, dataSet); + } + + return trash(context, dataSetMap.values(), deletionOptions); + } + + private void updateModificationDateAndModifierOfRelatedEntities(IOperationContext context, DataPE dataSet) + { + ExperimentPE experiment = dataSet.getExperiment(); + RelationshipUtils.updateModificationDateAndModifier(experiment, context.getSession()); + SamplePE sample = dataSet.tryGetSample(); + if (sample != null) + { + RelationshipUtils.updateModificationDateAndModifier(sample, context.getSession()); + } + updateModificationDateAndModifierOfRelatedDataSets(context, dataSet.getChildren()); + updateModificationDateAndModifierOfRelatedDataSets(context, dataSet.getParents()); + Set<DataSetRelationshipPE> relationships = dataSet.getParentRelationships(); + for (DataSetRelationshipPE relationship : RelationshipUtils.getContainerComponentRelationships(relationships)) + { + RelationshipUtils.updateModificationDateAndModifier(relationship.getParentDataSet(), context.getSession()); + } + } + + private void updateModificationDateAndModifierOfRelatedDataSets(IOperationContext context, List<DataPE> dataSets) + { + if (dataSets != null) + { + for (DataPE child : dataSets) + { + RelationshipUtils.updateModificationDateAndModifier(child, context.getSession()); + } + } + } + + private IDeletionId trash(IOperationContext context, Collection<DataPE> dataSets, DataSetDeletionOptions deletionOptions) + { + List<TechId> dataSetTechIds = new LinkedList<TechId>(); + for (DataPE dataSet : dataSets) + { + dataSetTechIds.add(new TechId(dataSet.getId())); + } + + ITrashBO trashBO = businessObjectFactory.createTrashBO(context.getSession()); + trashBO.createDeletion(deletionOptions.getReason()); + trashBO.trashDataSets(dataSetTechIds); + DeletionPE deletion = trashBO.getDeletion(); + return new DeletionTechId(deletion.getId()); + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/IDeleteDataSetExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/IDeleteDataSetExecutor.java new file mode 100644 index 00000000000..c8a8f4525e1 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/IDeleteDataSetExecutor.java @@ -0,0 +1,34 @@ +/* + * 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.dataset; + +import java.util.List; + +import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.dataset.DataSetDeletionOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.IDataSetId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.IDeletionId; + +/** + * @author pkupczyk + */ +public interface IDeleteDataSetExecutor +{ + + public IDeletionId delete(IOperationContext context, List<? extends IDataSetId> dataSetIds, DataSetDeletionOptions deletionOptions); + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/IMapDataSetByIdExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/IMapDataSetByIdExecutor.java new file mode 100644 index 00000000000..60b61b80cea --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/IMapDataSetByIdExecutor.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.dataset; + +import ch.ethz.sis.openbis.generic.server.api.v3.executor.common.IMapObjectByIdExecutor; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.IDataSetId; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; + +/** + * @author pkupczyk + */ +public interface IMapDataSetByIdExecutor extends IMapObjectByIdExecutor<IDataSetId, DataPE> +{ + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/MapDataSetByIdExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/MapDataSetByIdExecutor.java new file mode 100644 index 00000000000..3c96f03a6b9 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/dataset/MapDataSetByIdExecutor.java @@ -0,0 +1,68 @@ +/* + * 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.dataset; + +import java.util.LinkedList; +import java.util.List; + +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.common.AbstractMapObjectByIdExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.helper.common.IListObjectById; +import ch.ethz.sis.openbis.generic.server.api.v3.helper.dataset.ListDataSetByPermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.IDataSetId; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDataDAO; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; + +/** + * @author pkupczyk + */ +@Component +public class MapDataSetByIdExecutor extends AbstractMapObjectByIdExecutor<IDataSetId, DataPE> implements IMapDataSetByIdExecutor +{ + + private IDataDAO dataDAO; + + @SuppressWarnings("unused") + private MapDataSetByIdExecutor() + { + } + + public MapDataSetByIdExecutor(IDataDAO dataDAO) + { + this.dataDAO = dataDAO; + } + + @Override + protected List<IListObjectById<? extends IDataSetId, DataPE>> createListers(IOperationContext context) + { + List<IListObjectById<? extends IDataSetId, DataPE>> listers = + new LinkedList<IListObjectById<? extends IDataSetId, DataPE>>(); + listers.add(new ListDataSetByPermId(dataDAO)); + return listers; + } + + @Autowired + private void setDAOFactory(IDAOFactory daoFactory) + { + dataDAO = daoFactory.getDataDAO(); + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/ConfirmDeletionExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/ConfirmDeletionExecutor.java new file mode 100644 index 00000000000..d9a7b36806a --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/ConfirmDeletionExecutor.java @@ -0,0 +1,141 @@ +/* + * 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.deletion; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; + +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.shared.api.v3.dto.id.deletion.DeletionTechId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.IDeletionId; +import ch.ethz.sis.openbis.generic.shared.api.v3.exceptions.ObjectNotFoundException; +import ch.ethz.sis.openbis.generic.shared.api.v3.exceptions.UnauthorizedObjectAccessException; +import ch.systemsx.cisd.openbis.generic.server.ComponentNames; +import ch.systemsx.cisd.openbis.generic.server.authorization.AuthorizationDataProvider; +import ch.systemsx.cisd.openbis.generic.server.authorization.validator.DeletionValidator; +import ch.systemsx.cisd.openbis.generic.server.business.bo.ICommonBusinessObjectFactory; +import ch.systemsx.cisd.openbis.generic.server.business.bo.IDeletedDataSetTable; +import ch.systemsx.cisd.openbis.generic.server.business.bo.IDeletionTable; +import ch.systemsx.cisd.openbis.generic.server.business.bo.IExperimentBO; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDeletionDAO; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISampleDAO; +import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion; +import ch.systemsx.cisd.openbis.generic.shared.dto.DeletionPE; + +/** + * @author pkupczyk + */ +@Component +public class ConfirmDeletionExecutor implements IConfirmDeletionExecutor +{ + + @Autowired + private IMapDeletionByIdExecutor mapDeletionByIdExecutor; + + @Autowired + private IDAOFactory daoFactory; + + @Resource(name = ComponentNames.COMMON_BUSINESS_OBJECT_FACTORY) + ICommonBusinessObjectFactory businessObjectFactory; + + @Override + public void confirm(IOperationContext context, List<? extends IDeletionId> deletionIds) + { + IDeletionDAO deletionDAO = daoFactory.getDeletionDAO(); + Map<IDeletionId, DeletionPE> deletionMap = mapDeletionByIdExecutor.map(context, deletionIds); + + List<Long> deletionTechIds = new LinkedList<Long>(); + for (DeletionPE deletion : deletionMap.values()) + { + deletionTechIds.add(deletion.getId()); + } + + IDeletionTable table = businessObjectFactory.createDeletionTable(context.getSession()); + table.load(deletionTechIds, true); + List<Deletion> deletions = table.getDeletions(); + + DeletionValidator validator = new DeletionValidator(); + validator.init(new AuthorizationDataProvider(daoFactory)); + + for (Deletion deletion : deletions) + { + if (false == validator.doValidation(context.getSession().tryGetPerson(), deletion)) + { + throw new UnauthorizedObjectAccessException(new DeletionTechId(deletion.getId())); + } + } + + // NOTE: we can't do bulk deletions to preserve original reasons + for (IDeletionId deletionId : deletionIds) + { + DeletionPE deletion = deletionMap.get(deletionId); + + if (deletion == null) + { + throw new ObjectNotFoundException(deletionId); + } + + deleteDataSets(context, deletion); + deleteSamples(context, deletion); + deleteExperiments(context, deletion); + + // WORKAROUND to get the fresh deletion and fix org.hibernate.NonUniqueObjectException + DeletionPE freshDeletion = deletionDAO.getByTechId(TechId.create(deletion)); + deletionDAO.delete(freshDeletion); + } + + } + + private void deleteDataSets(IOperationContext context, DeletionPE deletion) + { + IDeletionDAO deletionDAO = daoFactory.getDeletionDAO(); + + List<TechId> deletionTechIds = Collections.singletonList(new TechId(deletion.getId())); + List<String> dataSetCodes = deletionDAO.findTrashedDataSetCodes(deletionTechIds); + + IDeletedDataSetTable deletedDataSetTable = + businessObjectFactory.createDeletedDataSetTable(context.getSession()); + deletedDataSetTable.loadByDataSetCodes(dataSetCodes); + deletedDataSetTable.permanentlyDeleteLoadedDataSets(deletion.getReason(), false); + } + + private void deleteSamples(IOperationContext context, DeletionPE deletion) + { + ISampleDAO sampleDAO = daoFactory.getSampleDAO(); + sampleDAO.deletePermanently(deletion, context.getSession().tryGetPerson()); + } + + private void deleteExperiments(IOperationContext context, DeletionPE deletion) + { + IDeletionDAO deletionDAO = daoFactory.getDeletionDAO(); + IExperimentBO experimentBO = businessObjectFactory.createExperimentBO(context.getSession()); + + List<TechId> deletionTechIds = Collections.singletonList(new TechId(deletion.getId())); + List<TechId> experimentTechIds = deletionDAO.findTrashedExperimentIds(deletionTechIds); + + experimentBO.deleteByTechIds(experimentTechIds, deletion.getReason()); + } +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IConfirmDeletionExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IConfirmDeletionExecutor.java new file mode 100644 index 00000000000..468e7ee9d79 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IConfirmDeletionExecutor.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.deletion; + +import java.util.List; + +import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.IDeletionId; + +/** + * @author pkupczyk + */ +public interface IConfirmDeletionExecutor +{ + + public void confirm(IOperationContext context, List<? extends IDeletionId> deletionIds); + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IListDeletionExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IListDeletionExecutor.java new file mode 100644 index 00000000000..8c6145591ed --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IListDeletionExecutor.java @@ -0,0 +1,33 @@ +/* + * 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.deletion; + +import java.util.List; + +import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.deletion.DeletionFetchOptions; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion; + +/** + * @author pkupczyk + */ +public interface IListDeletionExecutor +{ + + public List<Deletion> list(IOperationContext context, DeletionFetchOptions fetchOptions); + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IMapDeletionByIdExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IMapDeletionByIdExecutor.java new file mode 100644 index 00000000000..9eb2d1f9014 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IMapDeletionByIdExecutor.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.deletion; + +import ch.ethz.sis.openbis.generic.server.api.v3.executor.common.IMapObjectByIdExecutor; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.IDeletionId; +import ch.systemsx.cisd.openbis.generic.shared.dto.DeletionPE; + +/** + * @author pkupczyk + */ +public interface IMapDeletionByIdExecutor extends IMapObjectByIdExecutor<IDeletionId, DeletionPE> +{ + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IRevertDeletionExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IRevertDeletionExecutor.java new file mode 100644 index 00000000000..b1c47b59abf --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/IRevertDeletionExecutor.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.deletion; + +import java.util.List; + +import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.IDeletionId; + +/** + * @author pkupczyk + */ +public interface IRevertDeletionExecutor +{ + + public void revert(IOperationContext context, List<? extends IDeletionId> deletionIds); + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/ListDeletionExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/ListDeletionExecutor.java new file mode 100644 index 00000000000..053351ac253 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/ListDeletionExecutor.java @@ -0,0 +1,97 @@ +/* + * 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.deletion; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Component; + +import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.deletion.DeletionFetchOptions; +import ch.systemsx.cisd.openbis.generic.server.ComponentNames; +import ch.systemsx.cisd.openbis.generic.server.business.bo.ICommonBusinessObjectFactory; +import ch.systemsx.cisd.openbis.generic.server.business.bo.IDeletionTable; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion; + +/** + * @author pkupczyk + */ +@Component +public class ListDeletionExecutor implements IListDeletionExecutor +{ + + @Resource(name = ComponentNames.COMMON_BUSINESS_OBJECT_FACTORY) + ICommonBusinessObjectFactory businessObjectFactory; + + @Override + public List<Deletion> list(IOperationContext context, DeletionFetchOptions fetchOptions) + { + if (context == null) + { + throw new IllegalArgumentException("Context cannot be null"); + } + if (fetchOptions == null) + { + throw new IllegalArgumentException("Fetch options cannot be null"); + } + + List<Deletion> deletions = null; + + if (fetchOptions.hasDeletedObjects()) + { + deletions = listWithDeletedObjects(context); + } else + { + deletions = listWithoutDeletedObjects(context); + } + + if (deletions == null) + { + return Collections.emptyList(); + } else + { + Collections.sort(deletions, new Comparator<Deletion>() + { + @Override + public int compare(Deletion d1, Deletion d2) + { + return d1.getRegistrationDate().compareTo(d2.getRegistrationDate()); + } + }); + return deletions; + } + } + + private List<Deletion> listWithDeletedObjects(IOperationContext context) + { + IDeletionTable deletionTable = businessObjectFactory.createDeletionTable(context.getSession()); + deletionTable.loadOriginal(); + return deletionTable.getDeletions(); + } + + private List<Deletion> listWithoutDeletedObjects(IOperationContext context) + { + IDeletionTable deletionTable = businessObjectFactory.createDeletionTable(context.getSession()); + deletionTable.load(false); + return deletionTable.getDeletions(); + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/MapDeletionByIdExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/MapDeletionByIdExecutor.java new file mode 100644 index 00000000000..fd3d9dce056 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/MapDeletionByIdExecutor.java @@ -0,0 +1,68 @@ +/* + * 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.deletion; + +import java.util.LinkedList; +import java.util.List; + +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.common.AbstractMapObjectByIdExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.helper.common.IListObjectById; +import ch.ethz.sis.openbis.generic.server.api.v3.helper.deletion.ListDeletionByTechId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.IDeletionId; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDeletionDAO; +import ch.systemsx.cisd.openbis.generic.shared.dto.DeletionPE; + +/** + * @author pkupczyk + */ +@Component +public class MapDeletionByIdExecutor extends AbstractMapObjectByIdExecutor<IDeletionId, DeletionPE> implements IMapDeletionByIdExecutor +{ + + private IDeletionDAO deletionDAO; + + @SuppressWarnings("unused") + private MapDeletionByIdExecutor() + { + } + + public MapDeletionByIdExecutor(IDeletionDAO deletionDAO) + { + this.deletionDAO = deletionDAO; + } + + @Override + protected List<IListObjectById<? extends IDeletionId, DeletionPE>> createListers(IOperationContext context) + { + List<IListObjectById<? extends IDeletionId, DeletionPE>> listers = + new LinkedList<IListObjectById<? extends IDeletionId, DeletionPE>>(); + listers.add(new ListDeletionByTechId(deletionDAO)); + return listers; + } + + @Autowired + private void setDAOFactory(IDAOFactory daoFactory) + { + deletionDAO = daoFactory.getDeletionDAO(); + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/RevertDeletionExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/RevertDeletionExecutor.java new file mode 100644 index 00000000000..fbc4c1c3b0c --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/deletion/RevertDeletionExecutor.java @@ -0,0 +1,233 @@ +/* + * 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.deletion; + +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.annotation.Resource; + +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.shared.api.v3.dto.id.deletion.DeletionTechId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.IDeletionId; +import ch.ethz.sis.openbis.generic.shared.api.v3.exceptions.ObjectNotFoundException; +import ch.ethz.sis.openbis.generic.shared.api.v3.exceptions.UnauthorizedObjectAccessException; +import ch.systemsx.cisd.openbis.generic.server.ComponentNames; +import ch.systemsx.cisd.openbis.generic.server.authorization.AuthorizationDataProvider; +import ch.systemsx.cisd.openbis.generic.server.authorization.validator.DeletionValidator; +import ch.systemsx.cisd.openbis.generic.server.business.bo.ICommonBusinessObjectFactory; +import ch.systemsx.cisd.openbis.generic.server.business.bo.IDeletionTable; +import ch.systemsx.cisd.openbis.generic.server.business.bo.ITrashBO; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; +import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolderWithIdentifier; +import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetRelationshipPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.DeletionPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.SampleRelationshipPE; +import ch.systemsx.cisd.openbis.generic.shared.util.RelationshipUtils; + +/** + * @author pkupczyk + */ +@Component +public class RevertDeletionExecutor implements IRevertDeletionExecutor +{ + + @Autowired + private IMapDeletionByIdExecutor mapDeletionByIdExecutor; + + @Autowired + private IDAOFactory daoFactory; + + @Resource(name = ComponentNames.COMMON_BUSINESS_OBJECT_FACTORY) + private ICommonBusinessObjectFactory businessObjectFactory; + + @Override + public void revert(IOperationContext context, List<? extends IDeletionId> deletionIds) + { + if (context == null) + { + throw new IllegalArgumentException("Context cannot be null"); + } + if (deletionIds == null) + { + throw new IllegalArgumentException("Deletion ids cannot be null"); + } + + ITrashBO trashBO = businessObjectFactory.createTrashBO(context.getSession()); + + Set<TechId> deletedExperimentIds = new HashSet<TechId>(); + Set<TechId> deletedSampleIds = new HashSet<TechId>(); + Set<String> deletedDataSetCodes = new HashSet<String>(); + + for (Deletion deletion : getDeletions(context, deletionIds)) + { + List<IEntityInformationHolderWithIdentifier> deletedEntities = + deletion.getDeletedEntities(); + for (IEntityInformationHolderWithIdentifier deletedEntity : deletedEntities) + { + EntityKind entityKind = deletedEntity.getEntityKind(); + TechId entityId = new TechId(deletedEntity.getId()); + switch (entityKind) + { + case EXPERIMENT: + deletedExperimentIds.add(entityId); + break; + case SAMPLE: + deletedSampleIds.add(entityId); + break; + case DATA_SET: + deletedDataSetCodes.add(deletedEntity.getCode()); + break; + default: + } + } + trashBO.revertDeletion(new TechId(deletion.getId())); + } + + updateModificationDateAndModifierOfRelatedProjectsOfExperiments(context, deletedExperimentIds); + updateModificationDateAndModifierOfRelatedEntitiesOfSamples(context, deletedSampleIds); + updateModificationDateAndModifierOfRelatedEntitiesOfDataSets(context, deletedDataSetCodes); + } + + private List<Deletion> getDeletions(IOperationContext context, List<? extends IDeletionId> deletionIds) + { + Map<IDeletionId, DeletionPE> map = mapDeletionByIdExecutor.map(context, deletionIds); + List<Long> deletionTechIds = new LinkedList<Long>(); + + for (IDeletionId deletionId : deletionIds) + { + DeletionPE deletion = map.get(deletionId); + + if (deletion == null) + { + throw new ObjectNotFoundException(deletionId); + } else + { + deletionTechIds.add(deletion.getId()); + } + } + + IDeletionTable table = businessObjectFactory.createDeletionTable(context.getSession()); + table.load(deletionTechIds, true); + List<Deletion> deletions = table.getDeletions(); + + DeletionValidator validator = new DeletionValidator(); + validator.init(new AuthorizationDataProvider(daoFactory)); + + for (Deletion deletion : deletions) + { + if (false == validator.doValidation(context.getSession().tryGetPerson(), deletion)) + { + throw new UnauthorizedObjectAccessException(new DeletionTechId(deletion.getId())); + } + } + + return deletions; + } + + private void updateModificationDateAndModifierOfRelatedProjectsOfExperiments(IOperationContext context, Collection<TechId> experimentIds) + { + List<ExperimentPE> experiments = + daoFactory.getExperimentDAO().listByIDs(TechId.asLongs(experimentIds)); + for (ExperimentPE experiment : experiments) + { + RelationshipUtils.updateModificationDateAndModifier(experiment.getProject(), context.getSession()); + } + } + + private void updateModificationDateAndModifierOfRelatedEntitiesOfSamples(IOperationContext context, Collection<TechId> sampleIds) + { + List<SamplePE> samples = daoFactory.getSampleDAO().listByIDs(TechId.asLongs(sampleIds)); + for (SamplePE sample : samples) + { + ExperimentPE experiment = sample.getExperiment(); + if (experiment != null) + { + RelationshipUtils.updateModificationDateAndModifier(experiment, context.getSession()); + } + SamplePE container = sample.getContainer(); + if (container != null) + { + RelationshipUtils.updateModificationDateAndModifier(container, context.getSession()); + } + List<SamplePE> parents = sample.getParents(); + if (parents != null) + { + for (SamplePE parent : parents) + { + RelationshipUtils.updateModificationDateAndModifier(parent, context.getSession()); + } + } + Set<SampleRelationshipPE> childRelationships = sample.getChildRelationships(); + if (childRelationships != null) + { + for (SampleRelationshipPE childRelationship : childRelationships) + { + SamplePE childSample = childRelationship.getChildSample(); + RelationshipUtils.updateModificationDateAndModifier(childSample, context.getSession()); + } + } + } + } + + private void updateModificationDateAndModifierOfRelatedEntitiesOfDataSets(IOperationContext context, Collection<String> dataSetCodes) + { + List<DataPE> dataSets = daoFactory.getDataDAO().listByCode(new HashSet<String>(dataSetCodes)); + for (DataPE dataSet : dataSets) + { + ExperimentPE experiment = dataSet.getExperiment(); + RelationshipUtils.updateModificationDateAndModifier(experiment, context.getSession()); + SamplePE sample = dataSet.tryGetSample(); + if (sample != null) + { + RelationshipUtils.updateModificationDateAndModifier(sample, context.getSession()); + } + updateModificationDateAndModifierOfDataSets(context, dataSet.getChildren()); + updateModificationDateAndModifierOfDataSets(context, dataSet.getParents()); + Set<DataSetRelationshipPE> relationships = dataSet.getParentRelationships(); + for (DataSetRelationshipPE relationship : RelationshipUtils.getContainerComponentRelationships(relationships)) + { + RelationshipUtils.updateModificationDateAndModifier(relationship.getParentDataSet(), context.getSession()); + } + } + } + + private void updateModificationDateAndModifierOfDataSets(IOperationContext context, List<DataPE> dataSets) + { + if (dataSets != null) + { + for (DataPE child : dataSets) + { + RelationshipUtils.updateModificationDateAndModifier(child, context.getSession()); + } + } + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/experiment/DeleteExperimentExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/experiment/DeleteExperimentExecutor.java index 2f39a3647d7..cc35f822dea 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/experiment/DeleteExperimentExecutor.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/experiment/DeleteExperimentExecutor.java @@ -34,7 +34,6 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.exceptions.UnauthorizedObjectAc import ch.systemsx.cisd.openbis.generic.server.ComponentNames; import ch.systemsx.cisd.openbis.generic.server.authorization.validator.ExperimentByIdentiferValidator; import ch.systemsx.cisd.openbis.generic.server.business.bo.ICommonBusinessObjectFactory; -import ch.systemsx.cisd.openbis.generic.server.business.bo.IExperimentBO; import ch.systemsx.cisd.openbis.generic.server.business.bo.ITrashBO; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.dto.DeletionPE; @@ -57,6 +56,23 @@ public class DeleteExperimentExecutor implements IDeleteExperimentExecutor @Override public IDeletionId delete(IOperationContext context, List<? extends IExperimentId> experimentIds, ExperimentDeletionOptions deletionOptions) { + if (context == null) + { + throw new IllegalArgumentException("Context cannot be null"); + } + if (experimentIds == null) + { + throw new IllegalArgumentException("Experiment ids cannot be null"); + } + if (deletionOptions == null) + { + throw new IllegalArgumentException("Deletion options cannot be null"); + } + if (deletionOptions.getReason() == null) + { + throw new IllegalArgumentException("Deletion reason cannot be null"); + } + Map<IExperimentId, ExperimentPE> experimentMap = mapExperimentByIdExecutor.map(context, experimentIds); List<TechId> experimentTechIds = new LinkedList<TechId>(); @@ -74,16 +90,7 @@ public class DeleteExperimentExecutor implements IDeleteExperimentExecutor experimentTechIds.add(new TechId(experiment.getId())); } - switch (deletionOptions.getDeletionType()) - { - case PERMANENT: - deletePermanently(context, experimentTechIds, deletionOptions); - return null; - case TRASH: - return trash(context, experimentTechIds, deletionOptions); - default: - throw new IllegalArgumentException("Unknown deletion type: " + deletionOptions.getDeletionType()); - } + return trash(context, experimentTechIds, deletionOptions); } private void updateModificationDateAndModifierOfRelatedProject(IOperationContext context, ExperimentPE experiment) @@ -91,12 +98,6 @@ public class DeleteExperimentExecutor implements IDeleteExperimentExecutor RelationshipUtils.updateModificationDateAndModifier(experiment.getProject(), context.getSession()); } - private void deletePermanently(IOperationContext context, List<TechId> experimentTechIds, ExperimentDeletionOptions deletionOptions) - { - IExperimentBO experimentBO = businessObjectFactory.createExperimentBO(context.getSession()); - experimentBO.deleteByTechIds(experimentTechIds, deletionOptions.getReason()); - } - private IDeletionId trash(IOperationContext context, List<TechId> experimentTechIds, ExperimentDeletionOptions deletionOptions) { ITrashBO trashBO = businessObjectFactory.createTrashBO(context.getSession()); diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/sample/DeleteSampleExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/sample/DeleteSampleExecutor.java index 18a9185d534..15bb3030cee 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/sample/DeleteSampleExecutor.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/sample/DeleteSampleExecutor.java @@ -35,7 +35,6 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.exceptions.UnauthorizedObjectAc import ch.systemsx.cisd.openbis.generic.server.ComponentNames; import ch.systemsx.cisd.openbis.generic.server.authorization.validator.SampleByIdentiferValidator; import ch.systemsx.cisd.openbis.generic.server.business.bo.ICommonBusinessObjectFactory; -import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.ITrashBO; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.dto.DeletionPE; @@ -60,6 +59,23 @@ public class DeleteSampleExecutor implements IDeleteSampleExecutor @Override public IDeletionId delete(IOperationContext context, List<? extends ISampleId> sampleIds, SampleDeletionOptions deletionOptions) { + if (context == null) + { + throw new IllegalArgumentException("Context cannot be null"); + } + if (sampleIds == null) + { + throw new IllegalArgumentException("Sample ids cannot be null"); + } + if (deletionOptions == null) + { + throw new IllegalArgumentException("Deletion options cannot be null"); + } + if (deletionOptions.getReason() == null) + { + throw new IllegalArgumentException("Deletion reason cannot be null"); + } + Map<ISampleId, SamplePE> sampleMap = mapSampleByIdExecutor.map(context, sampleIds); List<TechId> sampleTechIds = new LinkedList<TechId>(); @@ -77,16 +93,7 @@ public class DeleteSampleExecutor implements IDeleteSampleExecutor sampleTechIds.add(new TechId(sample.getId())); } - switch (deletionOptions.getDeletionType()) - { - case PERMANENT: - deletePermanently(context, sampleTechIds, deletionOptions); - return null; - case TRASH: - return trash(context, sampleTechIds, deletionOptions); - default: - throw new IllegalArgumentException("Unknown deletion type: " + deletionOptions.getDeletionType()); - } + return trash(context, sampleTechIds, deletionOptions); } private void updateModificationDateAndModifierOfRelatedEntities(IOperationContext context, SamplePE sample) @@ -120,12 +127,6 @@ public class DeleteSampleExecutor implements IDeleteSampleExecutor } } - private void deletePermanently(IOperationContext context, List<TechId> sampleTechIds, SampleDeletionOptions deletionOptions) - { - ISampleTable sampleTable = businessObjectFactory.createSampleTable(context.getSession()); - sampleTable.deleteByTechIds(sampleTechIds, deletionOptions.getReason()); - } - private IDeletionId trash(IOperationContext context, List<TechId> sampleTechIds, SampleDeletionOptions deletionOptions) { ITrashBO trashBO = businessObjectFactory.createTrashBO(context.getSession()); diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/dataset/ListDataSetByPermId.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/dataset/ListDataSetByPermId.java new file mode 100644 index 00000000000..d0e3b83571e --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/dataset/ListDataSetByPermId.java @@ -0,0 +1,66 @@ +/* + * Copyright 2013 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.helper.dataset; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import ch.ethz.sis.openbis.generic.server.api.v3.helper.common.IListObjectById; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.DataSetPermId; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDataDAO; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; + +/** + * @author pkupczyk + */ +public class ListDataSetByPermId implements IListObjectById<DataSetPermId, DataPE> +{ + + private IDataDAO dataDAO; + + public ListDataSetByPermId(IDataDAO dataDAO) + { + this.dataDAO = dataDAO; + } + + @Override + public Class<DataSetPermId> getIdClass() + { + return DataSetPermId.class; + } + + @Override + public DataSetPermId createId(DataPE dataSet) + { + return new DataSetPermId(dataSet.getCode()); + } + + @Override + public List<DataPE> listByIds(List<DataSetPermId> ids) + { + Set<String> codes = new HashSet<String>(); + + for (DataSetPermId id : ids) + { + codes.add(id.getPermId()); + } + + return dataDAO.listByCode(codes); + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/deletion/ListDeletionByTechId.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/deletion/ListDeletionByTechId.java new file mode 100644 index 00000000000..ca357261122 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/deletion/ListDeletionByTechId.java @@ -0,0 +1,65 @@ +/* + * Copyright 2013 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.helper.deletion; + +import java.util.LinkedList; +import java.util.List; + +import ch.ethz.sis.openbis.generic.server.api.v3.helper.common.IListObjectById; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.DeletionTechId; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDeletionDAO; +import ch.systemsx.cisd.openbis.generic.shared.dto.DeletionPE; + +/** + * @author pkupczyk + */ +public class ListDeletionByTechId implements IListObjectById<DeletionTechId, DeletionPE> +{ + + private IDeletionDAO deletionDAO; + + public ListDeletionByTechId(IDeletionDAO deletionDAO) + { + this.deletionDAO = deletionDAO; + } + + @Override + public Class<DeletionTechId> getIdClass() + { + return DeletionTechId.class; + } + + @Override + public DeletionTechId createId(DeletionPE deletion) + { + return new DeletionTechId(deletion.getId()); + } + + @Override + public List<DeletionPE> listByIds(List<DeletionTechId> ids) + { + List<Long> techIds = new LinkedList<Long>(); + + for (DeletionTechId id : ids) + { + techIds.add(id.getTechId()); + } + + return deletionDAO.findAllById(techIds); + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/entity/deletion/DeletionTranslator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/entity/deletion/DeletionTranslator.java new file mode 100644 index 00000000000..51d39697da4 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/entity/deletion/DeletionTranslator.java @@ -0,0 +1,111 @@ +/* + * 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.translator.entity.deletion; + +import java.util.ArrayList; +import java.util.List; + +import ch.ethz.sis.openbis.generic.server.api.v3.translator.AbstractCachingTranslator; +import ch.ethz.sis.openbis.generic.server.api.v3.translator.Relations; +import ch.ethz.sis.openbis.generic.server.api.v3.translator.TranslationContext; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.DeletedObject; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.Deletion; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.deletion.DeletionFetchOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.DataSetPermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.DeletionTechId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.ExperimentPermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.MaterialPermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.SamplePermId; +import ch.systemsx.cisd.openbis.generic.server.authorization.AuthorizationDataProvider; +import ch.systemsx.cisd.openbis.generic.server.authorization.validator.DeletionValidator; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; +import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolderWithIdentifier; + +/** + * @author pkupczyk + */ +public class DeletionTranslator extends + AbstractCachingTranslator<ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion, Deletion, DeletionFetchOptions> +{ + + private IDAOFactory daoFactory; + + public DeletionTranslator(TranslationContext translationContext, DeletionFetchOptions fetchOptions, IDAOFactory daoFactory) + { + super(translationContext, fetchOptions); + this.daoFactory = daoFactory; + } + + @Override + protected boolean shouldTranslate(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion input) + { + DeletionValidator validator = new DeletionValidator(); + validator.init(new AuthorizationDataProvider(daoFactory)); + return validator.doValidation(getTranslationContext().getSession().tryGetPerson(), input); + } + + @Override + protected Deletion createObject(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion input) + { + Deletion deletion = new Deletion(); + deletion.setId(new DeletionTechId(input.getId())); + deletion.setReason(input.getReason()); + deletion.setFetchOptions(new DeletionFetchOptions()); + return deletion; + } + + @Override + protected void updateObject(ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion input, Deletion output, Relations relations) + { + if (getFetchOptions().hasDeletedObjects()) + { + output.getFetchOptions().fetchDeletedObjects(); + + if (input.getDeletedEntities() != null) + { + List<DeletedObject> deletedObjects = new ArrayList<DeletedObject>(input.getDeletedEntities().size()); + + for (IEntityInformationHolderWithIdentifier deletedEntity : input.getDeletedEntities()) + { + DeletedObject deletedObject = new DeletedObject(); + + switch (deletedEntity.getEntityKind()) + { + case EXPERIMENT: + deletedObject.setId(new ExperimentPermId(deletedEntity.getPermId())); + break; + case SAMPLE: + deletedObject.setId(new SamplePermId(deletedEntity.getPermId())); + break; + case DATA_SET: + deletedObject.setId(new DataSetPermId(deletedEntity.getPermId())); + break; + case MATERIAL: + deletedObject.setId(new MaterialPermId(deletedEntity.getPermId())); + break; + default: + throw new IllegalArgumentException("Unknown entity kind: " + deletedEntity.getEntityKind()); + } + + deletedObjects.add(deletedObject); + } + + output.setDeletedObjects(deletedObjects); + } + } + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java index 950a5c7881a..01a204b42c9 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java @@ -1616,7 +1616,7 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt @Override @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) @ReturnValueFilter(validatorClass = SearchDomainSearchResultValidator.class) - public List<SearchDomainSearchResultWithFullDataSet> searchOnSearchDomain(String sessionToken, + public List<SearchDomainSearchResultWithFullDataSet> searchOnSearchDomain(String sessionToken, String preferredSearchDomainOrNull, String searchString, Map<String, String> optionalParametersOrNull) { Session session = getSession(sessionToken); @@ -1631,7 +1631,7 @@ public final class CommonServer extends AbstractCommonServer<ICommonServerForInt public List<SearchDomain> listAvailableSearchDomains(String sessionToken) { Session session = getSession(sessionToken); - + IDataSetTable dataSetTable = businessObjectFactory.createDataSetTable(session); return dataSetTable.listAvailableSearchDomains(); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DeletionTable.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DeletionTable.java index d64fb3aa4e2..3e71dd1f2a2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DeletionTable.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/DeletionTable.java @@ -56,18 +56,33 @@ public class DeletionTable extends AbstractBusinessObject implements IDeletionTa @Override public void load(boolean withEntities) { - load(withEntities, false); + List<DeletionPE> deletionPEs = getDeletionDAO().listAllEntities(); + load(deletionPEs, withEntities, false); + } + + @Override + public void load(List<Long> deletionIds, boolean withEntities) + { + List<DeletionPE> deletionPEs = getDeletionDAO().findAllById(deletionIds); + load(deletionPEs, withEntities, false); } @Override public void loadOriginal() { - load(true, true); + List<DeletionPE> deletionPEs = getDeletionDAO().listAllEntities(); + load(deletionPEs, true, true); + } + + @Override + public void loadOriginal(List<Long> deletionIds) + { + List<DeletionPE> deletionPEs = getDeletionDAO().findAllById(deletionIds); + load(deletionPEs, true, true); } - private void load(boolean withEntities, boolean onlyOriginal) + private void load(List<DeletionPE> deletionPEs, boolean withEntities, boolean onlyOriginal) { - final List<DeletionPE> deletionPEs = getDeletionDAO().listAllEntities(); Collections.sort(deletionPEs); deletions = DeletionTranslator.translate(deletionPEs); if (false == withEntities) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IDeletionTable.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IDeletionTable.java index 795f12d04b0..627aca75d94 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IDeletionTable.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IDeletionTable.java @@ -30,15 +30,18 @@ public interface IDeletionTable /** * Load all {@link Deletion} objects. * - * @param withEntities If <code>true</code> deletion objects will be enriched with those deleted - * entities which are the root of the deletion tree. + * @param withEntities If <code>true</code> deletion objects will be enriched with those deleted entities which are the root of the deletion tree. */ public void load(boolean withEntities); + public void load(List<Long> deletionIds, boolean withEntities); + /** * Load all {@link Deletion} objects with original entities. */ public void loadOriginal(); + public void loadOriginal(List<Long> deletionIds); + public List<Deletion> getDeletions(); } diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/AbstractDeletionTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/AbstractDeletionTest.java new file mode 100644 index 00000000000..65c46537331 --- /dev/null +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/AbstractDeletionTest.java @@ -0,0 +1,142 @@ +/* + * 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 java.util.Collections; +import java.util.List; + +import junit.framework.Assert; + +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.Deletion; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experiment; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentCreation; +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; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.deletion.DeletionFetchOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.experiment.ExperimentFetchOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sample.SampleFetchOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.IDeletionId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.entitytype.EntityTypePermId; +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.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.SamplePermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.space.SpacePermId; + +/** + * @author pkupczyk + */ +public class AbstractDeletionTest extends AbstractTest +{ + + protected ExperimentPermId createExperimentToDelete() + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + + ExperimentCreation creation = new ExperimentCreation(); + creation.setCode("EXPERIMENT_TO_DELETE"); + creation.setTypeId(new EntityTypePermId("SIRNA_HCS")); + creation.setProjectId(new ProjectIdentifier("/CISD/DEFAULT")); + + List<ExperimentPermId> permIds = v3api.createExperiments(sessionToken, Collections.singletonList(creation)); + List<Experiment> experiments = v3api.listExperiments(sessionToken, permIds, new ExperimentFetchOptions()); + + Assert.assertEquals(1, experiments.size()); + Assert.assertEquals("EXPERIMENT_TO_DELETE", experiments.get(0).getCode()); + + return permIds.get(0); + } + + protected SamplePermId createSampleToDelete(IExperimentId experimentId) + { + final String sessionToken = v3api.login(TEST_USER, PASSWORD); + + SampleCreation creation = new SampleCreation(); + creation.setCode("SAMPLE_TO_DELETE"); + creation.setTypeId(new EntityTypePermId("CELL_PLATE")); + creation.setSpaceId(new SpacePermId("CISD")); + creation.setExperimentId(experimentId); + + List<SamplePermId> permIds = v3api.createSamples(sessionToken, Collections.singletonList(creation)); + List<Sample> samples = v3api.listSamples(sessionToken, permIds, new SampleFetchOptions()); + + Assert.assertEquals(1, samples.size()); + Assert.assertEquals("SAMPLE_TO_DELETE", samples.get(0).getCode()); + + return permIds.get(0); + } + + protected void assertExperimentExists(IExperimentId experimentId) + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + List<Experiment> result = v3api.listExperiments(sessionToken, Collections.singletonList(experimentId), new ExperimentFetchOptions()); + Assert.assertEquals(1, result.size()); + } + + protected void assertExperimentDoesNotExist(IExperimentId experimentId) + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + List<Experiment> result = v3api.listExperiments(sessionToken, Collections.singletonList(experimentId), new ExperimentFetchOptions()); + Assert.assertEquals(0, result.size()); + } + + protected void assertSampleExists(ISampleId sampleId) + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + List<Sample> result = v3api.listSamples(sessionToken, Collections.singletonList(sampleId), new SampleFetchOptions()); + Assert.assertEquals(1, result.size()); + } + + protected void assertSampleDoesNotExist(ISampleId sampleId) + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + List<Sample> result = v3api.listSamples(sessionToken, Collections.singletonList(sampleId), new SampleFetchOptions()); + Assert.assertEquals(0, result.size()); + } + + protected void assertDeletionExists(IDeletionId deletionId) + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + List<Deletion> result = v3api.listDeletions(sessionToken, new DeletionFetchOptions()); + + for (Deletion item : result) + { + if (item.getId().equals(deletionId)) + { + return; + } + } + + Assert.fail("Deletion " + deletionId + " does not exist"); + } + + protected void assertDeletionDoesNotExist(IDeletionId deletionId) + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + List<Deletion> result = v3api.listDeletions(sessionToken, new DeletionFetchOptions()); + + for (Deletion item : result) + { + if (item.getId().equals(deletionId)) + { + Assert.fail("Deletion " + deletionId + " exists"); + } + } + } + +} diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/ConfirmDeletionTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/ConfirmDeletionTest.java new file mode 100644 index 00000000000..dc7f16c94fa --- /dev/null +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/ConfirmDeletionTest.java @@ -0,0 +1,97 @@ +/* + * 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 java.util.Collections; + +import org.testng.annotations.Test; + +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.experiment.ExperimentDeletionOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.DeletionTechId; +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.sample.SamplePermId; +import ch.systemsx.cisd.common.action.IDelegatedAction; + +/** + * @author pkupczyk + */ +public class ConfirmDeletionTest extends AbstractDeletionTest +{ + + @Test + public void testConfirmDeletion() + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + + ExperimentPermId experimentId = createExperimentToDelete(); + SamplePermId sampleId = createSampleToDelete(experimentId); + + ExperimentDeletionOptions deletionOptions = new ExperimentDeletionOptions(); + deletionOptions.setReason("It is just a test"); + IDeletionId deletionId = v3api.deleteExperiments(sessionToken, Collections.singletonList(experimentId), deletionOptions); + + assertDeletionExists(deletionId); + assertExperimentDoesNotExist(experimentId); + assertSampleDoesNotExist(sampleId); + + v3api.confirmDeletions(sessionToken, Collections.singletonList(deletionId)); + + assertDeletionDoesNotExist(deletionId); + assertExperimentDoesNotExist(experimentId); + assertSampleDoesNotExist(sampleId); + } + + @Test + public void testConfirmDeletionWithNonexistentDeletion() + { + final IDeletionId deletionId = new DeletionTechId(-1L); + + assertObjectNotFoundException(new IDelegatedAction() + { + @Override + public void execute() + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + v3api.confirmDeletions(sessionToken, Collections.singletonList(deletionId)); + } + }, deletionId); + } + + @Test + public void testConfirmDeletionWithUnauthorizedDeletion() + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + + ExperimentPermId experimentId = createExperimentToDelete(); + + ExperimentDeletionOptions deletionOptions = new ExperimentDeletionOptions(); + deletionOptions.setReason("It is just a test"); + final IDeletionId deletionId = v3api.deleteExperiments(sessionToken, Collections.singletonList(experimentId), deletionOptions); + + assertUnauthorizedObjectAccessException(new IDelegatedAction() + { + @Override + public void execute() + { + String sessionToken2 = v3api.login(TEST_SPACE_USER, PASSWORD); + v3api.confirmDeletions(sessionToken2, Collections.singletonList(deletionId)); + } + }, deletionId); + } + +} diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/DeleteExperimentTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/DeleteExperimentTest.java index 4b842278870..0168a318448 100644 --- a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/DeleteExperimentTest.java +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/DeleteExperimentTest.java @@ -23,7 +23,6 @@ import junit.framework.Assert; import org.testng.annotations.Test; -import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.DeletionType; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.experiment.ExperimentDeletionOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experiment; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentCreation; @@ -41,14 +40,13 @@ public class DeleteExperimentTest extends AbstractExperimentTest { @Test - public void testDeleteExperimentWithTrashType() + public void testDeleteExperiment() { String sessionToken = v3api.login(TEST_USER, PASSWORD); ExperimentPermId permId = createExperimentToDelete(); ExperimentDeletionOptions options = new ExperimentDeletionOptions(); - options.setDeletionType(DeletionType.TRASH); options.setReason("It is just a test"); IDeletionId deletionId = v3api.deleteExperiments(sessionToken, Collections.singletonList(permId), options); @@ -71,7 +69,6 @@ public class DeleteExperimentTest extends AbstractExperimentTest String sessionToken = v3api.login(TEST_SPACE_USER, PASSWORD); ExperimentDeletionOptions options = new ExperimentDeletionOptions(); - options.setDeletionType(DeletionType.TRASH); options.setReason("It is just a test"); v3api.deleteExperiments(sessionToken, Collections.singletonList(permId), options); diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/DeleteSampleTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/DeleteSampleTest.java index bbd3c0fe428..f044d8d862f 100644 --- a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/DeleteSampleTest.java +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/DeleteSampleTest.java @@ -23,7 +23,6 @@ import junit.framework.Assert; import org.testng.annotations.Test; -import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.DeletionType; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.sample.SampleDeletionOptions; 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; @@ -41,14 +40,13 @@ public class DeleteSampleTest extends AbstractSampleTest { @Test - public void testDeleteSampleWithTrashType() + public void testDeleteSample() { String sessionToken = v3api.login(TEST_USER, PASSWORD); SamplePermId permId = createSampleToDelete(); SampleDeletionOptions options = new SampleDeletionOptions(); - options.setDeletionType(DeletionType.TRASH); options.setReason("It is just a test"); IDeletionId deletionId = v3api.deleteSamples(sessionToken, Collections.singletonList(permId), options); @@ -71,7 +69,6 @@ public class DeleteSampleTest extends AbstractSampleTest String sessionToken = v3api.login(TEST_SPACE_USER, PASSWORD); SampleDeletionOptions options = new SampleDeletionOptions(); - options.setDeletionType(DeletionType.TRASH); options.setReason("It is just a test"); v3api.deleteSamples(sessionToken, Collections.singletonList(permId), options); diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/ListDeletionTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/ListDeletionTest.java new file mode 100644 index 00000000000..83d609021ac --- /dev/null +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/ListDeletionTest.java @@ -0,0 +1,122 @@ +/* + * 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 java.util.Collections; +import java.util.List; + +import junit.framework.Assert; + +import org.testng.annotations.Test; + +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.Deletion; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.experiment.ExperimentDeletionOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.deletion.DeletionFetchOptions; +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.sample.SamplePermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.exceptions.NotFetchedException; + +/** + * @author pkupczyk + */ +public class ListDeletionTest extends AbstractDeletionTest +{ + + @Test + public void testListDeletionsWithoutDeletedObjects() + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + + DeletionFetchOptions fetchOptions = new DeletionFetchOptions(); + List<Deletion> beforeDeletions = v3api.listDeletions(sessionToken, fetchOptions); + + ExperimentPermId experimentId = createExperimentToDelete(); + SamplePermId sampleId = createSampleToDelete(experimentId); + + ExperimentDeletionOptions deletionOptions = new ExperimentDeletionOptions(); + deletionOptions.setReason("It is just a test"); + IDeletionId deletionId = v3api.deleteExperiments(sessionToken, Collections.singletonList(experimentId), deletionOptions); + + assertExperimentDoesNotExist(experimentId); + assertSampleDoesNotExist(sampleId); + + List<Deletion> afterDeletions = v3api.listDeletions(sessionToken, fetchOptions); + Assert.assertEquals(beforeDeletions.size() + 1, afterDeletions.size()); + Deletion latestDeletion = afterDeletions.get(afterDeletions.size() - 1); + Assert.assertEquals(deletionId, latestDeletion.getId()); + Assert.assertEquals(deletionOptions.getReason(), latestDeletion.getReason()); + try + { + latestDeletion.getDeletedObjects(); + Assert.fail(); + } catch (NotFetchedException e) + { + // that's expected + } + } + + @Test + public void testListDeletionsWithDeletedObjects() + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + + DeletionFetchOptions fetchOptions = new DeletionFetchOptions(); + fetchOptions.fetchDeletedObjects(); + List<Deletion> beforeDeletions = v3api.listDeletions(sessionToken, fetchOptions); + + ExperimentPermId experimentId = createExperimentToDelete(); + SamplePermId sampleId = createSampleToDelete(experimentId); + + ExperimentDeletionOptions deletionOptions = new ExperimentDeletionOptions(); + deletionOptions.setReason("It is just a test"); + IDeletionId deletionId = v3api.deleteExperiments(sessionToken, Collections.singletonList(experimentId), deletionOptions); + + assertExperimentDoesNotExist(experimentId); + assertSampleDoesNotExist(sampleId); + + List<Deletion> afterDeletions = v3api.listDeletions(sessionToken, fetchOptions); + Assert.assertEquals(beforeDeletions.size() + 1, afterDeletions.size()); + Deletion latestDeletion = afterDeletions.get(afterDeletions.size() - 1); + Assert.assertEquals(deletionId, latestDeletion.getId()); + Assert.assertEquals(deletionOptions.getReason(), latestDeletion.getReason()); + Assert.assertEquals(1, latestDeletion.getDeletedObjects().size()); + Assert.assertEquals(experimentId, latestDeletion.getDeletedObjects().get(0).getId()); + } + + @Test + public void testListDeletionsWithUnauthorizedDeletion() + { + String spaceSessionToken = v3api.login(TEST_SPACE_USER, PASSWORD); + + DeletionFetchOptions fetchOptions = new DeletionFetchOptions(); + List<Deletion> beforeDeletions = v3api.listDeletions(spaceSessionToken, fetchOptions); + + String adminSessionToken = v3api.login(TEST_USER, PASSWORD); + + ExperimentPermId experimentId = createExperimentToDelete(); + ExperimentDeletionOptions deletionOptions = new ExperimentDeletionOptions(); + deletionOptions.setReason("It is just a test"); + v3api.deleteExperiments(adminSessionToken, Collections.singletonList(experimentId), deletionOptions); + + assertExperimentDoesNotExist(experimentId); + + List<Deletion> afterDeletions = v3api.listDeletions(spaceSessionToken, fetchOptions); + Assert.assertEquals(beforeDeletions.size(), afterDeletions.size()); + } + +} diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/RevertDeletionTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/RevertDeletionTest.java new file mode 100644 index 00000000000..6cdb8a2b348 --- /dev/null +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/RevertDeletionTest.java @@ -0,0 +1,97 @@ +/* + * 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 java.util.Collections; + +import org.testng.annotations.Test; + +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.experiment.ExperimentDeletionOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.DeletionTechId; +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.sample.SamplePermId; +import ch.systemsx.cisd.common.action.IDelegatedAction; + +/** + * @author pkupczyk + */ +public class RevertDeletionTest extends AbstractDeletionTest +{ + + @Test + public void testRevertDeletionOfExperimentWithSample() + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + + ExperimentPermId experimentId = createExperimentToDelete(); + SamplePermId sampleId = createSampleToDelete(experimentId); + + ExperimentDeletionOptions deletionOptions = new ExperimentDeletionOptions(); + deletionOptions.setReason("It is just a test"); + IDeletionId deletionId = v3api.deleteExperiments(sessionToken, Collections.singletonList(experimentId), deletionOptions); + + assertDeletionExists(deletionId); + assertExperimentDoesNotExist(experimentId); + assertSampleDoesNotExist(sampleId); + + v3api.revertDeletions(sessionToken, Collections.singletonList(deletionId)); + + assertDeletionDoesNotExist(deletionId); + assertExperimentExists(experimentId); + assertSampleExists(sampleId); + } + + @Test + public void testRevertDeletionWithNonexistentDeletion() + { + final IDeletionId deletionId = new DeletionTechId(-1L); + + assertObjectNotFoundException(new IDelegatedAction() + { + @Override + public void execute() + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + v3api.revertDeletions(sessionToken, Collections.singletonList(deletionId)); + } + }, deletionId); + } + + @Test + public void testRevertDeletionWithUnauthorizedDeletion() + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + + ExperimentPermId experimentId = createExperimentToDelete(); + + ExperimentDeletionOptions deletionOptions = new ExperimentDeletionOptions(); + deletionOptions.setReason("It is just a test"); + final IDeletionId deletionId = v3api.deleteExperiments(sessionToken, Collections.singletonList(experimentId), deletionOptions); + + assertUnauthorizedObjectAccessException(new IDelegatedAction() + { + @Override + public void execute() + { + String sessionToken2 = v3api.login(TEST_SPACE_USER, PASSWORD); + v3api.revertDeletions(sessionToken2, Collections.singletonList(deletionId)); + } + }, deletionId); + } + +} diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/Deletion.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/Deletion.java index 772142fb813..4f9fdab4015 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/Deletion.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/Deletion.java @@ -20,7 +20,12 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.deletion.DeletionFetchOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.deletion.IDeletionId; +import ch.ethz.sis.openbis.generic.shared.api.v3.exceptions.NotFetchedException; import ch.systemsx.cisd.base.annotation.JsonObject; /** @@ -32,12 +37,30 @@ public class Deletion implements Serializable private static final long serialVersionUID = 1L; + @JsonProperty + private DeletionFetchOptions fetchOptions; + + @JsonProperty private IDeletionId id; + @JsonProperty private String reason; + @JsonProperty private List<DeletedObject> deletedObjects = new ArrayList<DeletedObject>(); + @JsonIgnore + public DeletionFetchOptions getFetchOptions() + { + return fetchOptions; + } + + public void setFetchOptions(DeletionFetchOptions fetchOptions) + { + this.fetchOptions = fetchOptions; + } + + @JsonIgnore public IDeletionId getId() { return id; @@ -48,6 +71,7 @@ public class Deletion implements Serializable this.id = id; } + @JsonIgnore public String getReason() { return reason; @@ -58,9 +82,17 @@ public class Deletion implements Serializable this.reason = reason; } + @JsonIgnore public List<DeletedObject> getDeletedObjects() { - return deletedObjects; + if (getFetchOptions().hasDeletedObjects()) + { + return deletedObjects; + } + else + { + throw new NotFetchedException("Deleted objects have not been fetched."); + } } public void setDeletedObjects(List<DeletedObject> deletedObjects) diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/AbstractTrashableObjectDeletionOptions.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/dataset/DataSetDeletionOptions.java similarity index 63% rename from openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/AbstractTrashableObjectDeletionOptions.java rename to openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/dataset/DataSetDeletionOptions.java index 15aa9d1c0fc..142b73a21a6 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/AbstractTrashableObjectDeletionOptions.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/dataset/DataSetDeletionOptions.java @@ -14,26 +14,18 @@ * limitations under the License. */ -package ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion; +package ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.dataset; + +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.AbstractObjectDeletionOptions; +import ch.systemsx.cisd.base.annotation.JsonObject; /** * @author pkupczyk */ -public class AbstractTrashableObjectDeletionOptions extends AbstractObjectDeletionOptions +@JsonObject("DataSetDeletionOptions") +public class DataSetDeletionOptions extends AbstractObjectDeletionOptions { private static final long serialVersionUID = 1L; - private DeletionType deletionType = DeletionType.TRASH; - - public DeletionType getDeletionType() - { - return deletionType; - } - - public void setDeletionType(DeletionType deletionType) - { - this.deletionType = deletionType; - } - } diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/experiment/ExperimentDeletionOptions.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/experiment/ExperimentDeletionOptions.java index 9d21b540b2f..e24ed79469e 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/experiment/ExperimentDeletionOptions.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/experiment/ExperimentDeletionOptions.java @@ -16,14 +16,14 @@ package ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.experiment; -import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.AbstractTrashableObjectDeletionOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.AbstractObjectDeletionOptions; import ch.systemsx.cisd.base.annotation.JsonObject; /** * @author pkupczyk */ @JsonObject("ExperimentDeletionOptions") -public class ExperimentDeletionOptions extends AbstractTrashableObjectDeletionOptions +public class ExperimentDeletionOptions extends AbstractObjectDeletionOptions { private static final long serialVersionUID = 1L; diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/sample/SampleDeletionOptions.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/sample/SampleDeletionOptions.java index 7974fdd5f1a..8fdb9c5b4f7 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/sample/SampleDeletionOptions.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/deletion/sample/SampleDeletionOptions.java @@ -16,14 +16,14 @@ package ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.sample; -import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.AbstractTrashableObjectDeletionOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.deletion.AbstractObjectDeletionOptions; import ch.systemsx.cisd.base.annotation.JsonObject; /** * @author pkupczyk */ @JsonObject("SampleDeletionOptions") -public class SampleDeletionOptions extends AbstractTrashableObjectDeletionOptions +public class SampleDeletionOptions extends AbstractObjectDeletionOptions { private static final long serialVersionUID = 1L; diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/deletion/DeletionFetchOptions.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/deletion/DeletionFetchOptions.java index 70ad5e1b63f..f817bb11ae6 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/deletion/DeletionFetchOptions.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/deletion/DeletionFetchOptions.java @@ -28,36 +28,20 @@ public class DeletionFetchOptions implements Serializable { private static final long serialVersionUID = 1L; - private DeletedObjectFetchOptions allDeletedObjects; + private DeletedObjectFetchOptions deletedObjects; - private DeletedObjectFetchOptions originallyDeletedObjects; - - public DeletedObjectFetchOptions fetchAllDeletedObjects() - { - if (allDeletedObjects == null) - { - allDeletedObjects = new DeletedObjectFetchOptions(); - } - return allDeletedObjects; - } - - public boolean hasAllDeletedObjects() - { - return allDeletedObjects != null; - } - - public DeletedObjectFetchOptions fetchOriginallyDeletedObjects() + public DeletedObjectFetchOptions fetchDeletedObjects() { - if (originallyDeletedObjects == null) + if (deletedObjects == null) { - originallyDeletedObjects = new DeletedObjectFetchOptions(); + deletedObjects = new DeletedObjectFetchOptions(); } - return originallyDeletedObjects; + return deletedObjects; } - public boolean hasOriginallyDeletedObjects() + public boolean hasDeletedObjects() { - return originallyDeletedObjects != null; + return deletedObjects != null; } } \ No newline at end of file -- GitLab