From 54ba57b20ec37b33f02e46dfbf319d88fa6bc9eb Mon Sep 17 00:00:00 2001 From: remillet Date: Fri, 24 Jun 2016 08:40:12 -0700 Subject: [PATCH] CSPACE-6959: Added support for optional property variables. Property variables with a '_OPT' suffix will be treat as optional. Non-optional property variables need to be defined as environment variables or JVM system variables. --- .../services/common/api/Tools.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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 7ab0ca009..52b5ebaeb 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 @@ -120,7 +120,7 @@ public class Tools { 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)); + String output = matcher.replaceAll(Matcher.quoteReplacement(replace)); return output; } @@ -128,6 +128,7 @@ public class Tools { static boolean m_fileSystemIsMac = ":".equals(File.separator); public final static String FILE_EXTENSION_SEPARATOR = "."; + public final static String OPTIONAL_VALUE_SUFFIX = "_OPT"; public static boolean fileSystemIsDOS(){return m_fileSystemIsDOS;} public static boolean fileSystemIsMac(){return m_fileSystemIsMac;} @@ -327,6 +328,14 @@ public class Tools { return result; } + + static public boolean isOptional(String properyValue) { + boolean result = false; + + result = properyValue.endsWith(OPTIONAL_VALUE_SUFFIX); + + return result; + } /** * Try to find the value of a property variable in the system or JVM environment. This code substitutes only property values formed @@ -361,7 +370,11 @@ public class Tools { if (result == null || result.isEmpty()) { String errMsg = String.format("Could find neither an environment variable nor a systen variable named '%s'", key); - throw new Exception(errMsg); + if (isOptional(key) == true) { + System.err.println(errMsg); + } else { + throw new Exception(errMsg); + } } } -- 2.47.3