]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5012: Simplified generation of collectionspace_core:uri values, based very...
authorAron Roberts <aron@socrates.berkeley.edu>
Thu, 24 May 2012 01:44:50 +0000 (18:44 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Thu, 24 May 2012 01:44:50 +0000 (18:44 -0700)
services/imports/service/pom.xml
services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java
services/imports/service/src/main/resources/templates/service-document.xml

index d295837993fcd304bb305b0086a46f526d6fef76..6cf6453eff32693e533f0369e8a5f520382dbb56 100644 (file)
             <artifactId>org.collectionspace.services.common</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.collectionspace.services</groupId>
+            <artifactId>org.collectionspace.services.client</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.collectionspace.services</groupId>
             <artifactId>org.collectionspace.services.authentication.service</artifactId>
index c48365fef17cf73572f62df2c4731cf63635f9fc..43d06f389680962e2b4cba2ad46aa3238497e8a6 100644 (file)
 
 package org.collectionspace.services.imports;
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.UUID;
 
-import org.collectionspace.services.common.IFragmentHandler;
-import org.collectionspace.services.common.XmlSaxFragmenter;
-import org.collectionspace.services.common.XmlTools;
+import org.collectionspace.services.client.AuthorityClient;
+import org.collectionspace.services.common.*;
 import org.collectionspace.services.common.api.FileTools;
 import org.collectionspace.services.common.api.Tools;
+import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
+import org.collectionspace.services.config.service.ServiceBindingType;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 
 import org.dom4j.Document;
@@ -47,6 +50,8 @@ import org.xml.sax.InputSource;
  * @author Laramie Crocker
  */
 public class TemplateExpander {
+    
+    static Map<String,String> docTypeSvcNameRegistry = new HashMap<String,String>();
 
     protected static String var(String theVar){
         return "\\$\\{"+theVar+"\\}";
@@ -81,6 +86,17 @@ public class TemplateExpander {
         String nowTime = GregorianCalendarDateTimeUtils.timestampUTC();
         wrapperTmpl = searchAndReplaceVar(wrapperTmpl, "createdDate", nowTime);
         wrapperTmpl = searchAndReplaceVar(wrapperTmpl, "updatedDate", nowTime);
+        
+        wrapperTmpl = Tools.searchAndReplace(wrapperTmpl, var("uri"),
+                getDocUri(tenantId, SERVICE_TYPE, docID));
+
+        /*
+        TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader();
+        ServiceBindingType sb = tReader.getServiceBindingForDocType(tenantId, SERVICE_TYPE);
+       String uri = "/" + sb.getName().toLowerCase() + "/" + docID;
+        wrapperTmpl = Tools.searchAndReplace(wrapperTmpl, var("uri"), uri);
+        * 
+        */
 
         String serviceDir = outDir+'/'+docID;
         FileTools.saveFile(serviceDir, "document.xml", wrapperTmpl, true/*true=create parent dirs*/);
@@ -123,6 +139,71 @@ public class TemplateExpander {
         XmlSaxFragmenter.parse(requestSource, chopPath, callback, false);
     }
 
+    private static String getDocUri(String tenantId, String SERVICE_TYPE, String docID) throws Exception {
+        
+        // FIXME: Use already-defined constants, likely to be found in another package
+        final String AUTHORITY_TYPE = "authority";
+        final String OBJECT_TYPE = "object";
+        final String PROCEDURE_TYPE = "procedure";
+
+        TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader();
+        ServiceBindingType sb = tReader.getServiceBindingForDocType(tenantId, SERVICE_TYPE);
+        
+        String serviceType = sb.getType();
+        String serviceName = "";
+        String uri = "";
+        if (serviceType.equalsIgnoreCase(AUTHORITY_TYPE)) {
+            String authoritySvcName = getAuthoritySvcName(SERVICE_TYPE);
+            if (authoritySvcName == null) {
+                return uri;
+            }
+            // FIXME: Get the inAuthority value from the payload or from a new param for this method
+            String inAuthorityID = "inAuthorityValueHere"; // stub
+            uri = getAuthorityUri(authoritySvcName, inAuthorityID, docID);
+       } else if (serviceType.equalsIgnoreCase(OBJECT_TYPE) ||
+               serviceType.equalsIgnoreCase(PROCEDURE_TYPE) ) {
+            serviceName = sb.getName().toLowerCase();
+            uri = getUri(serviceName, docID);
+       } else {
+           // Currently returns a blank URI for any other cases,
+           // including sub-resources like contacts
+         }
+        System.out.println("uri=" + uri); // temp for debugging
+        return uri;
+    }
+    
+    // Stub / mock of a registry of authority document types and their
+    // associated parent authority service names
+    private static Map<String,String> getDocTypeSvcNameRegistry() {
+        if (docTypeSvcNameRegistry.isEmpty()) {
+            docTypeSvcNameRegistry.put("Concept", "Conceptauthorities");
+            docTypeSvcNameRegistry.put("Location", "Locationauthorities");
+            docTypeSvcNameRegistry.put("Person", "Personauthorities");
+            docTypeSvcNameRegistry.put("Place", "Placeauthorities");
+            docTypeSvcNameRegistry.put("Organization", "Orgauthorities");
+            docTypeSvcNameRegistry.put("Taxon", "Taxonauthority");
+        }
+        return docTypeSvcNameRegistry;
+    }
+    
+    private static String getAuthoritySvcName(String docType) {
+        return getDocTypeSvcNameRegistry().get(docType);
+    }
+    
+    private static String getUri(String serviceName, String docID) {
+        return "/" + serviceName
+                + "/" + docID;
+    }
+
+    private static String getAuthorityUri(String authorityServiceName, String inAuthorityID, String docID) {
+        return "/" + authorityServiceName.toLowerCase()
+                + '/' + inAuthorityID
+                + '/' + AuthorityClient.ITEMS
+                + '/' + docID;
+    }
+    
+    // FIXME: Create equivalent getUri-type method(s) for sub-resources, such as contacts
+
     /** This inner class is the callback target for calls to XmlSaxFragmenter, for example:
      *     FragmentHandlerImpl callback = new FragmentHandlerImpl();
      *     XmlSaxFragmenter.parse(filename, "/imports/import", callback, false);
index 858fe6a573e9e6d53e99493e689d2ca1a459b5e1..2a9cc2de7731b17f2e035cf2a25292aa0273c9e9 100644 (file)
@@ -39,6 +39,7 @@
     <collectionspace_core:updatedAt>${updatedDate}</collectionspace_core:updatedAt>\r
     <collectionspace_core:createdAt>${createdDate}</collectionspace_core:createdAt>\r
     <collectionspace_core:tenantId>${tenantID}</collectionspace_core:tenantId>\r
+    <collectionspace_core:uri>${uri}</collectionspace_core:uri>\r
   </schema>\r
   ${Schema}\r
 </document>\r