diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/SpaceCodeHelper.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/SpaceCodeHelper.java index 16e7d4a9a5329c940f2b945b31d70a23711f4584..35086c17f3e0af54435344bf37634d76df8a00d2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/SpaceCodeHelper.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/SpaceCodeHelper.java @@ -16,8 +16,8 @@ package ch.systemsx.cisd.openbis.generic.shared.util; -import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE; import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE; import ch.systemsx.cisd.openbis.generic.shared.dto.exception.UndefinedSpaceException; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SpaceIdentifier; @@ -70,29 +70,48 @@ public class SpaceCodeHelper /** * Tries to find out the space. * <p> - * If given <var>spaceCode</var> is a home space, the real space must be specified as home space - * in given {@link PersonPE}. + * If given <var>spaceCode</var> specifies the home space, the home space of the + * {@link PersonPE} is returned. May return <code>null</code>, if no home space is defined for + * the user. * </p> - * - * @throws UndefinedSpaceException if no space could be found. */ - public final static String getSpaceCode(final PersonPE person, final String spaceCode) + public final static String tryGetSpaceCode(final PersonPE person, final String spaceCode) throws UndefinedSpaceException { if (isHomeSpace(spaceCode)) { - final SpacePE homeGroup = person.getHomeSpace(); - if (homeGroup == null) + final SpacePE homeSpace = person.getHomeSpace(); + if (homeSpace == null) { - throw new UndefinedSpaceException(); + return null; } - return homeGroup.getCode(); + return homeSpace.getCode(); } else { return spaceCode; } } + /** + * Tries to find out the space. + * <p> + * If given <var>spaceCode</var> is a home space, the real space must be specified as home space + * in given {@link PersonPE}. + * </p> + * + * @throws UndefinedSpaceException if no space could be found. + */ + public final static String getSpaceCode(final PersonPE person, final String spaceCode) + throws UndefinedSpaceException + { + final String spaceCodeOrNull = tryGetSpaceCode(person, spaceCode); + if (spaceCodeOrNull == null) + { + throw new UndefinedSpaceException(); + } + return spaceCodeOrNull; + } + /** * Tries to find out the space. * <p>