diff options
author | mojahidi <mojahidul.islam@amdocs.com> | 2017-11-15 15:13:59 +0530 |
---|---|---|
committer | Vitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com> | 2017-11-19 12:01:35 +0000 |
commit | 581e9aa490b015d9b46314663c165a8bf12523d8 (patch) | |
tree | eaaacd22bd59163220a0e19563940a13efcc2661 /openecomp-be/lib/openecomp-sdc-validation-lib | |
parent | b91470aaf45ccd77c56a7882f0babc9b4a2b9637 (diff) |
Adding common changes for all HEAT Validators
This commit is about adding common changes which will later be used for all validators.
Change-Id: I47cee23364c2f535482c721c25cb0038e9febc02
Issue-ID:SDC-572
Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib')
4 files changed, 73 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/ErrorMessageCode.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/ErrorMessageCode.java new file mode 100644 index 0000000000..a958d27740 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/ErrorMessageCode.java @@ -0,0 +1,36 @@ +package org.openecomp.core.validation; + +import java.util.Objects; + +public final class ErrorMessageCode { + private final String messageCode; + + public ErrorMessageCode(String messageCode) { + + this.messageCode = messageCode; + } + + public String getMessageCode() { + return messageCode; + } + + @Override + public String toString() { + return messageCode; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ErrorMessageCode that = (ErrorMessageCode) o; + + return Objects.equals(this.messageCode, that.messageCode); + } + + @Override + public int hashCode() { + return Objects.hashCode(this.messageCode); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/errors/ErrorMessagesFormatBuilder.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/errors/ErrorMessagesFormatBuilder.java index 5f4833a90f..0656b02089 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/errors/ErrorMessagesFormatBuilder.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/errors/ErrorMessagesFormatBuilder.java @@ -21,10 +21,28 @@ package org.openecomp.core.validation.errors; +import org.openecomp.core.validation.ErrorMessageCode; + public class ErrorMessagesFormatBuilder { + private static final String messagePattern = "[%s]: %s"; + public static String getErrorWithParameters(String error, String... params) { return String.format(error, params); } + /** + * Formatted message with error code. + * + * @param messageCode error code. + * @param errorMessage error message. + * @param params parameters used in formatting message. + * @return formatted message string. + */ + public static String getErrorWithParameters(ErrorMessageCode messageCode, + String errorMessage, String... params) { + String message = getErrorWithParameters(errorMessage, params); + return ( null != messageCode && null != messageCode.getMessageCode() ) ? + String.format(messagePattern, messageCode.getMessageCode(), message) : message; + } } diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/GlobalValidationContext.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/GlobalValidationContext.java index 1fb31a3d8d..bc401d4a45 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/GlobalValidationContext.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java/org/openecomp/core/validation/types/GlobalValidationContext.java @@ -21,6 +21,7 @@ package org.openecomp.core.validation.types; import org.apache.commons.collections4.CollectionUtils; +import org.openecomp.core.validation.ErrorMessageCode; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.datatypes.error.ErrorLevel; @@ -41,6 +42,16 @@ public class GlobalValidationContext { private static Logger logger = (Logger) LoggerFactory.getLogger(GlobalValidationContext.class); private Map<String, FileValidationContext> fileContextMap = new HashMap<>(); private Map<String, MessageContainer> messageContainerMap = new HashMap<>(); + private ErrorMessageCode messageCode; + + public ErrorMessageCode getMessageCode() { + return messageCode; + } + + public void setMessageCode(ErrorMessageCode messageCode) { + this.messageCode = messageCode; + } + /** * Add message. diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/ErrorMessagesTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/ErrorMessagesTest.java index 345aad330d..64b3d2bb3c 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/ErrorMessagesTest.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/ErrorMessagesTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; import org.openecomp.sdc.common.errors.Messages; import org.testng.Assert; +import org.openecomp.core.validation.ErrorMessageCode; public class ErrorMessagesTest { @@ -43,4 +44,11 @@ public class ErrorMessagesTest { "res"); Assert.assertNotNull(error1); } + @Test + public void testErrorFormatWithErrorCode() { + String error = ErrorMessagesFormatBuilder + .getErrorWithParameters(new ErrorMessageCode("TestCode"), Messages.MISSING_NOVA_SERVER_METADATA + .getErrorMessage(), "param"); + Assert.assertEquals("[TestCode]: Missing Nova Server Metadata property, Resource ID [param]", error); + } } |