aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authormojahidi <mojahidul.islam@amdocs.com>2017-12-26 12:13:02 +0530
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2017-12-26 09:50:09 +0000
commitc02ca56006057dcf5e8318b99a207430456024c4 (patch)
treeab5e809377b53c299660533aa87695f51b0b9de8 /openecomp-be
parentab248dba1d5b484c4665a0bb0ae39f7b03f49e35 (diff)
Fixed sonar issues - NeutronPortNamingConvention
Fixed all sonar issues Change-Id: Ibc328c6e7d7d6e71837107d34dc24731735db9d6 Issue-ID: SDC-343 Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NeutronPortNamingConventionValidator.java118
1 files changed, 70 insertions, 48 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NeutronPortNamingConventionValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NeutronPortNamingConventionValidator.java
index c12ad9b604..a3821f2a21 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NeutronPortNamingConventionValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NeutronPortNamingConventionValidator.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.MapUtils;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
@@ -20,13 +37,8 @@ import org.openecomp.sdc.validation.util.ValidationUtil;
import java.util.List;
import java.util.Map;
-import static java.util.Objects.nonNull;
-
-/**
- * Created by TALIO on 2/23/2017.
- */
public class NeutronPortNamingConventionValidator implements ResourceValidator {
- private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+ private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
private static final ErrorMessageCode ERROR_CODE_NNP1 = new ErrorMessageCode("NNP1");
private static final ErrorMessageCode ERROR_CODE_NNP2 = new ErrorMessageCode("NNP2");
private static final ErrorMessageCode ERROR_CODE_NNP3 = new ErrorMessageCode("NNP3");
@@ -45,10 +57,10 @@ public class NeutronPortNamingConventionValidator implements ResourceValidator {
HeatOrchestrationTemplate heatOrchestrationTemplate,
GlobalValidationContext globalContext) {
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
- mdcDataDebugMessage.debugExitMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
return;
}
String[] regexList = new String[]{".*_net_id", ".*_net_name", ".*_net_fqdn"};
@@ -64,23 +76,23 @@ public class NeutronPortNamingConventionValidator implements ResourceValidator {
.entrySet()
.stream()
.filter(propertyEntry ->
- propertyEntry.getKey().toLowerCase().equals("network".toLowerCase())
- || propertyEntry.getKey().equals("network_id"))
+ ("network").equalsIgnoreCase(propertyEntry.getKey())
+ || ("network_id").equals(propertyEntry.getKey()))
.forEach(propertyEntry -> validateParamNamingConvention(fileName, entry.getKey(),
- propertyEntry.getValue(), "Port", "Network", regexList,
+ propertyEntry.getValue(), regexList,
Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES, globalContext)));
- mdcDataDebugMessage.debugExitMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
}
private void validateFixedIpsNamingConvention(String fileName,
HeatOrchestrationTemplate heatOrchestrationTemplate,
GlobalValidationContext globalContext) {
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
- mdcDataDebugMessage.debugExitMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
return;
}
@@ -92,7 +104,7 @@ public class NeutronPortNamingConventionValidator implements ResourceValidator {
.equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE))
.forEach(entry -> checkNeutronPortFixedIpsName(fileName, entry, globalContext));
- mdcDataDebugMessage.debugExitMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
}
private void checkNeutronPortFixedIpsName(String fileName,
@@ -113,60 +125,70 @@ public class NeutronPortNamingConventionValidator implements ResourceValidator {
for (Object fixedIpsObject : fixedIpsList) {
Map.Entry<String, Object> fixedIpsEntry =
((Map<String, Object>) fixedIpsObject).entrySet().iterator().next();
- if (nonNull(fixedIpsEntry)) {
- if (fixedIpsEntry.getValue() instanceof Map) {
- String fixedIpsName = ValidationUtil.getWantedNameFromPropertyValueGetParam
- (fixedIpsEntry
- .getValue());
- if (nonNull(fixedIpsName)) {
- if (!ValidationUtil.evalPattern(fixedIpsName, regexList)) {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder.getErrorWithParameters(
- ERROR_CODE_NNP1,
- Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
- "Port", "Fixed_IPS", fixedIpsName, resourceEntry.getKey()),
- LoggerTragetServiceName.VALIDATE_FIXED_IPS_NAME,
- LoggerErrorDescription.NAME_NOT_ALIGNED_WITH_GUIDELINES);
- }
- }
- } else {
+
+ validateFixedIpsName(fileName, resourceEntry, globalContext, regexList, fixedIpsEntry);
+
+
+ }
+ }
+ }
+
+ private void validateFixedIpsName(String fileName, Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext,
+ String[] regexList, Map.Entry<String, Object> fixedIpsEntry) {
+ if (nonNull(fixedIpsEntry)) {
+ if (fixedIpsEntry.getValue() instanceof Map) {
+
+ String fixedIpsName = ValidationUtil
+ .getWantedNameFromPropertyValueGetParam(fixedIpsEntry.getValue());
+ if (nonNull(fixedIpsName) && !ValidationUtil
+ .evalPattern(fixedIpsName, regexList)) {
globalContext.addMessage(
fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_NNP2, Messages.MISSING_GET_PARAM.getErrorMessage(),
- "fixed_ips", resourceEntry.getKey()),
+ ErrorLevel.WARNING, ErrorMessagesFormatBuilder.getErrorWithParameters(
+ ERROR_CODE_NNP1,
+ Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
+ "Port", "Fixed_IPS", fixedIpsName, resourceEntry.getKey()),
LoggerTragetServiceName.VALIDATE_FIXED_IPS_NAME,
- LoggerErrorDescription.MISSING_GET_PARAM);
+ LoggerErrorDescription.NAME_NOT_ALIGNED_WITH_GUIDELINES);
}
- }
+
+
+ } else {
+ globalContext.addMessage(
+ fileName,
+ ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(
+ ERROR_CODE_NNP2, Messages.MISSING_GET_PARAM.getErrorMessage(),
+ "fixed_ips", resourceEntry.getKey()),
+ LoggerTragetServiceName.VALIDATE_FIXED_IPS_NAME,
+ LoggerErrorDescription.MISSING_GET_PARAM);
}
}
}
private void validateParamNamingConvention(String fileName, String resourceId,
- Object propertyValue, String resourceType,
- String wrongPropertyFormat, String[] regexList,
+ Object propertyValue,
+ String[] regexList,
Messages message,
GlobalValidationContext globalContext) {
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("file", fileName);
Object paramName;
if (propertyValue instanceof Map) {
paramName = ((Map) propertyValue).get("get_param");
- if (paramName instanceof String) {
- if (!ValidationUtil.evalPattern((String) paramName, regexList)) {
+ if (paramName instanceof String && !ValidationUtil
+ .evalPattern((String) paramName, regexList)) {
globalContext.addMessage(
fileName,
ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_NNP3, message.getErrorMessage(), resourceType,
- wrongPropertyFormat, (String) paramName, resourceId),
+ .getErrorWithParameters(ERROR_CODE_NNP3, message.getErrorMessage(), "Port",
+ "Network", (String) paramName, resourceId),
LoggerTragetServiceName.VALIDATE_PORT_NETWORK_NAME,
LoggerErrorDescription.NAME_NOT_ALIGNED_WITH_GUIDELINES);
}
- }
+
} else {
globalContext.addMessage(
fileName,
@@ -179,6 +201,6 @@ public class NeutronPortNamingConventionValidator implements ResourceValidator {
LoggerErrorDescription.MISSING_GET_PARAM);
}
- mdcDataDebugMessage.debugExitMessage("file", fileName);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("file", fileName);
}
}