]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5271: Simplified design of URI-building registry to assume just one URI templa...
authorAron Roberts <aron@socrates.berkeley.edu>
Wed, 15 Aug 2012 02:18:12 +0000 (19:18 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Wed, 15 Aug 2012 02:18:12 +0000 (19:18 -0700)
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/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java
services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java

index e5b70c6fa06861a8daee41ee1a917068dc869429..de9cf91d557b6cf76e7399bdee39480d15515b79 100644 (file)
@@ -962,27 +962,24 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     }
     
     protected String getItemDocType(String tenantId) {
-        return super.getDocType(tenantId, getItemServiceName());
+        return getDocType(tenantId, getItemServiceName());
     }
-    
-   /**
-    * 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.
-    * 
-    * @return a map of URI templates for the current resource
-    */
+        
+    /**
+     * Returns a UriRegistry entry: a map of tenant-qualified URI templates
+     * for the current resource, for all tenants
+     * 
+     * @return a map of URI templates for the current resource, for all tenants
+     */
     @Override
-    protected Map<UriTemplateFactory.UriTemplateType,StoredValuesUriTemplate> getUriTemplateMap() {
-        // Get the resource URI template from the superclass
-        Map<UriTemplateFactory.UriTemplateType,StoredValuesUriTemplate> uriTemplateMap = super.getUriTemplateMap();
-        // Add the item URI template here, and return both templates in the map
-        StoredValuesUriTemplate itemUriTemplate = getUriTemplate(UriTemplateFactory.ITEM);
-        if (itemUriTemplate == null) {
-            return uriTemplateMap; // return map as obtained from superclass
+    public Map<UriTemplateRegistryKey,StoredValuesUriTemplate> getUriRegistryEntries() {
+        Map<UriTemplateRegistryKey,StoredValuesUriTemplate> uriRegistryEntriesMap =
+                super.getUriRegistryEntries();
+        List<String> tenantIds = getTenantBindingsReader().getTenantIds();
+        for (String tenantId : tenantIds) {
+                uriRegistryEntriesMap.putAll(getUriRegistryEntries(tenantId, getItemDocType(tenantId), UriTemplateFactory.ITEM));
         }
-        uriTemplateMap.put(itemUriTemplate.getUriTemplateType(), itemUriTemplate);
-        return uriTemplateMap;
+        return uriRegistryEntriesMap;
     }
   
 }
index fb7d28f45de7faa30bdf2fcad7cf8d380e6bc08d..ef31879bb5d5b96c779d8434e1c031e6d5a271e6 100644 (file)
@@ -418,7 +418,7 @@ public abstract class ResourceBase
     protected String getDocType(String tenantId) {\r
         return getDocType(tenantId, getServiceName());\r
     }\r
-    \r
+\r
     /**\r
      * Returns the Nuxeo document type associated with a specified service, within a specified tenant.\r
      * \r
@@ -438,6 +438,7 @@ public abstract class ResourceBase
             return docType;\r
         }\r
         docType = sb.getObject().getName(); // Reads the Nuxeo Document Type from tenant bindings configuration\r
+        System.out.println(tenantId + " : " + serviceName + " : " + docType); // FIXME: for debugging\r
         return docType;\r
     }\r
     \r
@@ -447,40 +448,35 @@ public abstract class ResourceBase
      * \r
      * @return a map of URI templates for the current resource, for all tenants\r
      */\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
+    public Map<UriTemplateRegistryKey,StoredValuesUriTemplate> getUriRegistryEntries() {\r
+        Map<UriTemplateRegistryKey,StoredValuesUriTemplate> uriRegistryEntriesMap =\r
+                new HashMap<UriTemplateRegistryKey,StoredValuesUriTemplate>();\r
+        List<String> tenantIds = getTenantBindingsReader().getTenantIds();\r
         for (String tenantId : tenantIds) {\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
+                uriRegistryEntriesMap.putAll(getUriRegistryEntries(tenantId, getDocType(tenantId), UriTemplateFactory.RESOURCE));\r
         }\r
         return uriRegistryEntriesMap;\r
     }\r
     \r
-   \r
-   /**\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
-    * @return a map of URI templates for the current resource\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
+     * Returns a UriRegistry entry: a map of tenant-qualified URI templates\r
+     * for the current resource, for a specified tenants\r
+     * \r
+     * @return a map of URI templates for the current resource, for a specified tenant\r
+     */\r
+    protected Map<UriTemplateRegistryKey,StoredValuesUriTemplate> getUriRegistryEntries(String tenantId,\r
+            String docType, UriTemplateFactory.UriTemplateType type) {\r
+        Map<UriTemplateRegistryKey,StoredValuesUriTemplate> uriRegistryEntriesMap =\r
+                new HashMap<UriTemplateRegistryKey,StoredValuesUriTemplate>();\r
+        UriTemplateRegistryKey key;\r
+        if (Tools.isBlank(tenantId) || Tools.isBlank(docType)) {\r
+            return uriRegistryEntriesMap;\r
         }\r
-        uriTemplateMap.put(resourceUriTemplate.getUriTemplateType(), resourceUriTemplate);\r
-        return uriTemplateMap;\r
+        key = new UriTemplateRegistryKey();\r
+        key.setTenantId(tenantId);\r
+        key.setDocType(docType); \r
+        uriRegistryEntriesMap.put(key, getUriTemplate(type));\r
+        return uriRegistryEntriesMap;\r
     }\r
     \r
     /**\r
@@ -498,30 +494,6 @@ public abstract class ResourceBase
         return template;\r
     }\r
 \r
-    /**\r
-     * Returns a list of tenant IDs, from tenant bindings configuration\r
-     * \r
-     * @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
-        Hashtable<String, TenantBindingType> tenantBindings =\r
-                getTenantBindingsReader().getTenantBindings();\r
-        if (tenantBindings != null && !tenantBindings.isEmpty()) {\r
-            Enumeration keys = tenantBindings.keys();\r
-            while (keys.hasMoreElements()) {\r
-               tenantId = (String) keys.nextElement();\r
-               if (Tools.notBlank(tenantId)) {\r
-                   tenantIds.add(tenantId);\r
-               }\r
-            }\r
-        }\r
-        return tenantIds;\r
-    }\r
-    \r
     /**\r
      * Returns a reader for reading values from tenant bindings configuration\r
      * \r
index 13129f0190e2a6395f74eb4963fd912d4458a277..b95e149b52d6d4249b6bc8993aa2457f7838a275 100644 (file)
@@ -26,32 +26,19 @@ import java.util.HashMap;
 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<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
+public class UriTemplateRegistry extends HashMap<UriTemplateRegistryKey, StoredValuesUriTemplate> {\r
 \r
     /**\r
-     * Dump all registry settings, For debugging purposes.\r
+     * Dumps all registry settings for debugging purposes.\r
      */\r
     public void dump() {\r
-        for (Map.Entry<UriTemplateRegistryKey, Map<UriTemplateType, StoredValuesUriTemplate>> uriTemplateEntry : this.entrySet()) {\r
+        for (Map.Entry<UriTemplateRegistryKey, StoredValuesUriTemplate> uriTemplateEntry : this.entrySet()) {\r
 \r
             System.out.println(\r
                     "Tenant : DocType = "\r
@@ -59,14 +46,8 @@ public class UriTemplateRegistry extends HashMap<UriTemplateRegistryKey, Map<Uri
                     + " : "\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
+            System.out.println(" Value of Template = ");\r
+            System.out.println("  " + uriTemplateEntry.getValue().toString());\r
         }\r
     }\r
 }\r
index f6a4295d2f8aa6ba4cd44ba5c6276d37af69af84..4469f7a7af0829757cf803da3d566adde01c0ccb 100644 (file)
@@ -28,10 +28,12 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.List;
 
 import org.apache.commons.io.FileUtils;
+import org.collectionspace.services.common.api.Tools;
 import org.collectionspace.services.config.service.ServiceBindingType;
 import org.collectionspace.services.config.service.ServiceObjectType;
 import org.collectionspace.services.config.tenant.RepositoryDomainType;
@@ -472,4 +474,26 @@ public class TenantBindingConfigReaderImpl
     public String getResourcesDir(){
         return getConfigRootDir() + File.separator + "resources";
     }
+    
+    
+    /**
+     * Returns a list of tenant identifiers (tenant IDs).
+     * 
+     * @return a list of tenant IDs
+     */
+    public List<String> getTenantIds() {
+        List<String> tenantIds = new ArrayList<String>();
+        String tenantId;
+        Hashtable<String, TenantBindingType> tenantBindings = getTenantBindings();
+        if (tenantBindings != null && !tenantBindings.isEmpty()) {
+            Enumeration keys = tenantBindings.keys();
+            while (keys.hasMoreElements()) {
+                tenantId = (String) keys.nextElement();
+                if (Tools.notBlank(tenantId)) {
+                    tenantIds.add(tenantId);
+                }
+            }
+        }
+        return tenantIds;
+    }
 }
index 2bc3eb136ee98a113f1a68b1b266466c0dd9b9ac..b99ad31e396230389bbf089d6f2160309eaea45b 100644 (file)
@@ -24,6 +24,7 @@
 package org.collectionspace.services.contact;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
@@ -42,6 +43,7 @@ import javax.ws.rs.core.UriInfo;
 import org.collectionspace.services.client.*;
 import org.collectionspace.services.common.StoredValuesUriTemplate;
 import org.collectionspace.services.common.UriTemplateFactory;
+import org.collectionspace.services.common.UriTemplateRegistryKey;
 import org.collectionspace.services.common.vocabulary.AuthorityResource;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentFilter;
@@ -301,24 +303,21 @@ public abstract class AuthorityResourceWithContacts<AuthCommon, AuthItemHandler>
         return ContactConstants.NUXEO_DOCTYPE;
     }
     
-   /**
-    * 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.
-    * 
-    * @return a map of URI templates for the current resource
-    */
+    /**
+     * Returns a UriRegistry entry: a map of tenant-qualified URI templates
+     * for the current resource, for all tenants
+     * 
+     * @return a map of URI templates for the current resource, for all tenants
+     */
     @Override
-    protected Map<UriTemplateFactory.UriTemplateType,StoredValuesUriTemplate> getUriTemplateMap() {
-        // Get the resource and item URI templates from the superclass
-        Map<UriTemplateFactory.UriTemplateType,StoredValuesUriTemplate> uriTemplateMap = super.getUriTemplateMap();
-        // Add the contact URI template here, and return all three templates in the map
-        StoredValuesUriTemplate contactUriTemplate = getUriTemplate(UriTemplateFactory.CONTACT);
-        if (contactUriTemplate == null) {
-            return uriTemplateMap; // return map as obtained from superclass
+    public Map<UriTemplateRegistryKey,StoredValuesUriTemplate> getUriRegistryEntries() {
+        Map<UriTemplateRegistryKey,StoredValuesUriTemplate> uriRegistryEntriesMap =
+                super.getUriRegistryEntries();
+        List<String> tenantIds = getTenantBindingsReader().getTenantIds();
+        for (String tenantId : tenantIds) {
+                uriRegistryEntriesMap.putAll(getUriRegistryEntries(tenantId, getContactDocType(), UriTemplateFactory.CONTACT));
         }
-        uriTemplateMap.put(contactUriTemplate.getUriTemplateType(), contactUriTemplate);
-        return uriTemplateMap;
+        return uriRegistryEntriesMap;
     }
 
 }