]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5406: First pass at generating valid <uri> values in refObjs list items for...
authorAron Roberts <aron@socrates.berkeley.edu>
Thu, 19 Jul 2012 18:43:34 +0000 (11:43 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Thu, 19 Jul 2012 18:43:34 +0000 (11:43 -0700)
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java
services/config/src/main/java/org/collectionspace/services/common/config/URIUtils.java [new file with mode: 0644]
services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java

index ac72506ee8ce99f464bbf270239713937ccff6a6..e3bc6afd19f1cc51e843109cf53e92cd1d9aaf0c 100644 (file)
@@ -51,6 +51,7 @@ import org.collectionspace.services.common.api.RefNameUtils.AuthorityTermInfo;
 import org.collectionspace.services.common.authorityref.AuthorityRefDocList;\r
 import org.collectionspace.services.common.authorityref.AuthorityRefList;\r
 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;\r
+import org.collectionspace.services.common.config.URIUtils;\r
 import org.collectionspace.services.common.context.ServiceBindingUtils;\r
 import org.collectionspace.services.common.document.DocumentException;\r
 import org.collectionspace.services.common.document.DocumentFilter;\r
@@ -59,6 +60,7 @@ import org.collectionspace.services.common.document.DocumentUtils;
 import org.collectionspace.services.common.document.DocumentWrapper;\r
 import org.collectionspace.services.common.query.QueryManager;\r
 import org.collectionspace.services.common.repository.RepositoryClient;\r
+// import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;\r
 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;\r
 import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;\r
 import org.collectionspace.services.common.security.SecurityUtils;\r
@@ -556,7 +558,6 @@ public class RefNameServiceUtils {
                 throw new RuntimeException(\r
                         "getAuthorityRefDocs: No Service Binding for docType: " + docType);\r
             }\r
-            String serviceContextPath = "/" + sb.getName().toLowerCase() + "/";\r
 \r
             if (list == null) { // no list - should be update refName case.\r
                 if (newAuthorityRefName == null) {\r
@@ -570,7 +571,22 @@ public class RefNameServiceUtils {
                 ilistItem = new AuthorityRefDocList.AuthorityRefDocItem();\r
                 String csid = NuxeoUtils.getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());\r
                 ilistItem.setDocId(csid);\r
-                ilistItem.setUri(serviceContextPath + csid);\r
+                String uri = "";\r
+                // FIXME: Hack for CSPACE-5406; this instead should use the (forthcoming)\r
+                // URL pattern-to-Doctype registry described in CSPACE-5471 - ADR 2012-07-18\r
+                if (sb.getType().equalsIgnoreCase(URIUtils.AUTHORITY_SERVICE_CATEGORY)) {\r
+                    String authoritySvcName = URIUtils.getAuthoritySvcName(docType);\r
+                    String inAuthorityCsid;\r
+                    try {\r
+                        inAuthorityCsid = (String) docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY\r
+                        uri = URIUtils.getAuthorityItemUri(authoritySvcName, inAuthorityCsid, csid);\r
+                    } catch (Exception e) {\r
+                        logger.warn("Could not extract inAuthority property from authority item record: " + e.getMessage());\r
+                    }\r
+                } else {\r
+                    uri = URIUtils.getUri(sb.getName(), csid);;\r
+                }\r
+                ilistItem.setUri(uri);\r
                 try {\r
                     ilistItem.setWorkflowState(docModel.getCurrentLifeCycleState());\r
                     ilistItem.setUpdatedAt(DocHandlerBase.getUpdatedAtAsString(docModel));\r
diff --git a/services/config/src/main/java/org/collectionspace/services/common/config/URIUtils.java b/services/config/src/main/java/org/collectionspace/services/common/config/URIUtils.java
new file mode 100644 (file)
index 0000000..94307f4
--- /dev/null
@@ -0,0 +1,68 @@
+package org.collectionspace.services.common.config;
+
+// import org.collectionspace.services.client.AuthorityClient;
+import java.util.HashMap;
+import java.util.Map;
+
+// Hack for CSPACE-5
+
+public class URIUtils {
+
+    private static Map<String, String> docTypeSvcNameRegistry = new HashMap<String, String>();
+    
+    // FIXME: This is a quick hack, which assumes that URI construction
+    // behaviors are bound to categories of services.  Those behaviors
+    // should instead be specified on a per-service basis via a registry,
+    // the mechanism we are intending to use in v2.5.  (See comments below
+    // for more details.) - ADR 2012-05-24
+    public static final String AUTHORITY_SERVICE_CATEGORY = "authority";
+    public static final String OBJECT_SERVICE_CATEGORY = "object";
+    public static final String PROCEDURE_SERVICE_CATEGORY = "procedure";
+
+    // FIXME: This is a quick hack; a stub / mock of a registry of
+    // authority document types and their associated parent authority
+    // service names. This MUST be replaced by a more general mechanism
+    // in v2.5. 
+    // 
+    // Per Patrick, this registry needs to be available system-wide, not
+    // just here in the Imports service; extend to all relevant record types;
+    // and be automatically built in some manner, such as via per-resource
+    // registration, from configuration, etc. - ADR 2012-05-24
+    private static Map<String, String> getDocTypeSvcNameRegistry() {
+        if (docTypeSvcNameRegistry.isEmpty()) {
+            docTypeSvcNameRegistry.put("Conceptitem", "Conceptauthorities");
+            docTypeSvcNameRegistry.put("Locationitem", "Locationauthorities");
+            docTypeSvcNameRegistry.put("Person", "Personauthorities");
+            docTypeSvcNameRegistry.put("Placeitem", "Placeauthorities");
+            docTypeSvcNameRegistry.put("Organization", "Orgauthorities");
+            docTypeSvcNameRegistry.put("Taxon", "Taxonomyauthority");
+        }
+        return docTypeSvcNameRegistry;
+    }
+
+    /**
+     * Return the parent authority service name, based on the item document
+     * type.
+     */
+    public static String getAuthoritySvcName(String docType) {
+        return getDocTypeSvcNameRegistry().get(docType);
+    }
+
+    // FIXME: The following URI construction methods are also intended to be
+    // made generally available and associated to individual services, via the
+    // registry mechanism described above. - ADR, 2012-05-24
+    public static String getUri(String serviceName, String docID) {
+        return "/" + serviceName.toLowerCase()
+                + "/" + docID;
+    }
+
+    public static String getAuthorityItemUri(String authorityServiceName, String inAuthorityID, String docID) {
+        return "/" + authorityServiceName.toLowerCase()
+                + '/' + inAuthorityID
+                + '/' + "items" // AuthorityClient.ITEMS
+                + '/' + docID;
+    }
+    
+    // FIXME: Create equivalent getUri-type method(s) for sub-resources,
+    // such as contacts - ADR, 2012-05-24
+}
index e7c10a054b0a88f05c4b0d03d1abb21bcb2227f6..2ef9d3be65671c228516d48752cee5d04633def1 100644 (file)
@@ -32,7 +32,6 @@ import java.util.UUID;
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
-import org.collectionspace.services.client.AuthorityClient;
 import org.collectionspace.services.common.IFragmentHandler;
 import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.XmlSaxFragmenter;
@@ -40,6 +39,7 @@ import org.collectionspace.services.common.XmlTools;
 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.config.URIUtils;
 import org.collectionspace.services.common.context.ServiceBindingUtils;
 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
 import org.collectionspace.services.config.service.ServiceBindingType;
@@ -64,7 +64,6 @@ public class TemplateExpander {
     private final static Logger logger = LoggerFactory.getLogger(TemplateExpander.class);
     
     private static final String DEFAULT_WRAPPER_TEMPLATE_FILENAME = "service-document.xml";
-    private static Map<String,String> docTypeSvcNameRegistry = new HashMap<String,String>();
     private static XPath xpath = XPathFactory.newInstance().newXPath();
     // XPath expressions to match the value of the inAuthority field in authority item records.
     // The first expression matches namespace-qualified elements, while the second matches
@@ -208,15 +207,7 @@ public class TemplateExpander {
     // document type name
     private static String getDocUri(String tenantId, String docType, String docID,
             String partTmpl) throws Exception {
-        
-        // FIXME: This is a quick hack, which assumes that URI construction
-        // behaviors are bound to categories of services.  Those behaviors
-        // should instead be specified on a per-service basis via a registry,
-        // the mechanism we are intending to use in v2.5.  (See comments below
-        // for more details.) - ADR 2012-05-24
-        final String AUTHORITY_SERVICE_CATEGORY = "authority";
-        final String OBJECT_SERVICE_CATEGORY = "object";
-        final String PROCEDURE_SERVICE_CATEGORY = "procedure";
+
 
         TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader();
         // We may have been supplied with the tenant-qualified name
@@ -228,17 +219,17 @@ public class TemplateExpander {
 
         String serviceCategory = sb.getType();
         String uri = "";
-        if (serviceCategory.equalsIgnoreCase(AUTHORITY_SERVICE_CATEGORY)) {
-            String authoritySvcName = getAuthoritySvcName(docType);
+        if (serviceCategory.equalsIgnoreCase(URIUtils.AUTHORITY_SERVICE_CATEGORY)) {
+            String authoritySvcName = URIUtils.getAuthoritySvcName(docType);
             if (authoritySvcName == null) {
                 return uri;
             }
             String inAuthorityID = getInAuthorityValue(partTmpl);
-            uri = getAuthorityItemUri(authoritySvcName, inAuthorityID, docID);
-       } else if (serviceCategory.equalsIgnoreCase(OBJECT_SERVICE_CATEGORY) ||
-               serviceCategory.equalsIgnoreCase(PROCEDURE_SERVICE_CATEGORY) ) {
-            String serviceName = sb.getName().toLowerCase();
-            uri = getUri(serviceName, docID);
+            uri = URIUtils.getAuthorityItemUri(authoritySvcName, inAuthorityID, docID);
+       } else if (serviceCategory.equalsIgnoreCase(URIUtils.OBJECT_SERVICE_CATEGORY) ||
+               serviceCategory.equalsIgnoreCase(URIUtils.PROCEDURE_SERVICE_CATEGORY) ) {
+            String serviceName = sb.getName();
+            uri = URIUtils.getUri(serviceName, docID);
        } else {
            // Currently returns a blank URI for any other cases,
            // including sub-resources like contacts
@@ -246,52 +237,6 @@ public class TemplateExpander {
         return uri;
     }
     
-    // FIXME: This is a quick hack; a stub / mock of a registry of
-    // authority document types and their associated parent authority
-    // service names. This MUST be replaced by a more general mechanism
-    // in v2.5. 
-    // 
-    // Per Patrick, this registry needs to be available system-wide, not
-    // just here in the Imports service; extend to all relevant record types;
-    // and be automatically built in some manner, such as via per-resource
-    // registration, from configuration, etc. - ADR 2012-05-24
-    private static Map<String,String> getDocTypeSvcNameRegistry() {
-        if (docTypeSvcNameRegistry.isEmpty()) {
-            docTypeSvcNameRegistry.put("Conceptitem", "Conceptauthorities");
-            docTypeSvcNameRegistry.put("Locationitem", "Locationauthorities");
-            docTypeSvcNameRegistry.put("Person", "Personauthorities");
-            docTypeSvcNameRegistry.put("Placeitem", "Placeauthorities");
-            docTypeSvcNameRegistry.put("Organization", "Orgauthorities");
-            docTypeSvcNameRegistry.put("Taxon", "Taxonomyauthority");
-        }
-        return docTypeSvcNameRegistry;
-    }
-    
-    /**
-     * Return the parent authority service name, based on the item document type.
-     */
-    private static String getAuthoritySvcName(String docType) {
-        return getDocTypeSvcNameRegistry().get(docType);
-    }
-    
-    // FIXME: The following URI construction methods are also intended to be
-    // made generally available and associated to individual services, via the
-    // registry mechanism described above. - ADR, 2012-05-24
-    private static String getUri(String serviceName, String docID) {
-        return "/" + serviceName
-                + "/" + docID;
-    }
-
-    private static String getAuthorityItemUri(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 - ADR, 2012-05-24
-    
     // FIXME: It may also be desirable to explicitly validate the format of
     // CSID values provided in fields such as inAuthority, and perhaps later on,
     // their uniqueness against those already present in a running system.