From: Aron Roberts Date: Fri, 17 Aug 2012 01:57:54 +0000 (-0700) Subject: CSPACE-5271,CSPACE-5274: Imports service now uses URI template registry to populate... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=cc17c5337d2663870b37eb7699d9bdb3e3e1cd1a;p=tmp%2Fjakarta-migration.git CSPACE-5271,CSPACE-5274: Imports service now uses URI template registry to populate collectionspace_core:uri values in import template. --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java index 265e969bf..64ad5f971 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java @@ -573,23 +573,31 @@ public class RefNameServiceUtils { ilistItem = new AuthorityRefDocList.AuthorityRefDocItem(); String csid = NuxeoUtils.getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString()); ilistItem.setDocId(csid); + String 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 additionalValues = new HashMap(); if (template.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); + uri = template.buildUri(additionalValues); } catch (Exception e) { logger.warn("Could not extract inAuthority property from authority item record: " + e.getMessage()); } + // FIXME: Generating contact sub-resource URIs requires additional work, + // beyond CSPACE-5271 - ADR 2012-08-16 + } else if (template.getUriTemplateType() == UriTemplateFactory.CONTACT) { + // Return the default (empty string) value for URI, for now. } else { additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, csid); + uri = template.buildUri(additionalValues); } - String uriStr = template.buildUri(additionalValues); - ilistItem.setUri(uriStr); + ilistItem.setUri(uri); try { ilistItem.setWorkflowState(docModel.getCurrentLifeCycleState()); ilistItem.setUpdatedAt(DocHandlerBase.getUpdatedAtAsString(docModel)); diff --git a/services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java b/services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java index 2ef9d3be6..cb661e036 100644 --- a/services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java +++ b/services/imports/service/src/main/java/org/collectionspace/services/imports/TemplateExpander.java @@ -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 additionalValues = new HashMap(); + 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; }