summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2018-03-06 02:37:08 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-06 02:37:08 +0000
commit0ca791ec99d07b563cc28949d205c29b663437c1 (patch)
tree28d5f9421e5829dfa7b123a85d80f2ae4ca11e81 /ONAP-PAP-REST/src
parent48e538289151180b550b77c6905339f22d1d8097 (diff)
parent23c1e146852b43841c666aca584123dec896167e (diff)
Merge "Remove auto generated rule to the drl"
Diffstat (limited to 'ONAP-PAP-REST/src')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java80
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java2
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/BRMSPolicyTest.java4
3 files changed, 25 insertions, 61 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java
index 3ed2ee37d..4de65fd1e 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -86,7 +86,7 @@ public class CreateBrmsParamPolicy extends Policy {
Map<String,String> copyMap=new HashMap<>();
copyMap.putAll(brmsParamBody);
- copyMap.put("policyName", policyName.substring(0, policyName.replace(".xml", "").lastIndexOf(".")));
+ copyMap.put("policyName", policyName.substring(0, policyName.replace(".xml", "").lastIndexOf('.')));
copyMap.put("policyScope", policyAdapter.getDomainDir());
copyMap.put("policyVersion",policyAdapter.getHighestVersion().toString());
copyMap.put("unique", ("p"+policyName+UUID.randomUUID().toString()).replaceAll("[^A-Za-z0-9]", ""));
@@ -123,12 +123,10 @@ public class CreateBrmsParamPolicy extends Policy {
// Saving the Configurations file at server location for config policy.
protected void saveConfigurations(String policyName, String ruleBody) {
- try {
- if (policyName.endsWith(".xml")) {
- policyName = policyName.substring(0,
- policyName.lastIndexOf(".xml"));
- }
- PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName + ".txt");
+ if (policyName.endsWith(".xml")) {
+ policyName = policyName.substring(0, policyName.lastIndexOf(".xml"));
+ }
+ try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName + ".txt")) {
String expandedBody=expandConfigBody(ruleBody,policyAdapter.getBrmsParamBody());
out.println(expandedBody);
policyAdapter.setJsonBody(expandedBody);
@@ -251,7 +249,7 @@ public class CreateBrmsParamPolicy extends Policy {
if (flag) {
params.append(line);
}
- if (line.contains("declare PapParams")) {
+ if (line.contains("declare Params")) {
params.append(line);
flag = true;
}
@@ -259,7 +257,7 @@ public class CreateBrmsParamPolicy extends Policy {
break;
}
}
- String param = params.toString().replace("declare PapParams", "").replace("end", "")
+ String param = params.toString().replace("declare Params", "").replace("end", "")
.replaceAll("\\s+", "");
String[] components = param.split(":");
String caption = "";
@@ -327,60 +325,26 @@ public class CreateBrmsParamPolicy extends Policy {
if (policyAdapter.getData() != null) {
Map<String,String> ruleAndUIValue= policyAdapter.getBrmsParamBody();
- String tempateValue= ruleAndUIValue.get("templateName");
- String valueFromDictionary= getValueFromDictionary(tempateValue);
+ String templateValue= ruleAndUIValue.get("templateName");
+ String valueFromDictionary= getValueFromDictionary(templateValue);
- //Get the type of the UI Fields.
- Map<String,String> typeOfUIField=findType(valueFromDictionary);
- StringBuilder generatedRule = new StringBuilder();
StringBuilder body = new StringBuilder();
try {
-
- try {
- body.append("/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose. \n\t " +
- "<$%BRMSParamTemplate=" + tempateValue + "%$> \n */ \n");
- body.append(valueFromDictionary + "\n");
- generatedRule.append("rule \"" +policyName.substring(0, policyName.replace(".xml", "").lastIndexOf(".")) +".PapParams\" \n\tsalience 1000 \n\twhen\n\tthen\n\t\tPapParams params = new PapParams();");
-
- //We first read the map data structure(ruleAndUIValue) received from the PAP-ADMIN
- //We ignore if the key is "templateName as we are interested only in the UI fields and its value.
- //We have one more map data structure(typeOfUIField) created by parsing the Drools rule.
- //From the type of the UI field(String/int) we structure whether to put the "" or not.
- for (Map.Entry<String, String> entry : ruleAndUIValue.entrySet()) {
- if(entry.getKey()!="templateName")
- {
- for(Map.Entry<String, String> fieldType:typeOfUIField.entrySet())
- {
- if(fieldType.getKey().equalsIgnoreCase(entry.getKey()))
- {
- String key = entry.getKey().substring(0, 1).toUpperCase() + entry.getKey().substring(1);
- if(fieldType.getValue()=="String")
- {
- //Type is String
- generatedRule.append("\n\t\tparams.set"
- + key + "(\""
- + entry.getValue() + "\");");
- }
- else{
- generatedRule.append("\n\t\tparams.set"
- + key + "("
- + entry.getValue() + ");");
- }
- }
- }
- }
- }
-
- generatedRule.append("\n\t\tinsert(params);\nend");
- LOGGER.info("New rule generated with :" + generatedRule);
- body.append(generatedRule);
- } catch (Exception e) {
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving policy");
- }
+ body.append("/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose. \n\t " +
+ "<$%BRMSParamTemplate=" + templateValue + "%$> \n");
+ body.append("<%$Values=");
+ for (Map.Entry<String, String> entry : ruleAndUIValue.entrySet()) {
+ String uiKey = entry.getKey();
+ if(!"templateName".equals(uiKey)) {
+ body.append(uiKey+":-:"+entry.getValue()+":|:");
+ }
+ }
+ body.append("$%> \n*/ \n");
+ body.append(valueFromDictionary + "\n");
}
catch (Exception e) {
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving policy");
+ PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving policy");
}
saveConfigurations(policyName,body.toString());
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 2b84ccaf1..ca2b6797d 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
@@ -335,7 +335,7 @@ public class XACMLPAPTest {
template.setUserCreatedBy(userInfo);
String rule = "package com.sample;\n"
+ "import com.sample.DroolsTest.Message;\n"
- + "declare PapParams\n"
+ + "declare Params\n"
+ "samPoll : int\n"
+ "value : String\n"
+ "end\n"
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/BRMSPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/BRMSPolicyTest.java
index bb537db02..c13d1f1fe 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/BRMSPolicyTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/BRMSPolicyTest.java
@@ -46,8 +46,8 @@ public class BRMSPolicyTest {
@Test
public void testReadFile() throws IOException {
- String goodRule = "declare PapParams\nparam1 : int\nend\n";
- String badRule = "declare PapParams\nparam1+ : int\nend\n";
+ String goodRule = "declare Params\nparam1 : int\nend\n";
+ String badRule = "declare Params\nparam1+ : int\nend\n";
assertEquals(CreateBRMSRuleTemplate.validateRuleParams(goodRule), true);
assertEquals(CreateBRMSRuleTemplate.validateRuleParams(badRule), false);
}