From: Aron Roberts Date: Wed, 25 Apr 2012 22:17:52 +0000 (-0700) Subject: CSPACE-3917: Dollar signs (and backslashes) are now legal characters in import record... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=5f8a433c06d37e7091ebd1db3c3cd3b8f30b39af;p=tmp%2Fjakarta-migration.git CSPACE-3917: Dollar signs (and backslashes) are now legal characters in import record payloads. --- diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/import-objectexit-dollarsign.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/import-objectexit-dollarsign.xml new file mode 100644 index 000000000..244d2b48b --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/import-objectexit-dollarsign.xml @@ -0,0 +1,10 @@ + + + + + A dollar sign followed by '29.00': $29.00 And a backslash: \ + OE-IMPORT-TEST-1999.10 + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/imports.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/imports.xml index de7148f73..45f8e63ac 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/imports.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/imports.xml @@ -109,6 +109,36 @@ DELETE /cspace-services/objectexit/${importObjectExitWithDocID.recordCSID} + + + + 200 + POST + /cspace-services/imports + imports/import-objectexit-dollarsign.xml + + + imports/res/import-objectexit.res.xml + + + + 200 + GET + /cspace-services/objectexit/${importObjectExitWithDollarSign.got("//csid")} + + + imports/res/import-objectexit-dollarsign.res.xml + + + + + 200 + DELETE + /cspace-services/objectexit/${importObjectExitWithDollarSign.got("//csid")} + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/res/import-objectexit-dollarsign.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/res/import-objectexit-dollarsign.res.xml new file mode 100644 index 000000000..30dbe662e --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/res/import-objectexit-dollarsign.res.xml @@ -0,0 +1,8 @@ + + + + A dollar sign followed by '29.00': $29.00 And a backslash: \ + OE-IMPORT-TEST-1999.10 + + + diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java index c1bac1fa8..c56016185 100644 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java @@ -113,6 +113,13 @@ public class Tools { String output = matcher.replaceAll(replace); return output; } + + public static String searchAndReplaceWithQuoteReplacement(String source, String find, String replace){ + Pattern pattern = Pattern.compile(find); + Matcher matcher = pattern.matcher(source); + String output = matcher.replaceAll(matcher.quoteReplacement(replace)); + return output; + } static boolean m_fileSystemIsDOS = "\\".equals(File.separator); static boolean m_fileSystemIsMac = ":".equals(File.separator); 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 f1a2f0cb8..c48365fef 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 @@ -59,7 +59,7 @@ public class TemplateExpander { * @return the expanded template. */ public static String searchAndReplaceVar(String source, String theVar, String replace){ - return Tools.searchAndReplace(source, var(theVar), replace); + return Tools.searchAndReplaceWithQuoteReplacement(source, var(theVar), replace); } public static String doOneService(String tenantId, String outDir, String partTmpl, String wrapperTmpl, @@ -70,17 +70,17 @@ public class TemplateExpander { } else { docID = UUID.randomUUID().toString(); } - String part = Tools.searchAndReplace(partTmpl, var("docID"), docID); + String part = searchAndReplaceVar(partTmpl, "docID", docID); - wrapperTmpl = Tools.searchAndReplace(wrapperTmpl, var("Schema"), part); - wrapperTmpl = Tools.searchAndReplace(wrapperTmpl, var("docID"), docID); - wrapperTmpl = Tools.searchAndReplace(wrapperTmpl, var("tenantID"), tenantId); - wrapperTmpl = Tools.searchAndReplace(wrapperTmpl, var("ServiceType"), SERVICE_TYPE); - wrapperTmpl = Tools.searchAndReplace(wrapperTmpl, var("ServiceName"), SERVICE_NAME); + wrapperTmpl = searchAndReplaceVar(wrapperTmpl, "Schema", part); + wrapperTmpl = searchAndReplaceVar(wrapperTmpl, "docID", docID); + wrapperTmpl = searchAndReplaceVar(wrapperTmpl, "tenantID", tenantId); + wrapperTmpl = searchAndReplaceVar(wrapperTmpl, "ServiceType", SERVICE_TYPE); + wrapperTmpl = searchAndReplaceVar(wrapperTmpl, "ServiceName", SERVICE_NAME); //TODO: set timestamp via creating a ${created} variable. String nowTime = GregorianCalendarDateTimeUtils.timestampUTC(); - wrapperTmpl = Tools.searchAndReplace(wrapperTmpl, var("createdDate"), nowTime); - wrapperTmpl = Tools.searchAndReplace(wrapperTmpl, var("updatedDate"), nowTime); + wrapperTmpl = searchAndReplaceVar(wrapperTmpl, "createdDate", nowTime); + wrapperTmpl = searchAndReplaceVar(wrapperTmpl, "updatedDate", nowTime); String serviceDir = outDir+'/'+docID; FileTools.saveFile(serviceDir, "document.xml", wrapperTmpl, true/*true=create parent dirs*/);