]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3451: Fixed a multitenancy issue involving ambiguity in the repository domain...
authorRichard Millet <richard.millet@berkeley.edu>
Wed, 11 May 2011 21:41:26 +0000 (21:41 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Wed, 11 May 2011 21:41:26 +0000 (21:41 +0000)
services/common/src/main/cspace/config/services/tenants/collectionspace/tenant-bindings.xml
services/common/src/main/cspace/config/services/tenants/hearstmuseum/tenant-bindings.xml
services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java
services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java
services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java
services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/TenantRepository.java
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java
services/common/src/main/resources/tenant.xsd

index 65900ea3bfc2a67bd334bfa1bdb14156fc618f11..b0c1fb48ad8332ade6a9165563754897a58c9994 100644 (file)
@@ -8,7 +8,7 @@
 <tenant:TenantBindingConfig xmlns:tenant="http://collectionspace.org/services/common/tenant" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://collectionspace.org/services/common/tenant http://collectionspace.org/services/common/tenant.xsd">
   <!-- begin movingimages.us tenant meta-data -->
   <tenant:tenantBinding id="1" name="collectionspace.org" displayName="CollectionSpace Demo" version="0.1">
-    <tenant:repositoryDomain name="default-domain" repositoryClient="nuxeo-java" />
+    <tenant:repositoryDomain name="default-domain" storageName="default-domain" repositoryClient="nuxeo-java" />
     <tenant:properties>
       <types:item xmlns:types="http://collectionspace.org/services/common/types">
         <types:key>datePattern</types:key>
index e7d4f0732a4627a1fcefc2dbf0ff5c525a3677c1..3c0abecc811c0aeb2e532e0dc60edaeb524951d5 100644 (file)
@@ -8,7 +8,7 @@
 <tenant:TenantBindingConfig xmlns:tenant="http://collectionspace.org/services/common/tenant" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://collectionspace.org/services/common/tenant http://collectionspace.org/services/common/tenant.xsd">
   <!-- begin hearstmuseum.berkeley.edu tenant meta-data -->
   <tenant:tenantBinding id="2" name="hearstmuseum.berkeley.edu" displayName="Phoebe A. Hearst Museum of Anthropology" version="0.1">
-    <tenant:repositoryDomain name="default-domain" repositoryClient="nuxeo-java" />
+    <tenant:repositoryDomain name="default-domain" storageName="hearst-domain" repositoryClient="nuxeo-java" />
     <tenant:properties>
       <types:item xmlns:types="http://collectionspace.org/services/common/types">
         <types:key>datePattern</types:key>
index b819b823495a23337b49f67a723ff2ad6d77b00b..7b4b1567bf23aab7ab34b4b63661ea20f785a61d 100644 (file)
@@ -158,7 +158,9 @@ public class TenantBindingConfigReaderImpl
     
     private void readDomains(TenantBindingType tenantBinding) throws Exception {
         for (RepositoryDomainType domain : tenantBinding.getRepositoryDomain()) {
-            domains.put(domain.getName(), domain);
+               String key = getTenantQualifiedIdentifier(tenantBinding.getId(),
+                               domain.getName());
+            domains.put(key, domain);
         }
     }
 
@@ -239,7 +241,8 @@ public class TenantBindingConfigReaderImpl
             */
             return null;
         }
-        return domains.get(repoDomain.trim());
+        String key = this.getTenantQualifiedIdentifier(tenantId, repoDomain.trim());
+        return domains.get(key);
     }
 
     /**
@@ -295,7 +298,8 @@ public class TenantBindingConfigReaderImpl
      */
     public static String getTenantQualifiedServiceName(
             String tenantId, String serviceName) {
-        return tenantId + "." + serviceName.toLowerCase();
+//        return tenantId + "." + serviceName.toLowerCase();
+        return getTenantQualifiedIdentifier(tenantId, serviceName.toLowerCase());
     }
 
     public static String getTenantQualifiedIdentifier(String tenantId, String identifier) {
index 2f3798e3f2a870aab159d789eafdddbd34ef52b4..2dc344b092cbb36f79f1b17922f3fb62f37ec3a3 100644 (file)
@@ -283,6 +283,17 @@ public abstract class AbstractServiceContextImpl<IT, OT>
         return repositoryDomain.getName();
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryDomainName()
+     */
+    @Override
+    public String getRepositoryDomainStorageName() {
+        if (repositoryDomain == null) {
+            return null;
+        }
+        return repositoryDomain.getStorageName();
+    }
+
     /* (non-Javadoc)
      * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryWorkspaceId()
      */
index 872d04c2d959466df757836e946547bf646d7b0d..cd0fb5b31253ae59555c004ce811a97f2d41e3a5 100644 (file)
@@ -111,6 +111,11 @@ public interface ServiceContext<IT, OT> {
      * @return repository domain for the tenant
      */
     public String getRepositoryDomainName();
+    
+    /*
+     * Get's the name/label used to create the storage container (folder or directory name)
+     */
+    public String getRepositoryDomainStorageName();    
 
     /**
      * getRepositoryClientName returns the repository client name as
index 1c07ff356853d0cc8c6bcbca01ca5a46b2f4988a..c7b1ba101ba53aa6b491c59e2327dc160809724a 100644 (file)
@@ -43,7 +43,7 @@ public class QueryContext {
             throw new DocumentNotFoundException(\r
                     "Unable to find DocumentType for service " + ctx.getServiceName());\r
         }\r
-        domain = ctx.getRepositoryDomainName();\r
+        domain = ctx.getRepositoryDomainStorageName();\r
         tenantId = ctx.getTenantId();\r
         if (tenantId == null) {\r
             throw new IllegalArgumentException(\r
index eb8e399f3b84b71e2ebda6d4d9659f8ebe0ae265..b4fff66af4bd38180828ef358b1d63a8680f569d 100644 (file)
@@ -836,24 +836,28 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
     public String getDomainId(String domainName) throws Exception {
         String domainId = null;
         RepositoryInstance repoSession = null;
-        try {
-            repoSession = getRepositorySession();
-            DocumentRef docRef = new PathRef(
-                    "/" + domainName);
-            DocumentModel domain = repoSession.getDocument(docRef);
-            domainId = domain.getId();
-        } catch (Exception e) {
-            if (logger.isDebugEnabled()) {
-                logger.debug("Caught exception ", e);
-            }
-            //there is no way to identify if document does not exist due to
-            //lack of typed exception for getDocument method
-            return null;
-        } finally {
-            if (repoSession != null) {
-                releaseRepositorySession(repoSession);
-            }
+        
+        if (domainName != null && !domainName.isEmpty()) {
+               try {
+                   repoSession = getRepositorySession();
+                   DocumentRef docRef = new PathRef(
+                           "/" + domainName);
+                   DocumentModel domain = repoSession.getDocument(docRef);
+                   domainId = domain.getId();
+               } catch (Exception e) {
+                   if (logger.isDebugEnabled()) {
+                       logger.debug("Caught exception ", e);
+                   }
+                   //there is no way to identify if document does not exist due to
+                   //lack of typed exception for getDocument method
+                   return null;
+               } finally {
+                   if (repoSession != null) {
+                       releaseRepositorySession(repoSession);
+                   }
+               }
         }
+        
         return domainId;
     }
 
index 5527727c88d1025bdc6599447ed4025d1c5347cb..d87368d64c41030ea296e2adef6dfc3eeb1408a2 100644 (file)
@@ -122,9 +122,9 @@ public class TenantRepository {
             RepositoryDomainType repositoryDomain) throws Exception {
         String domainName = repositoryDomain.getName();
         RepositoryClient repositoryClient = getRepositoryClient(repositoryDomain);
-        String domainId = repositoryClient.getDomainId(domainName);
+        String domainId = repositoryClient.getDomainId(repositoryDomain.getStorageName());
         if (domainId == null) {
-            domainId = repositoryClient.createDomain(domainName);
+            domainId = repositoryClient.createDomain(repositoryDomain.getStorageName());
             if (logger.isDebugEnabled()) {
                 logger.debug("created repository domain for " + domainName
                         + " id=" + domainId);
@@ -153,7 +153,7 @@ public class TenantRepository {
         //retrieve all workspace ids for a domain
         //domain specific table of workspace name and id
         Hashtable<String, String> workspaceIds =
-                repositoryClient.retrieveWorkspaceIds(repositoryDomain.getName());
+                repositoryClient.retrieveWorkspaceIds(repositoryDomain.getStorageName());
         //verify if workspace exists for each service from the tenant binding
         for (ServiceBindingType serviceBinding : tenantBinding.getServiceBindings()) {
             String serviceName = serviceBinding.getName();
@@ -190,7 +190,7 @@ public class TenantRepository {
                                 + " in repository.  Creating new workspace ...");
                     }
                     workspaceId = repositoryClient.createWorkspace(
-                            repositoryDomain.getName(),
+                            repositoryDomain.getStorageName(),
                             serviceBinding.getName());
                     if (workspaceId == null) {
                         if (logger.isWarnEnabled()) {
index d58e54015f47014d08476be636ea5b358b244ad1..fe6789b975e5be9ff1f95e013bad4103803d1145 100644 (file)
@@ -431,7 +431,7 @@ public class NuxeoUtils {
      * @return PathRef
      */
     public static DocumentRef createPathRef(ServiceContext ctx, String id) {
-        return new PathRef("/" + ctx.getRepositoryDomainName() +
+        return new PathRef("/" + ctx.getRepositoryDomainStorageName() +
                 "/" + "workspaces" +
                 "/" + ctx.getRepositoryWorkspaceName() +
                 "/" + id);
index 43d00ac497bc3e461b0c65a1f82e83958e2bb81d..04cee10c3f3e008b8fdf71fe84e608481df7aa42 100644 (file)
@@ -65,6 +65,7 @@
         </xs:annotation>
         <xs:sequence/>
         <xs:attribute name="name" type="xs:string" use="required"/>
+        <xs:attribute name="storageName" type="xs:string" use="required"/>
         <xs:attribute name="repositoryClient" type="xs:string" use="optional" default="nuxeo-java"/>
     </xs:complexType>