Skip to content
Snippets Groups Projects
Commit 11febb71 authored by jakubs's avatar jakubs
Browse files

BIS-226 SP-341 add checking if there is a term in vocabulary

SVN: 27571
parent e9551a16
No related branches found
No related tags found
No related merge requests found
...@@ -19,8 +19,6 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1; ...@@ -19,8 +19,6 @@ package ch.systemsx.cisd.etlserver.registrator.api.v1;
import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v1.IVocabularyImmutable; import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v1.IVocabularyImmutable;
/** /**
*
*
* @author Jakub Straszewski * @author Jakub Straszewski
*/ */
public interface IVocabulary extends IVocabularyImmutable public interface IVocabulary extends IVocabularyImmutable
......
...@@ -16,15 +16,15 @@ ...@@ -16,15 +16,15 @@
package ch.systemsx.cisd.etlserver.registrator.api.v1.impl; package ch.systemsx.cisd.etlserver.registrator.api.v1.impl;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IVocabulary; import ch.systemsx.cisd.etlserver.registrator.api.v1.IVocabulary;
import ch.systemsx.cisd.etlserver.registrator.api.v1.IVocabularyTerm; import ch.systemsx.cisd.etlserver.registrator.api.v1.IVocabularyTerm;
import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v1.IVocabularyTermImmutable;
/** /**
*
*
* @author Jakub Straszewski * @author Jakub Straszewski
*/ */
public class Vocabulary extends VocabularyImmutable implements IVocabulary public class Vocabulary extends VocabularyImmutable implements IVocabulary
...@@ -79,4 +79,15 @@ public class Vocabulary extends VocabularyImmutable implements IVocabulary ...@@ -79,4 +79,15 @@ public class Vocabulary extends VocabularyImmutable implements IVocabulary
return newTerms; return newTerms;
} }
@Override
public List<IVocabularyTermImmutable> getTerms()
{
List<IVocabularyTermImmutable> results = super.getTerms();
for (IVocabularyTerm term : newTerms)
{
results.add(term);
}
return Collections.unmodifiableList(results);
}
} }
...@@ -25,8 +25,6 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Vocabulary; ...@@ -25,8 +25,6 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Vocabulary;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm;
/** /**
*
*
* @author Jakub Straszewski * @author Jakub Straszewski
*/ */
public class VocabularyImmutable implements IVocabularyImmutable public class VocabularyImmutable implements IVocabularyImmutable
...@@ -92,4 +90,16 @@ public class VocabularyImmutable implements IVocabularyImmutable ...@@ -92,4 +90,16 @@ public class VocabularyImmutable implements IVocabularyImmutable
return results; return results;
} }
@Override
public boolean containsTerm(String code)
{
for (IVocabularyTermImmutable term : getTerms())
{
if (term.getCode().equals(code))
{
return true;
}
}
return false;
}
} }
...@@ -20,7 +20,7 @@ import java.util.List; ...@@ -20,7 +20,7 @@ import java.util.List;
/** /**
* Read-only interface to a vocabulary. * Read-only interface to a vocabulary.
* *
* @author Jakub Straszewski * @author Jakub Straszewski
*/ */
public interface IVocabularyImmutable public interface IVocabularyImmutable
...@@ -59,4 +59,8 @@ public interface IVocabularyImmutable ...@@ -59,4 +59,8 @@ public interface IVocabularyImmutable
*/ */
List<IVocabularyTermImmutable> getTerms(); List<IVocabularyTermImmutable> getTerms();
/**
* Check if there is a term with given code in this vocabulary.
*/
boolean containsTerm(String code);
} }
...@@ -39,7 +39,13 @@ def process(transaction): ...@@ -39,7 +39,13 @@ def process(transaction):
vocabularyTerm.setDescription("new description") vocabularyTerm.setDescription("new description")
vocabularyTerm.setLabel("new label") 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) 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 = transaction.createNewSample("/VOC/NORMAL_NEW_TERM", "NORMAL")
sample.setPropertyValue("TEST_VOCABULARY", vocabularyTerm.getCode()) sample.setPropertyValue("TEST_VOCABULARY", vocabularyTerm.getCode())
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment