Skip to content
Snippets Groups Projects
Commit 51fb5414 authored by brinn's avatar brinn
Browse files

Add method SpaceCodeHelper.tryGetSpaceCode().

SVN: 26179
parent 66e7b4f5
No related branches found
No related tags found
No related merge requests found
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
package ch.systemsx.cisd.openbis.generic.shared.util; 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.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.exception.UndefinedSpaceException;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SpaceIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SpaceIdentifier;
...@@ -70,29 +70,48 @@ public class SpaceCodeHelper ...@@ -70,29 +70,48 @@ public class SpaceCodeHelper
/** /**
* Tries to find out the space. * Tries to find out the space.
* <p> * <p>
* If given <var>spaceCode</var> is a home space, the real space must be specified as home space * If given <var>spaceCode</var> specifies the home space, the home space of the
* in given {@link PersonPE}. * {@link PersonPE} is returned. May return <code>null</code>, if no home space is defined for
* the user.
* </p> * </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 throws UndefinedSpaceException
{ {
if (isHomeSpace(spaceCode)) if (isHomeSpace(spaceCode))
{ {
final SpacePE homeGroup = person.getHomeSpace(); final SpacePE homeSpace = person.getHomeSpace();
if (homeGroup == null) if (homeSpace == null)
{ {
throw new UndefinedSpaceException(); return null;
} }
return homeGroup.getCode(); return homeSpace.getCode();
} else } else
{ {
return spaceCode; 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. * Tries to find out the space.
* <p> * <p>
......
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