X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Frest%2Futil%2FPolicyValidation.java;h=6bab919ad4e2ebf8eb99cf523ed1a889c29e4b65;hb=89ef1958121b877e990ff8755f9087cd306d4b4c;hp=00c27eab56c1b6aea009980693adfbce48afec91;hpb=43dd8e5baa16c1fb1e68343b0b4b9ca0cd486500;p=policy%2Fengine.git
diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java
index 00c27eab5..6bab919ad 100644
--- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java
+++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java
@@ -3,13 +3,14 @@
* ONAP Policy Engine
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* 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.
@@ -26,9 +27,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
@@ -42,12 +40,16 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+
import javax.json.Json;
import javax.json.JsonException;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.json.JsonValue;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
+
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
@@ -67,41 +69,55 @@ import org.onap.policy.xacml.util.XACMLPolicyScanner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-
@Service
public class PolicyValidation {
-
private static final Logger LOGGER = FlexLogger.getLogger(PolicyValidation.class);
- public static final String CONFIG_POLICY = "Config";
- public static final String ACTION_POLICY = "Action";
- public static final String DECISION_POLICY = "Decision";
- public static final String DECISION_POLICY_MS = "Decision_MS";
- public static final String CLOSEDLOOP_POLICY = "ClosedLoop_Fault";
- public static final String CLOSEDLOOP_PM = "ClosedLoop_PM";
- public static final String ENFORCER_CONFIG_POLICY = "Enforcer Config";
- public static final String MICROSERVICES = "Micro Service";
- public static final String FIREWALL = "Firewall Config";
- public static final String OPTIMIZATION="Optimization";
- public static final String BRMSPARAM = "BRMS_Param";
- public static final String BRMSRAW = "BRMS_Raw";
- public static final String HTML_ITALICS_LNBREAK = "
";
- public static final String SUCCESS = "success";
- public static final String EMPTY_COMPONENT_ATTR =
- "Component Attributes: One or more Fields in Component Attributes is Empty.";
- public static final String ISREQUIRED = " is required";
- public static final String SPACESINVALIDCHARS = " : value has spaces or invalid characters
";
- private static final String REQUIRED_ATTRIBUTE = "required-true";
+ private static final String ACTION_POLICY = "Action";
+ private static final String BOOLEAN = "boolean";
+ private static final String BRMSPARAM = "BRMS_Param";
+ private static final String BRMSRAW = "BRMS_Raw";
+ private static final String CLOSEDLOOP_PM = "ClosedLoop_PM";
+ private static final String CLOSEDLOOP_POLICY = "ClosedLoop_Fault";
+ private static final String CONFIG_POLICY = "Config";
private static final String DECISION_MS_MODEL = "MicroService_Model";
+ private static final String DECISION_POLICY = "Decision";
+ private static final String DECISION_POLICY_MS = "Decision_MS";
+ private static final String ENFORCER_CONFIG_POLICY = "Enforcer Config";
+ private static final String FIREWALL = "Firewall Config";
+ private static final String HTML_ITALICS_LNBREAK = "
";
+ private static final String INTEGER = "integer";
+ private static final String ISREQUIRED = " is required";
+ private static final String JAVA = "java";
+ private static final String LIST = "list";
+ private static final String MAP = "map";
+ private static final String MICROSERVICES = "Micro Service";
+ private static final String MISSING_COMPONENT_ATTRIBUTE_VALUE = "Component Attributes:"
+ + " has one missing Component Attribute value
";
+ private static final String MISSING_ATTRIBUTE_VALUE = "Rule Attributes:"
+ + " has one missing Attribute value
";
+ private static final String MISSING_COMPONENT_ATTRIBUTE_KEY = "Component Attributes:"
+ + " has one missing Component Attribute key
";
+ private static final String OPTIMIZATION = "Optimization";
private static final String RAW = "Raw";
+ private static final String REQUIRED_ATTRIBUTE = "required-true";
+ private static final String RULE_ALGORITHMS = "Rule Algorithms:";
+ private static final String SELECT_AT_LEAST_ONE_D2_VIRTUALIZED_SERVICES = "D2/Virtualized Services: "
+ + "Select at least one D2/Virtualized Services";
+ private static final String SPACESINVALIDCHARS = " : value has spaces or invalid characters
";
+ private static final String STRING = "string";
+ private static final String SUCCESS = "success";
+ private static final String VALUE = "value";
private static Map mapAttribute = new HashMap<>();
private static Map jsonRequestMap = new HashMap<>();
private static List modelRequiredFieldsList = new ArrayList<>();
- private Set allReqTrueKeys = new HashSet<>();
private static CommonClassDao commonClassDao;
+ private Set allReqTrueKeys = new HashSet<>();
+ private Set allOptReqTrueKeys = new HashSet<>();
+
@Autowired
public PolicyValidation(CommonClassDao commonClassDao) {
PolicyValidation.commonClassDao = commonClassDao;
@@ -114,7 +130,6 @@ public class PolicyValidation {
// Empty constructor
}
-
/**
* Validate policy.
*
@@ -147,68 +162,64 @@ public class PolicyValidation {
}
if (!"API".equals(policyData.getApiflag()) && policyData.getAttributes() != null
- && !policyData.getAttributes().isEmpty()) {
+ && !policyData.getAttributes().isEmpty()) {
for (Object attribute : policyData.getAttributes()) {
if (attribute instanceof LinkedHashMap, ?>) {
- String value = null;
+ String attValue = null;
String key = null;
if (((LinkedHashMap, ?>) attribute).get("key") != null) {
key = ((LinkedHashMap, ?>) attribute).get("key").toString();
if (!PolicyUtils.policySpecialCharWithDashValidator(key).contains(SUCCESS)) {
- responseString.append("Attributes or Component Attributes:" + value
- + SPACESINVALIDCHARS);
+ responseString.append("Attributes or Component Attributes:" + attValue
+ + SPACESINVALIDCHARS);
valid = false;
}
} else {
if (CONFIG_POLICY.equals(policyData.getPolicyType())) {
if ("Base".equals(policyData.getConfigPolicyType())) {
- responseString
- .append("Attributes: has one missing Attribute key
");
+ responseString.append(
+ "Attributes: has one missing Attribute key
");
}
if (BRMSPARAM.equals(policyData.getConfigPolicyType())
- || BRMSRAW.equals(policyData.getConfigPolicyType())) {
- responseString
- .append("Rule Attributes: has one missing Attribute key
");
+ || BRMSRAW.equals(policyData.getConfigPolicyType())) {
+ responseString.append(
+ "Rule Attributes: has one missing Attribute key
");
}
} else {
- responseString.append(
- "Component Attributes: has one missing Component Attribute key
");
+ responseString.append(MISSING_COMPONENT_ATTRIBUTE_KEY);
}
valid = false;
}
- if (((LinkedHashMap, ?>) attribute).get("value") != null) {
- value = ((LinkedHashMap, ?>) attribute).get("value").toString();
- if (!PolicyUtils.policySpecialCharWithDashValidator(value).contains(SUCCESS)) {
+ if (((LinkedHashMap, ?>) attribute).get(VALUE) != null) {
+ attValue = ((LinkedHashMap, ?>) attribute).get(VALUE).toString();
+ if (!PolicyUtils.policySpecialCharWithDashValidator(attValue).contains(SUCCESS)) {
if (CONFIG_POLICY.equals(policyData.getPolicyType())) {
if ("Base".equals(policyData.getConfigPolicyType())) {
- responseString.append("Attributes:" + value
- + SPACESINVALIDCHARS);
+ responseString.append("Attributes:" + attValue + SPACESINVALIDCHARS);
}
if (BRMSPARAM.equals(policyData.getConfigPolicyType())
- || BRMSRAW.equals(policyData.getConfigPolicyType())) {
- responseString.append("Rule Attributes:" + value
- + SPACESINVALIDCHARS);
+ || BRMSRAW.equals(policyData.getConfigPolicyType())) {
+ responseString.append(
+ "Rule Attributes:" + attValue + SPACESINVALIDCHARS);
}
} else {
- responseString.append("Component Attributes:" + value
- + SPACESINVALIDCHARS);
+ responseString.append(
+ "Component Attributes:" + attValue + SPACESINVALIDCHARS);
}
valid = false;
}
} else {
if (CONFIG_POLICY.equals(policyData.getPolicyType())) {
if ("Base".equals(policyData.getConfigPolicyType())) {
- responseString
- .append("Attributes: has one missing Attribute value
");
+ responseString.append(
+ "Attributes: has one missing Attribute value
");
}
if (BRMSPARAM.equals(policyData.getConfigPolicyType())
- || BRMSRAW.equals(policyData.getConfigPolicyType())) {
- responseString.append(
- "Rule Attributes: has one missing Attribute value
");
+ || BRMSRAW.equals(policyData.getConfigPolicyType())) {
+ responseString.append(MISSING_ATTRIBUTE_VALUE);
}
} else {
- responseString.append(
- "Component Attributes: has one missing Component Attribute value
");
+ responseString.append(MISSING_COMPONENT_ATTRIBUTE_VALUE);
}
valid = false;
}
@@ -218,25 +229,24 @@ public class PolicyValidation {
// Decision Policy Attributes Validation
if (!"API".equals(policyData.getApiflag()) && policyData.getSettings() != null
- && !policyData.getSettings().isEmpty()) {
+ && !policyData.getSettings().isEmpty()) {
for (Object attribute : policyData.getAttributes()) {
if (attribute instanceof LinkedHashMap, ?>) {
String value = null;
if (((LinkedHashMap, ?>) attribute).get("key") == null) {
- responseString
- .append("Settings Attributes: has one missing Attribute key
");
+ responseString.append(
+ "Settings Attributes: has one missing Attribute key
");
valid = false;
}
- if (((LinkedHashMap, ?>) attribute).get("value") != null) {
- value = ((LinkedHashMap, ?>) attribute).get("value").toString();
+ if (((LinkedHashMap, ?>) attribute).get(VALUE) != null) {
+ value = ((LinkedHashMap, ?>) attribute).get(VALUE).toString();
if (!PolicyUtils.policySpecialCharValidator(value).contains(SUCCESS)) {
- responseString.append("Settings Attributes:" + value
- + SPACESINVALIDCHARS);
+ responseString.append("Settings Attributes:" + value + SPACESINVALIDCHARS);
valid = false;
}
} else {
- responseString
- .append("Settings Attributes: has one missing Attribute Value
");
+ responseString.append(
+ "Settings Attributes: has one missing Attribute Value
");
valid = false;
}
}
@@ -244,31 +254,28 @@ public class PolicyValidation {
}
if (!"API".equals(policyData.getApiflag()) && policyData.getRuleAlgorithmschoices() != null
- && !policyData.getRuleAlgorithmschoices().isEmpty()) {
+ && !policyData.getRuleAlgorithmschoices().isEmpty()) {
for (Object attribute : policyData.getRuleAlgorithmschoices()) {
if (attribute instanceof LinkedHashMap, ?>) {
String label = ((LinkedHashMap, ?>) attribute).get("id").toString();
if (((LinkedHashMap, ?>) attribute).get("dynamicRuleAlgorithmField1") == null) {
- responseString.append(
- "Rule Algorithms:" + label + " : Field 1 value is not selected
");
+ responseString.append(RULE_ALGORITHMS + label + " : Field 1 value is not selected
");
valid = false;
}
if (((LinkedHashMap, ?>) attribute).get("dynamicRuleAlgorithmCombo") == null) {
- responseString.append(
- "Rule Algorithms:" + label + " : Field 2 value is not selected
");
+ responseString.append(RULE_ALGORITHMS + label + " : Field 2 value is not selected
");
valid = false;
}
if (((LinkedHashMap, ?>) attribute).get("dynamicRuleAlgorithmField2") != null) {
- String value =
- ((LinkedHashMap, ?>) attribute).get("dynamicRuleAlgorithmField2").toString();
+ String value = ((LinkedHashMap, ?>) attribute).get("dynamicRuleAlgorithmField2")
+ .toString();
if (!PolicyUtils.policySpecialCharValidator(value).contains(SUCCESS)) {
- responseString.append("Rule Algorithms:" + label
- + " : Field 3 value has special characters
");
+ responseString.append(RULE_ALGORITHMS + label
+ + " : Field 3 value has special characters
");
valid = false;
}
} else {
- responseString
- .append("Rule Algorithms:" + label + " : Field 3 value is empty
");
+ responseString.append(RULE_ALGORITHMS + label + " : Field 3 value is empty
");
valid = false;
}
}
@@ -277,14 +284,15 @@ public class PolicyValidation {
if (CONFIG_POLICY.equalsIgnoreCase(policyData.getPolicyType())) {
if ("Base".equals(policyData.getConfigPolicyType())
- || CLOSEDLOOP_POLICY.equals(policyData.getConfigPolicyType())
- || CLOSEDLOOP_PM.equals(policyData.getConfigPolicyType())
- || ENFORCER_CONFIG_POLICY.equals(policyData.getConfigPolicyType())
- || MICROSERVICES.equals(policyData.getConfigPolicyType())
- || OPTIMIZATION.equals(policyData.getConfigPolicyType())) {
+ || CLOSEDLOOP_POLICY.equals(policyData.getConfigPolicyType())
+ || CLOSEDLOOP_PM.equals(policyData.getConfigPolicyType())
+ || ENFORCER_CONFIG_POLICY.equals(policyData.getConfigPolicyType())
+ || MICROSERVICES.equals(policyData.getConfigPolicyType())
+ || OPTIMIZATION.equals(policyData.getConfigPolicyType())) {
if (!Strings.isNullOrEmpty(policyData.getOnapName())) {
- String onapNameValidate = PolicyUtils.policySpecialCharWithDashValidator(policyData.getOnapName());
+ String onapNameValidate = PolicyUtils
+ .policySpecialCharWithDashValidator(policyData.getOnapName());
if (!onapNameValidate.contains(SUCCESS)) {
responseString.append("OnapName:" + onapNameValidate + HTML_ITALICS_LNBREAK);
valid = false;
@@ -356,25 +364,25 @@ public class PolicyValidation {
if (configType != null) {
if ("JSON".equals(configType)) {
if (!PolicyUtils.isJSONValid(configBodyData)) {
- responseString
- .append("Config Body: JSON Content is not valid" + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "Config Body: JSON Content is not valid" + HTML_ITALICS_LNBREAK);
valid = false;
}
} else if ("XML".equals(configType)) {
if (!PolicyUtils.isXMLValid(configBodyData)) {
- responseString.append(
- "Config Body: XML Content data is not valid" + HTML_ITALICS_LNBREAK);
+ responseString.append("Config Body: XML Content data is not valid"
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
} else if ("PROPERTIES".equals(configType)) {
if (!PolicyUtils.isPropValid(configBodyData) || "".equals(configBodyData)) {
- responseString
- .append("Config Body: Property data is not valid" + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "Config Body: Property data is not valid" + HTML_ITALICS_LNBREAK);
valid = false;
}
} else if ("OTHER".equals(configType) && ("".equals(configBodyData))) {
- responseString
- .append("Config Body: Config Body Should not be Empty" + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "Config Body: Config Body Should not be Empty" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
@@ -396,14 +404,14 @@ public class PolicyValidation {
valid = false;
}
if (policyData.getSecurityZone() == null || policyData.getSecurityZone().isEmpty()) {
- responseString
- .append("Security Zone: Security Zone is required" + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "Security Zone: Security Zone is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
// Validate BRMS_Param Policy Data
if (BRMSPARAM.equalsIgnoreCase(policyData.getConfigPolicyType())
- && Strings.isNullOrEmpty(policyData.getRuleName())) {
+ && Strings.isNullOrEmpty(policyData.getRuleName())) {
responseString.append("BRMS Template:BRMS Template is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
@@ -414,8 +422,8 @@ public class PolicyValidation {
// If there are any error other than Annotations then this is not Valid
if (message.contains("[ERR")) {
- responseString.append(
- "Raw Rule Validate:Raw Rule has error" + message + HTML_ITALICS_LNBREAK);
+ responseString.append("Raw Rule Validate:Raw Rule has error" + message
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
} else {
@@ -426,17 +434,17 @@ public class PolicyValidation {
// Validate ClosedLoop_PM Policy Data
if (CLOSEDLOOP_PM.equalsIgnoreCase(policyData.getConfigPolicyType())) {
try {
- if (Strings.isNullOrEmpty(
- policyData.getServiceTypePolicyName().get("serviceTypePolicyName").toString())) {
+ if (Strings.isNullOrEmpty(policyData.getServiceTypePolicyName().get("serviceTypePolicyName")
+ .toString())) {
responseString.append("ServiceType PolicyName:ServiceType PolicyName is required"
- + HTML_ITALICS_LNBREAK);
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
} catch (Exception e) {
LOGGER.error("ERROR in ClosedLoop_PM PolicyName", e);
responseString.append("ServiceType PolicyName:ServiceType PolicyName is required"
- + HTML_ITALICS_LNBREAK);
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
@@ -450,11 +458,9 @@ public class PolicyValidation {
valid = false;
}
}
- if ((pmBody.isGamma() || pmBody.isMcr() || pmBody.isTrinity() || pmBody.isvDNS()
- || pmBody.isvUSP()) != true) {
- responseString
- .append("D2/Virtualized Services: Select at least one D2/Virtualized Services"
- + HTML_ITALICS_LNBREAK);
+ if (!pmBody.isGamma() && !pmBody.isMcr() && !pmBody.isTrinity() && !pmBody.isvDNS()
+ && !pmBody.isvUSP()) {
+ responseString.append(SELECT_AT_LEAST_ONE_D2_VIRTUALIZED_SERVICES + HTML_ITALICS_LNBREAK);
valid = false;
}
if (pmBody.getGeoLink() != null && !pmBody.getGeoLink().isEmpty()) {
@@ -472,16 +478,17 @@ public class PolicyValidation {
String attributeValidate = PolicyUtils.policySpecialCharValidator(value);
if (!attributeValidate.contains(SUCCESS)) {
responseString.append("Attributes:" + key
- + " : value has spaces or invalid characters" + HTML_ITALICS_LNBREAK);
+ + " : value has spaces or invalid characters"
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
}
}
}
} else {
- responseString
- .append("D2/Virtualized Services:Select atleast one D2/Virtualized Services"
- + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "D2/Virtualized Services:Select atleast one D2/Virtualized Services"
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
}
@@ -496,38 +503,40 @@ public class PolicyValidation {
String apiCondition = (String) json.get("conditions");
if (Strings.isNullOrEmpty(apiCondition)) {
responseString.append("Conditions: Select At least one Condition"
- + HTML_ITALICS_LNBREAK);
+ + HTML_ITALICS_LNBREAK);
return responseString;
}
} else {
- responseString
- .append("Conditions: There were no conditions provided in configBody json"
- + HTML_ITALICS_LNBREAK);
+ responseString.append("Conditions:"
+ + " There were no conditions provided in configBody json"
+ + HTML_ITALICS_LNBREAK);
return responseString;
}
} else {
if (policyData.getTrapDatas().getTrap1() != null) {
if (policyData.getClearTimeOut() == null) {
- responseString.append(
- "Trigger Clear TimeOut: Trigger Clear TimeOut is required when atleast One Trigger Signature is enabled
");
+ responseString.append("Trigger Clear TimeOut: "
+ + "Trigger Clear TimeOut is required when at "
+ + "least One Trigger Signature is enabled
");
valid = false;
}
if (policyData.getTrapMaxAge() == null) {
- responseString.append(
- "Trap Max Age: Trap Max Age is required when atleast One Trigger Signature is enabled
");
+ responseString.append("Trap Max Age: Trap Max Age is required when at "
+ + "least One Trigger Signature is enabled
");
valid = false;
}
}
if (policyData.getFaultDatas().getTrap1() != null
- && policyData.getVerificationclearTimeOut() == null) {
+ && policyData.getVerificationclearTimeOut() == null) {
responseString.append(
- "Fault Clear TimeOut: Fault Clear TimeOut is required when atleast One Fault Signature is enabled
");
+ "Fault Clear TimeOut: Fault Clear TimeOut is required when at"
+ + "least One Fault Signature is enabled
");
valid = false;
}
}
- ClosedLoopFaultBody faultBody =
- mapper.readValue(policyData.getJsonBody(), ClosedLoopFaultBody.class);
+ ClosedLoopFaultBody faultBody = mapper.readValue(policyData.getJsonBody(),
+ ClosedLoopFaultBody.class);
if (faultBody.getEmailAddress() != null && !faultBody.getEmailAddress().isEmpty()) {
String result = emailValidation(faultBody.getEmailAddress(), responseString.toString());
if (!SUCCESS.equals(result)) {
@@ -536,26 +545,24 @@ public class PolicyValidation {
}
}
if (!(faultBody.isGamma() || faultBody.isMcr() || faultBody.isTrinity() || faultBody.isvDNS()
- || faultBody.isvUSP())) {
- responseString
- .append("D2/Virtualized Services: Select at least one D2/Virtualized Services"
- + HTML_ITALICS_LNBREAK);
+ || faultBody.isvUSP())) {
+ responseString.append(SELECT_AT_LEAST_ONE_D2_VIRTUALIZED_SERVICES + HTML_ITALICS_LNBREAK);
valid = false;
}
if (faultBody.getActions() == null || faultBody.getActions().isEmpty()) {
- responseString
- .append("vPRO Actions: vPRO Actions is required" + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "vPRO Actions: vPRO Actions is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if (faultBody.getClosedLoopPolicyStatus() == null
- || faultBody.getClosedLoopPolicyStatus().isEmpty()) {
- responseString.append(
- "Policy Status: Policy Status is required" + HTML_ITALICS_LNBREAK);
+ || faultBody.getClosedLoopPolicyStatus().isEmpty()) {
+ responseString.append("Policy Status: Policy Status is required"
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
if (faultBody.getConditions() == null) {
- responseString.append(
- "Conditions: Select At least one Condition" + HTML_ITALICS_LNBREAK);
+ responseString.append("Conditions: Select At least one Condition"
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
if (faultBody.getGeoLink() != null && !faultBody.getGeoLink().isEmpty()) {
@@ -566,28 +573,28 @@ public class PolicyValidation {
}
}
if (faultBody.getAgingWindow() == 0) {
- responseString
- .append("Aging Window: Aging Window is required" + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "Aging Window: Aging Window is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if (faultBody.getTimeInterval() == 0) {
- responseString.append(
- "Time Interval: Time Interval is required" + HTML_ITALICS_LNBREAK);
+ responseString.append("Time Interval: Time Interval is required"
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
if (faultBody.getRetrys() == 0) {
responseString.append("Number of Retries: Number of Retries is required"
- + HTML_ITALICS_LNBREAK);
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
if (faultBody.getTimeOutvPRO() == 0) {
- responseString.append(
- "APP-C Timeout: APP-C Timeout is required" + HTML_ITALICS_LNBREAK);
+ responseString.append("APP-C Timeout: APP-C Timeout is required"
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
if (faultBody.getTimeOutRuby() == 0) {
- responseString
- .append("TimeOutRuby: TimeOutRuby is required" + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "TimeOutRuby: TimeOutRuby is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if (faultBody.getVnfType() == null || faultBody.getVnfType().isEmpty()) {
@@ -595,31 +602,32 @@ public class PolicyValidation {
valid = false;
}
} else {
- responseString
- .append("D2/Virtualized Services: Select atleast one D2/Virtualized Services"
- + HTML_ITALICS_LNBREAK);
- responseString
- .append("vPRO Actions: vPRO Actions is required" + HTML_ITALICS_LNBREAK);
- responseString
- .append("Aging Window: Aging Window is required" + HTML_ITALICS_LNBREAK);
- responseString
- .append("Policy Status: Policy Status is required" + HTML_ITALICS_LNBREAK);
- responseString
- .append("Conditions: Select Atleast one Condition" + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "D2/Virtualized Services: Select atleast one D2/Virtualized Services"
+ + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "vPRO Actions: vPRO Actions is required" + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "Aging Window: Aging Window is required" + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "Policy Status: Policy Status is required" + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "Conditions: Select Atleast one Condition" + HTML_ITALICS_LNBREAK);
responseString.append("PEP Name: PEP Name is required" + HTML_ITALICS_LNBREAK);
responseString.append("PEP Action: PEP Action is required" + HTML_ITALICS_LNBREAK);
- responseString
- .append("Time Interval: Time Interval is required" + HTML_ITALICS_LNBREAK);
responseString.append(
- "Number of Retries: Number of Retries is required" + HTML_ITALICS_LNBREAK);
- responseString
- .append("APP-C Timeout: APP-C Timeout is required" + HTML_ITALICS_LNBREAK);
+ "Time Interval: Time Interval is required" + HTML_ITALICS_LNBREAK);
+ responseString.append("Number of Retries: Number of Retries is required"
+ + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "APP-C Timeout: APP-C Timeout is required" + HTML_ITALICS_LNBREAK);
responseString.append("TimeOutRuby: TimeOutRuby is required" + HTML_ITALICS_LNBREAK);
responseString.append("Vnf Type: Vnf Type is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
+ // Validate MicroService Policy Data
if (MICROSERVICES.equals(policyData.getConfigPolicyType())) {
boolean tmpValid = validateMsModel(policyData, responseString);
if (!tmpValid) {
@@ -628,162 +636,16 @@ public class PolicyValidation {
}
// Validate Optimization Policy Data
- if (OPTIMIZATION.equals(policyData.getConfigPolicyType())){
-
- if(!Strings.isNullOrEmpty(policyData.getServiceType())){
-
- modelRequiredFieldsList.clear();
- pullJsonKeyPairs((JsonNode) policyData.getPolicyJSON());
-
- String service;
- String version;
- if (policyData.getServiceType().contains("-v")){
- service = policyData.getServiceType().split("-v")[0];
- version = policyData.getServiceType().split("-v")[1];
- }else {
- service = policyData.getServiceType();
- version = policyData.getVersion();
- }
-
- if (!Strings.isNullOrEmpty(version)) {
- OptimizationModels returnModel = getOptimizationModelData(service, version);
-
- if (returnModel != null) {
-
- String annotation = returnModel.getAnnotation();
- String refAttributes = returnModel.getRefattributes();
- String subAttributes = returnModel.getSubattributes();
- String modelAttributes = returnModel.getAttributes();
-
- if (!Strings.isNullOrEmpty(annotation)) {
- Map rangeMap = Splitter.on(",").withKeyValueSeparator("=")
- .split(annotation);
- for (Entry rMap : rangeMap.entrySet()) {
- if (rMap.getValue().contains("range::")) {
- String value = mapAttribute.get(rMap.getKey().trim());
- String[] tempString = rMap.getValue().split("::")[1].split("-");
- int startNum = Integer.parseInt(tempString[0]);
- int endNum = Integer.parseInt(tempString[1]);
- String returnString = "InvalidreturnModel Range:" + rMap.getKey()
- + " must be between " + startNum + " - " + endNum + ",";
-
- if (value != null) {
- if (PolicyUtils.isInteger(value.replace("\"", ""))) {
- int result = Integer.parseInt(value.replace("\"", ""));
- if (result < startNum || result > endNum) {
- responseString.append(returnString);
- valid = false;
- }
- } else {
- responseString.append(returnString);
- valid = false;
- }
- } else {
- responseString.append("" + rMap.getKey() + ":" + rMap.getKey()
- + " is required for the Optimization model " + service
- + HTML_ITALICS_LNBREAK);
- valid = false;
- }
-
- }
- }
- }
-
- // If request comes from the API we need to validate required fields in the
- // Micro Service Model
- // GUI request are already validated from the SDK-APP
- if ("API".equals(policyData.getApiflag())) {
- // get list of required fields from the sub_Attributes of the Model
- if (!Strings.isNullOrEmpty(subAttributes)) {
- JsonObject subAttributesJson = stringToJsonObject(subAttributes);
- findRequiredFields(subAttributesJson);
- }
-
- // get list of required fields from the attributes of the Model
- if (!Strings.isNullOrEmpty(modelAttributes)) {
- Map modelAttributesMap = null;
- if (",".equals(modelAttributes.substring(modelAttributes.length() - 1))) {
- String attributeString = modelAttributes.substring(0,
- modelAttributes.length() - 1);
- modelAttributesMap = Splitter.on(",").withKeyValueSeparator("=")
- .split(attributeString);
- } else {
- modelAttributesMap = Splitter.on(",").withKeyValueSeparator("=")
- .split(modelAttributes);
- }
- String json = new ObjectMapper().writeValueAsString(modelAttributesMap);
- findRequiredFields(stringToJsonObject(json));
- }
-
- // get list of required fields from the ref_Attributes of the Model
- if (!Strings.isNullOrEmpty(refAttributes)) {
- Map refAttributesMap = null;
- if (",".equals(refAttributes.substring(refAttributes.length() - 1))) {
- String attributesString = refAttributes.substring(0,
- refAttributes.length() - 1);
- refAttributesMap = Splitter.on(",").withKeyValueSeparator("=")
- .split(attributesString);
- } else {
- refAttributesMap = Splitter.on(",").withKeyValueSeparator("=")
- .split(modelAttributes);
- }
- String json = new ObjectMapper().writeValueAsString(refAttributesMap);
- findRequiredFields(stringToJsonObject(json));
- }
-
- if (modelRequiredFieldsList != null || !modelRequiredFieldsList.isEmpty()) {
- // create jsonRequestMap with all json keys and values from request
- JsonNode rootNode = (JsonNode) policyData.getPolicyJSON();
- jsonRequestMap.clear();
- pullModelJsonKeyPairs(rootNode);
-
- // validate if the requiredFields are in the request
- for (String requiredField : modelRequiredFieldsList) {
- if (jsonRequestMap.containsKey(requiredField)) {
- String value = jsonRequestMap.get(requiredField);
- if (Strings.isNullOrEmpty(jsonRequestMap.get(requiredField))
- || "\"\"".equals(value)
- || "".equals(jsonRequestMap.get(requiredField))) {
- responseString.append("Optimization Service Model: "
- + requiredField + ISREQUIRED + HTML_ITALICS_LNBREAK);
- valid = false;
- }
- } else {
- responseString.append("Optimization Service Model: "
- + requiredField + ISREQUIRED + HTML_ITALICS_LNBREAK);
- valid = false;
- }
- }
- }
- }
- } else {
- responseString
- .append("Optimization Service Model: Invalid Model. The model name, "
- + service + " of version, " + version
- + " was not found in the dictionary" + HTML_ITALICS_LNBREAK);
- valid = false;
- }
- } else {
- responseString.append(
- "Optimization Service Version: Optimization Service Version is required"
- + HTML_ITALICS_LNBREAK);
- valid = false;
- }
- } else {
- responseString.append("Optimization Service: Optimization Service Model is required"
- + HTML_ITALICS_LNBREAK);
- valid = false;
- }
-
- if (Strings.isNullOrEmpty(policyData.getPriority())) {
- responseString.append("Priority: Priority is required" + HTML_ITALICS_LNBREAK);
+ if (OPTIMIZATION.equals(policyData.getConfigPolicyType())) {
+ boolean tmpValid = validateOptimization(policyData, responseString);
+ if (!tmpValid) {
valid = false;
}
}
}
if ((DECISION_POLICY.equalsIgnoreCase(policyData.getPolicyType()))
- || (DECISION_POLICY_MS.equalsIgnoreCase(policyData.getPolicyType()))) {
+ || (DECISION_POLICY_MS.equalsIgnoreCase(policyData.getPolicyType()))) {
if (!RAW.equalsIgnoreCase(policyData.getRuleProvider())) {
if (!Strings.isNullOrEmpty(policyData.getOnapName())) {
String onapNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getOnapName());
@@ -797,7 +659,8 @@ public class PolicyValidation {
}
}
if (RAW.equalsIgnoreCase(policyData.getRuleProvider())) {
- Object policy = XACMLPolicyScanner.readPolicy(new ByteArrayInputStream(StringEscapeUtils.unescapeXml(policyData.getRawXacmlPolicy()).getBytes(StandardCharsets.UTF_8)));
+ Object policy = XACMLPolicyScanner.readPolicy(new ByteArrayInputStream(StringEscapeUtils
+ .unescapeXml(policyData.getRawXacmlPolicy()).getBytes(StandardCharsets.UTF_8)));
if (!(policy instanceof PolicySetType || policy instanceof PolicyType)) {
responseString.append("Raw XACML: The XACML Content is not valid" + HTML_ITALICS_LNBREAK);
valid = false;
@@ -834,7 +697,7 @@ public class PolicyValidation {
valid = false;
}
if (!policyData.getRainyday().getTreatmentTableChoices().isEmpty()
- && policyData.getRainyday().getTreatmentTableChoices() != null) {
+ && policyData.getRainyday().getTreatmentTableChoices() != null) {
for (Object treatmentMap : policyData.getRainyday().getTreatmentTableChoices()) {
String errorCode = null;
@@ -850,20 +713,20 @@ public class PolicyValidation {
}
if (Strings.isNullOrEmpty(errorCode) && Strings.isNullOrEmpty(treatment)) {
- responseString.append(
- "Rainy Day Error Code and Desired Treatment cannot be empty
");
+ responseString.append("Rainy Day Error Code and "
+ + "Desired Treatment cannot be empty
");
valid = false;
break;
}
if (Strings.isNullOrEmpty(errorCode)) {
- responseString.append(
- "Rainy Day Error Code is Required for each Desired Treatment
");
+ responseString.append("Rainy Day Error Code is Required "
+ + "for each Desired Treatment
");
valid = false;
break;
}
if (Strings.isNullOrEmpty(treatment)) {
- responseString.append(
- "Rainy Day Desired Treatment is Required for each Error Code
");
+ responseString.append("Rainy Day Desired Treatment"
+ + " is Required for each Error Code
");
valid = false;
break;
}
@@ -877,8 +740,8 @@ public class PolicyValidation {
}
if ("GUARD_YAML".equals(policyData.getRuleProvider())
- || "GUARD_BL_YAML".equals(policyData.getRuleProvider())
- || "GUARD_MIN_MAX".equals(policyData.getRuleProvider())) {
+ || "GUARD_BL_YAML".equals(policyData.getRuleProvider())
+ || "GUARD_MIN_MAX".equals(policyData.getRuleProvider())) {
if (policyData.getYamlparams() == null) {
responseString.append(" Guard Params are Required " + HTML_ITALICS_LNBREAK);
valid = false;
@@ -892,13 +755,13 @@ public class PolicyValidation {
valid = false;
}
if (Strings.isNullOrEmpty(policyData.getYamlparams().getGuardActiveStart())) {
- responseString.append(
- "Guard Params Guard Active Start is Required " + HTML_ITALICS_LNBREAK);
+ responseString.append("Guard Params Guard Active Start is Required "
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
if (Strings.isNullOrEmpty(policyData.getYamlparams().getGuardActiveEnd())) {
- responseString
- .append("Guard Params Guard Active End is Required " + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "Guard Params Guard Active End is Required " + HTML_ITALICS_LNBREAK);
valid = false;
}
if ("GUARD_YAML".equals(policyData.getRuleProvider())) {
@@ -906,22 +769,22 @@ public class PolicyValidation {
responseString.append(" Guard Params Limit is Required " + HTML_ITALICS_LNBREAK);
valid = false;
} else if (!PolicyUtils.isInteger(policyData.getYamlparams().getLimit())) {
- responseString
- .append(" Guard Params Limit Should be Integer " + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ " Guard Params Limit Should be Integer " + HTML_ITALICS_LNBREAK);
valid = false;
}
if (Strings.isNullOrEmpty(policyData.getYamlparams().getTimeWindow())) {
- responseString
- .append("Guard Params Time Window is Required" + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "Guard Params Time Window is Required" + HTML_ITALICS_LNBREAK);
valid = false;
} else if (!PolicyUtils.isInteger(policyData.getYamlparams().getTimeWindow())) {
- responseString.append(
- " Guard Params Time Window Should be Integer " + HTML_ITALICS_LNBREAK);
+ responseString.append(" Guard Params Time Window Should be Integer "
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
if (Strings.isNullOrEmpty(policyData.getYamlparams().getTimeUnits())) {
- responseString
- .append("Guard Params Time Units is Required" + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ "Guard Params Time Units is Required" + HTML_ITALICS_LNBREAK);
valid = false;
}
} else if ("GUARD_MIN_MAX".equals(policyData.getRuleProvider())) {
@@ -929,32 +792,32 @@ public class PolicyValidation {
responseString.append(" Guard Params Min is Required " + HTML_ITALICS_LNBREAK);
valid = false;
} else if (!PolicyUtils.isInteger(policyData.getYamlparams().getMin())) {
- responseString
- .append(" Guard Params Min Should be Integer " + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ " Guard Params Min Should be Integer " + HTML_ITALICS_LNBREAK);
valid = false;
}
if (Strings.isNullOrEmpty(policyData.getYamlparams().getMax())) {
responseString.append(" Guard Params Max is Required " + HTML_ITALICS_LNBREAK);
valid = false;
} else if (!PolicyUtils.isInteger(policyData.getYamlparams().getMax())) {
- responseString
- .append(" Guard Params Max Should be Integer " + HTML_ITALICS_LNBREAK);
+ responseString.append(
+ " Guard Params Max Should be Integer " + HTML_ITALICS_LNBREAK);
valid = false;
}
} else if ("GUARD_BL_YAML".equals(policyData.getRuleProvider())
- && "Use Manual Entry".equals(policyData.getBlackListEntryType())) {
+ && "Use Manual Entry".equals(policyData.getBlackListEntryType())) {
if (policyData.getYamlparams().getBlackList() == null
- || policyData.getYamlparams().getBlackList().isEmpty()) {
- responseString
- .append(" Guard Params BlackList is Required " + HTML_ITALICS_LNBREAK);
+ || policyData.getYamlparams().getBlackList().isEmpty()) {
+ responseString.append(
+ " Guard Params BlackList is Required " + HTML_ITALICS_LNBREAK);
valid = false;
} else {
for (String blackList : policyData.getYamlparams().getBlackList()) {
- if (blackList == null
- || !(SUCCESS.equals(PolicyUtils.policySpecialCharValidator(blackList)))) {
+ if (blackList == null || !(SUCCESS
+ .equals(PolicyUtils.policySpecialCharValidator(blackList)))) {
responseString.append(" Guard Params BlackList Should be valid String"
- + HTML_ITALICS_LNBREAK);
+ + HTML_ITALICS_LNBREAK);
valid = false;
break;
}
@@ -973,21 +836,21 @@ public class PolicyValidation {
valid = false;
}
} else {
- responseString.append(
- "ActionPerformer: ActionPerformer Should not be empty" + HTML_ITALICS_LNBREAK);
+ responseString.append("ActionPerformer: ActionPerformer Should not be empty"
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
if (!Strings.isNullOrEmpty(policyData.getActionAttributeValue())) {
- String actionAttribute =
- PolicyUtils.policySpecialCharValidator(policyData.getActionAttributeValue());
+ String actionAttribute = PolicyUtils
+ .policySpecialCharValidator(policyData.getActionAttributeValue());
if (!actionAttribute.contains(SUCCESS)) {
responseString.append("ActionAttribute:" + actionAttribute + HTML_ITALICS_LNBREAK);
valid = false;
}
} else {
- responseString.append(
- "ActionAttribute: ActionAttribute Should not be empty" + HTML_ITALICS_LNBREAK);
+ responseString.append("ActionAttribute: ActionAttribute Should not be empty"
+ + HTML_ITALICS_LNBREAK);
valid = false;
}
}
@@ -997,7 +860,7 @@ public class PolicyValidation {
if (valid) {
if (commonClassDao != null) {
List