]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5733: Emit correct URLs in servicegroups' items list for authority items.
authorAron Roberts <aron@socrates.berkeley.edu>
Thu, 29 Nov 2012 02:03:48 +0000 (18:03 -0800)
committerAron Roberts <aron@socrates.berkeley.edu>
Thu, 29 Nov 2012 02:03:48 +0000 (18:03 -0800)
services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistry.java
services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java

index b95e149b52d6d4249b6bc8993aa2457f7838a275..7a80a9f2cc3e83171e1b1fc0db4507e882fa89f6 100644 (file)
@@ -38,16 +38,24 @@ public class UriTemplateRegistry extends HashMap<UriTemplateRegistryKey, StoredV
      * Dumps all registry settings for debugging purposes.\r
      */\r
     public void dump() {\r
+        System.out.println(this.toString());\r
+    }\r
+    \r
+    /**\r
+     * Dumps all registry settings for debugging purposes.\r
+     */\r
+    public String toString() {\r
+        StringBuffer sb = new StringBuffer("");\r
         for (Map.Entry<UriTemplateRegistryKey, StoredValuesUriTemplate> uriTemplateEntry : this.entrySet()) {\r
-\r
-            System.out.println(\r
-                    "Tenant : DocType = "\r
-                    + uriTemplateEntry.getKey().getTenantId()\r
-                    + " : "\r
-                    + uriTemplateEntry.getKey().getDocType());\r
-\r
-            System.out.println(" Value of Template = ");\r
-            System.out.println("  " + uriTemplateEntry.getValue().toString());\r
+            sb.append("Tenant : DocType = ");\r
+            sb.append(uriTemplateEntry.getKey().getTenantId());\r
+            sb.append(" : ");\r
+            sb.append(uriTemplateEntry.getKey().getDocType());\r
+            sb.append('\n');\r
+            sb.append(" Value of Template = ");\r
+            sb.append("  " + uriTemplateEntry.getValue().toString());\r
+            sb.append('\n');\r
         }\r
+        return sb.toString();\r
     }\r
 }\r
index b32601512d0fa6eb89084093d1fb6a2774471704..4ae167363b139721f67f59993d489c2c05399808 100644 (file)
@@ -43,6 +43,10 @@ import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.ServiceMessages;
+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.api.Tools;
 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
 import org.collectionspace.services.common.context.ServiceBindingUtils;
@@ -137,7 +141,7 @@ public class ServiceGroupDocumentModelHandler
                if (docList == null) { // found no authRef fields - nothing to process
                    return list;
                }
-               processDocList(docList, queriedServiceBindings, commonList);
+               processDocList(ctx.getTenantId(), docList, queriedServiceBindings, commonList);
                list.setItemsInPage(docList.size());
                list.setTotalItems(docList.totalSize());
                } catch (DocumentException de) {
@@ -180,7 +184,8 @@ public class ServiceGroupDocumentModelHandler
         return "/" + sb.getName().toLowerCase() + "/" + csid;
     }
     
-    private void processDocList(       
+    private void processDocList(
+                String tenantId,
                DocumentModelList docList,
                Map<String, ServiceBindingType> queriedServiceBindings,
                CommonList list ) {
@@ -207,8 +212,26 @@ public class ServiceGroupDocumentModelHandler
             }
             String csid = NuxeoUtils.getCsid(docModel);
             item.put(STANDARD_LIST_CSID_FIELD, csid);
+                        
+            UriTemplateRegistry uriTemplateRegistry = ServiceMain.getInstance().getUriTemplateRegistry();            
+            StoredValuesUriTemplate storedValuesResourceTemplate = uriTemplateRegistry.get(new UriTemplateRegistryKey(tenantId, docType));
+           Map<String, String> additionalValues = new HashMap<String, String>();
+           if (storedValuesResourceTemplate.getUriTemplateType() == UriTemplateFactory.ITEM) {
+                try {
+                    String inAuthorityCsid = (String) docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY
+                    additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, inAuthorityCsid);
+                    additionalValues.put(UriTemplateFactory.ITEM_IDENTIFIER_VAR, csid);
+                } catch (Exception e) {
+                    logger.warn("Could not extract inAuthority property from authority item record: " + e.getMessage());
+                }
+           } else {
+                additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, csid);
+            }
+            String uriStr = storedValuesResourceTemplate.buildUri(additionalValues);
             // Need to get the URI for the document, by it's type.
-            item.put(STANDARD_LIST_URI_FIELD, getUriFromServiceBinding(sb, csid));
+            // item.put(STANDARD_LIST_URI_FIELD, getUriFromServiceBinding(sb, csid));
+            item.put(STANDARD_LIST_URI_FIELD, uriStr);
+            
             try {
                item.put(STANDARD_LIST_UPDATED_AT_FIELD, getUpdatedAtAsString(docModel));
                 item.put(STANDARD_LIST_WORKFLOW_FIELD, docModel.getCurrentLifeCycleState());