X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fpolicycontroller%2FPolicyCreation.java;h=48f67aa94559b6beeeb6b462c78af56384f79de8;hb=9bf8e18042746f52b96155bb2654dfb472f09e14;hp=76fe4ae5de91736ff4f6da949ea6594d43ce3431;hpb=989ae85e3a25e059cb963a9bc293526be51273ca;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java index 76fe4ae5d..48f67aa94 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java @@ -20,6 +20,7 @@ package org.onap.policy.pap.xacml.rest.policycontroller; import java.io.File; +import java.util.Date; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; @@ -122,33 +123,33 @@ public class PolicyCreation extends AbstractPolicyCreation{ String policyType = policyData.getPolicyType(); String filePrefix = null; - if (policyType.equalsIgnoreCase("Config")) { + if ("Config".equalsIgnoreCase(policyType)) { policyConfigType = policyData.getConfigPolicyType(); - if (policyConfigType.equalsIgnoreCase("Firewall Config")) { + if ("Firewall Config".equalsIgnoreCase(policyConfigType)) { filePrefix = "Config_FW_"; - }else if (policyConfigType.equalsIgnoreCase("ClosedLoop_Fault")) { + }else if ("ClosedLoop_Fault".equalsIgnoreCase(policyConfigType)) { filePrefix = "Config_Fault_"; - }else if (policyConfigType.equalsIgnoreCase("ClosedLoop_PM")) { + }else if ("ClosedLoop_PM".equalsIgnoreCase(policyConfigType)) { filePrefix = "Config_PM_"; - }else if (policyConfigType.equalsIgnoreCase("Micro Service")) { + }else if ("Micro Service".equalsIgnoreCase(policyConfigType)) { filePrefix = "Config_MS_"; - }else if (policyConfigType.equalsIgnoreCase("BRMS_Raw")) { + }else if ("BRMS_Raw".equalsIgnoreCase(policyConfigType)) { filePrefix = "Config_BRMS_Raw_"; - }else if (policyConfigType.equalsIgnoreCase("BRMS_Param")) { + }else if ("BRMS_Param".equalsIgnoreCase(policyConfigType)) { filePrefix = "Config_BRMS_Param_"; }else { filePrefix = "Config_"; } - } else if (policyType.equalsIgnoreCase("Action")) { + } else if ("Action".equalsIgnoreCase(policyType)) { filePrefix = "Action_"; - } else if (policyType.equalsIgnoreCase("Decision")) { + } else if ("Decision".equalsIgnoreCase(policyType)) { filePrefix = "Decision_"; } int version = 0; int highestVersion = 0; - String createdBy = ""; - String modifiedBy = userId; + String createdBy; + String modifiedBy; String scopeCheck = policyData.getDomainDir().replace(".", File.separator); PolicyEditorScopes policyEditorScope = (PolicyEditorScopes) commonClassDao.getEntityItem(PolicyEditorScopes.class, "scopeName", scopeCheck); if(policyEditorScope == null){ @@ -184,13 +185,14 @@ public class PolicyCreation extends AbstractPolicyCreation{ policyVersionDao.setActiveVersion(version); policyVersionDao.setHigherVersion(version); policyVersionDao.setModifiedBy(modifiedBy); + policyVersionDao.setModifiedDate(new Date()); }else{ body = "policyExists"; status = HttpStatus.CONFLICT; response.setStatus(HttpServletResponse.SC_CONFLICT); response.addHeader("error", "policyExists"); response.addHeader("policyName", policyData.getPolicyName()); - return new ResponseEntity(body, status); + return new ResponseEntity<>(body, status); } }else{ // if policy does not exist and the request is updatePolicy return error @@ -229,14 +231,12 @@ public class PolicyCreation extends AbstractPolicyCreation{ policyData.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides"); if(policyData.getApiflag() == null){ //set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON - if(policyData.getAttributes() != null){ - if(policyData.getAttributes().size() > 0){ - for(Object attribute : policyData.getAttributes()){ - if(attribute instanceof LinkedHashMap){ - String key = ((LinkedHashMap) attribute).get("key").toString(); - String value = ((LinkedHashMap) attribute).get("value").toString(); - attributeMap.put(key, value); - } + if(policyData.getAttributes() != null && !policyData.getAttributes().isEmpty()){ + for(Object attribute : policyData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("key").toString(); + String value = ((LinkedHashMap) attribute).get("value").toString(); + attributeMap.put(key, value); } } } @@ -261,7 +261,7 @@ public class PolicyCreation extends AbstractPolicyCreation{ if(policyData.getApiflag() == null){ // If there is any dynamic field create the matches here String key="templateName"; - String value=(String) policyData.getRuleName(); + String value= policyData.getRuleName(); drlRuleAndUIParams.put(key, value); if(policyData.getRuleData().size() > 0){ for(Object keyValue: policyData.getRuleData().keySet()){ @@ -312,7 +312,7 @@ public class PolicyCreation extends AbstractPolicyCreation{ List dynamicRuleAlgorithmField2 = new LinkedList<>(); - if(policyData.getRuleAlgorithmschoices().size() > 0){ + if(!policyData.getRuleAlgorithmschoices().isEmpty()){ for(Object attribute : policyData.getRuleAlgorithmschoices()){ if(attribute instanceof LinkedHashMap){ String label = ((LinkedHashMap) attribute).get("id").toString(); @@ -329,25 +329,38 @@ public class PolicyCreation extends AbstractPolicyCreation{ String actionDictValue = policyData.getActionAttributeValue(); ActionPolicyDict jsonData = ((ActionPolicyDict) commonClassDao.getEntityItem(ActionPolicyDict.class, "attributeName", actionDictValue)); - String actionBodyString = jsonData.getBody(); - String actionDictHeader = jsonData.getHeader(); - String actionDictType = jsonData.getType(); - String actionDictUrl = jsonData.getUrl(); - String actionDictMethod = jsonData.getMethod(); - policyData.setActionDictHeader(actionDictHeader); - policyData.setActionDictType(actionDictType); - policyData.setActionDictUrl(actionDictUrl); - policyData.setActionDictMethod(actionDictMethod); + if(jsonData!=null){ + String actionBodyString = jsonData.getBody(); + String actionDictHeader = jsonData.getHeader(); + String actionDictType = jsonData.getType(); + String actionDictUrl = jsonData.getUrl(); + String actionDictMethod = jsonData.getMethod(); + policyData.setActionDictHeader(actionDictHeader); + policyData.setActionDictType(actionDictType); + policyData.setActionDictUrl(actionDictUrl); + policyData.setActionDictMethod(actionDictMethod); + if (actionBodyString != null) { + policyData.setActionBody(actionBodyString); + } + } policyData.setActionAttribute(actionDictValue); policyData.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels); policyData.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo); policyData.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1); policyData.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2); - if (actionBodyString != null) { - policyData.setActionBody(actionBodyString); + }else{ + // API request. + String comboDictValue = policyData.getActionAttribute(); + ActionPolicyDict jsonData = ((ActionPolicyDict) commonClassDao.getEntityItem(ActionPolicyDict.class, "attributeName", comboDictValue)); + if(jsonData!=null){ + policyData.setActionBody(jsonData.getBody()); + policyData.setActionDictHeader(jsonData.getHeader()); + policyData.setActionDictType(jsonData.getType()); + policyData.setActionDictUrl(jsonData.getUrl()); + policyData.setActionDictMethod(jsonData.getMethod()); } } - newPolicy = new ActionPolicy(policyData); + newPolicy = new ActionPolicy(policyData, commonClassDao); } else if (policyType.equalsIgnoreCase("Decision")) { if(policyData.getApiflag() == null){ Map settingsMap = new HashMap<>(); @@ -361,7 +374,7 @@ public class PolicyCreation extends AbstractPolicyCreation{ List errorCodeList = new LinkedList<>(); List treatmentList = new LinkedList<>(); - if(policyData.getSettings().size() > 0){ + if(!policyData.getSettings().isEmpty()){ for(Object settingsData : policyData.getSettings()){ if(settingsData instanceof LinkedHashMap){ String key = ((LinkedHashMap) settingsData).get("key").toString(); @@ -432,7 +445,7 @@ public class PolicyCreation extends AbstractPolicyCreation{ policyData.setErrorCodeList(errorCodeList); policyData.setTreatmentList(treatmentList); } - newPolicy = new DecisionPolicy(policyData); + newPolicy = new DecisionPolicy(policyData, commonClassDao); } if(newPolicy != null){ @@ -442,7 +455,7 @@ public class PolicyCreation extends AbstractPolicyCreation{ status = HttpStatus.INTERNAL_SERVER_ERROR; response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.addHeader("error", "error"); - return new ResponseEntity(body, status); + return new ResponseEntity<>(body, status); } PolicyDBDaoTransaction policyDBDaoTransaction = null;