X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=ONAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Frest%2Futil%2FPolicyValidation.java;h=e98a41f9e0fcd68bd05558f9db8847d53f17d504;hp=223381afe84033dc08225aed1ec3e92cd35c72e5;hb=82e81ac60d97b93847a26accc071e7043d831ab0;hpb=428150834ee60899b9a8da019bae3c8bf009adf1
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..e98a41f9e 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
@@ -60,6 +60,9 @@ 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<>();
@@ -84,7 +87,7 @@ public class PolicyValidation {
if(policyData.getPolicyName() != null){
String policyNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getPolicyName());
- if(!policyNameValidate.contains("success")){
+ if(!policyNameValidate.contains(SUCCESS)){
responseString.append("PolicyName:" + policyNameValidate + "
");
valid = false;
};
@@ -94,7 +97,7 @@ public class PolicyValidation {
}
if(policyData.getPolicyDescription() != null){
String descriptionValidate = PolicyUtils.descriptionValidator(policyData.getPolicyDescription());
- if(!descriptionValidate.contains("success")){
+ if(!descriptionValidate.contains(SUCCESS)){
responseString.append("Description:" + descriptionValidate + "
");
valid = false;
}
@@ -107,7 +110,7 @@ public class PolicyValidation {
if(!Strings.isNullOrEmpty(policyData.getOnapName())) {
String onapNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getOnapName());
- if(!onapNameValidate.contains("success")){
+ if(!onapNameValidate.contains(SUCCESS)){
responseString.append("OnapName:" + onapNameValidate + "
");
valid = false;
}
@@ -119,7 +122,7 @@ public class PolicyValidation {
if(!Strings.isNullOrEmpty(policyData.getRiskType())) {
String riskTypeValidate = PolicyUtils.policySpecialCharValidator(policyData.getRiskType());
- if(!riskTypeValidate.contains("success")){
+ if(!riskTypeValidate.contains(SUCCESS)){
responseString.append("RiskType:" + riskTypeValidate + "
");
valid = false;
}
@@ -130,7 +133,7 @@ public class PolicyValidation {
if(!Strings.isNullOrEmpty(policyData.getRiskLevel())) {
String validateRiskLevel = PolicyUtils.policySpecialCharValidator(policyData.getRiskLevel());
- if(!validateRiskLevel.contains("success")){
+ if(!validateRiskLevel.contains(SUCCESS)){
responseString.append("RiskLevel:" + validateRiskLevel + "
");
valid = false;
}
@@ -141,7 +144,7 @@ public class PolicyValidation {
if(!Strings.isNullOrEmpty(policyData.getGuard())) {
String validateGuard = PolicyUtils.policySpecialCharValidator(policyData.getGuard());
- if(!validateGuard.contains("success")){
+ if(!validateGuard.contains(SUCCESS)){
responseString.append("Guard:" + validateGuard + "
");
valid = false;
}
@@ -153,7 +156,7 @@ public class PolicyValidation {
if("Base".equalsIgnoreCase(policyData.getConfigPolicyType())){
if(!Strings.isNullOrEmpty(policyData.getConfigName())) {
String configNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getConfigName());
- if(!configNameValidate.contains("success")){
+ if(!configNameValidate.contains(SUCCESS)){
responseString.append("ConfigName:" + configNameValidate + "
");
valid = false;
}
@@ -163,7 +166,7 @@ public class PolicyValidation {
}
if(!Strings.isNullOrEmpty(policyData.getConfigType())) {
String configTypeValidate = PolicyUtils.policySpecialCharValidator(policyData.getConfigType());
- if(!configTypeValidate.contains("success")){
+ if(!configTypeValidate.contains(SUCCESS)){
responseString.append("ConfigType:" + configTypeValidate + "
");
valid = false;
}
@@ -190,11 +193,9 @@ public class PolicyValidation {
responseString.append("Config Body: Property data is not valid" + "
");
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" + "
");
+ valid = false;
}
}
}else{
@@ -203,27 +204,25 @@ public class PolicyValidation {
}
}
- 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,44 +230,45 @@ 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"){
+ if(result != SUCCESS){
responseString.append(result + "
");
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;
};
}
@@ -278,19 +278,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,11 +299,11 @@ 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;
}
}
@@ -311,79 +311,79 @@ public class PolicyValidation {
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"){
+ if(result != SUCCESS){
responseString.append(result+ "
");
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())){
pullJsonKeyPairs((JsonNode) policyData.getPolicyJSON());
- MicroServiceModels returnModel = new MicroServiceModels();
+
String service = null;
String version = null;
if (policyData.getServiceType().contains("-v")){
@@ -395,13 +395,12 @@ public class PolicyValidation {
}
if(!Strings.isNullOrEmpty(version)) {
- returnModel = getAttributeObject(service, version);
+ MicroServiceModels returnModel = getAttributeObject(service, version);
if(returnModel != null) {
String annotation = returnModel.getAnnotation();
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,7 +423,7 @@ 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;
}
@@ -433,20 +432,20 @@ public class PolicyValidation {
}
} 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 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 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,7 +453,7 @@ public class PolicyValidation {
if (DECISION_POLICY.equalsIgnoreCase(policyData.getPolicyType())){
if(!Strings.isNullOrEmpty(policyData.getOnapName())){
String onapNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getOnapName());
- if(!onapNameValidate.contains("success")){
+ if(!onapNameValidate.contains(SUCCESS)){
responseString.append("OnapName:" + onapNameValidate + "
");
valid = false;
}
@@ -570,7 +569,7 @@ public class PolicyValidation {
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" + "
");
valid = false;
break;
@@ -585,7 +584,7 @@ public class PolicyValidation {
if(ACTION_POLICY.equalsIgnoreCase(policyData.getPolicyType())){
if(!Strings.isNullOrEmpty(policyData.getActionPerformer())){
String actionPerformer = PolicyUtils.policySpecialCharValidator(policyData.getActionPerformer());
- if(!actionPerformer.contains("success")){
+ if(!actionPerformer.contains(SUCCESS)){
responseString.append("ActionPerformer:" + actionPerformer + "
");
valid = false;
}
@@ -601,25 +600,25 @@ public class PolicyValidation {
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." + "
");
+ responseString.append(EMPTY_COMPONENT_ATTR + "
");
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." + "
");
+ responseString.append(EMPTY_COMPONENT_ATTR + "
");
valid = false;
break;
}
}
}
}else{
- responseString.append("Component Attributes: One or more Fields in Component Attributes is Empty." + "
");
+ responseString.append(EMPTY_COMPONENT_ATTR + "
");
valid = false;
}
if(!Strings.isNullOrEmpty(policyData.getActionAttributeValue())){
String actionAttribute = PolicyUtils.policySpecialCharValidator(policyData.getActionAttributeValue());
- if(!actionAttribute.contains("success")){
+ if(!actionAttribute.contains(SUCCESS)){
responseString.append("ActionAttribute:" + actionAttribute + "
");
valid = false;
};
@@ -662,11 +661,11 @@ public class PolicyValidation {
value = "Message:" + safePolicyWarningData.getMessage();
}
}
- responseString.append("success" + "@#"+ value);
+ responseString.append(SUCCESS + "@#"+ value);
}
}else{
if(valid){
- responseString.append("success");
+ responseString.append(SUCCESS);
}
}
@@ -681,10 +680,10 @@ public class PolicyValidation {
protected String emailValidation(String email, String response){
if(email != null){
String validateEmail = PolicyUtils.validateEmailAddress(email.replace("\"", ""));
- if(!validateEmail.contains("success")){
- response += "Email:" + validateEmail+ "
";
+ if(!validateEmail.contains(SUCCESS)){
+ response += "Email:" + validateEmail + HTML_ITALICS_LNBREAK;
}else{
- return "success";
+ return SUCCESS;
}
}
return response;