From 060f21d7cf6a881783b4e4ea78aaae6070e457c7 Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Wed, 6 Apr 2016 08:03:39 +0000 Subject: [PATCH] SSDM-3401: searchMaterialTypes introduced, implemented and tested SVN: 36090 --- .../server/asapi/v3/ApplicationServerApi.java | 15 ++++ .../asapi/v3/ApplicationServerApiLogger.java | 10 +++ .../material/ISearchMaterialTypeExecutor.java | 31 ++++++++ .../material/SearchMaterialTypeExecutor.java | 37 +++++++++ .../ISearchMaterialTypeMethodExecutor.java | 31 ++++++++ .../SearchMaterialTypeSqlMethodExecutor.java | 59 ++++++++++++++ .../asapi/v3/SearchDataSetTypeTest.java | 1 - .../asapi/v3/SearchMaterialTypeTest.java | 79 +++++++++++++++++++ .../asapi/v3/IApplicationServerApi.java | 4 + 9 files changed, 266 insertions(+), 1 deletion(-) create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/material/ISearchMaterialTypeExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/material/SearchMaterialTypeExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/ISearchMaterialTypeMethodExecutor.java create mode 100644 openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/SearchMaterialTypeSqlMethodExecutor.java create mode 100644 openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchMaterialTypeTest.java diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApi.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApi.java index 4a49d72c106..4ea7bbd7aa8 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApi.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApi.java @@ -54,9 +54,11 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.global.GlobalSearchObject; import ch.ethz.sis.openbis.generic.asapi.v3.dto.global.fetchoptions.GlobalSearchObjectFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.global.search.GlobalSearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.Material; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.MaterialType; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.create.MaterialCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.delete.MaterialDeletionOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.fetchoptions.MaterialFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.fetchoptions.MaterialTypeFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.id.IMaterialId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.id.MaterialPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.search.MaterialSearchCriteria; @@ -135,6 +137,7 @@ import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.ISearchDeleti import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.ISearchExperimentMethodExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.ISearchExperimentTypeMethodExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.ISearchMaterialMethodExecutor; +import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.ISearchMaterialTypeMethodExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.ISearchObjectKindModificationMethodExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.ISearchProjectMethodExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.method.ISearchSampleMethodExecutor; @@ -266,6 +269,9 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> @Autowired private ISearchMaterialMethodExecutor searchMaterialExecutor; + @Autowired + private ISearchMaterialTypeMethodExecutor searchMaterialTypeExecutor; + @Autowired private ISearchVocabularyTermMethodExecutor searchVocabularyTermExecutor; @@ -625,6 +631,15 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> return searchMaterialExecutor.search(sessionToken, searchCriteria, fetchOptions); } + @Override + @Transactional(readOnly = true) + @RolesAllowed({ RoleWithHierarchy.SPACE_OBSERVER, RoleWithHierarchy.SPACE_ETL_SERVER }) + public SearchResult<MaterialType> searchMaterialTypes(String sessionToken, EntityTypeSearchCriteria searchCriteria, + MaterialTypeFetchOptions fetchOptions) + { + return searchMaterialTypeExecutor.search(sessionToken, searchCriteria, 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/asapi/v3/ApplicationServerApiLogger.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApiLogger.java index 14bf5478759..3d53dc96541 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApiLogger.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/ApplicationServerApiLogger.java @@ -50,9 +50,11 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.global.GlobalSearchObject; import ch.ethz.sis.openbis.generic.asapi.v3.dto.global.fetchoptions.GlobalSearchObjectFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.global.search.GlobalSearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.Material; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.MaterialType; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.create.MaterialCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.delete.MaterialDeletionOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.fetchoptions.MaterialFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.fetchoptions.MaterialTypeFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.id.IMaterialId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.id.MaterialPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.search.MaterialSearchCriteria; @@ -356,6 +358,14 @@ public class ApplicationServerApiLogger extends AbstractServerLogger implements return null; } + @Override + public SearchResult<MaterialType> searchMaterialTypes(String sessionToken, EntityTypeSearchCriteria searchCriteria, + MaterialTypeFetchOptions fetchOptions) + { + logAccess(sessionToken, "search-material-types", "SEARCH_CRITERIA:\n%s\nFETCH_OPTIONS:\n%s\n", searchCriteria, fetchOptions); + return null; + } + @Override public SearchResult<VocabularyTerm> searchVocabularyTerms(String sessionToken, VocabularyTermSearchCriteria searchCriteria, VocabularyTermFetchOptions fetchOptions) diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/material/ISearchMaterialTypeExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/material/ISearchMaterialTypeExecutor.java new file mode 100644 index 00000000000..39709d2411a --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/material/ISearchMaterialTypeExecutor.java @@ -0,0 +1,31 @@ +/* + * Copyright 2016 ETH Zuerich, SIS + * + * 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.asapi.v3.executor.material; + +import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.search.EntityTypeSearchCriteria; +import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.common.ISearchObjectExecutor; +import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialTypePE; + +/** + * + * + * @author Franz-Josef Elmer + */ +public interface ISearchMaterialTypeExecutor extends ISearchObjectExecutor<EntityTypeSearchCriteria, MaterialTypePE> +{ + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/material/SearchMaterialTypeExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/material/SearchMaterialTypeExecutor.java new file mode 100644 index 00000000000..38c9f19dff5 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/material/SearchMaterialTypeExecutor.java @@ -0,0 +1,37 @@ +/* + * Copyright 2016 ETH Zuerich, SIS + * + * 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.asapi.v3.executor.material; + +import org.springframework.stereotype.Component; + +import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.entity.AbstractSearchEntityTypeExecutor; +import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialTypePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind; + +/** + * + * + * @author Franz-Josef Elmer + */ +@Component +public class SearchMaterialTypeExecutor extends AbstractSearchEntityTypeExecutor<MaterialTypePE> implements ISearchMaterialTypeExecutor +{ + public SearchMaterialTypeExecutor() + { + super(EntityKind.MATERIAL); + } +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/ISearchMaterialTypeMethodExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/ISearchMaterialTypeMethodExecutor.java new file mode 100644 index 00000000000..82f5db89a7c --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/ISearchMaterialTypeMethodExecutor.java @@ -0,0 +1,31 @@ +/* + * Copyright 2016 ETH Zuerich, SIS + * + * 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.asapi.v3.executor.method; + +import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.search.EntityTypeSearchCriteria; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.MaterialType; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.fetchoptions.MaterialTypeFetchOptions; + +/** + * + * + * @author Franz-Josef Elmer + */ +public interface ISearchMaterialTypeMethodExecutor extends ISearchMethodExecutor<MaterialType, EntityTypeSearchCriteria, MaterialTypeFetchOptions> +{ + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/SearchMaterialTypeSqlMethodExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/SearchMaterialTypeSqlMethodExecutor.java new file mode 100644 index 00000000000..f33cc4c8859 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/method/SearchMaterialTypeSqlMethodExecutor.java @@ -0,0 +1,59 @@ +/* + * Copyright 2016 ETH Zuerich, SIS + * + * 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.asapi.v3.executor.method; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.search.EntityTypeSearchCriteria; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.MaterialType; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.fetchoptions.MaterialTypeFetchOptions; +import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.IOperationContext; +import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.material.ISearchMaterialTypeExecutor; +import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.ITranslator; +import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.entity.material.IMaterialTypeTranslator; +import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialTypePE; + +/** + * + * @author Franz-Josef Elmer + */ +@Component +public class SearchMaterialTypeSqlMethodExecutor extends AbstractIdSearchMethodExecutor<MaterialType, MaterialTypePE, EntityTypeSearchCriteria, MaterialTypeFetchOptions> + implements ISearchMaterialTypeMethodExecutor +{ + @Autowired + private ISearchMaterialTypeExecutor searchExecutor; + + @Autowired + private IMaterialTypeTranslator translator; + + @Override + protected List<MaterialTypePE> searchPEs(IOperationContext context, EntityTypeSearchCriteria criteria) + { + return searchExecutor.search(context, criteria); + } + + @Override + protected ITranslator<Long, MaterialType, MaterialTypeFetchOptions> getTranslator() + { + return translator; + } + +} diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchDataSetTypeTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchDataSetTypeTest.java index c2506ae6158..0e4a8fb4ab8 100644 --- a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchDataSetTypeTest.java +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchDataSetTypeTest.java @@ -72,7 +72,6 @@ public class SearchDataSetTypeTest extends AbstractTest assertEquals(codes.toString(), "[DELETION_TEST, DELETION_TEST_CONTAINER]"); assertEquals(types.get(0).getFetchOptions().hasPropertyAssignments(), true); List<PropertyAssignment> propertyAssignments = types.get(0).getPropertyAssignments(); - System.err.println(propertyAssignments.get(0).getPropertyType()); assertOrder(propertyAssignments, "ORGANISM", "DESCRIPTION", "BACTERIUM"); v3api.logout(sessionToken); } diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchMaterialTypeTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchMaterialTypeTest.java new file mode 100644 index 00000000000..6fc9d3c7e91 --- /dev/null +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchMaterialTypeTest.java @@ -0,0 +1,79 @@ +/* + * Copyright 2016 ETH Zuerich, SIS + * + * 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.asapi.v3; + +import static org.testng.Assert.assertEquals; + +import java.util.Collections; +import java.util.List; + +import org.testng.annotations.Test; + +import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchResult; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.search.EntityTypeSearchCriteria; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.MaterialType; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.fetchoptions.MaterialTypeFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment; +import ch.ethz.sis.openbis.generic.server.asapi.v3.helper.sort.CodeComparator; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class SearchMaterialTypeTest extends AbstractTest +{ + @Test + public void testSearchWithCodeThatStartsWithB() + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + EntityTypeSearchCriteria searchCriteria = new EntityTypeSearchCriteria(); + searchCriteria.withCode().thatStartsWith("B"); + MaterialTypeFetchOptions fetchOptions = new MaterialTypeFetchOptions(); + + SearchResult<MaterialType> searchResult = v3api.searchMaterialTypes(sessionToken, searchCriteria, fetchOptions); + + List<MaterialType> types = searchResult.getObjects(); + List<String> codes = extractCodes(types); + Collections.sort(codes); + assertEquals(codes.toString(), "[BACTERIUM]"); + assertEquals(types.get(0).getFetchOptions().hasPropertyAssignments(), false); + v3api.logout(sessionToken); + } + + @Test + public void testSearchWithPropertyAssignmentSortByLabelDesc() + { + String sessionToken = v3api.login(TEST_USER, PASSWORD); + EntityTypeSearchCriteria searchCriteria = new EntityTypeSearchCriteria(); + searchCriteria.withCode().thatStartsWith("B"); + MaterialTypeFetchOptions fetchOptions = new MaterialTypeFetchOptions(); + fetchOptions.withPropertyAssignments().sortBy().label().desc(); + + SearchResult<MaterialType> searchResult = v3api.searchMaterialTypes(sessionToken, searchCriteria, fetchOptions); + + List<MaterialType> types = searchResult.getObjects(); + Collections.sort(types, new CodeComparator<MaterialType>()); + List<String> codes = extractCodes(types); + assertEquals(codes.toString(), "[BACTERIUM]"); + assertEquals(types.get(0).getFetchOptions().hasPropertyAssignments(), true); + List<PropertyAssignment> propertyAssignments = types.get(0).getPropertyAssignments(); + assertOrder(propertyAssignments, "ORGANISM", "DESCRIPTION"); + v3api.logout(sessionToken); + } + +} diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/IApplicationServerApi.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/IApplicationServerApi.java index d89d93b6499..97d03e4edf2 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/IApplicationServerApi.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/IApplicationServerApi.java @@ -49,9 +49,11 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.global.GlobalSearchObject; import ch.ethz.sis.openbis.generic.asapi.v3.dto.global.fetchoptions.GlobalSearchObjectFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.global.search.GlobalSearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.Material; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.MaterialType; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.create.MaterialCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.delete.MaterialDeletionOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.fetchoptions.MaterialFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.fetchoptions.MaterialTypeFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.id.IMaterialId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.id.MaterialPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.search.MaterialSearchCriteria; @@ -190,6 +192,8 @@ public interface IApplicationServerApi extends IRpcService public SearchResult<Material> searchMaterials(String sessionToken, MaterialSearchCriteria searchCriteria, MaterialFetchOptions fetchOptions); + public SearchResult<MaterialType> searchMaterialTypes(String sessionToken, EntityTypeSearchCriteria searchCriteria, MaterialTypeFetchOptions fetchOptions); + public SearchResult<VocabularyTerm> searchVocabularyTerms(String sessionToken, VocabularyTermSearchCriteria searchCriteria, VocabularyTermFetchOptions fetchOptions); -- GitLab