]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3178 Adding module to be shared between services and app
authorLaramie Crocker <laramie@berkeley.edu>
Tue, 25 Jan 2011 21:08:41 +0000 (21:08 +0000)
committerLaramie Crocker <laramie@berkeley.edu>
Tue, 25 Jan 2011 21:08:41 +0000 (21:08 +0000)
services/common-api/pom.xml [new file with mode: 0755]
services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java [new file with mode: 0755]
services/common-api/src/main/java/org/collectionspace/services/common/api/RefName.java [new file with mode: 0755]

diff --git a/services/common-api/pom.xml b/services/common-api/pom.xml
new file mode 100755 (executable)
index 0000000..9ad5666
--- /dev/null
@@ -0,0 +1,17 @@
+<?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
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 (executable)
index 0000000..c4cba8a
--- /dev/null
@@ -0,0 +1,14 @@
+package org.collectionspace.services.common.api;\r
+\r
+/**\r
+ * User: laramie\r
+ * $LastChangedRevision:  $\r
+ * $LastChangedDate:  $\r
+ */\r
+public class CommonAPI {\r
+    public static final String COMMON_API = "services common api version 1";\r
+    public static String getVersionString(){\r
+        return COMMON_API;\r
+    }\r
+}\r
+\r
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 (executable)
index 0000000..de1959a
--- /dev/null
@@ -0,0 +1,55 @@
+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