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;
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));
}
}
// 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);
if (authority != null) {
result = true;
} else {
- AuthorityItem authItem = AuthorityItem.parse(refName); // See if it is a refname to an authority item or vocabulary term
+ AuthorityItem authItem = AuthorityItem.parse(refName, true); // See if it is a refname to an authority item or vocabulary term
result = authItem != null;
}
} catch (IllegalArgumentException e) {
private PoxPayloadOut getAuthorityItem(ServiceContext ctx, String termRefName) throws Exception {
PoxPayloadOut result = null;
- RefName.AuthorityItem item = RefName.AuthorityItem.parse(termRefName);
+ RefName.AuthorityItem item = RefName.AuthorityItem.parse(termRefName, true);
AuthorityResource authorityResource = (AuthorityResource) ctx.getResourceMap().get(item.inAuthority.resource);
AuthorityTermInfo authorityTermInfo = RefNameUtils.parseAuthorityTermInfo(termRefName);
try {
//String inAuthorityCsid = (String) NuxeoUtils.getProperyValue(docModel, "inAuthority"); //docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY
//String refName = (String) NuxeoUtils.getProperyValue(docModel, CollectionSpaceClient.COLLECTIONSPACE_CORE_REFNAME);
- RefName.AuthorityItem item = RefName.AuthorityItem.parse(termRefName);
+ RefName.AuthorityItem item = RefName.AuthorityItem.parse(termRefName, true);
} catch (IllegalArgumentException e) {
result = false;
}