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=446073d405049287a565af891680082bfa46e358;hb=b76e99abb13f51473cdd697aa6040d9a0265d695;hp=223381afe84033dc08225aed1ec3e92cd35c72e5;hpb=b3828de54af94f66e3a6e22bcaeb3372d14eab34;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 223381afe..446073d40 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
package org.onap.policy.rest.util;
import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -27,6 +29,12 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import javax.json.Json;
+import javax.json.JsonException;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonValue;
+
import org.apache.commons.lang.StringUtils;
import org.json.JSONObject;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
@@ -60,8 +68,13 @@ public class PolicyValidation {
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 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.";
private static Map mapAttribute = new HashMap<>();
+ private static Map jsonRequestMap = new HashMap<>();
+ private static List modelRequiredFieldsList = new ArrayList<>();
private static CommonClassDao commonClassDao;
@@ -73,7 +86,9 @@ public class PolicyValidation {
/*
* This is an empty constructor
*/
- public PolicyValidation(){}
+ public PolicyValidation(){
+ // Empty constructor
+ }
public StringBuilder validatePolicy(PolicyRestAdapter policyData) throws IOException{
@@ -84,22 +99,127 @@ public class PolicyValidation {
if(policyData.getPolicyName() != null){
String policyNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getPolicyName());
- if(!policyNameValidate.contains("success")){
- responseString.append("PolicyName:" + policyNameValidate + "
");
+ if(!policyNameValidate.contains(SUCCESS)){
+ responseString.append("PolicyName:" + policyNameValidate + HTML_ITALICS_LNBREAK);
valid = false;
- };
+ }
}else{
- responseString.append( "PolicyName: PolicyName Should not be empty" + "
");
+ responseString.append( "PolicyName: PolicyName Should not be empty" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(policyData.getPolicyDescription() != null){
String descriptionValidate = PolicyUtils.descriptionValidator(policyData.getPolicyDescription());
- if(!descriptionValidate.contains("success")){
- responseString.append("Description:" + descriptionValidate + "
");
+ if(!descriptionValidate.contains(SUCCESS)){
+ responseString.append("Description:" + descriptionValidate + HTML_ITALICS_LNBREAK);
valid = false;
}
}
+ if(!"API".equals(policyData.getApiflag()) && policyData.getAttributes() != null && !policyData.getAttributes().isEmpty()){
+ for(Object attribute : policyData.getAttributes()){
+ if(attribute instanceof LinkedHashMap, ?>){
+ String value = null;
+ String key = null;
+ if(((LinkedHashMap, ?>) attribute).get("key") != null){
+ key = ((LinkedHashMap, ?>) attribute).get("key").toString();
+ if(!PolicyUtils.policySpecialCharValidator(key).contains("success")){
+ responseString.append("Attributes or Component Attributes:" + value + " : value has spaces or invalid characters
");
+ valid = false;
+ }
+ }else{
+ if(CONFIG_POLICY.equals(policyData.getPolicyType())){
+ if("Base".equals(policyData.getConfigPolicyType())){
+ responseString.append("Attributes: has one missing Attribute key
");
+ }
+ if("BRMS_Param".equals(policyData.getConfigPolicyType()) || "BRMS_Raw".equals(policyData.getConfigPolicyType())){
+ responseString.append("Rule Attributes: has one missing Attribute key
");
+ }
+ }else{
+ responseString.append("Component Attributes: has one missing Component Attribute key
");
+ }
+ valid = false;
+ }
+ if(((LinkedHashMap, ?>) attribute).get("value") != null){
+ value = ((LinkedHashMap, ?>) attribute).get("value").toString();
+ if(!PolicyUtils.policySpecialCharValidator(value).contains("success")){
+ if(CONFIG_POLICY.equals(policyData.getPolicyType())){
+ if("Base".equals(policyData.getConfigPolicyType())){
+ responseString.append("Attributes:" + value + " : value has spaces or invalid characters
");
+ }
+ if("BRMS_Param".equals(policyData.getConfigPolicyType()) || "BRMS_Raw".equals(policyData.getConfigPolicyType())){
+ responseString.append("Rule Attributes:" + value + " : value has spaces or invalid characters
");
+ }
+ }else{
+ responseString.append("Component Attributes:" + value + " : value has spaces or invalid characters
");
+ }
+ valid = false;
+ }
+ }else{
+ if(CONFIG_POLICY.equals(policyData.getPolicyType())){
+ if("Base".equals(policyData.getConfigPolicyType())){
+ responseString.append("Attributes: has one missing Attribute value
");
+ }
+ if("BRMS_Param".equals(policyData.getConfigPolicyType()) || "BRMS_Raw".equals(policyData.getConfigPolicyType())){
+ responseString.append("Rule Attributes: has one missing Attribute value
");
+ }
+ }else{
+ responseString.append("Component Attributes: has one missing Component Attribute value
");
+ }
+ valid = false;
+ }
+ }
+ }
+ }
+
+ //Decision Policy Attributes Validation
+ if(!"API".equals(policyData.getApiflag()) && policyData.getSettings() != null && !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
");
+ valid = false;
+ }
+ if(((LinkedHashMap, ?>) attribute).get("value") != null){
+ value = ((LinkedHashMap, ?>) attribute).get("value").toString();
+ if(!PolicyUtils.policySpecialCharValidator(value).contains("success")){
+ responseString.append("Settings Attributes:" + value + " : value has spaces or invalid characters
");
+ valid = false;
+ }
+ }else{
+ responseString.append("Settings Attributes: has one missing Attribute Value
");
+ valid = false;
+ }
+ }
+ }
+ }
+
+ if(!"API".equals(policyData.getApiflag()) && policyData.getRuleAlgorithmschoices() != null && !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
");
+ valid = false;
+ }
+ if(((LinkedHashMap, ?>) attribute).get("dynamicRuleAlgorithmCombo") == null){
+ 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();
+ if(!PolicyUtils.policySpecialCharValidator(value).contains("success")){
+ responseString.append("Rule Algorithms:" + label + " : Field 3 value has special characters
");
+ valid = false;
+ }
+ }else{
+ responseString.append("Rule Algorithms:" + label + " : Field 3 value is empty
");
+ valid = false;
+ }
+ }
+ }
+ }
+
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())
@@ -107,123 +227,119 @@ public class PolicyValidation {
if(!Strings.isNullOrEmpty(policyData.getOnapName())) {
String onapNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getOnapName());
- if(!onapNameValidate.contains("success")){
- responseString.append("OnapName:" + onapNameValidate + "
");
+ if(!onapNameValidate.contains(SUCCESS)){
+ responseString.append("OnapName:" + onapNameValidate + HTML_ITALICS_LNBREAK);
valid = false;
}
}else{
- responseString.append("Onap Name: Onap Name Should not be empty" + "
");
+ responseString.append("Onap Name: Onap Name Should not be empty" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
if(!Strings.isNullOrEmpty(policyData.getRiskType())) {
String riskTypeValidate = PolicyUtils.policySpecialCharValidator(policyData.getRiskType());
- if(!riskTypeValidate.contains("success")){
- responseString.append("RiskType:" + riskTypeValidate + "
");
+ if(!riskTypeValidate.contains(SUCCESS)){
+ responseString.append("RiskType:" + riskTypeValidate + HTML_ITALICS_LNBREAK);
valid = false;
}
}else {
- responseString.append("Risk Type: Risk Type Should not be Empty" + "
");
+ responseString.append("RiskType: Risk Type Should not be Empty" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(!Strings.isNullOrEmpty(policyData.getRiskLevel())) {
String validateRiskLevel = PolicyUtils.policySpecialCharValidator(policyData.getRiskLevel());
- if(!validateRiskLevel.contains("success")){
- responseString.append("RiskLevel:" + validateRiskLevel + "
");
+ if(!validateRiskLevel.contains(SUCCESS)){
+ responseString.append("RiskLevel:" + validateRiskLevel + HTML_ITALICS_LNBREAK);
valid = false;
}
}else {
- responseString.append("Risk Level: Risk Level Should not be Empty" + "
");
+ responseString.append("RiskLevel: Risk Level Should not be Empty" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(!Strings.isNullOrEmpty(policyData.getGuard())) {
String validateGuard = PolicyUtils.policySpecialCharValidator(policyData.getGuard());
- if(!validateGuard.contains("success")){
- responseString.append("Guard:" + validateGuard + "
");
+ if(!validateGuard.contains(SUCCESS)){
+ responseString.append("Guard:" + validateGuard + HTML_ITALICS_LNBREAK);
valid = false;
}
}else {
- responseString.append("Guard: Guard Value Should not be Empty" + "
");
+ responseString.append("Guard: Guard Value Should not be Empty" + HTML_ITALICS_LNBREAK);
valid = false;
}
if("Base".equalsIgnoreCase(policyData.getConfigPolicyType())){
if(!Strings.isNullOrEmpty(policyData.getConfigName())) {
String configNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getConfigName());
- if(!configNameValidate.contains("success")){
- responseString.append("ConfigName:" + configNameValidate + "
");
+ if(!configNameValidate.contains(SUCCESS)){
+ responseString.append("ConfigName:" + configNameValidate + HTML_ITALICS_LNBREAK);
valid = false;
}
}else{
- responseString.append("Config Name: Config Name Should not be Empty" + "
");
+ responseString.append("Config Name: Config Name Should not be Empty" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(!Strings.isNullOrEmpty(policyData.getConfigType())) {
String configTypeValidate = PolicyUtils.policySpecialCharValidator(policyData.getConfigType());
- if(!configTypeValidate.contains("success")){
- responseString.append("ConfigType:" + configTypeValidate + "
");
+ if(!configTypeValidate.contains(SUCCESS)){
+ responseString.append("ConfigType:" + configTypeValidate + HTML_ITALICS_LNBREAK);
valid = false;
}
}else{
- responseString.append("Config Type: Config Type Should not be Empty" + "
");
+ responseString.append("Config Type: Config Type Should not be Empty" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(!Strings.isNullOrEmpty(policyData.getConfigBodyData())) {
String configBodyData = policyData.getConfigBodyData();
String configType = policyData.getConfigType();
if (configType != null) {
- if (configType.equals("JSON")) {
+ if ("JSON".equals(configType)) {
if (!PolicyUtils.isJSONValid(configBodyData)) {
- responseString.append("Config Body: JSON Content is not valid" + "
");
+ responseString.append("Config Body: JSON Content is not valid" + HTML_ITALICS_LNBREAK);
valid = false;
}
- } else if (configType.equals("XML")) {
+ } else if ("XML".equals(configType)) {
if (!PolicyUtils.isXMLValid(configBodyData)) {
- responseString.append("Config Body: XML Content data is not valid" + "
");
+ responseString.append("Config Body: XML Content data is not valid" + HTML_ITALICS_LNBREAK);
valid = false;
}
- } else if (configType.equals("PROPERTIES")) {
- if (!PolicyUtils.isPropValid(configBodyData)||configBodyData.equals("")) {
- responseString.append("Config Body: Property data is not valid" + "
");
+ } else if ("PROPERTIES".equals(configType)) {
+ if (!PolicyUtils.isPropValid(configBodyData) || "".equals(configBodyData)) {
+ responseString.append("Config Body: Property data is not valid" + HTML_ITALICS_LNBREAK);
valid = false;
}
- } else if (configType.equals("OTHER")) {
- if (configBodyData.equals("")) {
- responseString.append("Config Body: Config Body Should not be Empty" + "
");
- valid = false;
- }
+ } else if ("OTHER".equals(configType) && ("".equals(configBodyData))) {
+ responseString.append("Config Body: Config Body Should not be Empty" + HTML_ITALICS_LNBREAK);
+ valid = false;
}
}
}else{
- responseString.append("Config Body: Config Body Should not be Empty" + "
");
+ responseString.append("Config Body: Config Body Should not be Empty" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
- if("Firewall Config".equalsIgnoreCase(policyData.getConfigPolicyType())){
+ if(FIREWALL.equalsIgnoreCase(policyData.getConfigPolicyType())){
if(policyData.getConfigName() != null && !policyData.getConfigName().isEmpty()){
String configNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getConfigName());
- if(!configNameValidate.contains("success")){
- responseString.append("ConfigName:" + configNameValidate + "
");
+ if(!configNameValidate.contains(SUCCESS)){
+ responseString.append("ConfigName:" + configNameValidate + HTML_ITALICS_LNBREAK);
valid = false;
}
}else{
- responseString.append("Config Name: Config Name is required" + "
");
+ responseString.append("Config Name: Config Name is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(policyData.getSecurityZone() == null || policyData.getSecurityZone().isEmpty()){
- responseString.append("Security Zone: Security Zone is required" + "
");
+ responseString.append("Security Zone: Security Zone is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
- if("BRMS_Param".equalsIgnoreCase(policyData.getConfigPolicyType())){
- if(policyData.getRuleName() == null || policyData.getRuleName().isEmpty()){
- responseString.append("BRMS Template:BRMS Template is required
");
- valid = false;
- }
+ if("BRMS_Param".equalsIgnoreCase(policyData.getConfigPolicyType()) && Strings.isNullOrEmpty(policyData.getRuleName())){
+ responseString.append("BRMS Template:BRMS Template is required" + HTML_ITALICS_LNBREAK);
+ valid = false;
}
if("BRMS_Raw".equalsIgnoreCase(policyData.getConfigPolicyType())){
if(policyData.getConfigBodyData() != null && !policyData.getConfigBodyData().isEmpty()){
@@ -231,46 +347,47 @@ 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 +"
");
+ responseString.append("Raw Rule Validate:Raw Rule has error"+ message + HTML_ITALICS_LNBREAK);
valid = false;
}
}else{
- responseString.append("Raw Rule:Raw Rule is required
");
+ responseString.append("Raw Rule:Raw Rule is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
- if("ClosedLoop_PM".equalsIgnoreCase(policyData.getConfigPolicyType())){
+ if(CLOSEDLOOP_PM.equalsIgnoreCase(policyData.getConfigPolicyType())){
try{
if(Strings.isNullOrEmpty(policyData.getServiceTypePolicyName().get("serviceTypePolicyName").toString())){
- responseString.append("ServiceType PolicyName:ServiceType PolicyName is required
");
+ responseString.append("ServiceType PolicyName:ServiceType PolicyName is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}catch(Exception e){
LOGGER.error("ERROR in ClosedLoop_PM PolicyName" , e);
- responseString.append("ServiceType PolicyName:ServiceType PolicyName is required
");
+ responseString.append("ServiceType PolicyName:ServiceType PolicyName is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(policyData.getJsonBody() != null){
- ClosedLoopPMBody pmBody = (ClosedLoopPMBody)mapper.readValue(policyData.getJsonBody(), ClosedLoopPMBody.class);
+
+ ClosedLoopPMBody pmBody = mapper.readValue(policyData.getJsonBody(), ClosedLoopPMBody.class);
if(pmBody.getEmailAddress() != null){
String result = emailValidation(pmBody.getEmailAddress(), responseString.toString());
- if(result != "success"){
- responseString.append(result + "
");
+ if(result != SUCCESS){
+ responseString.append(result + HTML_ITALICS_LNBREAK);
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
");
+ responseString.append("D2/Virtualized Services: Select at least one D2/Virtualized Services" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(pmBody.getGeoLink() != null && !pmBody.getGeoLink().isEmpty()){
String result = PolicyUtils.policySpecialCharValidator(pmBody.getGeoLink());
- if(!result.contains("success")){
- responseString.append("GeoLink:" + result + "
");
+ if(!result.contains(SUCCESS)){
+ responseString.append("GeoLink:" + result + HTML_ITALICS_LNBREAK);
valid = false;
- };
+ }
}
if(pmBody.getAttributes() != null && !pmBody.getAttributes().isEmpty()){
for(Entry entry : pmBody.getAttributes().entrySet()){
@@ -278,19 +395,19 @@ public class PolicyValidation {
String value = entry.getValue();
if(!key.contains("Message")){
String attributeValidate = PolicyUtils.policySpecialCharValidator(value);
- if(!attributeValidate.contains("success")){
- responseString.append("Attributes:" + key + " : value has spaces or invalid characters
");
+ if(!attributeValidate.contains(SUCCESS)){
+ responseString.append("Attributes:" + key + " : value has spaces or invalid characters" + HTML_ITALICS_LNBREAK);
valid = false;
- };
+ }
}
}
}
}else{
- responseString.append("D2/Virtualized Services:Select atleast one D2/Virtualized Services
");
+ responseString.append("D2/Virtualized Services:Select atleast one D2/Virtualized Services" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
- if("ClosedLoop_Fault".equalsIgnoreCase(policyData.getConfigPolicyType())){
+ if(CLOSEDLOOP_POLICY.equalsIgnoreCase(policyData.getConfigPolicyType())){
if(policyData.getJsonBody() != null){
// For API we need to get the conditions key from the Json request and check it before deserializing to POJO due to the enum
@@ -299,93 +416,110 @@ public class PolicyValidation {
if(!json.isNull("conditions")){
String apiCondition = (String) json.get("conditions");
if(Strings.isNullOrEmpty(apiCondition)){
- responseString.append("Conditions: Select At least one Condition
");
+ responseString.append("Conditions: Select At least one Condition" + HTML_ITALICS_LNBREAK);
return responseString;
}
} else {
- responseString.append("Conditions: There were no conditions provided in configBody json
");
+ 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
");
+ valid = false;
+ }
+ if(policyData.getTrapMaxAge() == null){
+ responseString.append("Trap Max Age: Trap Max Age is required when atleast One Trigger Signature is enabled
");
+ valid = false;
+ }
+ }
+ if(policyData.getFaultDatas().getTrap1() != null && policyData.getVerificationclearTimeOut() == null){
+ responseString.append("Fault Clear TimeOut: Fault Clear TimeOut is required when atleast One Fault Signature is enabled
");
+ valid = false;
+ }
}
ClosedLoopFaultBody faultBody = mapper.readValue(policyData.getJsonBody(), ClosedLoopFaultBody.class);
if(faultBody.getEmailAddress() != null && !faultBody.getEmailAddress().isEmpty()){
String result = emailValidation(faultBody.getEmailAddress(), responseString.toString());
- if(result != "success"){
- responseString.append(result+ "
");
+ if(!SUCCESS.equals(result)){
+ responseString.append(result+ HTML_ITALICS_LNBREAK);
valid = false;
}
}
if((faultBody.isGamma() || faultBody.isMcr() || faultBody.isTrinity() || faultBody.isvDNS() || faultBody.isvUSP()) != true){
- responseString.append("D2/Virtualized Services: Select at least one D2/Virtualized Services
");
+ responseString.append("D2/Virtualized Services: 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
");
+ 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
");
+ 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
");
+ responseString.append("Conditions: Select At least one Condition" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(faultBody.getGeoLink() != null && !faultBody.getGeoLink().isEmpty()){
String result = PolicyUtils.policySpecialCharWithSpaceValidator(faultBody.getGeoLink());
- if(!result.contains("success")){
- responseString.append("GeoLink:" + result + "
");
+ if(!result.contains(SUCCESS)){
+ responseString.append("GeoLink:" + result + HTML_ITALICS_LNBREAK);
valid = false;
}
}
if(faultBody.getAgingWindow() == 0){
- responseString.append("Aging Window: Aging Window is required
");
+ 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
");
+ 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
");
+ responseString.append("Number of Retries: Number of Retries is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(faultBody.getTimeOutvPRO() == 0){
- responseString.append("APP-C Timeout: APP-C Timeout is required
");
+ 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
");
+ responseString.append("TimeOutRuby: TimeOutRuby is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(faultBody.getVnfType() == null || faultBody.getVnfType().isEmpty()){
- responseString.append("Vnf Type: Vnf Type is required
");
+ responseString.append("Vnf Type: Vnf Type is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}else{
- responseString.append("D2/Virtualized Services: Select atleast one D2/Virtualized Services
");
- responseString.append("vPRO Actions: vPRO Actions is required
");
- responseString.append("Aging Window: Aging Window is required
");
- responseString.append("Policy Status: Policy Status is required
");
- responseString.append("Conditions: Select Atleast one Condition
");
- responseString.append("PEP Name: PEP Name is required
");
- responseString.append("PEP Action: PEP Action is required
");
- responseString.append("Time Interval: Time Interval is required
");
- responseString.append("Number of Retries: Number of Retries is required
");
- responseString.append("APP-C Timeout: APP-C Timeout is required
");
- responseString.append("TimeOutRuby: TimeOutRuby is required
");
- responseString.append("Vnf Type: Vnf Type is required
");
+ 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);
+ responseString.append("TimeOutRuby: TimeOutRuby is required" + HTML_ITALICS_LNBREAK);
+ responseString.append("Vnf Type: Vnf Type is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
- if ("Micro Service".equals(policyData.getConfigPolicyType())){
+ if (MICROSERVICES.equals(policyData.getConfigPolicyType())){
if(!Strings.isNullOrEmpty(policyData.getServiceType())){
+
+ modelRequiredFieldsList = new ArrayList<>();
pullJsonKeyPairs((JsonNode) policyData.getPolicyJSON());
- MicroServiceModels returnModel = new MicroServiceModels();
- String service = null;
- String version = null;
+
+ String service;
+ String version;
if (policyData.getServiceType().contains("-v")){
service = policyData.getServiceType().split("-v")[0];
version = policyData.getServiceType().split("-v")[1];
@@ -395,13 +529,17 @@ public class PolicyValidation {
}
if(!Strings.isNullOrEmpty(version)) {
- returnModel = getAttributeObject(service, version);
+ MicroServiceModels returnModel = getAttributeObject(service, version);
if(returnModel != null) {
+
String annotation = returnModel.getAnnotation();
+ String refAttributes = returnModel.getRef_attributes();
+ String subAttributes = returnModel.getSub_attributes();
+ String modelAttributes = returnModel.getAttributes();
+
if (!Strings.isNullOrEmpty(annotation)){
- Map rangeMap = new HashMap<>();
- rangeMap = Splitter.on(",").withKeyValueSeparator("=").split(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());
@@ -424,29 +562,96 @@ public class PolicyValidation {
}
} else {
responseString.append(""+rMap.getKey()+":" + rMap.getKey()
- + " is required for the MicroService model " + service + "
");
+ + " is required for the MicroService model " + service + HTML_ITALICS_LNBREAK);
valid = false;
}
}
}
+ } else {
+ // Validate for configName, location, uuid, and policyScope if no annotations exist for this model
+ if(Strings.isNullOrEmpty(policyData.getMsLocation())){
+ responseString.append("Micro Service Model: location is required for this model" + HTML_ITALICS_LNBREAK);
+ valid = false;
+ }
+
+ if(Strings.isNullOrEmpty(policyData.getConfigName())){
+ responseString.append("Micro Service Model: configName is required for this model" + HTML_ITALICS_LNBREAK);
+ valid = false;
+ }
+
+ if(Strings.isNullOrEmpty(policyData.getUuid())){
+ responseString.append("Micro Service Model: uuid is required for this model" + HTML_ITALICS_LNBREAK);
+ valid = false;
+ }
+
+ if(Strings.isNullOrEmpty(policyData.getPolicyScope())){
+ responseString.append("Micro Service Model: policyScope is required for this model" + HTML_ITALICS_LNBREAK);
+ valid = false;
+ }
}
+
+ // 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 = 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 = Splitter.on(",").withKeyValueSeparator("=").split(refAttributes);
+ String json = new ObjectMapper().writeValueAsString(refAttributesMap);
+ findRequiredFields(stringToJsonObject(json));
+ }
+
+ // Validate Required Fields in the Micro Service Model
+ if (modelRequiredFieldsList!=null || !modelRequiredFieldsList.isEmpty()) {
+ // create jsonRequestMap with all json keys and values from request
+ JsonNode rootNode = (JsonNode) policyData.getPolicyJSON();
+ 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("Micro Service Model: " + requiredField + " is required" + HTML_ITALICS_LNBREAK);
+ valid = false;
+ }
+ } else {
+ responseString.append("Micro Service Model: " + requiredField + " is required" + HTML_ITALICS_LNBREAK);
+ valid = false;
+ }
+ }
+ }
+
+
+
} else {
responseString.append("Micro Service Model: Invalid Model. The model name, " + service +
- " of version, " + version + " was not found in the dictionary
");
+ " of version, " + version + " was not found in the dictionary" + HTML_ITALICS_LNBREAK);
valid = false;
}
} else {
- responseString.append("Micro Version: Micro Service Version is required" + "
");
+ responseString.append("Micro Service Version: Micro Service Version is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
} else {
- responseString.append("Micro Service: Micro Service is required" + "
");
+ responseString.append("Micro Service: Micro Service Model is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(Strings.isNullOrEmpty(policyData.getPriority())){
- responseString.append("Priority: Priority is required" + "
");
+ responseString.append("Priority: Priority is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
@@ -454,12 +659,12 @@ public class PolicyValidation {
if (DECISION_POLICY.equalsIgnoreCase(policyData.getPolicyType())){
if(!Strings.isNullOrEmpty(policyData.getOnapName())){
String onapNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getOnapName());
- if(!onapNameValidate.contains("success")){
- responseString.append("OnapName:" + onapNameValidate + "
");
+ if(!onapNameValidate.contains(SUCCESS)){
+ responseString.append("OnapName:" + onapNameValidate + HTML_ITALICS_LNBREAK);
valid = false;
}
}else{
- responseString.append("Onap Name: Onap Name Should not be empty" + "
");
+ responseString.append("Onap Name: Onap Name Should not be empty" + HTML_ITALICS_LNBREAK);
valid = false;
}
@@ -526,52 +731,52 @@ public class PolicyValidation {
if("GUARD_YAML".equals(policyData.getRuleProvider()) || "GUARD_BL_YAML".equals(policyData.getRuleProvider())){
if(policyData.getYamlparams()==null){
- responseString.append(" Guard Params are Required " + "
");
+ responseString.append(" Guard Params are Required " + HTML_ITALICS_LNBREAK);
valid = false;
}else{
if(Strings.isNullOrEmpty(policyData.getYamlparams().getActor())){
- responseString.append("Guard Params Actor is Required " + "
");
+ responseString.append("Guard Params Actor is Required " + HTML_ITALICS_LNBREAK);
valid = false;
}
if(Strings.isNullOrEmpty(policyData.getYamlparams().getRecipe())){
- responseString.append("Guard Params Recipe is Required " + "
");
+ responseString.append("Guard Params Recipe is Required " + HTML_ITALICS_LNBREAK);
valid = false;
}
if(Strings.isNullOrEmpty(policyData.getYamlparams().getGuardActiveStart())){
- responseString.append("Guard Params Guard Active Start is Required " + "
");
+ 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 " + "
");
+ responseString.append("Guard Params Guard Active End is Required " + HTML_ITALICS_LNBREAK);
valid = false;
}
if("GUARD_YAML".equals(policyData.getRuleProvider())){
if(Strings.isNullOrEmpty(policyData.getYamlparams().getLimit())){
- responseString.append(" Guard Params Limit is Required " + "
");
+ 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 " + "
");
+ 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" + "
");
+ 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 " + "
");
+ 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" + "
");
+ responseString.append("Guard Params Time Units is Required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}else if("GUARD_BL_YAML".equals(policyData.getRuleProvider())){
if(policyData.getYamlparams().getBlackList()==null || policyData.getYamlparams().getBlackList().isEmpty()){
- responseString.append(" Guard Params BlackList is Required " + "
");
+ 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)))){
- responseString.append(" Guard Params BlackList Should be valid String" + "
");
+ if(blackList==null || !(SUCCESS.equals(PolicyUtils.policySpecialCharValidator(blackList)))){
+ responseString.append(" Guard Params BlackList Should be valid String" + HTML_ITALICS_LNBREAK);
valid = false;
break;
}
@@ -585,71 +790,25 @@ public class PolicyValidation {
if(ACTION_POLICY.equalsIgnoreCase(policyData.getPolicyType())){
if(!Strings.isNullOrEmpty(policyData.getActionPerformer())){
String actionPerformer = PolicyUtils.policySpecialCharValidator(policyData.getActionPerformer());
- if(!actionPerformer.contains("success")){
- responseString.append("ActionPerformer:" + actionPerformer + "
");
+ if(!actionPerformer.contains(SUCCESS)){
+ responseString.append("ActionPerformer:" + actionPerformer + HTML_ITALICS_LNBREAK);
valid = false;
}
}else{
- responseString.append("ActionPerformer: ActionPerformer Should not be empty" + "
");
- valid = false;
- }
- if(policyData.getAttributes() != null){
- for(Object attribute : policyData.getAttributes()){
- if(attribute instanceof LinkedHashMap, ?>){
- try{
- //This is for validation check if the value exists or not
- String key = ((LinkedHashMap, ?>) attribute).get("key").toString();
- String value = ((LinkedHashMap, ?>) attribute).get("value").toString();
- if("".equals(key) || "".equals(value)){
- responseString.append("Component Attributes: One or more Fields in Component Attributes is Empty." + "
");
- valid = false;
- break;
- }
- }catch(Exception e){
- LOGGER.error("This is a Policy Validation check" +e);
- responseString.append("Component Attributes: One or more Fields in Component Attributes is Empty." + "
");
- valid = false;
- break;
- }
- }
- }
- }else{
- responseString.append("Component Attributes: One or more Fields in Component Attributes is Empty." + "
");
+ responseString.append("ActionPerformer: ActionPerformer Should not be empty" + HTML_ITALICS_LNBREAK);
valid = false;
}
+
if(!Strings.isNullOrEmpty(policyData.getActionAttributeValue())){
String actionAttribute = PolicyUtils.policySpecialCharValidator(policyData.getActionAttributeValue());
- if(!actionAttribute.contains("success")){
- responseString.append("ActionAttribute:" + actionAttribute + "
");
+ if(!actionAttribute.contains(SUCCESS)){
+ responseString.append("ActionAttribute:" + actionAttribute + HTML_ITALICS_LNBREAK);
valid = false;
- };
+ }
}else{
- responseString.append("ActionAttribute: ActionAttribute Should not be empty" + "
");
+ responseString.append("ActionAttribute: ActionAttribute Should not be empty" + HTML_ITALICS_LNBREAK);
valid = false;
}
-
- if(!policyData.getRuleAlgorithmschoices().isEmpty()){
- for(Object attribute : policyData.getRuleAlgorithmschoices()){
- if(attribute instanceof LinkedHashMap, ?>){
- try{
- String label = ((LinkedHashMap, ?>) attribute).get("id").toString();
- String key = ((LinkedHashMap, ?>) attribute).get("dynamicRuleAlgorithmField1").toString();
- String rule = ((LinkedHashMap, ?>) attribute).get("dynamicRuleAlgorithmCombo").toString();
- String value = ((LinkedHashMap, ?>) attribute).get("dynamicRuleAlgorithmField2").toString();
-
- if(Strings.isNullOrEmpty(label) || Strings.isNullOrEmpty(key) || Strings.isNullOrEmpty(rule) || Strings.isNullOrEmpty(value)){
- responseString.append("Rule Algorithms: One or more Fields in Rule Algorithms is Empty." + "
");
- valid = false;
- }
- }catch(Exception e){
- LOGGER.error("This is a Policy Validation check" +e);
- responseString.append("Rule Algorithms: One or more Fields in Rule Algorithms is Empty." + "
");
- valid = false;
- break;
- }
- }
- }
- }
}
if(CONFIG_POLICY.equals(policyData.getPolicyType())){
@@ -659,14 +818,14 @@ public class PolicyValidation {
List