From: Aron Roberts Date: Thu, 29 Nov 2012 02:03:48 +0000 (-0800) Subject: CSPACE-5733: Emit correct URLs in servicegroups' items list for authority items. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=ff891c5bb6074b3e230d42e98123f6b8b9f80a58;p=tmp%2Fjakarta-migration.git CSPACE-5733: Emit correct URLs in servicegroups' items list for authority items. --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistry.java b/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistry.java index b95e149b5..7a80a9f2c 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistry.java +++ b/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistry.java @@ -38,16 +38,24 @@ public class UriTemplateRegistry extends HashMap uriTemplateEntry : this.entrySet()) { - - System.out.println( - "Tenant : DocType = " - + uriTemplateEntry.getKey().getTenantId() - + " : " - + uriTemplateEntry.getKey().getDocType()); - - System.out.println(" Value of Template = "); - System.out.println(" " + uriTemplateEntry.getValue().toString()); + sb.append("Tenant : DocType = "); + sb.append(uriTemplateEntry.getKey().getTenantId()); + sb.append(" : "); + sb.append(uriTemplateEntry.getKey().getDocType()); + sb.append('\n'); + sb.append(" Value of Template = "); + sb.append(" " + uriTemplateEntry.getValue().toString()); + sb.append('\n'); } + return sb.toString(); } } diff --git a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java index b32601512..4ae167363 100644 --- a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java +++ b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java @@ -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 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 additionalValues = new HashMap(); + 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());