--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
+ <parent>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.main</artifactId>\r
+ <version>1.1-SNAPSHOT</version>\r
+ </parent>\r
+\r
+ <modelVersion>4.0.0</modelVersion>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.common-api</artifactId>\r
+ <name>services.common-api</name>\r
+ <packaging>jar</packaging>\r
+\r
+\r
+</project>\r
+\r
--- /dev/null
+package org.collectionspace.services.common.api;\r
+\r
+/**\r
+ * User: laramie\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ */\r
+public class RefName {\r
+\r
+ public static final String URN_PREFIX = "urn:cspace:";\r
+\r
+ public static String buildRefNameForAuthority(String tenantName,\r
+ String serviceName,\r
+ String authorityShortIdentifier,\r
+ String authorityDisplayName\r
+ ){\r
+ return buildRefName(tenantName, serviceName, authorityShortIdentifier, authorityDisplayName, "");\r
+ }\r
+\r
+ /** 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,\r
+ * you can call buildRefNameForItemInAuthority(authorityRefBaseName, itemShortIdentifier, itemDisplayName) */\r
+ public static String buildRefNameForItem(String tenantName, String serviceName, String authorityShortIdentifier, String itemShortIdentifier, String itemDisplayName){\r
+ String authorityRefBaseName = buildRefName(tenantName, serviceName, authorityShortIdentifier, "", "");\r
+ return buildRefName("", "", itemShortIdentifier, itemDisplayName, authorityRefBaseName);\r
+\r
+ }\r
+\r
+ /** Will build a refName string for you that is correct for an authority, or for an authority item, based on whether\r
+ * authorityRefBaseName is empty or not. This is a general utility method. If you want to just build a refName for an item,\r
+ * use buildRefNameForItem() and if you want to build one for an authority, use buildRefNameForAuthority(). You would\r
+ * use this method if you have the authority refName, and wish to build a refName for your item, without having to know\r
+ * the tenantName or service name, you can call buildRefNameForItemInAuthority(authorityRefBaseName, itemShortIdentifier, itemDisplayName). */\r
+ public static String buildRefName(String tenantName,\r
+ String serviceName,\r
+ String shortIdentifier,\r
+ String displayName,\r
+ String authorityRefBaseName){\r
+ //CSPACE-3178\r
+ String refname = "";\r
+ String displaySuffix = (displayName!=null&&(!displayName.isEmpty())) ? '\''+displayName+'\'' : "";\r
+ if (authorityRefBaseName!=null&&(!authorityRefBaseName.isEmpty())){\r
+ //Then I have a parent, so emit short version of me after parent refName, stripped of displayName.\r
+ String base = authorityRefBaseName;\r
+ if (authorityRefBaseName.endsWith("'")){\r
+ //strip off parent's displayName. Could be done using AuthorityInfo and AuthorityTermInfo objects instead.\r
+ base = base.substring(0, base.indexOf('\''));\r
+ }\r
+ refname = base+":items("+shortIdentifier+")"+displaySuffix;\r
+ } else {\r
+ //else I am the parent, just store my refName.\r
+ refname = URN_PREFIX+tenantName+':'+serviceName+"("+shortIdentifier+")"+displaySuffix;\r
+ }\r
+ return refname;\r
+ }\r
+}\r