From d86da782fa13652ab4fa7227394d4a3d1fe55e18 Mon Sep 17 00:00:00 2001 From: Michael Mokry Date: Tue, 26 Sep 2017 08:49:34 -0500 Subject: Policy API support for Rainy Day Decision Policy Enhances the Rainy Day Decision Policy by providing API support to manage Rainy Day Decision policies and dictionaries Change-Id: Ia7c49199ac057fa8bcc9de74f5e0b8dba395d43a Issue-ID: POLICY-269 Signed-off-by: Michael Mokry --- .../pap/xacml/rest/components/DecisionPolicy.java | 5 +++-- .../DecisionPolicyDictionaryController.java | 6 +++--- .../xacml/rest/handler/DictionaryHandlerImpl.java | 6 ++++++ .../pap/xacml/rest/handler/SavePolicyHandler.java | 2 ++ .../pap/xacml/rest/service/DictionaryService.java | 12 ++++++++++++ .../org/onap/policy/pap/test/XACMLPAPTest.java | 6 +++--- .../DecisionPolicyDictionaryControllerTest.java | 2 +- .../rest/api/services/DecisionPolicyService.java | 9 ++++++--- .../rest/api/services/GetDictionaryService.java | 3 +++ .../onap/policy/xacml/api/pap/OnapPAPPolicy.java | 2 +- .../onap/policy/xacml/std/pap/StdPAPPolicy.java | 22 +++++++++++++++++----- .../java/org/onap/policy/api/PolicyParameters.java | 21 ++++++++++++++++++++- .../java/org/onap/policy/api/RuleProvider.java | 6 +++++- 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 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 dynamicFieldTreatmentAttributes = policyAdapter.getRainydayMap(); + Map 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 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 duplicateData = commonClassDao.checkDuplicateEntry(decisionRainyDay.getBbid()+":"+decisionRainyDay.getWorkstep(), "bbid:workstep", RainyDayTreatments.class); @@ -416,7 +416,7 @@ public class DecisionPolicyDictionaryController { } class TreatmentValues { - private ArrayList userDataTypeValues; + private ArrayList userDataTypeValues = new ArrayList<>(); public ArrayList 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 matchingAttributes = null; Map 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 getDynamicFieldConfigAttributes(); + public Map getTreatments(); public Map getDynamicSettingsMap(); public List getDynamicRuleAlgorithmLabels(); public List 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 dyanamicFieldConfigAttributes = new HashMap<>(); + private Map treatments = new HashMap<>(); private Map dropDownMap = new HashMap<>(); private Map dynamicSettingsMap = new HashMap<>(); private List 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 attributes, Map settings, + //Constructor for Create/Update Decision Policies + public StdPAPPolicy(String policyName, String description, String onapName, String providerComboBox, + Map attributes, Map settings, Map treatments, List dynamicRuleAlgorithmLabels, List dynamicRuleAlgorithmCombo, List dynamicRuleAlgorithmField1, List dynamicRuleAlgorithmField2, Map dropDownMap, List dynamicVariableList, List 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 attributes, String configType, @@ -674,6 +676,11 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ return guard; } + @Override + public Map getTreatments() { + return treatments; + } + @Override public String toString() { return "StdPAPPolicy [policyName=" + policyName + ", policyDescription=" + policyDescription + ", onapName=" @@ -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 brmsDependency) { this.brmsDependency = brmsDependency; } + + public void setTreatments(Map 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> attributes; + private Map 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 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 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; -- cgit 1.2.3-korg