From 83c04f0d8fbe6a01022f6d39cc22502cd846c3ca Mon Sep 17 00:00:00 2001 From: gakin <gakin> Date: Mon, 30 Jan 2017 19:11:19 +0000 Subject: [PATCH] SSDM-4720 : Replacing referenced vocabulary term should update entity time stamps SVN: 37644 --- .../server/business/bo/VocabularyBO.java | 30 +++++++++ ...GeneralInformationChangingServiceTest.java | 61 +++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBO.java index 747f82c45f8..179af15ada8 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBO.java @@ -630,10 +630,40 @@ public class VocabularyBO extends AbstractBusinessObject implements IVocabularyB { 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() .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 diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationChangingServiceTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationChangingServiceTest.java index b6c09d897f4..fc2594cb605 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationChangingServiceTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationChangingServiceTest.java @@ -22,6 +22,7 @@ import static org.testng.AssertJUnit.assertNotNull; import static org.testng.AssertJUnit.assertNull; import static org.testng.AssertJUnit.assertTrue; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -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.MatchClause; 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.experiment.ExperimentIdentifierId; 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; 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.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.SystemTestCase; import ch.systemsx.cisd.openbis.util.GeneralInformationServiceUtil; @@ -125,6 +129,63 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase 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 public void testAssignMandatoryProperty() { -- GitLab