]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5271: Added missing registry key class; updated comments; added convenience...
authorAron Roberts <aron@socrates.berkeley.edu>
Sat, 11 Aug 2012 00:55:33 +0000 (17:55 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Sat, 11 Aug 2012 00:55:33 +0000 (17:55 -0700)
services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java
services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistry.java
services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistryKey.java [new file with mode: 0644]

index 313693ecdb74f970081df39b1db94f2650f77285..5173917a4700158766ddb6133002b705006ca70e 100644 (file)
@@ -149,10 +149,10 @@ public class CollectionSpaceJaxRsApplication extends Application
     
     /**
      *  Build a registry of URI templates by querying each resource
-     *  for its own entry in the registry.
+     *  for its own entries in the registry.
      * 
-     *  That entry consists of a tenant-qualified map of URI templates, each
-     *  associated with a specific document type
+     *  These entries consist of one or more URI templates for
+     *  building URIs for accessing that resource.
      */
     private void buildUriTemplateRegistry() {
         ResourceBase resource = null;
index 968554152e5c0d776f160bf5271599b3b4740f7c..13129f0190e2a6395f74eb4963fd912d4458a277 100644 (file)
@@ -34,6 +34,18 @@ import org.collectionspace.services.common.UriTemplateFactory.UriTemplateType;
  * Maps document types to templates for building URIs, per tenant.\r
  */\r
 public class UriTemplateRegistry extends HashMap<UriTemplateRegistryKey, Map<UriTemplateType, StoredValuesUriTemplate>> {\r
+    \r
+    /**\r
+     * Get a URI template by tenant, document type, and template type.\r
+     * \r
+     */\r
+    public StoredValuesUriTemplate get(UriTemplateRegistryKey key, UriTemplateType type) {\r
+        if (get(key) != null) {\r
+            return get(key).get(type);\r
+        } else {\r
+            return null;\r
+        }\r
+    }\r
 \r
     /**\r
      * Dump all registry settings, For debugging purposes.\r
diff --git a/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistryKey.java b/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistryKey.java
new file mode 100644 (file)
index 0000000..d7d3a15
--- /dev/null
@@ -0,0 +1,87 @@
+package org.collectionspace.services.common;
+
+/**
+ * Defines a compound key consisting of the combination of a tenant ID and a
+ * Nuxeo document type (docType), for accessing entries in the
+ * UriTemplateRegistry.
+ */
+public class UriTemplateRegistryKey {
+
+    private String tenantId;
+    private String docType;
+    
+    public void UriTemplateRegistryKey() {
+    }
+
+    public void UriTemplateRegistryKey(String tenantId, String docType) {
+        this.tenantId = tenantId;
+        this.docType = docType;
+    }
+
+    /**
+     * @return the tenantId
+     */
+    public String getTenantId() {
+        return tenantId;
+    }
+
+    /**
+     * @param tenantId the tenantId to set
+     */
+    public void setTenantId(String tenantId) {
+        this.tenantId = tenantId;
+    }
+
+    /**
+     * @return the docType
+     */
+    public String getDocType() {
+        return docType;
+    }
+
+    /**
+     * @param docType the docType to set
+     */
+    public void setDocType(String docType) {
+        this.docType = docType;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+
+        if (o == null) {
+            return false;
+        }
+        if (getClass() != o.getClass()) {
+            return false;
+        }
+
+        if (o == this) {
+            return true;
+        }
+
+        // Cast the compared-to object to an object of this type
+        UriTemplateRegistryKey key = (UriTemplateRegistryKey) o;
+
+        // If either the tenant ID or docType values dont't match, whether
+        // only one is null, or via a failure of an 'equals' test of their
+        // values, return false
+        if (tenantId == null ? key.tenantId != null : !tenantId.equals(key.tenantId)) {
+            return false;
+        }
+        if (docType == null ? key.docType != null : !docType.equals(key.docType)) {
+            return false;
+        }
+    
+        return true;
+
+    }
+
+    @Override
+    public int hashCode() {
+        int hash = 3;
+        hash = 89 * hash + (this.tenantId != null ? this.tenantId.hashCode() : 0);
+        hash = 89 * hash + (this.docType != null ? this.docType.hashCode() : 0);
+        return hash;
+    }
+}