Skip to content
Snippets Groups Projects
Commit f8ffa7c3 authored by felmer's avatar felmer
Browse files

SP-351, BIS-235: IMasterDataRegistrationTransaction.addVocabularyTermTo()...

SP-351, BIS-235: IMasterDataRegistrationTransaction.addVocabularyTermTo() removed. Logic of implementation is moved to VocabularyWrapper.addTerm(). Example term added to vocabulary TREATMENT_TYPE in core plugin 'proteomics-optional'.

SVN: 28445
parent 85827eee
No related branches found
No related tags found
No related merge requests found
......@@ -265,11 +265,6 @@ public interface IMasterDataRegistrationTransaction
*/
IVocabularyTerm createNewVocabularyTerm(String code);
/**
* Adds the specified vocabulary term to the specified vocabulary.
*/
void addVocabularyTermTo(IVocabularyImmutable vocabulary, IVocabularyTerm term);
/**
* Returns the vocabulary term with specified code from the specified vocabulary.
*
......
......@@ -418,24 +418,6 @@ public class MasterDataRegistrationTransaction implements IMasterDataRegistratio
return vocabulary;
}
@Override
public void addVocabularyTermTo(IVocabularyImmutable vocabulary, IVocabularyTerm term)
{
if (vocabulary instanceof Vocabulary)
{
((Vocabulary) vocabulary).addTerm(term);
return;
}
Long id = ((VocabularyImmutable) vocabulary).getVocabulary().getId();
List<VocabularyTerm> terms = createdVocabularyTerms.get(id);
if (terms == null)
{
terms = new ArrayList<VocabularyTerm>();
createdVocabularyTerms.put(id, terms);
}
terms.add((VocabularyTerm) term);
}
@Override
public IVocabularyTerm getVocabularyTerm(IVocabularyImmutable vocabulary,
String vocabularyTermCode)
......@@ -474,7 +456,7 @@ public class MasterDataRegistrationTransaction implements IMasterDataRegistratio
IVocabularyImmutable vocabulary = getVocabulary(code);
if (vocabulary != null)
{
return new VocabularyWrapper((VocabularyImmutable) vocabulary);
return new VocabularyWrapper((VocabularyImmutable) vocabulary, createdVocabularyTerms);
}
return createNewVocabulary(code);
}
......
......@@ -16,6 +16,10 @@
package ch.systemsx.cisd.openbis.generic.server.jython.api.v1.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import ch.systemsx.cisd.openbis.generic.server.jython.api.v1.IVocabulary;
import ch.systemsx.cisd.openbis.generic.server.jython.api.v1.IVocabularyTerm;
......@@ -26,9 +30,13 @@ import ch.systemsx.cisd.openbis.generic.server.jython.api.v1.IVocabularyTerm;
*/
class VocabularyWrapper extends VocabularyImmutable implements IVocabulary
{
VocabularyWrapper(VocabularyImmutable vocabulary)
private final Map<Long, List<VocabularyTerm>> createdVocabularyTerms;
VocabularyWrapper(VocabularyImmutable vocabulary,
Map<Long, List<VocabularyTerm>> createdVocabularyTerms)
{
super(vocabulary.getVocabulary());
this.createdVocabularyTerms = createdVocabularyTerms;
}
@Override
......@@ -59,5 +67,13 @@ class VocabularyWrapper extends VocabularyImmutable implements IVocabulary
@Override
public void addTerm(IVocabularyTerm term)
{
Long id = getVocabulary().getId();
List<VocabularyTerm> terms = createdVocabularyTerms.get(id);
if (terms == null)
{
terms = new ArrayList<VocabularyTerm>();
createdVocabularyTerms.put(id, terms);
}
terms.add((VocabularyTerm) term);
}
}
......@@ -502,7 +502,7 @@ public class MasterDataRegistrationTransactionTest extends AssertJUnit
IVocabularyTerm term = transaction.createNewVocabularyTerm("ABC");
term.setLabel("abc");
term.setDescription("Hello abc");
transaction.addVocabularyTermTo(voca, term);
voca.addTerm(term);
transaction.commit();
assertEquals("[abc [ABC]]", newTermsMatcher.recordedObject().toString());
......@@ -585,7 +585,7 @@ public class MasterDataRegistrationTransactionTest extends AssertJUnit
term2.setLabel("Beta");
term2.setDescription("Hello B");
term2.setOrdinal(1L);
transaction.addVocabularyTermTo(voca, term2);
voca.addTerm(term2);
transaction.commit();
NewVocabulary newVoca = newVocaMatcher.recordedObject();
......@@ -652,6 +652,7 @@ public class MasterDataRegistrationTransactionTest extends AssertJUnit
context.assertIsSatisfied();
}
@SuppressWarnings("unchecked")
@Test
public void testAddVocabularyTermsFailed()
{
......@@ -667,8 +668,8 @@ public class MasterDataRegistrationTransactionTest extends AssertJUnit
});
IVocabulary voca = transaction.getOrCreateNewVocabulary(KNOWN);
transaction.addVocabularyTermTo(voca, transaction.createNewVocabularyTerm("ABC"));
transaction.addVocabularyTermTo(voca, transaction.createNewVocabularyTerm("Delta"));
voca.addTerm(transaction.createNewVocabularyTerm("ABC"));
voca.addTerm(transaction.createNewVocabularyTerm("Delta"));
transaction.commit();
assertEquals("Failed to register new terms [ABC, DELTA]: Oohps!", transaction
......
......@@ -30,6 +30,14 @@ file_type_ZIP.setDescription('A zipped package')
vocabulary_TREATMENT_TYPE = tr.getVocabulary('TREATMENT_TYPE')
vocabulary_TREATMENT_TYPE.addTerm(vocabulary_term_TREATMENT_TYPE_PH)
vocabulary_term_TREATMENT_TYPE_PH = tr.createNewVocabularyTerm('PH')
vocabulary_term_TREATMENT_TYPE_PH.setDescription(None)
vocabulary_term_TREATMENT_TYPE_PH.setUrl(None)
vocabulary_term_TREATMENT_TYPE_PH.setLabel('ph')
vocabulary_term_TREATMENT_TYPE_PH.setOrdinal(1)
vocabulary_TREATMENT_TYPE.addTerm(vocabulary_term_TREATMENT_TYPE_PH)
exp_type_BIOLOGICAL_EXPERIMENT = tr.getOrCreateNewExperimentType('BIOLOGICAL_EXPERIMENT')
exp_type_BIOLOGICAL_EXPERIMENT.setDescription('A biological experiment')
......
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