summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTej, Tarun <tt3868@att.com>2017-10-10 17:11:54 -0400
committerTej, Tarun <tt3868@att.com>2017-10-10 17:12:31 -0400
commit6200a3b57dcce7890df56c80ec388608c8ea391d (patch)
tree4008ff9660a77086516f827d841ef26209125989
parent2ebd62710f2bcd92627e6a79da25da25ac2750af (diff)
Fixing the BRMS rule generation issue
Fixing the rule params section to look for PapParams istead of Params. This will be a temporary solution for now. Issue-Id: POLICY-302 Change-Id: I4b6b415b3eacf121be374d2dfd50303049c35aba Signed-off-by: Tej, Tarun <tt3868@att.com>
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java60
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java2
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java12
-rw-r--r--POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt2
-rw-r--r--POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Raw_TestBRMSRawPolicy.1.txt2
-rw-r--r--PolicyEngineClient/testResources/test.drl2
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PolicyUtilsTest.java2
7 files changed, 39 insertions, 43 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 b27dd22ca..3ed2ee37d 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
@@ -34,6 +34,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -116,10 +117,8 @@ public class CreateBrmsParamPolicy extends Policy {
// Utility to read json data from the existing file to a string
static String readFile(String path, Charset encoding) throws IOException {
-
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
-
}
// Saving the Configurations file at server location for config policy.
@@ -135,8 +134,6 @@ public class CreateBrmsParamPolicy extends Policy {
policyAdapter.setJsonBody(expandedBody);
policyAdapter.setConfigBodyData(expandedBody);
out.close();
-
-
} catch (Exception e) {
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving configuration file");
}
@@ -207,7 +204,7 @@ public class CreateBrmsParamPolicy extends Policy {
Map<String, String> mapFieldType= new HashMap<>();
if(rule!=null){
try {
- String params = "";
+ StringBuilder params = new StringBuilder();
Boolean flag = false;
Boolean comment = false;
String lines[] = rule.split("\n");
@@ -252,19 +249,19 @@ public class CreateBrmsParamPolicy extends Policy {
continue;
}
if (flag) {
- params = params + line;
+ params.append(line);
}
- if (line.contains("declare Params")) {
- params = params + line;
+ if (line.contains("declare PapParams")) {
+ params.append(line);
flag = true;
}
if (line.contains("end") && flag) {
break;
}
}
- params = params.replace("declare Params", "").replace("end", "")
+ String param = params.toString().replace("declare PapParams", "").replace("end", "")
.replaceAll("\\s+", "");
- String[] components = params.split(":");
+ String[] components = param.split(":");
String caption = "";
for (int i = 0; i < components.length; i++) {
String type = "";
@@ -335,16 +332,16 @@ public class CreateBrmsParamPolicy extends Policy {
//Get the type of the UI Fields.
Map<String,String> typeOfUIField=findType(valueFromDictionary);
- String generatedRule=null;
- String body = "";
+ StringBuilder generatedRule = new StringBuilder();
+ StringBuilder body = new StringBuilder();
try {
try {
- body = "/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose. \n\t " +
- "<$%BRMSParamTemplate=" + tempateValue + "%$> \n */ \n";
- body = body + valueFromDictionary + "\n";
- generatedRule = "rule \"" +policyName.substring(0, policyName.replace(".xml", "").lastIndexOf(".")) +".Params\" \n\tsalience 1000 \n\twhen\n\tthen\n\t\tParams params = new Params();";
+ 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.
@@ -361,24 +358,23 @@ public class CreateBrmsParamPolicy extends Policy {
if(fieldType.getValue()=="String")
{
//Type is String
- generatedRule = generatedRule + "\n\t\tparams.set"
+ generatedRule.append("\n\t\tparams.set"
+ key + "(\""
- + entry.getValue() + "\");";
+ + entry.getValue() + "\");");
}
else{
- generatedRule = generatedRule + "\n\t\tparams.set"
+ generatedRule.append("\n\t\tparams.set"
+ key + "("
- + entry.getValue() + ");";
+ + entry.getValue() + ");");
}
}
}
}
}
- generatedRule = generatedRule
- + "\n\t\tinsert(params);\nend";
+ generatedRule.append("\n\t\tinsert(params);\nend");
LOGGER.info("New rule generated with :" + generatedRule);
- body = body + generatedRule;
+ body.append(generatedRule);
} catch (Exception e) {
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving policy");
}
@@ -387,10 +383,10 @@ public class CreateBrmsParamPolicy extends Policy {
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving policy");
}
- saveConfigurations(policyName,body);
+ saveConfigurations(policyName,body.toString());
// Make sure the filename ends with an extension
- if (policyName.endsWith(".xml") == false) {
+ if (!policyName.endsWith(".xml")) {
policyName = policyName + ".xml";
}
@@ -429,7 +425,7 @@ public class CreateBrmsParamPolicy extends Policy {
anyOf.getAllOf().add(allOf);
TargetType target = new TargetType();
- ((TargetType) target).getAnyOf().add(anyOf);
+ target.getAnyOf().add(anyOf);
// Adding the target to the policy element
configPolicy.setTarget((TargetType) target);
@@ -536,14 +532,14 @@ public class CreateBrmsParamPolicy extends Policy {
assignment2.setAttributeId("URLID");
assignment2.setCategory(CATEGORY_RESOURCE);
assignment2.setIssuer("");
- AttributeValueType AttributeValue = new AttributeValueType();
- AttributeValue.setDataType(URI_DATATYPE);
+ AttributeValueType attributeValue = new AttributeValueType();
+ attributeValue.setDataType(URI_DATATYPE);
String content = CONFIG_URL + "/Config/"+ getConfigFile(policyName);
- AttributeValue.getContent().add(content);
+ attributeValue.getContent().add(content);
assignment2.setExpression(new ObjectFactory()
- .createAttributeValue(AttributeValue));
+ .createAttributeValue(attributeValue));
advice.getAttributeAssignmentExpression().add(assignment2);
// Policy Name Assignment
@@ -624,8 +620,8 @@ public class CreateBrmsParamPolicy extends Policy {
// Dynamic Field Config Attributes.
Map<String, String> dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes();
- for (String keyField : dynamicFieldConfigAttributes.keySet()) {
- advice.getAttributeAssignmentExpression().add(createResponseAttributes("key:"+keyField, dynamicFieldConfigAttributes.get(keyField)));
+ for (Entry<String, String> map : dynamicFieldConfigAttributes.entrySet()) {
+ advice.getAttributeAssignmentExpression().add(createResponseAttributes("key:"+map.getKey(), map.getValue()));
}
//Risk Attributes
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 ba5539f4b..82088937e 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
@@ -320,7 +320,7 @@ public class XACMLPAPTest {
template.setUserCreatedBy(userInfo);
String rule = "package com.sample;\n"
+ "import com.sample.DroolsTest.Message;\n"
- + "declare Params\n"
+ + "declare PapParams\n"
+ "samPoll : int\n"
+ "value : String\n"
+ "end\n"
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java
index fc7cb60e5..4dc45425a 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java
@@ -173,7 +173,7 @@ public class CreateBRMSParamController extends RestrictedBaseController {
if (flag) {
params.append(line);
}
- if (line.contains("declare Params")) {
+ if (line.contains("declare PapParams")) {
params.append(line);
flag = true;
}
@@ -181,7 +181,7 @@ public class CreateBRMSParamController extends RestrictedBaseController {
break;
}
}
- params = new StringBuilder(params.toString().replace("declare Params", "").replace("end", "").replaceAll("\\s+", ""));
+ params = new StringBuilder(params.toString().replace("declare PapParams", "").replace("end", "").replaceAll("\\s+", ""));
String[] components = params.toString().split(":");
String caption = "";
for (int i = 0; i < components.length; i++) {
@@ -400,7 +400,7 @@ public class CreateBRMSParamController extends RestrictedBaseController {
if (flag) {
params.append(line);
}
- if (line.contains("rule") && line.contains(".Params\"")) {
+ if (line.contains("rule") && line.contains(".PapParams\"")) {
params.append(line);
flag = true;
}
@@ -408,8 +408,8 @@ public class CreateBRMSParamController extends RestrictedBaseController {
break;
}
}
- params = new StringBuilder(params.substring(params.indexOf(".Params\"")+ 8));
- params = new StringBuilder(params.toString().replaceAll("\\s+", "").replace("salience1000whenthenParamsparams=newParams();","")
+ params = new StringBuilder(params.substring(params.indexOf(".PapParams\"")+ 11));
+ params = new StringBuilder(params.toString().replaceAll("\\s+", "").replace("salience1000whenthenPapParamsparams=newPapParams();","")
.replace("insert(params);end", "")
.replace("params.set", ""));
String[] components = params.toString().split("\\);");
@@ -462,7 +462,7 @@ public class CreateBRMSParamController extends RestrictedBaseController {
brmsTemplateVlaue + policyData.getRuleName() + "%$> \n */ \n";
body = body + findRule((String) policyData.getRuleName()) + "\n";
StringBuilder generatedRule = new StringBuilder();
- generatedRule.append("rule \""+ policyData.getDomainDir().replace("\\", ".") +".Config_BRMS_Param_" + policyData.getPolicyName()+".Params\" \n\tsalience 1000 \n\twhen\n\tthen\n\t\tParams params = new Params();");
+ generatedRule.append("rule \""+ policyData.getDomainDir().replace("\\", ".") +".Config_BRMS_Param_" + policyData.getPolicyName()+".PapParams\" \n\tsalience 1000 \n\twhen\n\tthen\n\t\tPapParams params = new PapParams();");
if(policyData.getRuleData().size() > 0){
for(Object keyValue: policyData.getRuleData().keySet()){
diff --git a/POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt b/POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt
index 6ff244ea4..63f93cbe2 100644
--- a/POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt
+++ b/POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt
@@ -88,7 +88,7 @@ import org.onap.policy.drools.system.PolicyEngine;
//
// These parameters are required to build the runtime policy
//
-declare Params
+declare PapParams
closedLoopControlName : String
actor : String
aaiURL : String
diff --git a/POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Raw_TestBRMSRawPolicy.1.txt b/POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Raw_TestBRMSRawPolicy.1.txt
index 6924fc3a9..a3cdb7851 100644
--- a/POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Raw_TestBRMSRawPolicy.1.txt
+++ b/POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Raw_TestBRMSRawPolicy.1.txt
@@ -1,7 +1,7 @@
package com.sample
import com.sample.DroolsTest.Message;
// Declare the Parameters here.
-declare Params
+declare PapParams
samPoll : int
value : String
end
diff --git a/PolicyEngineClient/testResources/test.drl b/PolicyEngineClient/testResources/test.drl
index 7accc63ae..10cd5b717 100644
--- a/PolicyEngineClient/testResources/test.drl
+++ b/PolicyEngineClient/testResources/test.drl
@@ -83,7 +83,7 @@ import org.onap.policy.drools.system.PolicyEngine;
//
// These parameters are required to build the runtime policy
//
-declare Params
+declare PapParams
closedLoopControlName : String
actor : String
aaiURL : String
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PolicyUtilsTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PolicyUtilsTest.java
index 586ab356d..34ed6b8b8 100644
--- a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PolicyUtilsTest.java
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PolicyUtilsTest.java
@@ -148,7 +148,7 @@ public class PolicyUtilsTest {
public void testBRMSValidate(){
String rule = "package com.sample;\n"
+ "import com.sample.DroolsTest.Message;\n"
- + "declare Params\n"
+ + "declare PapParams\n"
+ "samPoll : int\n"
+ "value : String\n"
+ "end\n"