summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NestedResourceValidator.java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NestedResourceValidator.java')
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NestedResourceValidator.java92
1 files changed, 37 insertions, 55 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NestedResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NestedResourceValidator.java
index 4a5a996777..06d1f8942f 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NestedResourceValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NestedResourceValidator.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.validation.impl.validators.heatresource;
import java.util.ArrayList;
@@ -22,7 +21,6 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
-
import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
@@ -38,64 +36,48 @@ import org.openecomp.sdc.validation.impl.util.HeatValidationService;
* Created by TALIO on 2/22/2017.
*/
public class NestedResourceValidator implements ResourceValidator {
- private static final ErrorMessageCode ERROR_CODE_HNR1 = new ErrorMessageCode("HNR1");
- private static final ErrorMessageCode ERROR_CODE_HNR2 = new ErrorMessageCode("HNR2");
- private static final ErrorMessageCode ERROR_CODE_HNR3 = new ErrorMessageCode("HNR3");
- private static final ErrorMessageCode ERROR_CODE_HNR4 = new ErrorMessageCode("HNR4");
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
+ private static final ErrorMessageCode ERROR_CODE_HNR1 = new ErrorMessageCode("HNR1");
+ private static final ErrorMessageCode ERROR_CODE_HNR2 = new ErrorMessageCode("HNR2");
+ private static final ErrorMessageCode ERROR_CODE_HNR3 = new ErrorMessageCode("HNR3");
+ private static final ErrorMessageCode ERROR_CODE_HNR4 = new ErrorMessageCode("HNR4");
- handleNestedResourceType(fileName, resourceEntry.getKey(), resourceEntry.getValue(),
- Optional.empty(), globalContext);
- }
+ private static void handleNestedResourceType(String fileName, String resourceName, Resource resource, Optional<String> indexVarValue,
+ GlobalValidationContext globalContext) {
+ validateAllPropertiesMatchNestedParameters(fileName, resourceName, resource, indexVarValue, globalContext);
+ validateLoopsOfNestingFromFile(fileName, resource.getType(), globalContext);
+ }
- private static void handleNestedResourceType(String fileName, String resourceName,
- Resource resource, Optional<String> indexVarValue,
- GlobalValidationContext globalContext) {
- validateAllPropertiesMatchNestedParameters(fileName, resourceName, resource, indexVarValue,
- globalContext);
- validateLoopsOfNestingFromFile(fileName, resource.getType(), globalContext);
- }
+ public static void validateAllPropertiesMatchNestedParameters(String fileName, String resourceName, Resource resource,
+ Optional<String> indexVarValue, GlobalValidationContext globalContext) {
+ String resourceType = resource.getType();
+ if (globalContext.getFileContextMap().containsKey(resourceType)) {
+ Set<String> propertiesNames = resource.getProperties() == null ? null : resource.getProperties().keySet();
+ if (CollectionUtils.isNotEmpty(propertiesNames)) {
+ globalContext.setMessageCode(ERROR_CODE_HNR3);
+ HeatValidationService
+ .checkNestedParametersNoMissingParameterInNested(fileName, resourceType, resourceName, propertiesNames, globalContext);
+ globalContext.setMessageCode(ERROR_CODE_HNR4);
+ HeatValidationService
+ .checkNestedInputValuesAlignWithType(fileName, resourceType, resourceName, resource, indexVarValue, globalContext);
+ }
+ } else {
+ globalContext.addMessage(resourceType, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_HNR1, Messages.MISSING_NESTED_FILE.getErrorMessage(), resourceType));
+ }
+ }
- public static void validateAllPropertiesMatchNestedParameters(String fileName,
- String resourceName,
- Resource resource,
- Optional<String> indexVarValue,
- GlobalValidationContext
- globalContext) {
- String resourceType = resource.getType();
- if (globalContext.getFileContextMap().containsKey(resourceType)) {
- Set<String> propertiesNames =
- resource.getProperties() == null ? null : resource.getProperties().keySet();
- if (CollectionUtils.isNotEmpty(propertiesNames)) {
- globalContext.setMessageCode(ERROR_CODE_HNR3);
- HeatValidationService
- .checkNestedParametersNoMissingParameterInNested(fileName, resourceType, resourceName,
- propertiesNames,
- globalContext);
- globalContext.setMessageCode(ERROR_CODE_HNR4);
- HeatValidationService
- .checkNestedInputValuesAlignWithType(fileName, resourceType, resourceName, resource,
- indexVarValue, globalContext);
- }
- } else {
- globalContext.addMessage(resourceType, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HNR1,
- Messages.MISSING_NESTED_FILE.getErrorMessage(),
- resourceType));
+ public static void validateLoopsOfNestingFromFile(String fileName, String resourceType, GlobalValidationContext globalContext) {
+ List<String> filesInLoop = new ArrayList<>(Collections.singletonList(fileName));
+ if (HeatValidationService.isNestedLoopExistInFile(fileName, resourceType, filesInLoop, globalContext)) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HNR2, Messages.NESTED_LOOP.getErrorMessage(), HeatValidationService.drawFilesLoop(filesInLoop)));
+ }
}
- }
- public static void validateLoopsOfNestingFromFile(String fileName, String resourceType,
- GlobalValidationContext globalContext) {
- List<String> filesInLoop = new ArrayList<>(Collections.singletonList(fileName));
- if (HeatValidationService
- .isNestedLoopExistInFile(fileName, resourceType, filesInLoop, globalContext)) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_HNR2, Messages.NESTED_LOOP.getErrorMessage(),
- HeatValidationService.drawFilesLoop(filesInLoop)));
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ ValidationContext validationContext) {
+ handleNestedResourceType(fileName, resourceEntry.getKey(), resourceEntry.getValue(), Optional.empty(), globalContext);
}
- }
}