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 934a654783778fc01a45962e4d87b03ff7bbb0d7..16c6dc3685d9d381bfab8678f55ba10638a788ee 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 @@ -329,19 +329,24 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.search.SearchTagsOperationRe import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.search.TagSearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.update.TagUpdate; import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.update.UpdateTagsOperation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.Vocabulary; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.VocabularyTerm; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.create.CreateVocabularyTermsOperation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.create.CreateVocabularyTermsOperationResult; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.create.VocabularyTermCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.delete.DeleteVocabularyTermsOperation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.delete.VocabularyTermDeletionOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.fetchoptions.VocabularyFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.fetchoptions.VocabularyTermFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.get.GetVocabularyTermsOperation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.get.GetVocabularyTermsOperationResult; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.id.IVocabularyTermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.id.VocabularyTermPermId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.SearchVocabulariesOperation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.SearchVocabulariesOperationResult; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.SearchVocabularyTermsOperation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.SearchVocabularyTermsOperationResult; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.VocabularySearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.VocabularyTermSearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.update.UpdateVocabularyTermsOperation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.update.VocabularyTermUpdate; @@ -857,6 +862,15 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> return result.getSearchResult(); } + @Override + @Transactional(readOnly = true) + public SearchResult<Vocabulary> searchVocabularies(String sessionToken, VocabularySearchCriteria searchCriteria, + VocabularyFetchOptions fetchOptions) + { + SearchVocabulariesOperationResult result = executeOperation(sessionToken, new SearchVocabulariesOperation(searchCriteria, fetchOptions)); + return result.getSearchResult(); + } + @Override @Transactional(readOnly = true) public SearchResult<VocabularyTerm> searchVocabularyTerms(String sessionToken, VocabularyTermSearchCriteria searchCriteria, @@ -885,6 +899,7 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> } @Override + @Transactional(readOnly = true) public SearchResult<RoleAssignment> searchRoleAssignments(String sessionToken, RoleAssignmentSearchCriteria searchCriteria, RoleAssignmentFetchOptions fetchOptions) { @@ -893,6 +908,7 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi> } @Override + @Transactional(readOnly = true) public SearchResult<Person> searchPersons(String sessionToken, PersonSearchCriteria searchCriteria, PersonFetchOptions fetchOptions) { SearchPersonsOperationResult result = executeOperation(sessionToken, new SearchPersonsOperation(searchCriteria, fetchOptions)); 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 6c575998cb7d967955322df9289c44496c19c8c4..6ccb34ef19a76a99f669a9186718047c7b365642 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 @@ -174,12 +174,15 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.id.ITagId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.id.TagPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.search.TagSearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.update.TagUpdate; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.Vocabulary; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.VocabularyTerm; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.create.VocabularyTermCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.delete.VocabularyTermDeletionOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.fetchoptions.VocabularyFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.fetchoptions.VocabularyTermFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.id.IVocabularyTermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.id.VocabularyTermPermId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.VocabularySearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.VocabularyTermSearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.update.VocabularyTermUpdate; import ch.ethz.sis.openbis.generic.asapi.v3.dto.webapp.WebAppSettings; @@ -621,6 +624,14 @@ public class ApplicationServerApiLogger extends AbstractServerLogger implements return null; } + @Override + public SearchResult<Vocabulary> searchVocabularies(String sessionToken, VocabularySearchCriteria searchCriteria, + VocabularyFetchOptions fetchOptions) + { + logAccess(sessionToken, "search-vocabularies", "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/operation/OperationsExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/operation/OperationsExecutor.java index 799d10989e0ffdfaaaf1df8670d489ea5dbb4ea8..6f751e3f4fc74737da030433705f896472241937 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/operation/OperationsExecutor.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/operation/OperationsExecutor.java @@ -123,6 +123,7 @@ import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.tag.IUpdateTagsOpera import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.vocabulary.ICreateVocabularyTermsOperationExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.vocabulary.IDeleteVocabularyTermsOperationExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.vocabulary.IGetVocabularyTermsOperationExecutor; +import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.vocabulary.ISearchVocabulariesOperationExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.vocabulary.ISearchVocabularyTermsOperationExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.vocabulary.IUpdateVocabularyTermsOperationExecutor; import ch.ethz.sis.openbis.generic.server.asapi.v3.utils.ExceptionUtils; @@ -371,6 +372,9 @@ public class OperationsExecutor implements IOperationsExecutor @Autowired private ISearchExternalDmsOperationExecutor searchExternalDmsExecutor; + @Autowired + private ISearchVocabulariesOperationExecutor searchVocabulariesExecutor; + @Autowired private ISearchVocabularyTermsOperationExecutor searchVocabularyTermsExecutor; @@ -493,6 +497,7 @@ public class OperationsExecutor implements IOperationsExecutor resultMap.putAll(searchRoleAssignmentsExecutor.execute(context, operations)); resultMap.putAll(searchPersonsExecutor.execute(context, operations)); resultMap.putAll(searchExternalDmsExecutor.execute(context, operations)); + resultMap.putAll(searchVocabulariesExecutor.execute(context, operations)); resultMap.putAll(searchVocabularyTermsExecutor.execute(context, operations)); resultMap.putAll(searchExperimentTypesExecutor.execute(context, operations)); resultMap.putAll(searchSampleTypesExecutor.execute(context, operations)); diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/vocabulary/ISearchVocabulariesOperationExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/vocabulary/ISearchVocabulariesOperationExecutor.java new file mode 100644 index 0000000000000000000000000000000000000000..7189f1526df03e6846a168d70deb2df8531c7091 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/vocabulary/ISearchVocabulariesOperationExecutor.java @@ -0,0 +1,29 @@ +/* + * Copyright 2018 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.vocabulary; + +import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.common.search.ISearchObjectsOperationExecutor; + +/** + * + * + * @author Franz-Josef Elmer + */ +public interface ISearchVocabulariesOperationExecutor extends ISearchObjectsOperationExecutor +{ + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/vocabulary/SearchVocabulariesOperationExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/vocabulary/SearchVocabulariesOperationExecutor.java new file mode 100644 index 0000000000000000000000000000000000000000..6a4580273978e1cdb3fbe0ef5412343f43194672 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/vocabulary/SearchVocabulariesOperationExecutor.java @@ -0,0 +1,76 @@ +/* + * Copyright 2018 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.vocabulary; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchObjectsOperation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchObjectsOperationResult; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchResult; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.Vocabulary; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.fetchoptions.VocabularyFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.SearchVocabulariesOperation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.SearchVocabulariesOperationResult; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.VocabularySearchCriteria; +import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.common.search.ISearchObjectExecutor; +import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.common.search.SearchObjectsPEOperationExecutor; +import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.ITranslator; +import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.vocabulary.IVocabularyTranslator; +import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE; + +/** + * + * + * @author Franz-Josef Elmer + */ +@Component +public class SearchVocabulariesOperationExecutor + extends SearchObjectsPEOperationExecutor<Vocabulary, VocabularyPE, VocabularySearchCriteria, VocabularyFetchOptions> + implements ISearchVocabulariesOperationExecutor +{ + @Autowired + private ISearchVocabularyExecutor searchExecutor; + + @Autowired + private IVocabularyTranslator translator; + + @Override + protected Class<? extends SearchObjectsOperation<VocabularySearchCriteria, VocabularyFetchOptions>> getOperationClass() + { + return SearchVocabulariesOperation.class; + } + + @Override + protected ISearchObjectExecutor<VocabularySearchCriteria, VocabularyPE> getExecutor() + { + return searchExecutor; + } + + @Override + protected ITranslator<Long, Vocabulary, VocabularyFetchOptions> getTranslator() + { + return translator; + } + + @Override + protected SearchObjectsOperationResult<Vocabulary> getOperationResult(SearchResult<Vocabulary> searchResult) + { + return new SearchVocabulariesOperationResult(searchResult); + } + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/IVocabularyVocabularyTermTranslator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/IVocabularyVocabularyTermTranslator.java new file mode 100644 index 0000000000000000000000000000000000000000..4a527b064cf5762f2fc8c2c8aaebc8f2382a5b10 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/IVocabularyVocabularyTermTranslator.java @@ -0,0 +1,31 @@ +/* + * Copyright 2018 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.translator.vocabulary; + +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.VocabularyTerm; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.fetchoptions.VocabularyTermFetchOptions; +import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.common.IObjectToManyRelationTranslator; + +/** + * + * + * @author Franz-Josef Elmer + */ +public interface IVocabularyVocabularyTermTranslator extends IObjectToManyRelationTranslator<VocabularyTerm, VocabularyTermFetchOptions> +{ + +} diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/VocabularyQuery.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/VocabularyQuery.java index 90072191ba12f2aa0b71e21f22001b0d59ef8a67..051fc8ffb6e50bc612f2204876cb30e7bed03751 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/VocabularyQuery.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/VocabularyQuery.java @@ -16,6 +16,7 @@ package ch.ethz.sis.openbis.generic.server.asapi.v3.translator.vocabulary; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.longs.LongSet; import java.util.List; @@ -53,4 +54,8 @@ public interface VocabularyQuery extends ObjectQuery + "from controlled_vocabulary_terms t where t.id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE) public List<ObjectRelationRecord> getTermVocabularyIds(LongSet termIds); + @Select(sql = "select covo_id as objectId, id as relatedId from controlled_vocabulary_terms where covo_id = any(?{1})", + parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE) + public List<ObjectRelationRecord> getTermsIds(LongOpenHashSet vocabularyIds); + } diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/VocabularyTranslator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/VocabularyTranslator.java index 60ed190f1d73b0dbac9d6aad42818760ae4e2b23..58c1402f628df578cb4bf4c5ebcf9bf49b7e3516 100644 --- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/VocabularyTranslator.java +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/VocabularyTranslator.java @@ -17,11 +17,13 @@ package ch.ethz.sis.openbis.generic.server.asapi.v3.translator.vocabulary; import java.util.Collection; +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.vocabulary.Vocabulary; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.VocabularyTerm; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.fetchoptions.VocabularyFetchOptions; import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.AbstractCachingTranslator; import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.TranslationContext; @@ -40,6 +42,9 @@ public class VocabularyTranslator extends AbstractCachingTranslator<Long, Vocabu @Autowired private IVocabularyRegistratorTranslator registratorTranslator; + + @Autowired + private IVocabularyVocabularyTermTranslator termTranslator; @Override protected Vocabulary createObject(TranslationContext context, Long vocabularyId, VocabularyFetchOptions fetchOptions) @@ -61,6 +66,10 @@ public class VocabularyTranslator extends AbstractCachingTranslator<Long, Vocabu relations.put(IVocabularyRegistratorTranslator.class, registratorTranslator.translate(context, vocabularyIds, fetchOptions.withRegistrator())); } + if (fetchOptions.hasTerms()) + { + relations.put(IVocabularyVocabularyTermTranslator.class, termTranslator.translate(context, vocabularyIds, fetchOptions.withTerms())); + } return relations; } @@ -82,7 +91,11 @@ public class VocabularyTranslator extends AbstractCachingTranslator<Long, Vocabu result.setRegistrator(relations.get(IVocabularyRegistratorTranslator.class, vocabularyId)); result.getFetchOptions().withRegistratorUsing(fetchOptions.withRegistrator()); } - + if (fetchOptions.hasTerms()) + { + result.setTerms((List<VocabularyTerm>) relations.get(IVocabularyVocabularyTermTranslator.class, vocabularyId)); + result.getFetchOptions().withTermsUsing(fetchOptions.withTerms()); + } } } diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/VocabularyVocabularyTermTranslator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/VocabularyVocabularyTermTranslator.java new file mode 100644 index 0000000000000000000000000000000000000000..457dd8f5c06faa79996e1d313408080757fcc696 --- /dev/null +++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/vocabulary/VocabularyVocabularyTermTranslator.java @@ -0,0 +1,69 @@ +/* + * Copyright 2018 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.translator.vocabulary; + +import java.util.ArrayList; +import java.util.Collection; +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.asapi.v3.dto.vocabulary.VocabularyTerm; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.fetchoptions.VocabularyTermFetchOptions; +import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.TranslationContext; +import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.common.ObjectRelationRecord; +import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.common.ObjectToManyRelationTranslator; + +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import net.lemnik.eodsql.QueryTool; + +/** + * + * + * @author Franz-Josef Elmer + */ +@Component +public class VocabularyVocabularyTermTranslator + extends ObjectToManyRelationTranslator<VocabularyTerm, VocabularyTermFetchOptions> + implements IVocabularyVocabularyTermTranslator +{ + @Autowired + private IVocabularyTermTranslator termTranslator; + + @Override + protected List<ObjectRelationRecord> loadRecords(LongOpenHashSet vocabularyIds) + { + VocabularyQuery query = QueryTool.getManagedQuery(VocabularyQuery.class); + return query.getTermsIds(vocabularyIds); + } + + @Override + protected Map<Long, VocabularyTerm> translateRelated(TranslationContext context, Collection<Long> relatedIds, + VocabularyTermFetchOptions relatedFetchOptions) + { + return termTranslator.translate(context, relatedIds, relatedFetchOptions); + } + + @Override + protected Collection<VocabularyTerm> createCollection() + { + return new ArrayList<VocabularyTerm>(); + } + +} diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchVocabularyTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchVocabularyTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e893ba0acfcb6926de57c797be394a3aa1cd5680 --- /dev/null +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchVocabularyTest.java @@ -0,0 +1,72 @@ +/* + * Copyright 2018 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.List; + +import org.testng.annotations.Test; + +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.Vocabulary; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.fetchoptions.VocabularyFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.VocabularySearchCriteria; + +/** + * @author Franz-Josef Elmer + */ +public class SearchVocabularyTest extends AbstractTest +{ + @Test + public void testWithoutFetchingTerms() + { + // Given + String sessionToken = v3api.login(TEST_USER, PASSWORD); + VocabularySearchCriteria criteria = new VocabularySearchCriteria(); + criteria.withCode().thatContains("GANI"); + + // When + List<Vocabulary> vocabularies = + v3api.searchVocabularies(sessionToken, criteria, new VocabularyFetchOptions()).getObjects(); + + // Then + assertEquals(vocabularies.get(0).getCode(), "ORGANISM"); + assertEquals(vocabularies.get(0).getDescription(), "available-organism"); + } + + @Test + public void testWithFetchingTerms() + { + // Given + String sessionToken = v3api.login(TEST_USER, PASSWORD); + VocabularySearchCriteria criteria = new VocabularySearchCriteria(); + criteria.withCode().thatContains("GANI"); + VocabularyFetchOptions fetchOptions = new VocabularyFetchOptions(); + fetchOptions.withTerms(); + + // When + List<Vocabulary> vocabularies = + v3api.searchVocabularies(sessionToken, criteria, fetchOptions).getObjects(); + + // Then + assertEquals(vocabularies.get(0).getCode(), "ORGANISM"); + assertEquals(vocabularies.get(0).getDescription(), "available-organism"); + assertEquals(vocabularies.get(0).getTerms().toString(), + "[VocabularyTerm DOG, VocabularyTerm FLY, VocabularyTerm GORILLA, VocabularyTerm HUMAN, VocabularyTerm RAT]"); + assertEquals(vocabularies.size(), 1); + } +} 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 b04139c58e72f52c364b10ed718dde2eebf9a8f2..c903dfe09a430a31f30c03d2d8cc59d1d54dd937 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 @@ -173,12 +173,15 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.id.ITagId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.id.TagPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.search.TagSearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.update.TagUpdate; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.Vocabulary; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.VocabularyTerm; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.create.VocabularyTermCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.delete.VocabularyTermDeletionOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.fetchoptions.VocabularyFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.fetchoptions.VocabularyTermFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.id.IVocabularyTermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.id.VocabularyTermPermId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.VocabularySearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.search.VocabularyTermSearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.update.VocabularyTermUpdate; import ch.ethz.sis.openbis.generic.asapi.v3.dto.webapp.WebAppSettings; @@ -350,9 +353,12 @@ public interface IApplicationServerApi extends IRpcService public SearchResult<MaterialType> searchMaterialTypes(String sessionToken, MaterialTypeSearchCriteria searchCriteria, MaterialTypeFetchOptions fetchOptions); + public SearchResult<Vocabulary> searchVocabularies(String sessionToken, VocabularySearchCriteria searchCriteria, + VocabularyFetchOptions fetchOptions); + public SearchResult<VocabularyTerm> searchVocabularyTerms(String sessionToken, VocabularyTermSearchCriteria searchCriteria, VocabularyTermFetchOptions fetchOptions); - + public SearchResult<Tag> searchTags(String sessionToken, TagSearchCriteria searchCriteria, TagFetchOptions fetchOptions); public SearchResult<AuthorizationGroup> searchAuthorizationGroups(String sessionToken, AuthorizationGroupSearchCriteria searchCriteria, AuthorizationGroupFetchOptions fetchOptions); diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/Vocabulary.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/Vocabulary.java index 5a60dae4f02a73aac7f8d5447a7a03d6679e394e..8253f51376991cc7568c69b49182d93fddb402c3 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/Vocabulary.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/Vocabulary.java @@ -28,6 +28,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import java.io.Serializable; import java.util.Date; +import java.util.List; /* * Class automatically generated with DtoGenerator @@ -54,6 +55,9 @@ public class Vocabulary implements Serializable, ICodeHolder, IDescriptionHolder @JsonProperty private Date modificationDate; + + @JsonProperty + private List<VocabularyTerm> terms; // Method automatically generated with DtoGenerator @JsonIgnore @@ -145,6 +149,20 @@ public class Vocabulary implements Serializable, ICodeHolder, IDescriptionHolder this.modificationDate = modificationDate; } + public List<VocabularyTerm> getTerms() + { + if (getFetchOptions() != null && getFetchOptions().hasTerms()) + { + return terms; + } + throw new NotFetchedException("Terms have not been fetched."); + } + + public void setTerms(List<VocabularyTerm> terms) + { + this.terms = terms; + } + // Method automatically generated with DtoGenerator @Override public String toString() diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/fetchoptions/VocabularyFetchOptions.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/fetchoptions/VocabularyFetchOptions.java index 855b4eebc24411985a20b13965e74b4a025cd951..f0b6f4226ac9979fcd89ca9a3f3446ed0a0c6015 100644 --- a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/fetchoptions/VocabularyFetchOptions.java +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/fetchoptions/VocabularyFetchOptions.java @@ -33,6 +33,9 @@ public class VocabularyFetchOptions extends FetchOptions<Vocabulary> implements @JsonProperty private PersonFetchOptions registrator; + + @JsonProperty + private VocabularyTermFetchOptions terms; @JsonProperty private VocabularySortOptions sort; @@ -58,6 +61,25 @@ public class VocabularyFetchOptions extends FetchOptions<Vocabulary> implements { return registrator != null; } + + public VocabularyTermFetchOptions withTerms() + { + if (terms == null) + { + terms = new VocabularyTermFetchOptions(); + } + return terms; + } + + public VocabularyTermFetchOptions withTermsUsing(VocabularyTermFetchOptions fetchOptions) + { + return terms = fetchOptions; + } + + public boolean hasTerms() + { + return terms != null; + } // Method automatically generated with DtoGenerator @Override diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/search/SearchVocabulariesOperation.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/search/SearchVocabulariesOperation.java new file mode 100644 index 0000000000000000000000000000000000000000..411d8deda89830264ba56da1bb2df14c3fec10a7 --- /dev/null +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/search/SearchVocabulariesOperation.java @@ -0,0 +1,44 @@ +/* + * Copyright 2018 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.asapi.v3.dto.vocabulary.search; + +import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchObjectsOperation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.fetchoptions.VocabularyFetchOptions; +import ch.systemsx.cisd.base.annotation.JsonObject; + +/** + * + * + * @author Franz-Josef Elmer + */ +@JsonObject("as.dto.vocabulary.search.SearchVocabulariesOperation") +public class SearchVocabulariesOperation extends SearchObjectsOperation<VocabularySearchCriteria, VocabularyFetchOptions> +{ + + private static final long serialVersionUID = 1L; + + @SuppressWarnings("unused") + private SearchVocabulariesOperation() + { + } + + public SearchVocabulariesOperation(VocabularySearchCriteria criteria, VocabularyFetchOptions fetchOptions) + { + super(criteria, fetchOptions); + } + +} diff --git a/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/search/SearchVocabulariesOperationResult.java b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/search/SearchVocabulariesOperationResult.java new file mode 100644 index 0000000000000000000000000000000000000000..4265aaabe93db70ad1c28899033f44e898da73e6 --- /dev/null +++ b/openbis_api/source/java/ch/ethz/sis/openbis/generic/asapi/v3/dto/vocabulary/search/SearchVocabulariesOperationResult.java @@ -0,0 +1,45 @@ +/* + * Copyright 2018 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.asapi.v3.dto.vocabulary.search; + +import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchObjectsOperationResult; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.SearchResult; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.Vocabulary; +import ch.systemsx.cisd.base.annotation.JsonObject; + +/** + * + * + * @author Franz-Josef Elmer + */ +@JsonObject("as.dto.vocabulary.search.SearchVocabulariesOperationResult") +public class SearchVocabulariesOperationResult extends SearchObjectsOperationResult<Vocabulary> +{ + + private static final long serialVersionUID = 1L; + + @SuppressWarnings("unused") + private SearchVocabulariesOperationResult() + { + } + + public SearchVocabulariesOperationResult(SearchResult<Vocabulary> searchResult) + { + super(searchResult); + } + +} diff --git a/openbis_api/sourceTest/java/ch/ethz/sis/openbis/generic/sharedapi/v3/dictionary.txt b/openbis_api/sourceTest/java/ch/ethz/sis/openbis/generic/sharedapi/v3/dictionary.txt index 6aed9e65cc4da8bcb2328baccde29808b7a01755..7957a4bd4ed2b9b9277fa13714c23e5efe58267f 100644 --- a/openbis_api/sourceTest/java/ch/ethz/sis/openbis/generic/sharedapi/v3/dictionary.txt +++ b/openbis_api/sourceTest/java/ch/ethz/sis/openbis/generic/sharedapi/v3/dictionary.txt @@ -1842,3 +1842,13 @@ delete Entity Types Delete Entity Types Operation Delete Entity Types Operation Result Entity Type Deletion Options + +get Terms +has Terms +search Vocabularies +Search Vocabularies Operation +Search Vocabularies Operation Result +set Terms +with Terms +with Terms Using +