From b414e99c1c9ebfe1a044611d6d22143d677bc2a1 Mon Sep 17 00:00:00 2001 From: remillet Date: Sun, 26 Feb 2017 00:05:31 -0800 Subject: [PATCH] DRYD-90: Fixed problem with /servicegroupd/common/item/${csid} when csid pointed to an authority term --- .../services/common/api/RefName.java | 19 ++++++++++++++++--- .../services/common/NuxeoBasedResource.java | 2 +- .../services/nuxeo/util/NuxeoUtils.java | 2 +- .../nuxeo/RelationValidatorHandler.java | 2 +- .../ServiceGroupDocumentModelHandler.java | 4 ++-- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/RefName.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/RefName.java index ee87e0bca..4541efd7c 100644 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/RefName.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/RefName.java @@ -173,14 +173,27 @@ public class RefName { public String shortIdentifier = ""; public String displayName = ""; - public static AuthorityItem parse(String urn) throws IllegalArgumentException { + // Returns null value if urn can't be parsed and exceptionOnFail is set to 'false' + // Throws exception if urn can't be parsed and exceptionOnFail is set to 'true' + public static AuthorityItem parse(String urn, boolean exceptionOnFail) throws IllegalArgumentException { AuthorityItem authorityItem = null; - RefNameUtils.AuthorityTermInfo termInfo = RefNameUtils.parseAuthorityTermInfo(urn); - authorityItem = authorityItemFromTermInfo(termInfo); + try { + RefNameUtils.AuthorityTermInfo termInfo = RefNameUtils.parseAuthorityTermInfo(urn); + authorityItem = authorityItemFromTermInfo(termInfo); + } catch (IllegalArgumentException e) { + if (exceptionOnFail == true) { + throw e; + } + } return authorityItem; } + + // Returns null value if urn can't be parsed + public static AuthorityItem parse(String urn) { + return parse(urn, false); + } public String getDisplayName() { return this.displayName; diff --git a/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java b/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java index bdd234001..14cc33603 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java +++ b/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java @@ -657,6 +657,6 @@ public abstract class NuxeoBasedResource public DocumentModel getDocModelForRefName(CoreSessionInterface repoSession, String refName) throws Exception, DocumentNotFoundException { - return getDocModelForAuthorityItem(repoSession, RefName.AuthorityItem.parse(refName)); + return getDocModelForAuthorityItem(repoSession, RefName.AuthorityItem.parse(refName, true)); } } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java index 4afb237fc..e8a213641 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java @@ -742,7 +742,7 @@ public class NuxeoUtils { // Let's see if our refname refers to an authority item/term. // try { - item = RefName.AuthorityItem.parse(refName); + item = RefName.AuthorityItem.parse(refName, true); if (item != null) { NuxeoBasedResource resource = (NuxeoBasedResource) resourceMap.get(item.inAuthority.resource); return resource.getDocModelForAuthorityItem(repoSession, item); diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationValidatorHandler.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationValidatorHandler.java index 90ffd2f0d..d00793877 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationValidatorHandler.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationValidatorHandler.java @@ -116,7 +116,7 @@ public class RelationValidatorHandler extends ValidatorHandlerImpl