X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ECOMP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fpolicycontroller%2FPolicyCreation.java;h=3437dab039be08d59812a4d7af110a2752dc27c5;hb=fc5c07705edc4dcb7083b39116a43844bb6a1490;hp=46d02d94e9998889d064dc8999e410373bfb7828;hpb=7e547eaa55920dfbc9691eab33bb728395b50cf2;p=policy%2Fengine.git diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/policycontroller/PolicyCreation.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/policycontroller/PolicyCreation.java index 46d02d94e..3437dab03 100644 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/policycontroller/PolicyCreation.java +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/policycontroller/PolicyCreation.java @@ -29,6 +29,7 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang.StringUtils; import org.openecomp.policy.common.logging.eelf.PolicyLogger; import org.openecomp.policy.common.logging.flexlogger.FlexLogger; import org.openecomp.policy.common.logging.flexlogger.Logger; @@ -93,8 +94,8 @@ public class PolicyCreation extends AbstractPolicyCreation{ public ResponseEntity savePolicy(@RequestBody PolicyRestAdapter policyData, HttpServletResponse response) throws Exception{ String body = null; HttpStatus status = HttpStatus.BAD_REQUEST; - Map successMap = new HashMap(); - Map attributeMap = new HashMap(); + Map successMap = new HashMap<>(); + Map attributeMap = new HashMap<>(); PolicyVersion policyVersionDao; try { @@ -161,8 +162,8 @@ public class PolicyCreation extends AbstractPolicyCreation{ highestVersion = policyVersion.getHigherVersion(); } - if(highestVersion != 0){ - if(policyData.isEditPolicy){ + if(highestVersion != 0 && policyVersion != null){ + if(policyData.isEditPolicy()){ version = highestVersion +1; if(userId ==null){ modifiedBy = "API"; @@ -239,7 +240,7 @@ public class PolicyCreation extends AbstractPolicyCreation{ }else if (policyConfigType.equalsIgnoreCase("BRMS_Param")) { policyData.setEcompName("DROOLS"); policyData.setConfigName("BRMS_PARAM_RULE"); - Map drlRuleAndUIParams = new HashMap(); + Map drlRuleAndUIParams = new HashMap<>(); if(policyData.getApiflag() == null){ // If there is any dynamic field create the matches here String key="templateName"; @@ -288,10 +289,10 @@ public class PolicyCreation extends AbstractPolicyCreation{ } }else if(policyType.equalsIgnoreCase("Action")) { if(policyData.getApiflag() == null){ - List dynamicRuleAlgorithmLabels = new LinkedList(); - List dynamicRuleAlgorithmCombo = new LinkedList(); - List dynamicRuleAlgorithmField1 = new LinkedList(); - List dynamicRuleAlgorithmField2 = new LinkedList(); + List dynamicRuleAlgorithmLabels = new LinkedList<>(); + List dynamicRuleAlgorithmCombo = new LinkedList<>(); + List dynamicRuleAlgorithmField1 = new LinkedList<>(); + List dynamicRuleAlgorithmField2 = new LinkedList<>(); if(policyData.getRuleAlgorithmschoices().size() > 0){ @@ -332,13 +333,13 @@ public class PolicyCreation extends AbstractPolicyCreation{ newPolicy = new ActionPolicy(policyData); } else if (policyType.equalsIgnoreCase("Decision")) { if(policyData.getApiflag() == null){ - Map settingsMap = new HashMap(); - List dynamicRuleAlgorithmLabels = new LinkedList(); - List dynamicRuleAlgorithmCombo = new LinkedList(); - List dynamicRuleAlgorithmField1 = new LinkedList(); - List dynamicRuleAlgorithmField2 = new LinkedList(); - List dynamicVariableList = new LinkedList(); - List dataTypeList = new LinkedList(); + Map settingsMap = new HashMap<>(); + List dynamicRuleAlgorithmLabels = new LinkedList<>(); + List dynamicRuleAlgorithmCombo = new LinkedList<>(); + List dynamicRuleAlgorithmField1 = new LinkedList<>(); + List dynamicRuleAlgorithmField2 = new LinkedList<>(); + List dynamicVariableList = new LinkedList<>(); + List dataTypeList = new LinkedList<>(); if(policyData.getSettings().size() > 0){ for(Object settingsData : policyData.getSettings()){ @@ -363,13 +364,17 @@ public class PolicyCreation extends AbstractPolicyCreation{ } } } - if(policyData.getRuleProvider()!=null && policyData.getRuleProvider().equals(DecisionPolicy.GUARD_YAML) && policyData.getYamlparams()!=null){ - attributeMap.put("actor", policyData.getYamlparams().getActor()); + if(policyData.getRuleProvider()!=null && (policyData.getRuleProvider().equals(DecisionPolicy.GUARD_YAML)|| policyData.getRuleProvider().equals(DecisionPolicy.GUARD_BL_YAML)) + && policyData.getYamlparams()!=null){ attributeMap.put("actor", policyData.getYamlparams().getActor()); attributeMap.put("recipe", policyData.getYamlparams().getRecipe()); attributeMap.put("limit", policyData.getYamlparams().getLimit()); attributeMap.put("timeWindow", policyData.getYamlparams().getTimeWindow()); attributeMap.put("guardActiveStart", policyData.getYamlparams().getGuardActiveStart()); attributeMap.put("guardActiveEnd", policyData.getYamlparams().getGuardActiveEnd()); + if(policyData.getYamlparams().getBlackList()!=null){ + String blackList = StringUtils.join(policyData.getYamlparams().getBlackList(), ","); + attributeMap.put("blackList", blackList); + } } policyData.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels); policyData.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo); @@ -383,7 +388,15 @@ public class PolicyCreation extends AbstractPolicyCreation{ newPolicy = new DecisionPolicy(policyData); } - newPolicy.prepareToSave(); + if(newPolicy != null){ + newPolicy.prepareToSave(); + }else{ + body = "error"; + status = HttpStatus.INTERNAL_SERVER_ERROR; + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + response.addHeader("error", "error"); + return new ResponseEntity(body, status); + } PolicyDBDaoTransaction policyDBDaoTransaction = null; try{ @@ -393,7 +406,7 @@ public class PolicyCreation extends AbstractPolicyCreation{ successMap = newPolicy.savePolicies(); if(successMap.containsKey("success")){ policyDBDaoTransaction.commitTransaction(); - if(policyData.isEditPolicy){ + if(policyData.isEditPolicy()){ commonClassDao.update(policyVersionDao); }else{ commonClassDao.save(policyVersionDao); @@ -461,9 +474,10 @@ public class PolicyCreation extends AbstractPolicyCreation{ response.addHeader("error", "error"); } }catch(Exception e){ - policyDBDaoTransaction.rollbackTransaction(); + if(policyDBDaoTransaction != null){ + policyDBDaoTransaction.rollbackTransaction(); + } } - } catch (Exception e){ LOGGER.error("Exception Occured"+e);