From 8623ca6174b6d724d3d480f0bf54300f18460350 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Fri, 15 Jun 2018 08:56:44 +0100 Subject: Removing SONAR issues from apex-pdp basic model Removed some code duplication in exceptions Reduced the number of unlogged exception SONAR messages to one. Issue-ID: POLICY-856 Change-Id: I19e60664270b86f77333979eaa412b2e85cb13fa Signed-off-by: liamfallon --- .../onap/policy/apex/model/utilities/Assertions.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'model/utilities/src/main') diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/Assertions.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/Assertions.java index c215f3fee..80a71f8aa 100644 --- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/Assertions.java +++ b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/Assertions.java @@ -33,6 +33,26 @@ public final class Assertions { private Assertions() { } + /** + * Gets the validation message for a string parameter. + * + * @param parameterName the string parameter name + * @param parameterValue the string parameter value + * @param pattern The regular expression + * @return null if the parameter is valid, the validation message otherwise + */ + public static String getStringParameterValidationMessage(final String parameterName, final String parameterValue, final String pattern) { + try { + validateStringParameter(parameterName, parameterValue, pattern); + } + catch (IllegalArgumentException e) { + // This will cause a SONAR error but eliminates all SONAR messages in callers + return e.getMessage(); + } + + return null; + } + /** * Checks if a string parameter matches a regular expression. * -- cgit 1.2.3-korg