]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5271: Contact UriTemplate now has correct template type and path when stored...
authorAron Roberts <aron@socrates.berkeley.edu>
Sat, 9 Jun 2012 16:19:57 +0000 (09:19 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Sat, 9 Jun 2012 16:19:57 +0000 (09:19 -0700)
services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java
services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java
services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java

index 15a3008a3f2923d48cffe60463f1b3d4b0c948d8..c34b83663b0a557f9e64d146a70daa36ebbe6245 100644 (file)
@@ -129,7 +129,8 @@ public class CollectionSpaceJaxRsApplication extends Application
 
         singletons.add(new IDResource());
         
-        // FIXME: Temporary for CSPACE-5271
+        // FIXME: Temporary for CSPACE-5271 - please remove once
+        // that issue is resolved
         uriTemplateRegistry.dump();
         
         /*
@@ -143,7 +144,15 @@ public class CollectionSpaceJaxRsApplication extends Application
     private void addResourceToMapAndSingletons(ResourceBase resource) {
         singletons.add(resource);
         resourceMap.put(resource.getServiceName(), resource);
-        uriTemplateRegistry.putAll(resource.getUriTemplateMap());
+        // 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
+        // building URIs for resources that have contacts as a sub-resource
+        //
+        // FIXME: There may be a more elegant way to filter this out; or it may
+        // fall out during implementation of CSPACE-2698
+        if (! (resource instanceof ContactResource)) {
+            uriTemplateRegistry.putAll(resource.getUriTemplateMap());
+        }
     }
 
     @Override
index fa8b065f64adbbc3b9cf71130d5d989b17f6d3d9..adce97fd3d58b5da2d01002ad899e71481ce6ec2 100644 (file)
@@ -398,13 +398,13 @@ public abstract class ResourceBase
     \r
     public String getDocType(String serviceName) {\r
         String docType = "";\r
-        String arbitraryTenantId = "";\r
+        String anyTenantId = "";\r
         TenantBindingConfigReaderImpl reader = ServiceMain.getInstance().getTenantBindingConfigReader();\r
         // FIXME: Makes the likely unsupportable assumption that the list of service names and associated\r
         // document types is materially identical across tenants\r
-        arbitraryTenantId = getArbitraryTenantId(reader);\r
-        if (Tools.notBlank(arbitraryTenantId)) {\r
-            ServiceBindingType sb = reader.getServiceBinding(arbitraryTenantId, serviceName);\r
+        anyTenantId = getAnyTenantId(reader);\r
+        if (Tools.notBlank(anyTenantId)) {\r
+            ServiceBindingType sb = reader.getServiceBinding(anyTenantId, serviceName);\r
             docType = sb.getObject().getName(); // reads the Nuxeo Document Type from tenant bindings configuration\r
         }\r
         return docType;\r
@@ -433,19 +433,19 @@ public abstract class ResourceBase
         return template;\r
     }\r
 \r
-    public String getArbitraryTenantId(TenantBindingConfigReaderImpl reader) {\r
-        String arbitraryTenantId = "";\r
+    public String getAnyTenantId(TenantBindingConfigReaderImpl reader) {\r
+        String anyTenantId = "";\r
         Hashtable<String, TenantBindingType> tenantBindings = reader.getTenantBindings();\r
         if (tenantBindings != null && !tenantBindings.isEmpty()) {\r
             Enumeration keys = tenantBindings.keys();\r
             while (keys.hasMoreElements()) {\r
-               arbitraryTenantId = (String) keys.nextElement();\r
-               if (Tools.notBlank(arbitraryTenantId)) {\r
+               anyTenantId = (String) keys.nextElement();\r
+               if (Tools.notBlank(anyTenantId)) {\r
                    break;\r
                }\r
             }\r
         }\r
-        return arbitraryTenantId;\r
+        return anyTenantId;\r
     }\r
 \r
 }\r
index edf510c8a0b25813c47c8fef2fd4780f1baf310f..9d6f219ea70c89f16521869d08a100f22a7d13e5 100644 (file)
@@ -301,9 +301,9 @@ public abstract class AuthorityResourceWithContacts<AuthCommon, AuthItemHandler>
         return ContactConstants.NUXEO_DOCTYPE;
     }
 
-    // FIXME: This currently populates only one entry in the UriTemplateRegistry
+    // This 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 is called more than once,
+    // 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
     public Map<String,StoredValuesUriTemplate> getUriTemplateMap() {
@@ -318,6 +318,9 @@ public abstract class AuthorityResourceWithContacts<AuthCommon, AuthItemHandler>
         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);
         return uriTemplateMap;
     }