From d408809ac6b6b701ceab208a2d9a27660bbce560 Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Mon, 4 Apr 2011 11:38:06 +0000 Subject: [PATCH] [LMS-2177] fixed inconsistencies in showing db instance for samples (never show home instance) SVN: 20638 --- .../bo/samplelister/SampleListingWorker.java | 19 +++++++++-------- .../shared/basic/dto/DatabaseInstance.java | 12 +++++++++++ .../dto/identifier/IdentifierHelper.java | 8 +++++-- .../DatabaseInstanceTranslator.java | 1 + .../api/v1/GeneralInformationServiceTest.java | 2 +- .../plugin/generic/SampleBrowsingTest.java | 21 ++++++++----------- 6 files changed, 39 insertions(+), 24 deletions(-) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorker.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorker.java index 0c4b2862979..0d3b66fc8b0 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorker.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorker.java @@ -53,10 +53,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space; import ch.systemsx.cisd.openbis.generic.shared.dto.CodeConverter; -import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier; -import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.IdentifierHelper; -import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; /** * A business worker object for fast sample listing. It has only one interface method, which is @@ -626,17 +623,21 @@ final class SampleListingWorker extends AbstractLister private void setSpace(final Sample sample, final Space space) { sample.setSpace(space); - final GroupIdentifier groupId = - new GroupIdentifier(databaseInstance.getCode(), space.getCode()); - sample.setIdentifier(new SampleIdentifier(groupId, sample.getCode()).toString()); + // final DatabaseInstanceIdentifier dbId = + // databaseInstance.isHomeDatabase() ? DatabaseInstanceIdentifier.HOME_INSTANCE + // : new DatabaseInstanceIdentifier(databaseInstance.getCode()); + // final GroupIdentifier groupId = new GroupIdentifier(dbId, space.getCode()); + sample.setIdentifier(IdentifierHelper.createSampleIdentifier(sample).toString()); } private void setDatabaseInstance(final Sample sample) { sample.setDatabaseInstance(databaseInstance); - final DatabaseInstanceIdentifier dbId = - new DatabaseInstanceIdentifier(databaseInstance.getCode()); - sample.setIdentifier(new SampleIdentifier(dbId, sample.getCode()).toString()); + // final DatabaseInstanceIdentifier dbId = + // databaseInstance.isHomeDatabase() ? DatabaseInstanceIdentifier.HOME_INSTANCE + // : new DatabaseInstanceIdentifier(databaseInstance.getCode()); + sample.setIdentifier(IdentifierHelper.createSampleIdentifier(sample).toString()); + // new SampleIdentifier(dbId, sample.getCode()).toString()); } private void addRelatedContainerSampleToRequested(long containerId) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DatabaseInstance.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DatabaseInstance.java index 372d11523cf..babaf51fded 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DatabaseInstance.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DatabaseInstance.java @@ -29,6 +29,8 @@ public class DatabaseInstance extends Code<DatabaseInstance> private String identifier; + private boolean isHomeDatabase; + public final String getUuid() { return uuid; @@ -58,4 +60,14 @@ public class DatabaseInstance extends Code<DatabaseInstance> { this.id = id; } + + public boolean isHomeDatabase() + { + return isHomeDatabase; + } + + public void setHomeDatabase(boolean isHomeDatabase) + { + this.isHomeDatabase = isHomeDatabase; + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/identifier/IdentifierHelper.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/identifier/IdentifierHelper.java index 23782322047..cbd7058413c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/identifier/IdentifierHelper.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/identifier/IdentifierHelper.java @@ -108,13 +108,17 @@ public final class IdentifierHelper final Space space = sample.getSpace(); if (space != null) { + DatabaseInstanceIdentifier instanceIdentifier = + space.getInstance().isHomeDatabase() ? DatabaseInstanceIdentifier.HOME_INSTANCE + : new DatabaseInstanceIdentifier(space.getInstance().getCode()); GroupIdentifier groupIdentifier = - new GroupIdentifier(space.getInstance().getCode(), space.getCode()); + new GroupIdentifier(instanceIdentifier, space.getCode()); return new SampleIdentifier(groupIdentifier, sample.getCode()); } else { DatabaseInstanceIdentifier instanceIdentifier = - new DatabaseInstanceIdentifier(sample.getDatabaseInstance().getCode()); + (sample.getDatabaseInstance().isHomeDatabase()) ? DatabaseInstanceIdentifier.HOME_INSTANCE + : new DatabaseInstanceIdentifier(sample.getDatabaseInstance().getCode()); return new SampleIdentifier(instanceIdentifier, sample.getCode()); } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/DatabaseInstanceTranslator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/DatabaseInstanceTranslator.java index 0450e3780dc..7e443982e07 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/DatabaseInstanceTranslator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/DatabaseInstanceTranslator.java @@ -44,6 +44,7 @@ public final class DatabaseInstanceTranslator result.setId(HibernateUtils.getId(databaseInstance)); result.setCode(databaseInstance.getCode()); result.setUuid(databaseInstance.getUuid()); + result.setHomeDatabase(databaseInstance.isOriginalSource()); result.setIdentifier(IdentifierHelper.createDatabaseInstanceIdentifier(databaseInstance) .toString()); return result; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationServiceTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationServiceTest.java index 5b3214d1307..8587ae920c3 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationServiceTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationServiceTest.java @@ -110,7 +110,7 @@ public class GeneralInformationServiceTest extends SystemTestCase sc.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "*")); List<Sample> result = generalInformationService.searchForSamples(sessionToken, sc); assertEquals(true, result.size() > 0); - String expectedSampleIdentifier = "CISD:/CISD/CL1"; + String expectedSampleIdentifier = "/CISD/CL1"; for (Sample sample : result) { if (expectedSampleIdentifier.equals(sample.getIdentifier())) diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/SampleBrowsingTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/SampleBrowsingTest.java index 3d1b4a8ce1b..ddd4007b712 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/SampleBrowsingTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/plugin/generic/SampleBrowsingTest.java @@ -51,8 +51,6 @@ public class SampleBrowsingTest extends GenericSystemTestCase { private static final boolean DEBUG = false; - private static final String DEFAULT_INSTANCE = "CISD"; - private static final String DEFAULT_GROUP = "CISD"; private static final String DEFAULT_PLATE_GEOMETRY_VALUE = "384_WELLS_16X24"; @@ -94,10 +92,10 @@ public class SampleBrowsingTest extends GenericSystemTestCase // test that 3 parents of a 'REINFECT_PLATE' are loaded Sample s3 = getSample(list, createSampleIdentifier("RP1-A2X")); assertEquals("REINFECT_PLATE", s3.getSampleType().getCode()); - assertEquals("CISD:/CISD/CP1-A2", s3.getGeneratedFrom().getIdentifier()); - assertEquals("CISD:/CISD/DP1-A", s3.getGeneratedFrom().getGeneratedFrom().getIdentifier()); - assertEquals("CISD:/CISD/MP1-MIXED", s3.getGeneratedFrom().getGeneratedFrom() - .getGeneratedFrom().getIdentifier()); + assertEquals("/CISD/CP1-A2", s3.getGeneratedFrom().getIdentifier()); + assertEquals("/CISD/DP1-A", s3.getGeneratedFrom().getGeneratedFrom().getIdentifier()); + assertEquals("/CISD/MP1-MIXED", s3.getGeneratedFrom().getGeneratedFrom().getGeneratedFrom() + .getIdentifier()); } @Test @@ -170,7 +168,7 @@ public class SampleBrowsingTest extends GenericSystemTestCase Sample s = getSample(list, createSampleIdentifier("3VCP1")); assertNotNull(s.getInvalidation()); assertEquals("/CISD/NEMO/EXP1", s.getExperiment().getIdentifier()); - assertEquals("CISD:/CISD/3V-123", s.getGeneratedFrom().getIdentifier()); + assertEquals("/CISD/3V-123", s.getGeneratedFrom().getIdentifier()); assertNull(s.getGeneratedFrom().getGeneratedFrom()); } @@ -203,18 +201,17 @@ public class SampleBrowsingTest extends GenericSystemTestCase private static String createSampleIdentifier(String sampleCode) { - return createSampleIdentifier(DEFAULT_INSTANCE, DEFAULT_GROUP, sampleCode); + return createSampleIdentifier(DEFAULT_GROUP, sampleCode); } private static String createSharedSampleIdentifier(String sampleCode) { - return createSampleIdentifier(DEFAULT_INSTANCE, null, sampleCode); + return createSampleIdentifier(null, sampleCode); } - private static String createSampleIdentifier(String instanceCode, String spaceCode, - String sampleCode) + private static String createSampleIdentifier(String spaceCode, String sampleCode) { - return instanceCode + ":/" + (spaceCode == null ? "" : spaceCode + "/") + sampleCode; + return "/" + (spaceCode == null ? "" : spaceCode + "/") + sampleCode; } private SampleType getAllSampleType() -- GitLab