From 82e81ac60d97b93847a26accc071e7043d831ab0 Mon Sep 17 00:00:00 2001 From: Michael Mokry Date: Mon, 11 Dec 2017 10:07:43 -0600 Subject: Adding SONAR fixes for - pushPolicy defect fixes for POLICY-486 - Common Policy Validation feature for POLIYC-449 Change-Id: I8d54aa5a9b819c6eb4427dfa47c4ce963a21c2e0 Issue-ID: POLICY-449,POLICY-486 Signed-off-by: Michael Mokry --- .../policy/rest/adapter/ClosedLoopFaultBody.java | 16 - .../policy/rest/adapter/PolicyRestAdapter.java | 553 ++++++++++----------- .../rest/daoimpl/PolicyValidationDaoImpl.java | 56 ++- .../onap/policy/rest/util/PolicyValidation.java | 171 ++++--- .../rest/util/PolicyValidationRequestWrapper.java | 95 ++-- 5 files changed, 434 insertions(+), 457 deletions(-) (limited to 'ONAP-REST/src/main/java/org') diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ClosedLoopFaultBody.java b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ClosedLoopFaultBody.java index 3d85f9f93..73909d923 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ClosedLoopFaultBody.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ClosedLoopFaultBody.java @@ -221,22 +221,6 @@ public class ClosedLoopFaultBody { this.verificationSignatures = verificationSignatures; } - /*public ArrayList getD2Services() { - return d2Services; - } - - public void setD2Services(ArrayList d2Services) { - this.d2Services = d2Services; - } - - public ArrayList getSiteNames() { - return siteNames; - } - - public void setSiteNames(ArrayList siteNames) { - this.siteNames = siteNames; - }*/ - public boolean isvDNS() { return vDNS; } diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java index 6de0c9b78..de424683d 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java @@ -342,12 +342,6 @@ public class PolicyRestAdapter { public void setReadOnly(boolean readOnly) { this.readOnly = readOnly; } - public String getUserGitPath() { - return gitPath; - } - public void setUserGitPath(String gitPath) { - this.gitPath = gitPath; - } public boolean isValidData() { return isValidData; } @@ -629,281 +623,274 @@ public class PolicyRestAdapter { public void setNewFileName(String newFileName) { this.newFileName = newFileName; } - - public String getDomain() { - return domain; - } - public void setDomain(String domain) { - this.domain = domain; - } - public OnapName getOnapNameField() { - return onapNameField; - } - public void setOnapNameField(OnapName onapNameField) { - this.onapNameField = onapNameField; - } - public Object getJsonBodyData() { - return jsonBodyData; - } - public void setJsonBodyData(Object jsonBodyData) { - this.jsonBodyData = jsonBodyData; - } - public String getDirPath() { - return dirPath; - } - public void setDirPath(String dirPath) { - this.dirPath = dirPath; - } - public String getConfigBodyPath() { - return configBodyPath; - } - public void setConfigBodyPath(String configBodyPath) { - this.configBodyPath = configBodyPath; - } - public ArrayList getAttributes() { - return attributes; - } - public void setAttributes(ArrayList attributes) { - this.attributes = attributes; - } - public ArrayList getSettings() { - return settings; - } - public void setSettings(ArrayList settings) { - this.settings = settings; - } - public ArrayList getRuleAlgorithmschoices() { - return ruleAlgorithmschoices; - } - public void setRuleAlgorithmschoices(ArrayList ruleAlgorithmschoices) { - this.ruleAlgorithmschoices = ruleAlgorithmschoices; - } - public LinkedHashMap getServiceTypePolicyName() { - return serviceTypePolicyName; - } - public void setServiceTypePolicyName(LinkedHashMap serviceTypePolicyName) { - this.serviceTypePolicyName = serviceTypePolicyName; - } - public LinkedHashMap getVerticaMetrics() { - return verticaMetrics; - } - public void setVerticaMetrics(LinkedHashMap verticaMetrics) { - this.verticaMetrics = verticaMetrics; - } - public LinkedHashMap getDescription() { - return description; - } - public void setDescription(LinkedHashMap description) { - this.description = description; - } - public LinkedHashMap getAttributeFields() { - return attributeFields; - } - public void setAttributeFields(LinkedHashMap attributeFields) { - this.attributeFields = attributeFields; - } - public String getClearTimeOut() { - return clearTimeOut; - } - public void setClearTimeOut(String clearTimeOut) { - this.clearTimeOut = clearTimeOut; - } - public String getTrapMaxAge() { - return trapMaxAge; - } - public void setTrapMaxAge(String trapMaxAge) { - this.trapMaxAge = trapMaxAge; - } - public String getVerificationclearTimeOut() { - return verificationclearTimeOut; - } - public void setVerificationclearTimeOut(String verificationclearTimeOut) { - this.verificationclearTimeOut = verificationclearTimeOut; - } - public Map getDynamicLayoutMap() { - return dynamicLayoutMap; - } - public void setDynamicLayoutMap(Map dynamicLayoutMap) { - this.dynamicLayoutMap = dynamicLayoutMap; - } - public String getFwPolicyType() { - return fwPolicyType; - } - public void setFwPolicyType(String fwPolicyType) { - this.fwPolicyType = fwPolicyType; - } - public ArrayList getFwattributes() { - return fwattributes; - } - public void setFwattributes(ArrayList fwattributes) { - this.fwattributes = fwattributes; - } - public String getParentForChild() { - return parentForChild; - } - public void setParentForChild(String parentForChild) { - this.parentForChild = parentForChild; - } - public String getRuleName() { - return ruleName; - } - public void setRuleName(String ruleName) { - this.ruleName = ruleName; - } - public LinkedHashMap getRuleData() { - return ruleData; - } - public void setRuleData(LinkedHashMap ruleData) { - this.ruleData = ruleData; - } - public LinkedHashMap getRuleListData() { - return ruleListData; - } - public void setRuleListData(LinkedHashMap ruleListData) { - this.ruleListData = ruleListData; - } - public String getSecurityZone() { - return securityZone; - } - public void setSecurityZone(String securityZone) { - this.securityZone = securityZone; - } - public String getActionAttributeValue() { - return actionAttributeValue; - } - public void setActionAttributeValue(String actionAttributeValue) { - this.actionAttributeValue = actionAttributeValue; - } - public String getRuleProvider() { - return ruleProvider; - } - public void setRuleProvider(String ruleProvider) { - this.ruleProvider = ruleProvider; - } - public String getMsLocation() { - return msLocation; - } - public void setMsLocation(String msLocation) { - this.msLocation = msLocation; - } - public Map getDrlRuleAndUIParams() { - return drlRuleAndUIParams; - } - public void setDrlRuleAndUIParams(Map drlRuleAndUIParams) { - this.drlRuleAndUIParams = drlRuleAndUIParams; - } - public String getActionBody() { - return actionBody; - } - public void setActionBody(String actionBody) { - this.actionBody = actionBody; - } - public String getActionDictHeader() { - return actionDictHeader; - } - public void setActionDictHeader(String actionDictHeader) { - this.actionDictHeader = actionDictHeader; - } - public String getActionDictType() { - return actionDictType; - } - public void setActionDictType(String actionDictType) { - this.actionDictType = actionDictType; - } - public String getActionDictUrl() { - return actionDictUrl; - } - public void setActionDictUrl(String actionDictUrl) { - this.actionDictUrl = actionDictUrl; - } - public String getActionDictMethod() { - return actionDictMethod; - } - public void setActionDictMethod(String actionDictMethod) { - this.actionDictMethod = actionDictMethod; - } - public String getClWarning() { - return clWarning; - } - public void setClWarning(String clWarning) { - this.clWarning = clWarning; - } - public String getNewCLName() { - return newCLName; - } - public void setNewCLName(String newCLName) { - this.newCLName = newCLName; - } - public String getExistingCLName() { - return existingCLName; - } - public void setExistingCLName(String existingCLName) { - this.existingCLName = existingCLName; - } - public YAMLParams getYamlparams() { - return yamlparams; - } - public void setYamlparams(YAMLParams yamlparams) { - this.yamlparams = yamlparams; - } - /** - * @return the rainyday - */ - public RainyDayParams getRainyday() { - return rainyday; - } - /** - * @param rainyday the rainyday to set - */ - public void setRainyday(RainyDayParams rainyday) { - this.rainyday = rainyday; - } - /** - * @return the errorCodeList - */ - public List getErrorCodeList() { - return errorCodeList; - } - /** - * @param errorCodeList the errorCodeList to set - */ - public void setErrorCodeList(List errorCodeList) { - this.errorCodeList = errorCodeList; - } - /** - * @return the treatmentList - */ - public List getTreatmentList() { - return treatmentList; - } - /** - * @param treatmentList the treatmentList to set - */ - public void setTreatmentList(List treatmentList) { - this.treatmentList = treatmentList; - } - /** - * @return the rainydayMap - */ - public Map getRainydayMap() { - return rainydayMap; - } - /** - * @param rainydayMap the rainydayMap to set - */ - public void setRainydayMap(Map rainydayMap) { - this.rainydayMap = rainydayMap; - } - /** - * @return the policyJSON - */ - public Object getPolicyJSON() { - return policyJSON; - } - /** - * @param policyJSON the policyJSON to set - */ - public void setPolicyJSON(Object policyJSON) { - this.policyJSON = policyJSON; - } + public OnapName getOnapNameField() { + return onapNameField; + } + public void setOnapNameField(OnapName onapNameField) { + this.onapNameField = onapNameField; + } + public Object getJsonBodyData() { + return jsonBodyData; + } + public void setJsonBodyData(Object jsonBodyData) { + this.jsonBodyData = jsonBodyData; + } + public String getDirPath() { + return dirPath; + } + public void setDirPath(String dirPath) { + this.dirPath = dirPath; + } + public String getConfigBodyPath() { + return configBodyPath; + } + public void setConfigBodyPath(String configBodyPath) { + this.configBodyPath = configBodyPath; + } + public ArrayList getAttributes() { + return attributes; + } + public void setAttributes(ArrayList attributes) { + this.attributes = attributes; + } + public ArrayList getSettings() { + return settings; + } + public void setSettings(ArrayList settings) { + this.settings = settings; + } + public ArrayList getRuleAlgorithmschoices() { + return ruleAlgorithmschoices; + } + public void setRuleAlgorithmschoices(ArrayList ruleAlgorithmschoices) { + this.ruleAlgorithmschoices = ruleAlgorithmschoices; + } + public LinkedHashMap getServiceTypePolicyName() { + return serviceTypePolicyName; + } + public void setServiceTypePolicyName(LinkedHashMap serviceTypePolicyName) { + this.serviceTypePolicyName = serviceTypePolicyName; + } + public LinkedHashMap getVerticaMetrics() { + return verticaMetrics; + } + public void setVerticaMetrics(LinkedHashMap verticaMetrics) { + this.verticaMetrics = verticaMetrics; + } + public LinkedHashMap getDescription() { + return description; + } + public void setDescription(LinkedHashMap description) { + this.description = description; + } + public LinkedHashMap getAttributeFields() { + return attributeFields; + } + public void setAttributeFields(LinkedHashMap attributeFields) { + this.attributeFields = attributeFields; + } + public String getClearTimeOut() { + return clearTimeOut; + } + public void setClearTimeOut(String clearTimeOut) { + this.clearTimeOut = clearTimeOut; + } + public String getTrapMaxAge() { + return trapMaxAge; + } + public void setTrapMaxAge(String trapMaxAge) { + this.trapMaxAge = trapMaxAge; + } + public String getVerificationclearTimeOut() { + return verificationclearTimeOut; + } + public void setVerificationclearTimeOut(String verificationclearTimeOut) { + this.verificationclearTimeOut = verificationclearTimeOut; + } + public Map getDynamicLayoutMap() { + return dynamicLayoutMap; + } + public void setDynamicLayoutMap(Map dynamicLayoutMap) { + this.dynamicLayoutMap = dynamicLayoutMap; + } + public String getFwPolicyType() { + return fwPolicyType; + } + public void setFwPolicyType(String fwPolicyType) { + this.fwPolicyType = fwPolicyType; + } + public ArrayList getFwattributes() { + return fwattributes; + } + public void setFwattributes(ArrayList fwattributes) { + this.fwattributes = fwattributes; + } + public String getParentForChild() { + return parentForChild; + } + public void setParentForChild(String parentForChild) { + this.parentForChild = parentForChild; + } + public String getRuleName() { + return ruleName; + } + public void setRuleName(String ruleName) { + this.ruleName = ruleName; + } + public LinkedHashMap getRuleData() { + return ruleData; + } + public void setRuleData(LinkedHashMap ruleData) { + this.ruleData = ruleData; + } + public LinkedHashMap getRuleListData() { + return ruleListData; + } + public void setRuleListData(LinkedHashMap ruleListData) { + this.ruleListData = ruleListData; + } + public String getSecurityZone() { + return securityZone; + } + public void setSecurityZone(String securityZone) { + this.securityZone = securityZone; + } + public String getActionAttributeValue() { + return actionAttributeValue; + } + public void setActionAttributeValue(String actionAttributeValue) { + this.actionAttributeValue = actionAttributeValue; + } + public String getRuleProvider() { + return ruleProvider; + } + public void setRuleProvider(String ruleProvider) { + this.ruleProvider = ruleProvider; + } + public String getMsLocation() { + return msLocation; + } + public void setMsLocation(String msLocation) { + this.msLocation = msLocation; + } + public Map getDrlRuleAndUIParams() { + return drlRuleAndUIParams; + } + public void setDrlRuleAndUIParams(Map drlRuleAndUIParams) { + this.drlRuleAndUIParams = drlRuleAndUIParams; + } + public String getActionBody() { + return actionBody; + } + public void setActionBody(String actionBody) { + this.actionBody = actionBody; + } + public String getActionDictHeader() { + return actionDictHeader; + } + public void setActionDictHeader(String actionDictHeader) { + this.actionDictHeader = actionDictHeader; + } + public String getActionDictType() { + return actionDictType; + } + public void setActionDictType(String actionDictType) { + this.actionDictType = actionDictType; + } + public String getActionDictUrl() { + return actionDictUrl; + } + public void setActionDictUrl(String actionDictUrl) { + this.actionDictUrl = actionDictUrl; + } + public String getActionDictMethod() { + return actionDictMethod; + } + public void setActionDictMethod(String actionDictMethod) { + this.actionDictMethod = actionDictMethod; + } + public String getClWarning() { + return clWarning; + } + public void setClWarning(String clWarning) { + this.clWarning = clWarning; + } + public String getNewCLName() { + return newCLName; + } + public void setNewCLName(String newCLName) { + this.newCLName = newCLName; + } + public String getExistingCLName() { + return existingCLName; + } + public void setExistingCLName(String existingCLName) { + this.existingCLName = existingCLName; + } + public YAMLParams getYamlparams() { + return yamlparams; + } + public void setYamlparams(YAMLParams yamlparams) { + this.yamlparams = yamlparams; + } + /** + * @return the rainyday + */ + public RainyDayParams getRainyday() { + return rainyday; + } + /** + * @param rainyday the rainyday to set + */ + public void setRainyday(RainyDayParams rainyday) { + this.rainyday = rainyday; + } + /** + * @return the errorCodeList + */ + public List getErrorCodeList() { + return errorCodeList; + } + /** + * @param errorCodeList the errorCodeList to set + */ + public void setErrorCodeList(List errorCodeList) { + this.errorCodeList = errorCodeList; + } + /** + * @return the treatmentList + */ + public List getTreatmentList() { + return treatmentList; + } + /** + * @param treatmentList the treatmentList to set + */ + public void setTreatmentList(List treatmentList) { + this.treatmentList = treatmentList; + } + /** + * @return the rainydayMap + */ + public Map getRainydayMap() { + return rainydayMap; + } + /** + * @param rainydayMap the rainydayMap to set + */ + public void setRainydayMap(Map rainydayMap) { + this.rainydayMap = rainydayMap; + } + /** + * @return the policyJSON + */ + public Object getPolicyJSON() { + return policyJSON; + } + /** + * @param policyJSON the policyJSON to set + */ + public void setPolicyJSON(Object policyJSON) { + this.policyJSON = policyJSON; + } } diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImpl.java b/ONAP-REST/src/main/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImpl.java index f6682eb40..8aa04356f 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImpl.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImpl.java @@ -20,6 +20,7 @@ package org.onap.policy.rest.daoimpl; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -42,12 +43,13 @@ import org.onap.policy.rest.jpa.PolicyRoles; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; @Component public class PolicyValidationDaoImpl implements CommonClassDao{ private static final Logger LOGGER = FlexLogger.getLogger(PolicyValidationDaoImpl.class); + private static final String DB_CONNECTION_CLOSING_ERROR = "Error While Closing Connection/Statement"; + private static final String DBTABLE_QUERY_ERROR = "Error While Querying Table"; private static SessionFactory sessionfactory; public static SessionFactory getSessionfactory() { @@ -76,12 +78,12 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ Criteria cr = session.createCriteria(className); data = cr.list(); }catch(Exception e){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Table"+e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DBTABLE_QUERY_ERROR + e); }finally{ try{ session.close(); }catch(Exception e){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR+e); } } return data; @@ -106,12 +108,12 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ } data = cr.list(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Table"+e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DBTABLE_QUERY_ERROR + e); }finally{ try{ session.close(); }catch(Exception e1){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } return data; @@ -125,12 +127,12 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ session.persist(entity); tx.commit(); }catch(Exception e){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving data to Table"+e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving data to Table"+e); }finally{ try{ session.close(); }catch(Exception e1){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } @@ -149,7 +151,7 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ try{ session.close(); }catch(Exception e1){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } @@ -169,7 +171,7 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ try{ session.close(); }catch(Exception e1){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } @@ -207,7 +209,7 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ try{ session.close(); }catch(Exception e1){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } return data; @@ -240,7 +242,7 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ try{ session.close(); }catch(Exception e1){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } return rolesData; @@ -249,12 +251,14 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ @Override public List checkExistingGroupListforUpdate(String arg0, String arg1) { - return null; + return Collections.emptyList(); } @Override - public void deleteAll() {} + public void deleteAll() { + // Do nothing because this method is not used and is a placeholder to avoid 'Unimplemented Method' error + } @SuppressWarnings("unchecked") @@ -276,13 +280,13 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ data = hbquery.list(); tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Database Table"+e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DBTABLE_QUERY_ERROR + e); throw e; }finally{ try{ session.close(); }catch(HibernateException e1){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } return data; @@ -309,12 +313,12 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ data = cr.list().get(0); tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Database Table"+e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DBTABLE_QUERY_ERROR + e); }finally{ try{ session.close(); }catch(Exception e1){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } return data; @@ -322,11 +326,15 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ @Override - public void updateClAlarms(String arg0, String arg1) {} + public void updateClAlarms(String arg0, String arg1) { + // Do nothing because this method is not used and is a placeholder to avoid 'Unimplemented Method' error + } @Override - public void updateClYaml(String arg0, String arg1) {} + public void updateClYaml(String arg0, String arg1) { + // Do nothing because this method is not used and is a placeholder to avoid 'Unimplemented Method' error + } @Override @@ -343,7 +351,7 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ try{ session.close(); }catch(Exception e1){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } @@ -360,12 +368,12 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ cr.setProjection(Projections.property(columnName)); data = cr.list(); }catch(Exception e){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Table"+e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DBTABLE_QUERY_ERROR + e); }finally{ try{ session.close(); }catch(Exception e){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e); } } return data; @@ -396,12 +404,12 @@ public class PolicyValidationDaoImpl implements CommonClassDao{ entityData = cr.add(disjunction).list(); tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Table" +className +e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DBTABLE_QUERY_ERROR + className + e); }finally{ try{ session.close(); }catch(Exception e1){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1); } } return entityData; 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; diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java index 072462297..03c1fb0c7 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java @@ -63,16 +63,14 @@ public class PolicyValidationRequestWrapper { policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); JsonObject json = null; - if(root != null){ - json = stringToJsonObject(root.toString()); - - if(json != null){ - if(json.containsKey("policyJSON")){ - policyData.setPolicyJSON(root.get("policyJSON")); - }else{ - String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); - policyData.setJsonBody(jsonBodyData); - } + json = stringToJsonObject(root.toString()); + + if(json != null){ + if(json.containsKey("policyJSON")){ + policyData.setPolicyJSON(root.get("policyJSON")); + }else{ + String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString(); + policyData.setJsonBody(jsonBodyData); } } @@ -127,13 +125,13 @@ public class PolicyValidationRequestWrapper { // Set Matching attributes in RainyDayParams in adapter RainyDayParams rainyday = new RainyDayParams(); - rainyday.setServiceType(matching.get("ServiceType")); - rainyday.setVnfType(matching.get("VNFType")); - rainyday.setBbid(matching.get("BB_ID")); - rainyday.setWorkstep(matching.get("WorkStep")); - - - + if(matching != null) { + rainyday.setServiceType(matching.get("ServiceType")); + rainyday.setVnfType(matching.get("VNFType")); + rainyday.setBbid(matching.get("BB_ID")); + rainyday.setWorkstep(matching.get("WorkStep")); + } + Map treatments = parameters.getTreatments(); ArrayList treatmentsTableChoices = new ArrayList<>(); @@ -153,32 +151,32 @@ public class PolicyValidationRequestWrapper { // Set Matching attributes in YAMLParams in adapter YAMLParams yamlparams = new YAMLParams(); - yamlparams.setActor(matching.get("actor")); - yamlparams.setRecipe(matching.get("recipe")); - yamlparams.setGuardActiveStart(matching.get("guardActiveStart")); - yamlparams.setGuardActiveEnd(matching.get("guardActiveEnd")); - - if("GUARD_YAML".equals(ruleProvider)){ - yamlparams.setLimit(matching.get("limit")); - yamlparams.setTimeWindow(matching.get("timeWindow")); - yamlparams.setTimeUnits(matching.get("timeUnits")); - }else{ + if (matching != null) { + yamlparams.setActor(matching.get("actor")); + yamlparams.setRecipe(matching.get("recipe")); + yamlparams.setGuardActiveStart(matching.get("guardActiveStart")); + yamlparams.setGuardActiveEnd(matching.get("guardActiveEnd")); - List blackList = new ArrayList<>(); + if("GUARD_YAML".equals(ruleProvider)){ + yamlparams.setLimit(matching.get("limit")); + yamlparams.setTimeWindow(matching.get("timeWindow")); + yamlparams.setTimeUnits(matching.get("timeUnits")); + }else{ + + List blackList = new ArrayList<>(); - if(!Strings.isNullOrEmpty(matching.get("blackList"))){ - String[] blackListArray = matching.get("blackList").split(","); - for(String element : blackListArray){ - blackList.add(element); - } - } - - yamlparams.setBlackList(blackList); + if(!Strings.isNullOrEmpty(matching.get("blackList"))){ + String[] blackListArray = matching.get("blackList").split(","); + for(String element : blackListArray){ + blackList.add(element); + } + } + + yamlparams.setBlackList(blackList); - } - + } + } policyData.setYamlparams(yamlparams); -; } } else if("Action".equals(parameters.getPolicyClass().toString())){ @@ -216,15 +214,16 @@ public class PolicyValidationRequestWrapper { policyData.setRuleAlgorithmschoices(ruleAlgorithmChoices); ArrayList attributeList = new ArrayList<>(); - - for (String keyField : matching.keySet()) { - LinkedHashMap attributeMap = new LinkedHashMap<>(); - String key = keyField; - String value = matching.get(keyField); - attributeMap.put("key", key); - attributeMap.put("value", value); - attributeList.add(attributeMap); - } + if (matching != null) { + for (String keyField : matching.keySet()) { + LinkedHashMap attributeMap = new LinkedHashMap<>(); + String key = keyField; + String value = matching.get(keyField); + attributeMap.put("key", key); + attributeMap.put("value", value); + attributeList.add(attributeMap); + } + } policyData.setAttributes(attributeList); policyData.setActionAttributeValue(parameters.getActionAttribute()); -- cgit 1.2.3-korg