From 6f47eecf52ba9b8d692bd0c30ddab96ba1c80040 Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Tue, 20 Dec 2016 07:44:31 +0000 Subject: [PATCH] SSDM-4187: do no allow sample code alone without default sapce or home space. This should fix uitest. SVN: 37524 --- .../server/NormalizedSampleIdentifier.java | 29 +++++++++++-------- .../NormalizedSampleIdentifierTest.java | 15 ++++++++++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/NormalizedSampleIdentifier.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/NormalizedSampleIdentifier.java index 04ee3d71bd8..a94442d9396 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/NormalizedSampleIdentifier.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/NormalizedSampleIdentifier.java @@ -35,6 +35,7 @@ public class NormalizedSampleIdentifier private String space; private String project; private String code; + private boolean codeOnly; private void extractPartsFrom(String identifier) { @@ -57,6 +58,7 @@ public class NormalizedSampleIdentifier } else { code = identifier; + codeOnly = true; } } @@ -123,19 +125,22 @@ public class NormalizedSampleIdentifier String identifier = sample.getIdentifier().toUpperCase(); identifierParts.extractPartsFrom(identifier); - if (identifierParts.space == null) + if (identifierParts.codeOnly) { - identifierParts.space = normalizeSpaceCode(sample.getDefaultSpaceIdentifier()); - } - - if (identifierParts.space == null) - { - identifierParts.space = normalizeSpaceCode(homeSpace); - } - - if (identifierParts.space == null) - { -// throw UserFailureException.fromTemplate("Cannot determine space for sample " + sample); + if (identifierParts.space == null) + { + identifierParts.space = normalizeSpaceCode(sample.getDefaultSpaceIdentifier()); + } + + if (identifierParts.space == null) + { + identifierParts.space = normalizeSpaceCode(homeSpace); + } + + if (identifierParts.space == null) + { + throw UserFailureException.fromTemplate("Cannot determine space for sample " + sample); + } } if (identifierParts.code.contains(":")) diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/NormalizedSampleIdentifierTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/NormalizedSampleIdentifierTest.java index ce4bb2614c6..d56c5e89323 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/NormalizedSampleIdentifierTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/NormalizedSampleIdentifierTest.java @@ -57,6 +57,21 @@ public class NormalizedSampleIdentifierTest assertEquals(identifier.getContainerCode(), null); } + @Test + public void testNewSharedSampleWithCodeNoHomeSpaceNoDefaultSpace() + { + newSample.setIdentifier("a"); + newSample.setDefaultSpaceIdentifier(null); + + try + { + new NormalizedSampleIdentifier(newSample, null); + } catch (UserFailureException ex) + { + assertEquals(ex.getMessage(), "Cannot determine space for sample A"); + } + } + @Test public void testNewSharedSampleComponent() { -- GitLab