From c2d7b009af3d8cf2bf5f9e0c1102243fc7097737 Mon Sep 17 00:00:00 2001 From: pkupczyk <pkupczyk> Date: Wed, 18 Mar 2015 11:00:08 +0000 Subject: [PATCH] SSDM-1626 : V3 AS API - create/update/delete/map/search spaces/projects - project creation finished + tests SVN: 33684 --- .../server/api/v3/ApplicationServerApi.java | 24 ++ .../api/v3/ApplicationServerApiLogger.java | 10 + .../person/IMapPersonByIdExecutor.java | 29 ++ .../person/MapPersonByIdExecutor.java | 68 +++++ .../project/SetProjectLeaderExecutor.java | 8 +- .../v3/helper/person/ListPersonByPermId.java | 65 +++++ .../entity/project/ProjectTranslator.java | 19 ++ .../systemtest/api/v3/CreateProjectTest.java | 249 ++++++++++++++++++ .../shared/api/v3/IApplicationServerApi.java | 6 + .../api/v3/dto/entity/project/Project.java | 51 +++- .../project/ProjectFetchOptions.java | 51 ++++ .../api/v3/dto/generators/Generator.java | 3 + 12 files changed, 580 insertions(+), 3 deletions(-) create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/person/IMapPersonByIdExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/person/MapPersonByIdExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/person/ListPersonByPermId.java create mode 100644 openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateProjectTest.java diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApi.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApi.java index 77553434f37..3c9ae2e608d 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 @@ -43,6 +43,7 @@ import ch.ethz.sis.openbis.generic.server.api.v3.executor.material.ICreateMateri import ch.ethz.sis.openbis.generic.server.api.v3.executor.material.IDeleteMaterialExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.material.IMapMaterialByIdExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.project.ICreateProjectExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.executor.project.IMapProjectByIdExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.sample.ICreateSampleExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.sample.IDeleteSampleExecutor; import ch.ethz.sis.openbis.generic.server.api.v3.executor.sample.IMapSampleByIdExecutor; @@ -60,6 +61,7 @@ import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.dataset.DataS 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.material.MaterialTranslator; +import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.project.ProjectTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.sample.SampleTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.space.SpaceTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.utils.ExceptionUtils; @@ -77,6 +79,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experimen import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentUpdate; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.Material; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.MaterialCreation; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.Project; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.ProjectCreation; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.Sample; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.SampleCreation; @@ -88,6 +91,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.dataset.DataSe 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.material.MaterialFetchOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.project.ProjectFetchOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sample.SampleFetchOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.space.SpaceFetchOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.IDataSetId; @@ -96,6 +100,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.ExperimentPer import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.IExperimentId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.IMaterialId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.MaterialPermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.IProjectId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.ProjectPermId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.ISampleId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.SamplePermId; @@ -124,6 +129,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.RoleWithHierarchy; import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; import ch.systemsx.cisd.openbis.generic.shared.dto.Session; import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO; @@ -167,6 +173,9 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> @Autowired private IMapSpaceByIdExecutor mapSpaceByIdExecutor; + @Autowired + private IMapProjectByIdExecutor mapProjectByIdExecutor; + @Autowired private IMapExperimentByIdExecutor mapExperimentByIdExecutor; @@ -460,6 +469,21 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> fetchOptions)); } + @Override + @Transactional(readOnly = true) + @RolesAllowed({ RoleWithHierarchy.SPACE_OBSERVER, RoleWithHierarchy.SPACE_ETL_SERVER }) + public Map<IProjectId, Project> mapProjects(String sessionToken, List<? extends IProjectId> projectIds, ProjectFetchOptions fetchOptions) + { + Session session = getSession(sessionToken); + OperationContext context = new OperationContext(session); + + Map<IProjectId, ProjectPE> map = mapProjectByIdExecutor.map(context, projectIds); + + return new MapTranslator<IProjectId, IProjectId, ProjectPE, Project>().translate(map, new IdentityTranslator<IProjectId>(), + new ProjectTranslator(new TranslationContext(session, managedPropertyEvaluatorFactory), + fetchOptions)); + } + @Override @Transactional(readOnly = true) @RolesAllowed({ RoleWithHierarchy.SPACE_OBSERVER, RoleWithHierarchy.SPACE_ETL_SERVER }) diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApiLogger.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApiLogger.java index 9b9bf0108fc..2ab2f86d33b 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApiLogger.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/ApplicationServerApiLogger.java @@ -33,6 +33,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experimen import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentUpdate; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.Material; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.MaterialCreation; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.Project; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.ProjectCreation; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.Sample; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.SampleCreation; @@ -44,6 +45,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.dataset.DataSe 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.material.MaterialFetchOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.project.ProjectFetchOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sample.SampleFetchOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.space.SpaceFetchOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.IDataSetId; @@ -52,6 +54,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.ExperimentPer import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.IExperimentId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.IMaterialId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.MaterialPermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.IProjectId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.ProjectPermId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.ISampleId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.SamplePermId; @@ -177,6 +180,13 @@ public class ApplicationServerApiLogger extends AbstractServerLogger implements return null; } + @Override + public Map<IProjectId, Project> mapProjects(String sessionToken, List<? extends IProjectId> projectIds, ProjectFetchOptions fetchOptions) + { + logAccess(sessionToken, "map-projects", "PROJECT_IDS(%s) FETCH_OPTIONS(%s)", projectIds, fetchOptions); + return null; + } + @Override public Map<IExperimentId, Experiment> mapExperiments(String sessionToken, List<? extends IExperimentId> experimentIds, ExperimentFetchOptions fetchOptions) diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/person/IMapPersonByIdExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/person/IMapPersonByIdExecutor.java new file mode 100644 index 00000000000..0a4523abcd5 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/person/IMapPersonByIdExecutor.java @@ -0,0 +1,29 @@ +/* + * Copyright 2014 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.ethz.sis.openbis.generic.server.api.v3.executor.person; + +import ch.ethz.sis.openbis.generic.server.api.v3.executor.common.IMapObjectByIdExecutor; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.person.IPersonId; +import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; + +/** + * @author pkupczyk + */ +public interface IMapPersonByIdExecutor extends IMapObjectByIdExecutor<IPersonId, PersonPE> +{ + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/person/MapPersonByIdExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/person/MapPersonByIdExecutor.java new file mode 100644 index 00000000000..2a90f8514ba --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/person/MapPersonByIdExecutor.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.person; + +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.person.ListPersonByPermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.person.IPersonId; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IPersonDAO; +import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; + +/** + * @author pkupczyk + */ +@Component +public class MapPersonByIdExecutor extends AbstractMapObjectByIdExecutor<IPersonId, PersonPE> implements IMapPersonByIdExecutor +{ + + private IPersonDAO personDAO; + + @SuppressWarnings("unused") + private MapPersonByIdExecutor() + { + } + + public MapPersonByIdExecutor(IPersonDAO personDAO) + { + this.personDAO = personDAO; + } + + @Override + protected List<IListObjectById<? extends IPersonId, PersonPE>> createListers(IOperationContext context) + { + List<IListObjectById<? extends IPersonId, PersonPE>> listers = + new LinkedList<IListObjectById<? extends IPersonId, PersonPE>>(); + listers.add(new ListPersonByPermId(personDAO)); + return listers; + } + + @Autowired + private void setDAOFactory(IDAOFactory daoFactory) + { + personDAO = daoFactory.getPersonDAO(); + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/project/SetProjectLeaderExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/project/SetProjectLeaderExecutor.java index df34f23b8a7..328aa225ca4 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/project/SetProjectLeaderExecutor.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/project/SetProjectLeaderExecutor.java @@ -19,10 +19,12 @@ package ch.ethz.sis.openbis.generic.server.api.v3.executor.project; import java.util.List; import java.util.Map; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import ch.ethz.sis.openbis.generic.server.api.v3.executor.IOperationContext; import ch.ethz.sis.openbis.generic.server.api.v3.executor.entity.AbstractSetEntityRelationExecutor; +import ch.ethz.sis.openbis.generic.server.api.v3.executor.person.IMapPersonByIdExecutor; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.ProjectCreation; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.person.IPersonId; import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; @@ -36,6 +38,9 @@ public class SetProjectLeaderExecutor extends AbstractSetEntityRelationExecutor< ISetProjectLeaderExecutor { + @Autowired + private IMapPersonByIdExecutor mapPersonByIdExecutor; + @Override protected IPersonId getRelatedId(ProjectCreation creation) { @@ -45,8 +50,7 @@ public class SetProjectLeaderExecutor extends AbstractSetEntityRelationExecutor< @Override protected Map<IPersonId, PersonPE> map(IOperationContext context, List<IPersonId> relatedIds) { - // TODO Auto-generated method stub - return null; + return mapPersonByIdExecutor.map(context, relatedIds); } @Override diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/person/ListPersonByPermId.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/person/ListPersonByPermId.java new file mode 100644 index 00000000000..8c3a08913d0 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/helper/person/ListPersonByPermId.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.person; + +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.person.PersonPermId; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IPersonDAO; +import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; + +/** + * @author pkupczyk + */ +public class ListPersonByPermId implements IListObjectById<PersonPermId, PersonPE> +{ + + private IPersonDAO personDAO; + + public ListPersonByPermId(IPersonDAO personDAO) + { + this.personDAO = personDAO; + } + + @Override + public Class<PersonPermId> getIdClass() + { + return PersonPermId.class; + } + + @Override + public PersonPermId createId(PersonPE person) + { + return new PersonPermId(person.getUserId()); + } + + @Override + public List<PersonPE> listByIds(List<PersonPermId> ids) + { + List<String> userIds = new LinkedList<String>(); + + for (PersonPermId id : ids) + { + userIds.add(id.getPermId()); + } + + return personDAO.listByCodes(userIds); + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/entity/project/ProjectTranslator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/entity/project/ProjectTranslator.java index f18b8072b14..bc54f997ffb 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/entity/project/ProjectTranslator.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/translator/entity/project/ProjectTranslator.java @@ -16,15 +16,18 @@ package ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.project; +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.server.api.v3.translator.common.ListTranslator; +import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.attachment.AttachmentTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.experiment.ExperimentTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.person.PersonTranslator; import ch.ethz.sis.openbis.generic.server.api.v3.translator.entity.space.SpaceTranslator; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.attachment.Attachment; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experiment; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.Project; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.project.ProjectFetchOptions; @@ -89,6 +92,13 @@ public class ProjectTranslator extends AbstractCachingTranslator<ProjectPE, Proj result.getFetchOptions().withModifierUsing(getFetchOptions().withModifier()); } + if (getFetchOptions().hasLeader()) + { + result.setLeader(new PersonTranslator(getTranslationContext(), getFetchOptions().withLeader()).translate(project + .getProjectLeader())); + result.getFetchOptions().withLeaderUsing(getFetchOptions().withLeader()); + } + if (getFetchOptions().hasExperiments()) { List<Experiment> experiments = @@ -97,5 +107,14 @@ public class ProjectTranslator extends AbstractCachingTranslator<ProjectPE, Proj result.setExperiments(experiments); result.getFetchOptions().withExperimentsUsing(getFetchOptions().withExperiments()); } + + if (getFetchOptions().hasAttachments()) + { + ArrayList<Attachment> attachments = + AttachmentTranslator.translate(getTranslationContext(), project, getFetchOptions().withAttachments()); + result.setAttachments(attachments); + result.getFetchOptions().withAttachmentsUsing(getFetchOptions().withAttachments()); + } + } } diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateProjectTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateProjectTest.java new file mode 100644 index 00000000000..2761818399e --- /dev/null +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/api/v3/CreateProjectTest.java @@ -0,0 +1,249 @@ +/* + * Copyright 2014 ETH Zuerich, Scientific IT Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.ethz.sis.openbis.systemtest.api.v3; + +import static org.testng.Assert.assertEquals; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.attachment.Attachment; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.attachment.AttachmentCreation; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.Project; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.ProjectCreation; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.project.ProjectFetchOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.person.IPersonId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.person.PersonPermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.IProjectId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.ProjectPermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.space.ISpaceId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.space.SpacePermId; +import ch.systemsx.cisd.common.action.IDelegatedAction; + +/** + * @author pkupczyk + */ +public class CreateProjectTest extends AbstractTest +{ + + @Test + public void testCreateWithCodeNull() + { + final String sessionToken = v3api.login(TEST_USER, PASSWORD); + + final ProjectCreation project = new ProjectCreation(); + project.setSpaceId(new SpacePermId("CISD")); + + assertUserFailureException(new IDelegatedAction() + { + @Override + public void execute() + { + v3api.createProjects(sessionToken, Arrays.asList(project)); + } + }, "Code cannot be empty"); + } + + @Test + public void testCreateWithCodeExisting() + { + final String sessionToken = v3api.login(TEST_USER, PASSWORD); + + final ProjectCreation project = new ProjectCreation(); + project.setCode("PROJECT_WITH_EXISTING_CODE"); + project.setSpaceId(new SpacePermId("CISD")); + + v3api.createProjects(sessionToken, Arrays.asList(project)); + + assertUserFailureException(new IDelegatedAction() + { + @Override + public void execute() + { + v3api.createProjects(sessionToken, Arrays.asList(project)); + } + }, "Project already exists in the database and needs to be unique"); + } + + @Test + public void testCreateWithCodeIncorrect() + { + final String sessionToken = v3api.login(TEST_USER, PASSWORD); + + final ProjectCreation project = new ProjectCreation(); + project.setCode("?!*"); + project.setSpaceId(new SpacePermId("CISD")); + + assertUserFailureException(new IDelegatedAction() + { + @Override + public void execute() + { + v3api.createProjects(sessionToken, Arrays.asList(project)); + } + }, "The code '?!*' contains illegal characters"); + } + + @Test + public void testCreateWithSpaceNull() + { + final String sessionToken = v3api.login(TEST_USER, PASSWORD); + + final ProjectCreation project = new ProjectCreation(); + project.setCode("TEST_PROJECT"); + + assertUserFailureException(new IDelegatedAction() + { + @Override + public void execute() + { + v3api.createProjects(sessionToken, Arrays.asList(project)); + } + }, "Space id cannot be null"); + } + + @Test + public void testCreateWithSpaceUnauthorized() + { + final String sessionToken = v3api.login(TEST_SPACE_USER, PASSWORD); + + final ISpaceId spaceId = new SpacePermId("CISD"); + final ProjectCreation project = new ProjectCreation(); + project.setCode("TEST_PROJECT"); + project.setSpaceId(spaceId); + + assertUnauthorizedObjectAccessException(new IDelegatedAction() + { + @Override + public void execute() + { + v3api.createProjects(sessionToken, Arrays.asList(project)); + } + }, spaceId); + } + + @Test + public void testCreateWithSpaceNonexistent() + { + final String sessionToken = v3api.login(TEST_USER, PASSWORD); + + final ISpaceId spaceId = new SpacePermId("IDONTEXIST"); + final ProjectCreation project = new ProjectCreation(); + project.setCode("TEST_PROJECT"); + project.setSpaceId(spaceId); + + assertObjectNotFoundException(new IDelegatedAction() + { + @Override + public void execute() + { + v3api.createProjects(sessionToken, Arrays.asList(project)); + } + }, spaceId); + } + + @Test + public void testCreateWithLeaderNonexistent() + { + final String sessionToken = v3api.login(TEST_USER, PASSWORD); + + IPersonId leaderId = new PersonPermId("IDONTEXIST"); + final ProjectCreation project = new ProjectCreation(); + project.setCode("TEST_PROJECT"); + project.setSpaceId(new SpacePermId("CISD")); + project.setLeaderId(leaderId); + + assertObjectNotFoundException(new IDelegatedAction() + { + @Override + public void execute() + { + v3api.createProjects(sessionToken, Arrays.asList(project)); + } + }, leaderId); + } + + @Test + public void testCreateWithMultipleProjects() + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + + SpacePermId spaceId1 = new SpacePermId("CISD"); + SpacePermId spaceId2 = new SpacePermId("TEST-SPACE"); + + PersonPermId leaderId1 = new PersonPermId(TEST_SPACE_USER); + + ProjectCreation creation1 = new ProjectCreation(); + creation1.setCode("TEST_PROJECT_1"); + creation1.setDescription("description 1"); + creation1.setSpaceId(spaceId1); + creation1.setLeaderId(leaderId1); + + AttachmentCreation attachmentCreation = new AttachmentCreation(); + byte[] attachmentContent = "attachment".getBytes(); + attachmentCreation.setContent(attachmentContent); + attachmentCreation.setDescription("attachment description"); + attachmentCreation.setFileName("attachment.txt"); + attachmentCreation.setTitle("attachment title"); + creation1.setAttachments(Arrays.asList(attachmentCreation)); + + ProjectCreation creation2 = new ProjectCreation(); + creation2.setCode("TEST_PROJECT_2"); + creation2.setSpaceId(spaceId2); + + List<ProjectPermId> permIds = v3api.createProjects(sessionToken, Arrays.asList(creation1, creation2)); + + assertEquals(permIds.size(), 2); + + ProjectFetchOptions fetchOptions = new ProjectFetchOptions(); + fetchOptions.withSpace(); + fetchOptions.withModifier(); + fetchOptions.withRegistrator(); + fetchOptions.withLeader(); + fetchOptions.withAttachments().withContent(); + + Map<IProjectId, Project> map = v3api.mapProjects(sessionToken, permIds, fetchOptions); + + Assert.assertEquals(2, map.size()); + + Project project1 = map.get(permIds.get(0)); + assertEquals(project1.getCode(), creation1.getCode()); + assertEquals(project1.getSpace().getCode(), spaceId1.getPermId()); + assertEquals(project1.getIdentifier().getIdentifier(), "/" + spaceId1.getPermId() + "/" + creation1.getCode()); + assertEquals(project1.getDescription(), creation1.getDescription()); + assertEquals(project1.getRegistrator().getUserId(), TEST_USER); + assertEquals(project1.getModifier().getUserId(), TEST_USER); + assertEquals(project1.getLeader().getUserId(), leaderId1.getPermId()); + + List<Attachment> attachments = project1.getAttachments(); + assertEquals(attachments.size(), 1); + assertEquals(attachments.get(0).getContent(), attachmentContent); + + Project project2 = map.get(permIds.get(1)); + + assertEquals(project2.getCode(), creation2.getCode()); + assertEquals(project2.getIdentifier().getIdentifier(), "/" + spaceId2.getPermId() + "/" + creation2.getCode()); + assertEquals(project2.getSpace().getCode(), spaceId2.getPermId()); + assertEquals(project2.getModifier().getUserId(), TEST_USER); + assertEquals(project2.getRegistrator().getUserId(), TEST_USER); + } + +} diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/IApplicationServerApi.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/IApplicationServerApi.java index 6baefd7294c..1de153a2a77 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/IApplicationServerApi.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/IApplicationServerApi.java @@ -32,6 +32,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experimen import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.ExperimentUpdate; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.Material; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.material.MaterialCreation; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.Project; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project.ProjectCreation; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.Sample; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.sample.SampleCreation; @@ -43,6 +44,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.dataset.DataSe 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.material.MaterialFetchOptions; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.project.ProjectFetchOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.sample.SampleFetchOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.space.SpaceFetchOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.dataset.IDataSetId; @@ -51,6 +53,7 @@ import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.ExperimentPer import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.experiment.IExperimentId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.IMaterialId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.material.MaterialPermId; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.IProjectId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.project.ProjectPermId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.ISampleId; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.id.sample.SamplePermId; @@ -132,6 +135,9 @@ public interface IApplicationServerApi extends IRpcService public Map<ISpaceId, Space> mapSpaces(String sessionToken, List<? extends ISpaceId> spaceIds, SpaceFetchOptions fetchOptions); + public Map<IProjectId, Project> mapProjects(String sessionToken, List<? extends IProjectId> projectIds, + ProjectFetchOptions fetchOptions); + // REPLACES: // - ServiceForDataStoreServer.tryGetExperiment(ExperimentIdentifier) // - ServiceForDataStoreServer.listExperiments(List<ExperimentIdentifier>, ExperimentFetchOptions) diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/entity/project/Project.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/entity/project/Project.java index 97fd747f008..db0cc4740aa 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/entity/project/Project.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/entity/project/Project.java @@ -15,7 +15,9 @@ */ package ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.project; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.attachment.Attachment; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.experiment.Experiment; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IAttachmentsHolder; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IModificationDateHolder; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IModifierHolder; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.entity.interfaces.IRegistrationDateHolder; @@ -38,7 +40,7 @@ import java.util.List; * Class automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator} */ @JsonObject("dto.entity.project.Project") -public class Project implements Serializable, ISpaceHolder, IModifierHolder, IModificationDateHolder, IRegistratorHolder, IRegistrationDateHolder +public class Project implements Serializable, ISpaceHolder, IModifierHolder, IModificationDateHolder, IAttachmentsHolder, IRegistratorHolder, IRegistrationDateHolder { private static final long serialVersionUID = 1L; @@ -75,6 +77,12 @@ public class Project implements Serializable, ISpaceHolder, IModifierHolder, IMo @JsonProperty private Person modifier; + @JsonProperty + private Person leader; + + @JsonProperty + private List<Attachment> attachments; + // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator} @JsonIgnore public ProjectFetchOptions getFetchOptions() @@ -251,4 +259,45 @@ public class Project implements Serializable, ISpaceHolder, IModifierHolder, IMo this.modifier = modifier; } + // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator} + @JsonIgnore + public Person getLeader() + { + if (getFetchOptions().hasLeader()) + { + return leader; + } + else + { + throw new NotFetchedException("Leader has not been fetched."); + } + } + + // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator} + public void setLeader(Person leader) + { + this.leader = leader; + } + + // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator} + @JsonIgnore + @Override + public List<Attachment> getAttachments() + { + if (getFetchOptions().hasAttachments()) + { + return attachments; + } + else + { + throw new NotFetchedException("Attachments have not been fetched."); + } + } + + // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator} + public void setAttachments(List<Attachment> attachments) + { + this.attachments = attachments; + } + } diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/project/ProjectFetchOptions.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/project/ProjectFetchOptions.java index 410a9ece1f6..a474bbf5792 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/project/ProjectFetchOptions.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/fetchoptions/project/ProjectFetchOptions.java @@ -15,6 +15,7 @@ */ package ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.project; +import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.attachment.AttachmentFetchOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.experiment.ExperimentFetchOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.person.PersonFetchOptions; import ch.ethz.sis.openbis.generic.shared.api.v3.dto.fetchoptions.space.SpaceFetchOptions; @@ -42,6 +43,12 @@ public class ProjectFetchOptions implements Serializable @JsonProperty private PersonFetchOptions modifier; + @JsonProperty + private PersonFetchOptions leader; + + @JsonProperty + private AttachmentFetchOptions attachments; + // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator} public ExperimentFetchOptions withExperiments() { @@ -130,4 +137,48 @@ public class ProjectFetchOptions implements Serializable return modifier != null; } + // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator} + public PersonFetchOptions withLeader() + { + if (leader == null) + { + leader = new PersonFetchOptions(); + } + return leader; + } + + // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator} + public PersonFetchOptions withLeaderUsing(PersonFetchOptions fetchOptions) + { + return leader = fetchOptions; + } + + // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator} + public boolean hasLeader() + { + return leader != null; + } + + // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator} + public AttachmentFetchOptions withAttachments() + { + if (attachments == null) + { + attachments = new AttachmentFetchOptions(); + } + return attachments; + } + + // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator} + public AttachmentFetchOptions withAttachmentsUsing(AttachmentFetchOptions fetchOptions) + { + return attachments = fetchOptions; + } + + // Method automatically generated with {@link ch.ethz.sis.openbis.generic.shared.api.v3.dto.generators.DtoGenerator} + public boolean hasAttachments() + { + return attachments != null; + } + } diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/generators/Generator.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/generators/Generator.java index efe67c84be1..21eb8c3c50e 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/generators/Generator.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/shared/api/v3/dto/generators/Generator.java @@ -339,6 +339,9 @@ public class Generator extends AbstractGenerator addRegistrator(gen); addModifier(gen); + gen.addFetchedField(Person.class, "leader", "Leader", PersonFetchOptions.class); + addAttachments(gen); + return gen; } -- GitLab