]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5271: List of docType keys for the UriTemplateRegistry now comes from tenant...
authorAron Roberts <aron@socrates.berkeley.edu>
Sat, 9 Jun 2012 00:44:57 +0000 (17:44 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Sat, 9 Jun 2012 00:44:57 +0000 (17:44 -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/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java

index b2aca1fd55301042627ccc971aa58ed82a29efbf..e1543c2c80078c7b1421c7659ae697f8ae4bd072 100644 (file)
@@ -86,6 +86,10 @@ import java.util.List;
 import java.util.Map;
 import org.collectionspace.services.client.*;
 import org.collectionspace.services.common.*;
+
+import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
+import org.collectionspace.services.config.service.ServiceBindingType;
+
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 
 /**
@@ -963,7 +967,33 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     
     public String getItemDocType() {
         // FIXME: Proof of concept placeholder
-        return "item-" + getServiceName();
+        // return "item-" + getServiceName();
+        
+        return super.getDocType(getItemServiceName());
+        
+        /*
+        // FIXME: Replace this outrageous hack; a tenant with this ID may not exist
+        String docType = "";
+        final String DEFAULT_TENANT_ID = "1";
+        TenantBindingConfigReaderImpl reader = ServiceMain.getInstance().getTenantBindingConfigReader();
+        ServiceBindingType sb = reader.getServiceBinding(DEFAULT_TENANT_ID, getItemServiceName());
+        docType = sb.getObject().getName();
+        return docType;
+        
+        String docType = "";
+        String arbitraryTenantId = "";
+        ServiceBindingType sb;
+        TenantBindingConfigReaderImpl reader = ServiceMain.getInstance().getTenantBindingConfigReader();
+        // FIXME: Makes the outrageous assumption that the list of service names and associated
+        // document types is essentially identical across tenants
+        arbitraryTenantId = getArbitraryTenantId(reader);
+        if (Tools.notBlank(arbitraryTenantId)) {
+            ServiceBindingType sb = reader.getServiceBinding(arbitraryTenantId, getItemServiceName());
+            docType = sb.getObject().getName();
+        }
+        return docType;
+        * 
+        */
     }
 
     @Override
index 578159891a97c4447f727973ab7d522e17817327..5eecf059d63c63eea83713ce4eb1494bf5fa1c07 100644 (file)
@@ -23,6 +23,7 @@
  */\r
 package org.collectionspace.services.common;\r
 \r
+import java.util.*;\r
 import org.collectionspace.services.client.IQueryManager;\r
 import org.collectionspace.services.client.PoxPayloadIn;\r
 import org.collectionspace.services.client.PoxPayloadOut;\r
@@ -47,9 +48,11 @@ import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
 import javax.ws.rs.*;\r
 import javax.ws.rs.core.*;\r
 \r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
+\r
+import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;\r
+import org.collectionspace.services.config.service.ServiceBindingType;\r
+import org.collectionspace.services.config.tenant.TenantBindingType;\r
+\r
 \r
 /**\r
  * $LastChangedRevision:  $\r
@@ -383,8 +386,29 @@ public abstract class ResourceBase
     }\r
     \r
     public String getDocType() {\r
-        // FIXME: Proof of concept placeholder\r
-        return getServiceName();\r
+        return getDocType(getServiceName());\r
+    }\r
+        \r
+    // FIXME: This may well be a dreadful hack, just to get this initially working.\r
+    //\r
+    // Question:\r
+    // At the point we're seeking to populate docTypes in the uriTemplateRegistry, during system startup,\r
+    // we're not yet logged into any tenant, but instead it appears we are acting as the user SPRING_ADMIN.\r
+    // Could this potentially suggest reasonable method(s), other than those below, by which we can obtain\r
+    // the docType(s) associated with the current resource?\r
+    \r
+    public String getDocType(String serviceName) {\r
+        String docType = "";\r
+        String arbitraryTenantId = "";\r
+        TenantBindingConfigReaderImpl reader = ServiceMain.getInstance().getTenantBindingConfigReader();\r
+        // FIXME: Makes the outrageous assumption that the list of service names and associated\r
+        // document types is essentially identical across tenants\r
+        arbitraryTenantId = getArbitraryTenantId(reader);\r
+        if (Tools.notBlank(arbitraryTenantId)) {\r
+            ServiceBindingType sb = reader.getServiceBinding(arbitraryTenantId, serviceName);\r
+            docType = sb.getObject().getName();\r
+        }\r
+        return docType;\r
     }\r
     \r
     public Map<String,StoredValuesUriTemplate> getUriTemplateMap() {\r
@@ -410,5 +434,19 @@ public abstract class ResourceBase
         return template;\r
     }\r
 \r
+    public String getArbitraryTenantId(TenantBindingConfigReaderImpl reader) {\r
+        String arbitraryTenantId = "";\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
+                   break;\r
+               }\r
+            }\r
+        }\r
+        return arbitraryTenantId;\r
+    }\r
 \r
 }\r
index 5d5553fd537fd711f438ade6c0bb508e9f3c30eb..d81256c789432b740584ba502a15cf218c8cf30d 100644 (file)
@@ -49,6 +49,7 @@ import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.contact.ContactResource;
 import org.collectionspace.services.contact.ContactsCommon;
 import org.collectionspace.services.contact.ContactJAXBSchema;
+import org.collectionspace.services.contact.nuxeo.ContactConstants;
 import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.jboss.resteasy.util.HttpResponseCodes;
@@ -297,8 +298,7 @@ public abstract class AuthorityResourceWithContacts<AuthCommon, AuthItemHandler>
     }
     
     public String getContactDocType() {
-        // FIXME: Proof of concept placeholder
-        return "contact-" + getServiceName();
+        return ContactConstants.NUXEO_DOCTYPE;
     }
 
     @Override