diff options
author | Jorge Hernandez <jh1730@att.com> | 2017-09-28 03:40:01 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-09-28 03:40:01 +0000 |
commit | b6dee4c18a7384e765a36a8dbbaef301da232847 (patch) | |
tree | 75f3981be56fe1d4420cde6e564b71916cbc01b3 | |
parent | b5caf28492a151d811dd3ce7e6ade26e56deade9 (diff) | |
parent | d86da782fa13652ab4fa7227394d4a3d1fe55e18 (diff) |
Merge "Policy API support for Rainy Day Decision Policy"
13 files changed, 82 insertions, 20 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java index d870ca86c..22d2da311 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java @@ -230,7 +230,8 @@ public class DecisionPolicy extends Policy { decisionPolicy.setTarget(target); Map<String, String> dynamicFieldDecisionSettings = policyAdapter.getDynamicSettingsMap(); - if(policyAdapter.getRuleProvider()!=null && policyAdapter.getRuleProvider().equals(AAFPROVIDER)){ + if(policyAdapter.getRuleProvider()!=null && (policyAdapter.getRuleProvider().equals(AAFPROVIDER)|| + policyAdapter.getRuleProvider().equals(RAINY_DAY))){ dynamicFieldDecisionSettings = new HashMap<>(); } @@ -242,8 +243,8 @@ public class DecisionPolicy extends Policy { VariableDefinitionType dynamicVariable = createDynamicVariable(key, value, dataType); decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(dynamicVariable); } - Map<String, String> dynamicFieldTreatmentAttributes = policyAdapter.getRainydayMap(); + Map<String, String> dynamicFieldTreatmentAttributes = policyAdapter.getRainydayMap(); if(policyAdapter.getRuleProvider().equals(RAINY_DAY)){ for(String keyField : dynamicFieldTreatmentAttributes.keySet()) { String errorcode = keyField; diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java index aac777a67..ab077b9ca 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java @@ -264,7 +264,7 @@ public class DecisionPolicyDictionaryController { @RequestMapping(value={"/get_RainyDayDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getRainyDayDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getRainyDayDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -329,8 +329,8 @@ public class DecisionPolicyDictionaryController { counter ++; } } + decisionRainyDay.setTreatments(userValue); } - decisionRainyDay.setTreatments(userValue); if(decisionRainyDay.getId() == 0){ List<Object> duplicateData = commonClassDao.checkDuplicateEntry(decisionRainyDay.getBbid()+":"+decisionRainyDay.getWorkstep(), "bbid:workstep", RainyDayTreatments.class); @@ -416,7 +416,7 @@ public class DecisionPolicyDictionaryController { } class TreatmentValues { - private ArrayList<Object> userDataTypeValues; + private ArrayList<Object> userDataTypeValues = new ArrayList<>(); public ArrayList<Object> getUserDataTypeValues() { return userDataTypeValues; diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java index 13eee4a3f..ae749adb5 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java @@ -69,6 +69,9 @@ public class DictionaryHandlerImpl implements DictionaryHandler{ case "Settings": dictionary.getSettingsDictionary(response); break; + case "RainyDayTreatments": + dictionary.getRainyDayDictionary(response); + break; case "DescriptiveScope": dictionary.getDescriptiveDictionary(response); break; @@ -212,6 +215,9 @@ public class DictionaryHandlerImpl implements DictionaryHandler{ case "Settings": result = dictionary.saveSettingsDictionary(request, response); break; + case "RainyDayTreatments": + result = dictionary.saveRainyDayDictionary(request, response); + break; case "DescriptiveScope": result = dictionary.saveDescriptiveDictionary(request, response); break; diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java index c86ded43f..e7680c3e2 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java @@ -131,6 +131,8 @@ public class SavePolicyHandler { policyAdapter.setRuleProvider(policy.getProviderComboBox()); policyAdapter.setDomainDir(policyAdapter.getPolicyScope()); policyAdapter.setDomain(policyAdapter.getPolicyScope()); + policyAdapter.setRainydayMap(policy.getTreatments()); + return policyAdapter; } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java index 5b2fc4cd7..6e19b9b1c 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java @@ -121,6 +121,13 @@ public class DictionaryService { return result.getViewName(); } + public String saveRainyDayDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + + DecisionPolicyDictionaryController dictionary = new DecisionPolicyDictionaryController(); + ModelAndView result = dictionary.saveRainyDayDictionary(request, response); + return result.getViewName(); + } + public String saveDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ DescriptiveDictionaryController dictionary = new DescriptiveDictionaryController(); @@ -343,6 +350,11 @@ public class DictionaryService { dictionary.getSettingsDictionaryEntityData(response); } + public void getRainyDayDictionary(HttpServletResponse response){ + DecisionPolicyDictionaryController dictionary = new DecisionPolicyDictionaryController(); + dictionary.getRainyDayDictionaryEntityData(response); + } + public void getDescriptiveDictionary(HttpServletResponse response){ DescriptiveDictionaryController dictionary = new DescriptiveDictionaryController(); dictionary.getDescriptiveDictionaryEntityData(response); diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java index 0463585cb..ba5539f4b 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java @@ -206,7 +206,7 @@ public class XACMLPAPTest { Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create"); Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision"); StdPAPPolicy newPAPPolicy = new StdPAPPolicy("test", "test rule", "ONAP", "AAF", null, null, null, - null, null, null, null, null, null, false, "test", 0); + null, null, null, null, null, null, null, false, "test", 0); MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes()); Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); @@ -238,7 +238,7 @@ public class XACMLPAPTest { matchingAttributes.put("guardActiveStart","05:00"); matchingAttributes.put("guardActiveEnd","10:00"); StdPAPPolicy newPAPPolicy = new StdPAPPolicy("testGuard", "test rule", "PDPD", "GUARD_YAML", matchingAttributes , null, null, - null, null, null, null, null, null, false, "test", 0); + null, null, null, null, null, null, null, false, "test", 0); MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes()); Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); @@ -267,7 +267,7 @@ public class XACMLPAPTest { matchingAttributes.put("guardActiveEnd","10:00"); matchingAttributes.put("blackList","bl1,bl2"); StdPAPPolicy newPAPPolicy = new StdPAPPolicy("testblGuard", "test rule", "PDPD", "GUARD_BL_YAML", matchingAttributes , null, null, - null, null, null, null, null, null, false, "test", 0); + null, null, null, null, null, null, null, false, "test", 0); MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes()); Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java index 529047181..a2c67ea81 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java @@ -198,7 +198,7 @@ public class DecisionPolicyDictionaryControllerTest { MockHttpServletResponse response = new MockHttpServletResponse(); - controller.getRainyDayDictionaryEntityData(request, response); + controller.getRainyDayDictionaryEntityData(response); try { assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas")); diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyService.java index c283ff14c..915e3b30f 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyService.java @@ -80,6 +80,8 @@ public class DecisionPolicyService{ } Map<String,String> matchingAttributes = null; Map<String,String> settingsAttributes = null; + + //Get the MATCHING and/or SETTINGS attributes if (policyParameters.getAttributes()!=null && policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)) { matchingAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING); settingsAttributes = policyParameters.getAttributes().get(AttributeType.SETTINGS); @@ -88,9 +90,10 @@ public class DecisionPolicyService{ }else if(policyParameters.getAttributes()!=null && policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && !policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)){ matchingAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING); } - // Create Policy. - StdPAPPolicy newPAPPolicy = new StdPAPPolicy(policyName, policyParameters.getPolicyDescription(), onapName, ruleProvider.toString(), matchingAttributes, settingsAttributes, policyParameters.getDynamicRuleAlgorithmLabels(), - policyParameters.getDynamicRuleAlgorithmFunctions(), policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmField2(), null, null, null, updateFlag, policyScope, 0); + // Create StdPAPPolicy object used to send policy data to PAP-REST. + StdPAPPolicy newPAPPolicy = new StdPAPPolicy(policyName, policyParameters.getPolicyDescription(), onapName, ruleProvider.toString(), matchingAttributes, settingsAttributes, + policyParameters.getTreatments(), policyParameters.getDynamicRuleAlgorithmLabels(), policyParameters.getDynamicRuleAlgorithmFunctions(), + policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmField2(), null, null, null, updateFlag, policyScope, 0); // Send JSON to PAP. response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Decision"}, policyParameters.getRequestID(), "Decision"); LOGGER.info(message); diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java index 8f88ef7c7..d3628f3c1 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java @@ -171,6 +171,9 @@ public class GetDictionaryService { case "Settings": jsonString = jsonString.replace("settingsDictionaryDatas", "DictionaryDatas"); break; + case "RainyDayTreatments": + jsonString = jsonString.replace("rainyDayDictionaryDatas", "DictionaryDatas"); + break; case "DescriptiveScope": jsonString = jsonString.replace("descriptiveScopeDictionaryDatas", "DictionaryDatas"); break; diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/api/pap/OnapPAPPolicy.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/api/pap/OnapPAPPolicy.java index 78ce354e0..4539b4225 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/api/pap/OnapPAPPolicy.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/api/pap/OnapPAPPolicy.java @@ -46,6 +46,7 @@ public interface OnapPAPPolicy { public String getOnapName(); public String getConfigName(); public Map<String, String> getDynamicFieldConfigAttributes(); + public Map<String, String> getTreatments(); public Map<String, String> getDynamicSettingsMap(); public List<String> getDynamicRuleAlgorithmLabels(); public List<String> getDynamicRuleAlgorithmCombo(); @@ -81,7 +82,6 @@ public interface OnapPAPPolicy { public String getDictionaryType(); public String getDictionary(); public String getDictionaryFields(); - public String getRiskLevel(); public String getGuard(); public String getRiskType(); diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java index 56676f38b..034c08bfa 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java @@ -36,6 +36,7 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ private String onapName = null; private String configName = null; private Map<String, String> dyanamicFieldConfigAttributes = new HashMap<>(); + private Map<String, String> treatments = new HashMap<>(); private Map<String, String> dropDownMap = new HashMap<>(); private Map<String, String> dynamicSettingsMap = new HashMap<>(); private List<String> dynamicRuleAlgorithmLabels; @@ -125,8 +126,9 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ } - //Constructor for Create/Update Decision Policies from Admin Console - public StdPAPPolicy(String policyName, String description, String onapName, String providerComboBox, Map<String, String> attributes, Map<String, String> settings, + //Constructor for Create/Update Decision Policies + public StdPAPPolicy(String policyName, String description, String onapName, String providerComboBox, + Map<String, String> attributes, Map<String, String> settings, Map<String, String> treatments, List<String> dynamicRuleAlgorithmLabels, List<String> dynamicRuleAlgorithmCombo, List<String> dynamicRuleAlgorithmField1, List<String> dynamicRuleAlgorithmField2, Map<String, String> dropDownMap, List<Object> dynamicVariableList, List<String> dataTypeList, Boolean editPolicy, String domain, int highestVersion) { @@ -147,10 +149,10 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ this.editPolicy = editPolicy; this.domain = domain; this.highestVersion = highestVersion; + this.treatments = treatments; } - //Constructor for Create Config Policies from API and Admin Console //Constructor for Updating Config Policies from the API public StdPAPPolicy(String configPolicyType, String policyName, String description, String onapName, String configName, Map<String, String> attributes, String configType, @@ -675,6 +677,11 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ } @Override + public Map<String, String> getTreatments() { + return treatments; + } + + @Override public String toString() { return "StdPAPPolicy [policyName=" + policyName + ", policyDescription=" + policyDescription + ", onapName=" + onapName + ", configName=" + configName + ", dyanamicFieldConfigAttributes=" + dyanamicFieldConfigAttributes + ", configBodyData=" + configBodyData @@ -688,9 +695,10 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ + ",dataTypeList=" + dataTypeList + ",draft=" + ",oldPolicyFileName=" + oldPolicyFileName + ",serviceType=" + serviceType + ",uuid=" + uuid + ",msLocation=" + msLocation + ",priority=" + priority + ",deleteCondition=" + deleteCondition + ",dictionaryType=" + dictionaryType + ",dictionary=" + dictionary + ",dictionaryFields=" + dictionaryFields + ",uuid=" + uuid + ",msLocation=" + msLocation + ",priority=" - + priority + ",deleteCondition=" + deleteCondition + ",riskType="+riskType + ",riskLevel="+riskLevel + ",guard="+ guard + ",ttlDate="+ ttlDate + "]"; + + priority + ",deleteCondition=" + deleteCondition + ",riskType="+riskType + ",riskLevel="+riskLevel + ",guard="+ guard + ",ttlDate="+ ttlDate + + ",treatments=" + treatments + "]"; } - + // Methods needed for JSON Deserialization public void setPolicyName(String policyName) { this.policyName = policyName; @@ -907,4 +915,8 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ public void setBrmsDependency(ArrayList<String> brmsDependency) { this.brmsDependency = brmsDependency; } + + public void setTreatments(Map<String, String> treatments) { + this.treatments = treatments; + } }
\ No newline at end of file diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyParameters.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyParameters.java index 2062638cf..ae9ba8a88 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyParameters.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyParameters.java @@ -40,6 +40,7 @@ public class PolicyParameters { private String onapName; private String configName; private Map<AttributeType, Map<String,String>> attributes; + private Map<String, String> treatments; private String configBody; private PolicyType configBodyType; private String actionPerformer; @@ -568,6 +569,24 @@ public class PolicyParameters { this.extendedOption = extendedOption; } + /** + * Gets Allowed Treatments Map for Rainy Day Decision Policy + * + * @return Map of String format for treatments per errorcode + */ + public Map<String, String> getTreatments() { + return treatments; + } + + /** + * Sets Allowed Treatments Map for Rainy Day Decision Policy + * + * @param treatments Map that contains the treatment per errorcode + */ + public void setTreatments(Map<String, String> treatments) { + this.treatments = treatments; + } + @Override public String toString() { return "PolicyParameters [ policyName=" + policyName + ", policyDescription=" + policyDescription + ", onapName="+ onapName @@ -576,6 +595,6 @@ public class PolicyParameters { + ",dynamicRuleAlgorithmField1=" + dynamicRuleAlgorithmField1 + ",dynamicRuleAlgorithmField2=" + dynamicRuleAlgorithmField2 + ", actionPerformer=" + actionPerformer + ", actionAttribute=" + actionAttribute + ", priority=" + priority + ", ruleProvider= " + ruleProvider + ", riskLevel= " + riskLevel + ", riskType= " + riskType + ", extendedOption= " + extendedOption - + "]"; + + ", treatments= " + treatments + "]"; } } diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/RuleProvider.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/RuleProvider.java index 94ad67861..2e45549fc 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/RuleProvider.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/RuleProvider.java @@ -44,7 +44,11 @@ public enum RuleProvider { /** * Indicates Guard BLACKLIST YAML */ - GUARD_BL_YAML("GUARD_BL_YAML") + GUARD_BL_YAML("GUARD_BL_YAML"), + /** + * Indicates Guard BLACKLIST YAML + */ + RAINY_DAY("Rainy_Day") ; private String name; |