Skip to content
Snippets Groups Projects
Commit 83c04f0d authored by gakin's avatar gakin
Browse files

SSDM-4720 : Replacing referenced vocabulary term should update entity time stamps

SVN: 37644
parent 63064128
No related branches found
No related tags found
No related merge requests found
...@@ -630,10 +630,40 @@ public class VocabularyBO extends AbstractBusinessObject implements IVocabularyB ...@@ -630,10 +630,40 @@ public class VocabularyBO extends AbstractBusinessObject implements IVocabularyB
{ {
for (Map.Entry<Class<? extends IEntityInformationWithPropertiesHolder>, List<Long>> entry : changedEntitiesMap.entrySet()) for (Map.Entry<Class<? extends IEntityInformationWithPropertiesHolder>, List<Long>> entry : changedEntitiesMap.entrySet())
{ {
Class<? extends IEntityInformationWithPropertiesHolder> key = entry.getKey();
// update modification timestamps of the entities
EntityKind entityKind = getEntityKind(key.getClass());
IEntityPropertyTypeDAO entityPropertyTypeDAO = getEntityPropertyTypeDAO(entityKind);
entityPropertyTypeDAO.updateEntityModificationTimestamps(entry.getValue());
getPersistencyResources().getDynamicPropertyEvaluationScheduler() getPersistencyResources().getDynamicPropertyEvaluationScheduler()
.scheduleUpdate(DynamicPropertyEvaluationOperation.evaluate(entry.getKey(), entry.getValue())); .scheduleUpdate(DynamicPropertyEvaluationOperation.evaluate(entry.getKey(), entry.getValue()));
} }
} }
} }
@SuppressWarnings("rawtypes")
private EntityKind getEntityKind(Class clazz)
{
if (clazz.isInstance(ExperimentPE.class))
{
return EntityKind.EXPERIMENT;
}
else if (clazz.isInstance(SamplePE.class))
{
return EntityKind.SAMPLE;
}
else if (clazz.isInstance(DataPE.class))
{
return EntityKind.DATA_SET;
}
else if (clazz.isInstance(MaterialPE.class))
{
return EntityKind.DATA_SET;
} else
{
throw new IllegalArgumentException("Unsupported entity class: " + clazz);
}
}
} }
\ No newline at end of file
...@@ -22,6 +22,7 @@ import static org.testng.AssertJUnit.assertNotNull; ...@@ -22,6 +22,7 @@ import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull; import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertTrue; import static org.testng.AssertJUnit.assertTrue;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -50,6 +51,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample; ...@@ -50,6 +51,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.MatchClause; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.MatchClause;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.MatchClauseAttribute; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.MatchClauseAttribute;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Vocabulary;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.dataset.DataSetCodeId; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.dataset.DataSetCodeId;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.experiment.ExperimentIdentifierId; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.experiment.ExperimentIdentifierId;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.material.MaterialCodeAndTypeCodeId; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.material.MaterialCodeAndTypeCodeId;
...@@ -60,6 +62,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; ...@@ -60,6 +62,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Metaproject; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Metaproject;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewETPTAssignment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewETPTAssignment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTermReplacement;
import ch.systemsx.cisd.openbis.systemtest.PropertyHistory; import ch.systemsx.cisd.openbis.systemtest.PropertyHistory;
import ch.systemsx.cisd.openbis.systemtest.SystemTestCase; import ch.systemsx.cisd.openbis.systemtest.SystemTestCase;
import ch.systemsx.cisd.openbis.util.GeneralInformationServiceUtil; import ch.systemsx.cisd.openbis.util.GeneralInformationServiceUtil;
...@@ -125,6 +129,63 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase ...@@ -125,6 +129,63 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase
history.toString()); history.toString());
} }
@Test
public void testVocabularyAdditionAndReplacement()
{
TechId id = new TechId(1043L);
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sampleBefore = localCommonServer.getSampleInfo(sessionToken, id).getParent();
assertProperties("[ANY_MATERIAL: 2 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), "
+ "COMMENT: extremely simple stuff, ORGANISM: GORILLA, SIZE: 321]",
sampleBefore);
NewETPTAssignment newETPTAssignment = new NewETPTAssignment();
newETPTAssignment.setEntityKind(EntityKind.SAMPLE);
newETPTAssignment.setDynamic(false);
newETPTAssignment.setMandatory(true);
newETPTAssignment.setDefaultValue("FEMALE");
newETPTAssignment.setPropertyTypeCode("GENDER");
newETPTAssignment.setOrdinal(1L);
newETPTAssignment.setEntityTypeCode("CELL_PLATE");
newETPTAssignment.setShownInEditView(true);
newETPTAssignment.setShowRawValue(true);
localCommonServer.assignPropertyType(sessionToken, newETPTAssignment);
Session hibernateSession = getHibernateSession();
hibernateSession.clear();
assertProperties("[ANY_MATERIAL: 2 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), "
+ "COMMENT: extremely simple stuff, GENDER: FEMALE, ORGANISM: GORILLA, SIZE: 321]",
localCommonServer.getSampleInfo(sessionToken, id).getParent());
List<Vocabulary> listVocabularies = generalInformationService.listVocabularies(sessionToken);
Vocabulary genderVocab = null;
for (Vocabulary vocabulary : listVocabularies)
{
if (vocabulary.getCode().equals("GENDER"))
{
genderVocab = vocabulary;
}
}
assertNotNull(genderVocab);
VocabularyTermReplacement replacement = new VocabularyTermReplacement();
VocabularyTerm vocabularyTerm = new VocabularyTerm();
vocabularyTerm.setCode("FEMALE");
vocabularyTerm.setOrdinal(1L);
replacement.setTerm(vocabularyTerm);
replacement.setReplacementCode("MALE");
localCommonServer.deleteVocabularyTerms(sessionToken, new TechId(genderVocab.getId()),
Collections.<VocabularyTerm> emptyList(), Arrays.asList(replacement));
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sampleAfter = localCommonServer.getSampleInfo(sessionToken, id)
.getParent();
assertProperties("[ANY_MATERIAL: 2 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), "
+ "COMMENT: extremely simple stuff, GENDER: MALE, ORGANISM: GORILLA, SIZE: 321]", sampleAfter);
hibernateSession.clear();
assertFalse(sampleBefore.getModificationDate().equals(sampleAfter.getModificationDate()));
}
@Test @Test
public void testAssignMandatoryProperty() public void testAssignMandatoryProperty()
{ {
......
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