]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5271: URI template registry now returns templates retrievable via a composite...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 10 Aug 2012 23:31:36 +0000 (16:31 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 10 Aug 2012 23:31:36 +0000 (16:31 -0700)
services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java
services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistry.java
services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java

index 6910ea3f4ce4b634d0c3cf59aa44ff62e970e04e..313693ecdb74f970081df39b1db94f2650f77285 100644 (file)
@@ -87,7 +87,7 @@ public class CollectionSpaceJaxRsApplication extends Application
     private Set<Object> singletons = new HashSet<Object>();
     private Set<Class<?>> empty = new HashSet<Class<?>>();    
     private ResourceMap resourceMap = new ResourceMapImpl();
-    private static UriTemplateRegistry uriTemplateRegistry = new UriTemplateRegistry();
+    private UriTemplateRegistry uriTemplateRegistry = new UriTemplateRegistry();
     private ServletContext servletContext = null;
 
     public CollectionSpaceJaxRsApplication() {         
@@ -159,9 +159,9 @@ public class CollectionSpaceJaxRsApplication extends Application
         ResourceMap resources = getResourceMap();
         for (Map.Entry<String, ResourceBase> entry : resources.entrySet()) {
             resource = entry.getValue();
-            System.out.println(resource.getServiceName()); // for debugging
-            getUriTemplateRegistry().putAll(resource.getUriRegistryEntries());
-            getUriTemplateRegistry().dump(); // for debugging
+            Map<UriTemplateRegistryKey, Map<UriTemplateFactory.UriTemplateType, StoredValuesUriTemplate>> entries =
+                    resource.getUriRegistryEntries();
+            getUriTemplateRegistry().putAll(entries);
         }
         // Contacts itself should not have an entry in the URI template registry;
         // there should be a Contacts entry in that registry only for use in
@@ -189,6 +189,10 @@ public class CollectionSpaceJaxRsApplication extends Application
         return resourceMap;
     }
     
+    private void setUriTemplateRegistry(UriTemplateRegistry registry) {
+        this.uriTemplateRegistry = registry;
+    }
+    
     public UriTemplateRegistry getUriTemplateRegistry() {
         return uriTemplateRegistry;
     }
@@ -200,5 +204,6 @@ public class CollectionSpaceJaxRsApplication extends Application
     public ServletContext getServletContext() {
        return this.servletContext;
     }
+
 }
 
index 37aa1ae66b4404402d0c4f770fb784a977609948..e5b70c6fa06861a8daee41ee1a917068dc869429 100644 (file)
@@ -964,28 +964,24 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     protected String getItemDocType(String tenantId) {
         return super.getDocType(tenantId, getItemServiceName());
     }
-
+    
    /**
-    * Constructs and returns a map of URI templates for the current resource,
-    * for the specified tenant
+    * Constructs and returns a map of URI templates for the current resource.
+    * This map assumes that there will be only one URI template of a given type
+    * ("resource", "item", etc.) for each resource.
     * 
-    * @param tenantId a tenant ID
-    * @return a map of URI templates for the current resource, for the specified tenant
+    * @return a map of URI templates for the current resource
     */
     @Override
-    protected Map<String,StoredValuesUriTemplate> getUriTemplateMap(String tenantId) {
+    protected Map<UriTemplateFactory.UriTemplateType,StoredValuesUriTemplate> getUriTemplateMap() {
         // Get the resource URI template from the superclass
-        Map<String,StoredValuesUriTemplate> uriTemplateMap = super.getUriTemplateMap(tenantId);
+        Map<UriTemplateFactory.UriTemplateType,StoredValuesUriTemplate> uriTemplateMap = super.getUriTemplateMap();
         // Add the item URI template here, and return both templates in the map
-        String itemDocType = getItemDocType(tenantId);
-        if (itemDocType == null) {
-            return uriTemplateMap; // return map as obtained from superclass
-        }
         StoredValuesUriTemplate itemUriTemplate = getUriTemplate(UriTemplateFactory.ITEM);
         if (itemUriTemplate == null) {
             return uriTemplateMap; // return map as obtained from superclass
         }
-        uriTemplateMap.put(itemDocType, itemUriTemplate);
+        uriTemplateMap.put(itemUriTemplate.getUriTemplateType(), itemUriTemplate);
         return uriTemplateMap;
     }
   
index 0a3ba97f4768b5fcb4e0617f90dba125152f5d94..04b919f492cdf30a6f12f53eae68ca7013ab9098 100644 (file)
@@ -27,6 +27,8 @@ import java.util.*;
 import org.collectionspace.services.client.IQueryManager;\r
 import org.collectionspace.services.client.PoxPayloadIn;\r
 import org.collectionspace.services.client.PoxPayloadOut;\r
+import org.collectionspace.services.common.UriTemplateFactory.UriTemplateType;\r
+import org.collectionspace.services.common.UriTemplateRegistryKey;\r
 import org.collectionspace.services.common.api.RefName;\r
 import org.collectionspace.services.common.api.Tools;\r
 import org.collectionspace.services.common.authorityref.AuthorityRefList;\r
@@ -417,13 +419,25 @@ public abstract class ResourceBase
         return getDocType(tenantId, getServiceName());\r
     }\r
     \r
+    /**\r
+     * Returns the Nuxeo document type associated with a specified service, within a specified tenant.\r
+     * \r
+     * @param tenantId a tenant ID\r
+     * @param serviceName a service name\r
+     * @return the Nuxeo document type associated with that service and tenant.\r
+     */\r
     // FIXME: This method may properly belong in a different services package or class.\r
+    // Also, we need to check for any existing methods that may duplicate this one.\r
     protected String getDocType(String tenantId, String serviceName) {\r
         String docType = "";\r
-        if (Tools.notBlank(tenantId)) {\r
-            ServiceBindingType sb = getTenantBindingsReader().getServiceBinding(tenantId, serviceName);\r
-            docType = sb.getObject().getName(); // Reads the Nuxeo Document Type from tenant bindings configuration\r
+        if (Tools.isBlank(tenantId)) {\r
+            return docType;\r
         }\r
+        ServiceBindingType sb = getTenantBindingsReader().getServiceBinding(tenantId, serviceName);\r
+        if (sb == null) {\r
+            return docType;\r
+        }\r
+        docType = sb.getObject().getName(); // Reads the Nuxeo Document Type from tenant bindings configuration\r
         return docType;\r
     }\r
     \r
@@ -433,47 +447,48 @@ public abstract class ResourceBase
      * \r
      * @return a map of URI templates for the current resource, for all tenants\r
      */\r
-    public HashMap<String,Map<String,StoredValuesUriTemplate>> getUriRegistryEntries() {\r
-        HashMap<String,Map<String,StoredValuesUriTemplate>> uriRegistryEntriesMap =\r
-                new HashMap<String, Map<String,StoredValuesUriTemplate>>();\r
+    public Map<UriTemplateRegistryKey,Map<UriTemplateType,StoredValuesUriTemplate>> getUriRegistryEntries() {\r
+        Map<UriTemplateRegistryKey,Map<UriTemplateType,StoredValuesUriTemplate>> uriRegistryEntriesMap =\r
+                new HashMap<UriTemplateRegistryKey,Map<UriTemplateType,StoredValuesUriTemplate>>();\r
         List<String> tenantIds = getTenantIds();\r
+        UriTemplateRegistryKey key;\r
+        String docType = "";\r
         for (String tenantId : tenantIds) {\r
-            uriRegistryEntriesMap.put(tenantId, getUriTemplateMap(tenantId));\r
+            docType = getDocType(tenantId);\r
+            if (Tools.notBlank(docType)) {\r
+                key = new UriTemplateRegistryKey();\r
+                key.setTenantId(tenantId);\r
+                key.setDocType(docType); \r
+                uriRegistryEntriesMap.put(key, getUriTemplateMap());\r
+            }\r
         }\r
         return uriRegistryEntriesMap;\r
     }\r
     \r
    \r
    /**\r
-    * Constructs and returns a map of URI templates for the current resource,\r
-    * for the specified tenant\r
+    * Constructs and returns a map of URI templates for the current resource.\r
+    * This map assumes that there will be only one URI template of a given type\r
+    * ("reesource", "item", etc.) for each resource.\r
     * \r
-    * @param tenantId a tenant ID\r
-    * @return a map of URI templates for the current resource, for the specified tenant\r
+    * @return a map of URI templates for the current resource\r
     */\r
-   protected Map<String,StoredValuesUriTemplate> getUriTemplateMap(String tenantId) {\r
-        Map<String,StoredValuesUriTemplate> uriTemplateMap = new HashMap<String, StoredValuesUriTemplate>();\r
-        if (tenantId == null) {\r
-            return uriTemplateMap; // return an empty map\r
-        }\r
-        String docType = getDocType(tenantId);\r
-        if (docType == null) {\r
-            return uriTemplateMap; // return an empty map\r
-        }\r
+   protected Map<UriTemplateType,StoredValuesUriTemplate> getUriTemplateMap() {\r
+        Map<UriTemplateType,StoredValuesUriTemplate> uriTemplateMap = new HashMap<UriTemplateType, StoredValuesUriTemplate>();\r
         StoredValuesUriTemplate resourceUriTemplate = getUriTemplate(UriTemplateFactory.RESOURCE);\r
         if (resourceUriTemplate == null) {\r
             return uriTemplateMap; // return an empty map\r
         }\r
-        uriTemplateMap.put(docType, resourceUriTemplate);\r
+        uriTemplateMap.put(resourceUriTemplate.getUriTemplateType(), resourceUriTemplate);\r
         return uriTemplateMap;\r
     }\r
     \r
     /**\r
-     * Returns a UriTemplate of the appropriate type, populated with the\r
+     * Returns a URI template of the appropriate type, populated with the\r
      * current service name as one of its stored values.\r
-     * \r
-     * @param type a UriTemplate type\r
-     * @return a UriTemplate of the appropriate type\r
+     *      * \r
+     * @param type a URI template type\r
+     * @return a URI template of the appropriate type.\r
      */\r
     protected StoredValuesUriTemplate getUriTemplate(UriTemplateFactory.UriTemplateType type) {\r
         Map<String,String> storedValuesMap = new HashMap<String,String>();\r
@@ -489,6 +504,7 @@ public abstract class ResourceBase
      * @return a list of tenant IDs\r
      */\r
     // FIXME: This method may properly belong in a different services package or class.\r
+    // Also, we need to check for any existing methods that may duplicate this one.\r
     protected List<String> getTenantIds() {\r
         List<String> tenantIds = new ArrayList<String>();\r
         String tenantId;\r
index 3929120e0511809188a60bd2bccc7ce50e3c5298..968554152e5c0d776f160bf5271599b3b4740f7c 100644 (file)
@@ -24,24 +24,36 @@ package org.collectionspace.services.common;
 \r
 import java.util.HashMap;\r
 import java.util.Map;\r
+import java.util.Set;\r
+import org.collectionspace.services.common.UriTemplateRegistryKey;\r
+import org.collectionspace.services.common.UriTemplateFactory.UriTemplateType;\r
 \r
 /**\r
  * UriTemplateRegistry.java\r
  *\r
  * Maps document types to templates for building URIs, per tenant.\r
  */\r
-public class UriTemplateRegistry extends HashMap<String, Map<String, StoredValuesUriTemplate>> {\r
+public class UriTemplateRegistry extends HashMap<UriTemplateRegistryKey, Map<UriTemplateType, StoredValuesUriTemplate>> {\r
 \r
-    // For debugging\r
+    /**\r
+     * Dump all registry settings, For debugging purposes.\r
+     */\r
     public void dump() {\r
-        for (String tenantId : this.keySet()) {\r
-            System.out.println("###############################");\r
-            System.out.println("Tenant ID = " + tenantId);\r
-            System.out.println("###############################");\r
-            for (Map.Entry<String, StoredValuesUriTemplate> uriTemplateEntry : this.get(tenantId).entrySet()) {\r
-                System.out.println("Key = " + uriTemplateEntry.getKey()\r
-                        + ", Value = " + uriTemplateEntry.getValue().getUriTemplateType()\r
-                        + " : " + uriTemplateEntry.getValue().toString());\r
+        for (Map.Entry<UriTemplateRegistryKey, Map<UriTemplateType, StoredValuesUriTemplate>> uriTemplateEntry : this.entrySet()) {\r
+\r
+            System.out.println(\r
+                    "Tenant : DocType = "\r
+                    + uriTemplateEntry.getKey().getTenantId()\r
+                    + " : "\r
+                    + uriTemplateEntry.getKey().getDocType());\r
+\r
+            System.out.println(" Value(s) of TemplateType : Template = ");\r
+            for (Map.Entry<UriTemplateType, StoredValuesUriTemplate> template : uriTemplateEntry.getValue().entrySet()) {\r
+                System.out.println(\r
+                        "  "\r
+                        + template.getKey()\r
+                        + " : "\r
+                        + template.getValue().toString());\r
             }\r
         }\r
     }\r
index fc581dd2781852196a22a11e78e9e3f2614def78..2bc3eb136ee98a113f1a68b1b266466c0dd9b9ac 100644 (file)
@@ -300,35 +300,24 @@ public abstract class AuthorityResourceWithContacts<AuthCommon, AuthItemHandler>
     protected String getContactDocType() {
         return ContactConstants.NUXEO_DOCTYPE;
     }
-
+    
    /**
-    * Constructs and returns a map of URI templates for the current resource,
-    * for the specified tenant
+    * Constructs and returns a map of URI templates for the current resource.
+    * This map assumes that there will be only one URI template of a given type
+    * ("resource", "item", "contacts" etc.) for each resource.
     * 
-    * @param tenantId a tenant ID
-    * @return a map of URI templates for the current resource, for the specified tenant
+    * @return a map of URI templates for the current resource
     */
-    // FIXME: This method currently populates only one entry in the UriTemplateRegistry
-    // for the Contacts docType, even though contacts can be a sub-resource of
-    // multiple authority item resources.  (This method may be called more than once,
-    // but each time the existing item with the same key in the map is overwritten.)
     @Override
-    protected Map<String,StoredValuesUriTemplate> getUriTemplateMap(String tenantId) {
+    protected Map<UriTemplateFactory.UriTemplateType,StoredValuesUriTemplate> getUriTemplateMap() {
         // Get the resource and item URI templates from the superclass
-        Map<String,StoredValuesUriTemplate> uriTemplateMap = super.getUriTemplateMap(tenantId);
+        Map<UriTemplateFactory.UriTemplateType,StoredValuesUriTemplate> uriTemplateMap = super.getUriTemplateMap();
         // Add the contact URI template here, and return all three templates in the map
-        String contactDocType = getContactDocType();
-        if (contactDocType == null) {
-            return uriTemplateMap; // return map as obtained from superclass
-        }
         StoredValuesUriTemplate contactUriTemplate = getUriTemplate(UriTemplateFactory.CONTACT);
         if (contactUriTemplate == null) {
             return uriTemplateMap; // return map as obtained from superclass
         }
-        // Remove any service name value stored in the template, as the service name
-        // for contact resources will vary, and must be provided at URI build time 
-        contactUriTemplate.getStoredValuesMap().put(UriTemplateFactory.SERVICENAME_VAR, "");
-        uriTemplateMap.put(contactDocType, contactUriTemplate);
+        uriTemplateMap.put(contactUriTemplate.getUriTemplateType(), contactUriTemplate);
         return uriTemplateMap;
     }