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 <mm117s@att.com>
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 d870ca8..22d2da3 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 @@
 			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 @@
 				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 aac777a..ab077b9 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 @@
 
 	
 	@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 @@
 						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 @@
 }
 
 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 13eee4a..ae749ad 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 @@
 			case "Settings":
 				dictionary.getSettingsDictionary(response);
 				break;
+			case "RainyDayTreatments":
+				dictionary.getRainyDayDictionary(response);
+				break;
 			case "DescriptiveScope":
 				dictionary.getDescriptiveDictionary(response);
 				break;
@@ -212,6 +215,9 @@
 			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 c86ded4..e7680c3 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 @@
 		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 5b2fc4c..6e19b9b 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 @@
 		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 @@
 			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 0463585..ba5539f 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 @@
         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 @@
         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 @@
         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 5290471..a2c67ea 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 @@
 
 		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 c283ff1..915e3b3 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 @@
 		}
 		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 @@
 		}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 8f88ef7..d3628f3 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 @@
         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 78ce354..4539b42 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 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 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 56676f3..034c08b 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 @@
 	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 @@
 
 	}
 
-	//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 @@
 		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 @@
 	}
 
 	@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 @@
 				+ ",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 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 2062638..ae9ba8a 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 @@
 	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 @@
 		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 @@
 				+ ",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 94ad678..2e45549 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 @@
 	/**
 	 * 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;