From aa5d991c29730211227817060ff9ec878e29e538 Mon Sep 17 00:00:00 2001 From: Laramie Crocker Date: Tue, 25 Jan 2011 21:08:41 +0000 Subject: [PATCH] CSPACE-3178 Adding module to be shared between services and app --- services/common-api/pom.xml | 17 ++++++ .../services/common/api/CommonAPI.java | 14 +++++ .../services/common/api/RefName.java | 55 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100755 services/common-api/pom.xml create mode 100755 services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java create mode 100755 services/common-api/src/main/java/org/collectionspace/services/common/api/RefName.java diff --git a/services/common-api/pom.xml b/services/common-api/pom.xml new file mode 100755 index 000000000..9ad566665 --- /dev/null +++ b/services/common-api/pom.xml @@ -0,0 +1,17 @@ + + + + org.collectionspace.services + org.collectionspace.services.main + 1.1-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.common-api + services.common-api + jar + + + + diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java new file mode 100755 index 000000000..c4cba8ac4 --- /dev/null +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java @@ -0,0 +1,14 @@ +package org.collectionspace.services.common.api; + +/** + * User: laramie + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class CommonAPI { + public static final String COMMON_API = "services common api version 1"; + public static String getVersionString(){ + return COMMON_API; + } +} + 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 new file mode 100755 index 000000000..de1959a3d --- /dev/null +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/RefName.java @@ -0,0 +1,55 @@ +package org.collectionspace.services.common.api; + +/** + * User: laramie + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class RefName { + + public static final String URN_PREFIX = "urn:cspace:"; + + public static String buildRefNameForAuthority(String tenantName, + String serviceName, + String authorityShortIdentifier, + String authorityDisplayName + ){ + return buildRefName(tenantName, serviceName, authorityShortIdentifier, authorityDisplayName, ""); + } + + /** Build a full refName given all the parameters; if you don't know the tenantName or the serviceName, but you do knw the authority's refName, + * you can call buildRefNameForItemInAuthority(authorityRefBaseName, itemShortIdentifier, itemDisplayName) */ + public static String buildRefNameForItem(String tenantName, String serviceName, String authorityShortIdentifier, String itemShortIdentifier, String itemDisplayName){ + String authorityRefBaseName = buildRefName(tenantName, serviceName, authorityShortIdentifier, "", ""); + return buildRefName("", "", itemShortIdentifier, itemDisplayName, authorityRefBaseName); + + } + + /** Will build a refName string for you that is correct for an authority, or for an authority item, based on whether + * authorityRefBaseName is empty or not. This is a general utility method. If you want to just build a refName for an item, + * use buildRefNameForItem() and if you want to build one for an authority, use buildRefNameForAuthority(). You would + * use this method if you have the authority refName, and wish to build a refName for your item, without having to know + * the tenantName or service name, you can call buildRefNameForItemInAuthority(authorityRefBaseName, itemShortIdentifier, itemDisplayName). */ + public static String buildRefName(String tenantName, + String serviceName, + String shortIdentifier, + String displayName, + String authorityRefBaseName){ + //CSPACE-3178 + String refname = ""; + String displaySuffix = (displayName!=null&&(!displayName.isEmpty())) ? '\''+displayName+'\'' : ""; + if (authorityRefBaseName!=null&&(!authorityRefBaseName.isEmpty())){ + //Then I have a parent, so emit short version of me after parent refName, stripped of displayName. + String base = authorityRefBaseName; + if (authorityRefBaseName.endsWith("'")){ + //strip off parent's displayName. Could be done using AuthorityInfo and AuthorityTermInfo objects instead. + base = base.substring(0, base.indexOf('\'')); + } + refname = base+":items("+shortIdentifier+")"+displaySuffix; + } else { + //else I am the parent, just store my refName. + refname = URN_PREFIX+tenantName+':'+serviceName+"("+shortIdentifier+")"+displaySuffix; + } + return refname; + } +} -- 2.47.3