From dd537b2c409c580efd98d887a61c50f7f53458c5 Mon Sep 17 00:00:00 2001 From: mojahidi Date: Wed, 22 Nov 2017 17:52:37 +0530 Subject: ForbiddenResourceGuideLine Validator This task is about updating error messages with error codes for ForbiddenResourceGuideLine Change-Id: Id692b43e05443dc1313b51533e685dd3c7ad6ca6 Issue-ID: SDC-572 Signed-off-by: mojahidi --- .../ForbiddenResourceGuideLineValidator.java | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main') diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidator.java index 569f2bb760..2dad766c45 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidator.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidator.java @@ -1,6 +1,7 @@ package org.openecomp.sdc.validation.impl.validators; import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.validation.ErrorMessageCode; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; import org.openecomp.core.validation.types.GlobalValidationContext; import org.openecomp.sdc.common.errors.Messages; @@ -29,6 +30,9 @@ import java.util.Set; public class ForbiddenResourceGuideLineValidator implements Validator { private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); private static Set forbiddenResources = new HashSet<>(); + private static final ErrorMessageCode ERROR_CODE_FRG_1 = new ErrorMessageCode("FRG1"); + private static final ErrorMessageCode ERROR_CODE_FRG_2 = new ErrorMessageCode("FRG2"); + private static final ErrorMessageCode ERROR_CODE_FRG_3 = new ErrorMessageCode("FRG3"); private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); @@ -40,10 +44,6 @@ public class ForbiddenResourceGuideLineValidator implements Validator { forbiddenResourcesMap.entrySet().stream() .filter(entry -> isResourceEnabled(entry.getValue().get("enable"))) .forEach(entry -> forbiddenResources.add(entry.getKey())); - - - - } private boolean isResourceEnabled(Object enableValue){ @@ -78,8 +78,10 @@ public class ForbiddenResourceGuideLineValidator implements Validator { } private void validate(String fileName, GlobalValidationContext globalContext) { + globalContext.setMessageCode(ERROR_CODE_FRG_3); HeatOrchestrationTemplate - heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext); + heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition( + fileName, globalContext); if (heatOrchestrationTemplate == null) { return; } @@ -103,18 +105,19 @@ public class ForbiddenResourceGuideLineValidator implements Validator { String resourceType = resourceEntry.getValue().getType(); if (Objects.isNull(resourceType)) { globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.INVALID_RESOURCE_TYPE.getErrorMessage(), "null", + .getErrorWithParameters(ERROR_CODE_FRG_1, + Messages.INVALID_RESOURCE_TYPE.getErrorMessage(),"null", resourceEntry.getKey()), LoggerTragetServiceName.VALIDATE_RESOURCE_TYPE, LoggerErrorDescription.INVALID_RESOURCE_TYPE); } else { - if(isResourceForbidden(resourceType)){ - globalContext.addMessage( + if (isResourceForbidden(resourceType)){ + globalContext.addMessage( fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.FORBIDDEN_RESOURCE_IN_USE.getErrorMessage(), - resourceType, - resourceEntry.getKey()), + .getErrorWithParameters(ERROR_CODE_FRG_2, Messages.FORBIDDEN_RESOURCE_IN_USE + .getErrorMessage(), + resourceType, resourceEntry.getKey()), LoggerTragetServiceName.VALIDATE_FORBIDDEN_RESOURCE, LoggerErrorDescription.FLOATING_IP_IN_USE); } -- cgit 1.2.3-korg