From 11febb71def139d9d33d1ff7c0951c53f593274d Mon Sep 17 00:00:00 2001 From: jakubs <jakubs> Date: Mon, 12 Nov 2012 12:32:04 +0000 Subject: [PATCH] BIS-226 SP-341 add checking if there is a term in vocabulary SVN: 27571 --- .../etlserver/registrator/api/v1/IVocabulary.java | 2 -- .../registrator/api/v1/impl/Vocabulary.java | 15 +++++++++++++-- .../api/v1/impl/VocabularyImmutable.java | 14 ++++++++++++-- .../api/internal/v1/IVocabularyImmutable.java | 6 +++++- .../vocabularies-api/vocabularies-api.py | 6 ++++++ 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IVocabulary.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IVocabulary.java index 4299b3fc1b8..564ec7eda5b 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IVocabulary.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/IVocabulary.java @@ -19,8 +19,6 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1; import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v1.IVocabularyImmutable; /** - * - * * @author Jakub Straszewski */ public interface IVocabulary extends IVocabularyImmutable diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/Vocabulary.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/Vocabulary.java index 895d228d99a..c082986799d 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/Vocabulary.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/Vocabulary.java @@ -16,15 +16,15 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1.impl; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import ch.systemsx.cisd.etlserver.registrator.api.v1.IVocabulary; import ch.systemsx.cisd.etlserver.registrator.api.v1.IVocabularyTerm; +import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v1.IVocabularyTermImmutable; /** - * - * * @author Jakub Straszewski */ public class Vocabulary extends VocabularyImmutable implements IVocabulary @@ -79,4 +79,15 @@ public class Vocabulary extends VocabularyImmutable implements IVocabulary return newTerms; } + @Override + public List<IVocabularyTermImmutable> getTerms() + { + List<IVocabularyTermImmutable> results = super.getTerms(); + for (IVocabularyTerm term : newTerms) + { + results.add(term); + } + return Collections.unmodifiableList(results); + } + } diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/VocabularyImmutable.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/VocabularyImmutable.java index a780f4a219b..fbdafb4c159 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/VocabularyImmutable.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v1/impl/VocabularyImmutable.java @@ -25,8 +25,6 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Vocabulary; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm; /** - * - * * @author Jakub Straszewski */ public class VocabularyImmutable implements IVocabularyImmutable @@ -92,4 +90,16 @@ public class VocabularyImmutable implements IVocabularyImmutable return results; } + @Override + public boolean containsTerm(String code) + { + for (IVocabularyTermImmutable term : getTerms()) + { + if (term.getCode().equals(code)) + { + return true; + } + } + return false; + } } diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/internal/v1/IVocabularyImmutable.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/internal/v1/IVocabularyImmutable.java index a0aa73c9d23..c2cc8d101a7 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/internal/v1/IVocabularyImmutable.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/api/internal/v1/IVocabularyImmutable.java @@ -20,7 +20,7 @@ import java.util.List; /** * Read-only interface to a vocabulary. - * + * * @author Jakub Straszewski */ public interface IVocabularyImmutable @@ -59,4 +59,8 @@ public interface IVocabularyImmutable */ List<IVocabularyTermImmutable> getTerms(); + /** + * Check if there is a term with given code in this vocabulary. + */ + boolean containsTerm(String code); } diff --git a/datastore_server/sourceTest/core-plugins/generic-test/1/dss/drop-boxes/vocabularies-api/vocabularies-api.py b/datastore_server/sourceTest/core-plugins/generic-test/1/dss/drop-boxes/vocabularies-api/vocabularies-api.py index 963cc762fbf..70529a66d26 100644 --- a/datastore_server/sourceTest/core-plugins/generic-test/1/dss/drop-boxes/vocabularies-api/vocabularies-api.py +++ b/datastore_server/sourceTest/core-plugins/generic-test/1/dss/drop-boxes/vocabularies-api/vocabularies-api.py @@ -39,7 +39,13 @@ def process(transaction): vocabularyTerm.setDescription("new description") vocabularyTerm.setLabel("new label") + if vocabulary.containsTerm("NEW_TERM"): + raise Exception("Assertion failure: the NEW_TERM has not been yet added to the vocabulary") + vocabulary.addTerm(vocabularyTerm) + if not vocabulary.containsTerm("NEW_TERM"): + raise Exception("Assertion failure: the NEW_TERM has already been added to the vocabulary and should be seen") + sample = transaction.createNewSample("/VOC/NORMAL_NEW_TERM", "NORMAL") sample.setPropertyValue("TEST_VOCABULARY", vocabularyTerm.getCode()) \ No newline at end of file -- GitLab