diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/main/java')
3 files changed, 65 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. |