From 0bd36ba28ab4dac0ae4e76e668a1159e534f3ea2 Mon Sep 17 00:00:00 2001 From: mojahidi Date: Tue, 26 Dec 2017 12:10:29 +0530 Subject: Fixed sonar issues - ContrailServiceTemplate Fixed all sonar issues Change-Id: I2ecf439dac9e180fd1640c53abb0e15991434704 Issue-ID: SDC-343 Signed-off-by: mojahidi --- ...ilServiceTemplateNamingConventionValidator.java | 46 ++++++++++++++-------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'openecomp-be/lib') diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidator.java index 280b723dd8..53defcd39a 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidator.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/ContrailServiceTemplateNamingConventionValidator.java @@ -1,5 +1,22 @@ +/* + * Copyright © 2016-2017 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.openecomp.sdc.validation.impl.validators.namingconvention; +import static java.util.Objects.nonNull; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -24,13 +41,9 @@ import java.util.Objects; import java.util.Optional; import java.util.regex.Pattern; -import static java.util.Objects.nonNull; -/** - * Created by TALIO on 2/24/2017. - */ public class ContrailServiceTemplateNamingConventionValidator implements ResourceValidator { - private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage(); private static final ErrorMessageCode ERROR_CODE_NST1 = new ErrorMessageCode("NST1"); private static final ErrorMessageCode ERROR_CODE_NST2 = new ErrorMessageCode("NST2"); private static final ErrorMessageCode ERROR_CODE_NST3 = new ErrorMessageCode("NST3"); @@ -45,7 +58,7 @@ public class ContrailServiceTemplateNamingConventionValidator implements Resourc Map.Entry entry, GlobalValidationContext globalContext) { - mdcDataDebugMessage.debugEntryMessage("file", fileName); + MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName); if (MapUtils.isEmpty(entry.getValue().getProperties())) { return; @@ -71,7 +84,7 @@ public class ContrailServiceTemplateNamingConventionValidator implements Resourc propertiesMap); } - mdcDataDebugMessage.debugExitMessage("file", fileName); + MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName); } private void validateServiceTemplatePropertiesValuesVmtypesAreIdentical(String fileName, @@ -79,14 +92,14 @@ public class ContrailServiceTemplateNamingConventionValidator implements Resourc GlobalValidationContext globalContext, Map propertiesMap) { - mdcDataDebugMessage.debugEntryMessage("file", fileName); + MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName); Pair vmTypeImagePair = new ImmutablePair<>("image_name", "\\_image\\_name"); Pair vmTypeFlavorPair = new ImmutablePair<>("flavor", "\\_flavor\\_name"); validatePropertiesValuesVmtypesAreIdentical(Arrays.asList(vmTypeImagePair, vmTypeFlavorPair), fileName, entry, propertiesMap, globalContext); - mdcDataDebugMessage.debugExitMessage("file", fileName); + MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName); } private void validatePropertiesValuesVmtypesAreIdentical(List propertiesToMatch, @@ -96,7 +109,7 @@ public class ContrailServiceTemplateNamingConventionValidator implements Resourc GlobalValidationContext globalContext) { - mdcDataDebugMessage.debugEntryMessage("file", fileName); + MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName); if (CollectionUtils.isEmpty(propertiesToMatch)) { return; @@ -113,13 +126,13 @@ public class ContrailServiceTemplateNamingConventionValidator implements Resourc handleFirstIteration(previousPropertyValueValue, currentPropVmType); if (addWarningIfCurrentVmTypeIsDifferentFromPrevious(fileName, resourceEntry, globalContext, previousPropertyValueValue, currentPropVmType)) { - mdcDataDebugMessage.debugExitMessage("file", fileName); + MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName); return; } } } - mdcDataDebugMessage.debugExitMessage("file", fileName); + MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName); } private boolean addWarningIfCurrentVmTypeIsDifferentFromPrevious(String fileName, @@ -147,8 +160,7 @@ public class ContrailServiceTemplateNamingConventionValidator implements Resourc Map propertiesMap, GlobalValidationContext globalContext) { String propertyName = propertyNameAndRegex.getKey(); - Object nameValue = - propertiesMap.get(propertyName) == null ? null : propertiesMap.get(propertyName); + Object nameValue = propertiesMap.get(propertyName); String[] regexList = new String[]{propertyNameAndRegex.getValue()}; if (nonNull(nameValue)) { if (nameValue instanceof Map) { @@ -209,10 +221,12 @@ public class ContrailServiceTemplateNamingConventionValidator implements Resourc } private String handleFirstIteration(String previousPropertyValueValue, String currentPropVmType) { + String previousPropertyValue; if (Objects.isNull(previousPropertyValueValue)) { - previousPropertyValueValue = currentPropVmType; + previousPropertyValue = currentPropVmType; + return previousPropertyValue; } - return previousPropertyValueValue; + return previousPropertyValueValue; } } -- cgit 1.2.3-korg