]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5271:CSPACE-5453: Handles cases where URI template cannot be retrieved from...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 17 Aug 2012 03:01:13 +0000 (20:01 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 17 Aug 2012 03:01:13 +0000 (20:01 -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 64ad5f9710aeddae0ffa3ab657954deac805e4e2..e6691991aaee677efc77d9fca90f9512775e8613 100644 (file)
@@ -577,25 +577,32 @@ public class RefNameServiceUtils {
                 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
+                if (template != null) {\r
+                    Map<String, String> additionalValues = new HashMap<String, String>();\r
+                    if (template.getUriTemplateType() == UriTemplateFactory.RESOURCE) {\r
+                        additionalValues.put(UriTemplateFactory.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
+                    } else 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
+                    } else if (template.getUriTemplateType() == UriTemplateFactory.CONTACT) {\r
+                        // FIXME: Generating contact sub-resource URIs requires additional work,\r
+                        // as a follow-on to CSPACE-5271 - ADR 2012-08-16\r
+                        // Sets the default (empty string) value for uri, for now\r
+                    } else {\r
+                        logger.warn("Unrecognized URI template type = " + template.getUriTemplateType());\r
+                        // Sets the default (empty string) value for uri\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
+                } else { // (if template == null)\r
+                    logger.warn("Could not retrieve URI template from registry via tenant ID "\r
+                            + tenantId + " and docType " + docType);\r
+                    // Sets the default (empty string) value for uri\r
                 }\r
                 ilistItem.setUri(uri);\r
                 try {\r
index cb661e03661299bb126a092f2a0baa11bed15083..bbf13fe53eb7004db3e978106c50fe30242e6c4e 100644 (file)
@@ -215,26 +215,33 @@ public class TemplateExpander {
         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);
+        if (template != null) {
+            Map<String, String> additionalValues = new HashMap<String, String>();
+            if (template.getUriTemplateType() == UriTemplateFactory.RESOURCE) {
+                additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, docID);
                 uri = template.buildUri(additionalValues);
-
-            } catch (Exception e) {
-                logger.warn("Could not extract inAuthority property from authority item record: " + e.getMessage());
+            } else 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());
+                    // Returns the default (empty string) value for uri
+                }
+            } else if (template.getUriTemplateType() == UriTemplateFactory.CONTACT) {
+                // FIXME: Generating contact sub-resource URIs requires additional work,
+                // as a follow-on to CSPACE-5271 - ADR 2012-08-16
+                // Returns the default (empty string) value for uri, for now
+            } else {
+                logger.warn("Unrecognized URI template type = " + template.getUriTemplateType());
+                // Returns the default (empty string) value for uri
             }
-            // 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);
+        } else { // (if template == null)
+            logger.warn("Could not retrieve URI template from registry via tenant ID "
+                    + tenantId + " and docType " + docType);
+            // Returns the default (empty string) value for uri
         }
         return uri;
     }