From: Aron Roberts Date: Thu, 24 May 2012 01:44:50 +0000 (-0700) Subject: CSPACE-5012: Simplified generation of collectionspace_core:uri values, based very... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=e915c802358b3de4f1e703df53822d93c39465d4;p=tmp%2Fjakarta-migration.git CSPACE-5012: Simplified generation of collectionspace_core:uri values, based very loosely on a discussion of future registry directions with Patrick. inAuthority value in authority item uri values is currently stubbed. --- diff --git a/services/imports/service/pom.xml b/services/imports/service/pom.xml index d29583799..6cf6453ef 100644 --- a/services/imports/service/pom.xml +++ b/services/imports/service/pom.xml @@ -23,6 +23,11 @@ org.collectionspace.services.common ${project.version} + + org.collectionspace.services + org.collectionspace.services.client + ${project.version} + org.collectionspace.services org.collectionspace.services.authentication.service 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 c48365fef..43d06f389 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 @@ -24,14 +24,17 @@ package org.collectionspace.services.imports; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; -import org.collectionspace.services.common.IFragmentHandler; -import org.collectionspace.services.common.XmlSaxFragmenter; -import org.collectionspace.services.common.XmlTools; +import org.collectionspace.services.client.AuthorityClient; +import org.collectionspace.services.common.*; import org.collectionspace.services.common.api.FileTools; import org.collectionspace.services.common.api.Tools; +import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl; import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; +import org.collectionspace.services.config.service.ServiceBindingType; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.dom4j.Document; @@ -47,6 +50,8 @@ import org.xml.sax.InputSource; * @author Laramie Crocker */ public class TemplateExpander { + + static Map docTypeSvcNameRegistry = new HashMap(); protected static String var(String theVar){ return "\\$\\{"+theVar+"\\}"; @@ -81,6 +86,17 @@ public class TemplateExpander { String nowTime = GregorianCalendarDateTimeUtils.timestampUTC(); wrapperTmpl = searchAndReplaceVar(wrapperTmpl, "createdDate", nowTime); wrapperTmpl = searchAndReplaceVar(wrapperTmpl, "updatedDate", nowTime); + + wrapperTmpl = Tools.searchAndReplace(wrapperTmpl, var("uri"), + getDocUri(tenantId, SERVICE_TYPE, docID)); + + /* + TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader(); + ServiceBindingType sb = tReader.getServiceBindingForDocType(tenantId, SERVICE_TYPE); + String uri = "/" + sb.getName().toLowerCase() + "/" + docID; + wrapperTmpl = Tools.searchAndReplace(wrapperTmpl, var("uri"), uri); + * + */ String serviceDir = outDir+'/'+docID; FileTools.saveFile(serviceDir, "document.xml", wrapperTmpl, true/*true=create parent dirs*/); @@ -123,6 +139,71 @@ public class TemplateExpander { XmlSaxFragmenter.parse(requestSource, chopPath, callback, false); } + private static String getDocUri(String tenantId, String SERVICE_TYPE, String docID) throws Exception { + + // FIXME: Use already-defined constants, likely to be found in another package + final String AUTHORITY_TYPE = "authority"; + final String OBJECT_TYPE = "object"; + final String PROCEDURE_TYPE = "procedure"; + + TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader(); + ServiceBindingType sb = tReader.getServiceBindingForDocType(tenantId, SERVICE_TYPE); + + String serviceType = sb.getType(); + String serviceName = ""; + String uri = ""; + if (serviceType.equalsIgnoreCase(AUTHORITY_TYPE)) { + String authoritySvcName = getAuthoritySvcName(SERVICE_TYPE); + if (authoritySvcName == null) { + return uri; + } + // FIXME: Get the inAuthority value from the payload or from a new param for this method + String inAuthorityID = "inAuthorityValueHere"; // stub + uri = getAuthorityUri(authoritySvcName, inAuthorityID, docID); + } else if (serviceType.equalsIgnoreCase(OBJECT_TYPE) || + serviceType.equalsIgnoreCase(PROCEDURE_TYPE) ) { + serviceName = sb.getName().toLowerCase(); + uri = getUri(serviceName, docID); + } else { + // Currently returns a blank URI for any other cases, + // including sub-resources like contacts + } + System.out.println("uri=" + uri); // temp for debugging + return uri; + } + + // Stub / mock of a registry of authority document types and their + // associated parent authority service names + private static Map getDocTypeSvcNameRegistry() { + if (docTypeSvcNameRegistry.isEmpty()) { + docTypeSvcNameRegistry.put("Concept", "Conceptauthorities"); + docTypeSvcNameRegistry.put("Location", "Locationauthorities"); + docTypeSvcNameRegistry.put("Person", "Personauthorities"); + docTypeSvcNameRegistry.put("Place", "Placeauthorities"); + docTypeSvcNameRegistry.put("Organization", "Orgauthorities"); + docTypeSvcNameRegistry.put("Taxon", "Taxonauthority"); + } + return docTypeSvcNameRegistry; + } + + private static String getAuthoritySvcName(String docType) { + return getDocTypeSvcNameRegistry().get(docType); + } + + private static String getUri(String serviceName, String docID) { + return "/" + serviceName + + "/" + docID; + } + + private static String getAuthorityUri(String authorityServiceName, String inAuthorityID, String docID) { + return "/" + authorityServiceName.toLowerCase() + + '/' + inAuthorityID + + '/' + AuthorityClient.ITEMS + + '/' + docID; + } + + // FIXME: Create equivalent getUri-type method(s) for sub-resources, such as contacts + /** This inner class is the callback target for calls to XmlSaxFragmenter, for example: * FragmentHandlerImpl callback = new FragmentHandlerImpl(); * XmlSaxFragmenter.parse(filename, "/imports/import", callback, false); diff --git a/services/imports/service/src/main/resources/templates/service-document.xml b/services/imports/service/src/main/resources/templates/service-document.xml index 858fe6a57..2a9cc2de7 100644 --- a/services/imports/service/src/main/resources/templates/service-document.xml +++ b/services/imports/service/src/main/resources/templates/service-document.xml @@ -39,6 +39,7 @@ ${updatedDate} ${createdDate} ${tenantID} + ${uri} ${Schema}