]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5271,CSPACE-5274: Imports service now uses URI template registry to populate...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 17 Aug 2012 01:57:54 +0000 (18:57 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 17 Aug 2012 01:57:54 +0000 (18:57 -0700)
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java
services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java

index 265e969bf7317e0aa1ac7066f053cd0240bd7283..64ad5f9710aeddae0ffa3ab657954deac805e4e2 100644 (file)
@@ -573,23 +573,31 @@ public class RefNameServiceUtils {
                 ilistItem = new AuthorityRefDocList.AuthorityRefDocItem();\r
                 String csid = NuxeoUtils.getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());\r
                 ilistItem.setDocId(csid);\r
+                String uri = "";\r
                 UriTemplateRegistry registry = ServiceMain.getInstance().getUriTemplateRegistry();\r
                 UriTemplateRegistryKey key = new UriTemplateRegistryKey(tenantId, docType);\r
                 StoredValuesUriTemplate template = registry.get(key);\r
+                // FIXME: Need to check here for any failure to retrieve a URI Template\r
+                // from the registry, given a tenant ID and docType\r
                 Map<String, String> additionalValues = new HashMap<String, String>();\r
                 if (template.getUriTemplateType() == UriTemplateFactory.ITEM) {\r
                     try {\r
                         String inAuthorityCsid = (String) docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY\r
                         additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, inAuthorityCsid);\r
                         additionalValues.put(UriTemplateFactory.ITEM_IDENTIFIER_VAR, csid);\r
+                        uri = template.buildUri(additionalValues);\r
                     } catch (Exception e) {\r
                         logger.warn("Could not extract inAuthority property from authority item record: " + e.getMessage());\r
                     }\r
+                    // FIXME: Generating contact sub-resource URIs requires additional work,\r
+                    // beyond CSPACE-5271 - ADR 2012-08-16\r
+                } else if (template.getUriTemplateType() == UriTemplateFactory.CONTACT) {\r
+                    // Return the default (empty string) value for URI, for now.\r
                 } else {\r
                     additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, csid);\r
+                    uri = template.buildUri(additionalValues);\r
                 }\r
-                String uriStr = template.buildUri(additionalValues);\r
-                ilistItem.setUri(uriStr);\r
+                ilistItem.setUri(uri);\r
                 try {\r
                     ilistItem.setWorkflowState(docModel.getCurrentLifeCycleState());\r
                     ilistItem.setUpdatedAt(DocHandlerBase.getUpdatedAtAsString(docModel));\r
index 2ef9d3be65671c228516d48752cee5d04633def1..cb661e03661299bb126a092f2a0baa11bed15083 100644 (file)
@@ -34,6 +34,10 @@ import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
 import org.collectionspace.services.common.IFragmentHandler;
 import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.StoredValuesUriTemplate;
+import org.collectionspace.services.common.UriTemplateFactory;
+import org.collectionspace.services.common.UriTemplateRegistry;
+import org.collectionspace.services.common.UriTemplateRegistryKey;
 import org.collectionspace.services.common.XmlSaxFragmenter;
 import org.collectionspace.services.common.XmlTools;
 import org.collectionspace.services.common.api.FileTools;
@@ -207,33 +211,31 @@ public class TemplateExpander {
     // document type name
     private static String getDocUri(String tenantId, String docType, String docID,
             String partTmpl) throws Exception {
-
-
-        TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader();
-        // We may have been supplied with the tenant-qualified name
-        // of an extension to a document type, and thus need to
-        // get the base document type name.
-        docType = ServiceBindingUtils.getUnqualifiedTenantDocType(docType);
-        ServiceBindingType sb =
-            tReader.getServiceBindingForDocType(tenantId, docType);        
-
-        String serviceCategory = sb.getType();
         String uri = "";
-        if (serviceCategory.equalsIgnoreCase(URIUtils.AUTHORITY_SERVICE_CATEGORY)) {
-            String authoritySvcName = URIUtils.getAuthoritySvcName(docType);
-            if (authoritySvcName == null) {
-                return uri;
+        UriTemplateRegistry registry = ServiceMain.getInstance().getUriTemplateRegistry();
+        UriTemplateRegistryKey key = new UriTemplateRegistryKey(tenantId, docType);
+        StoredValuesUriTemplate template = registry.get(key);
+        // FIXME: Need to check here for any failure to retrieve a URI Template
+        // from the registry, given a tenant ID and docType
+        Map<String, String> additionalValues = new HashMap<String, String>();
+        if (template.getUriTemplateType() == UriTemplateFactory.ITEM) {
+            try {
+                String inAuthorityCsid = getInAuthorityValue(partTmpl);
+                additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, inAuthorityCsid);
+                additionalValues.put(UriTemplateFactory.ITEM_IDENTIFIER_VAR, docID);
+                uri = template.buildUri(additionalValues);
+
+            } catch (Exception e) {
+                logger.warn("Could not extract inAuthority property from authority item record: " + e.getMessage());
             }
-            String inAuthorityID = getInAuthorityValue(partTmpl);
-            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
-         }
+            // FIXME: Generating contact sub-resource URIs requires additional work,
+            // beyond CSPACE-5271 - ADR 2012-08-16
+        } else if (template.getUriTemplateType() == UriTemplateFactory.CONTACT) {
+            return uri;
+        } else {
+            additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, docID);
+            uri = template.buildUri(additionalValues);
+        }
         return uri;
     }