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>
import java.util.Iterator;
import java.util.List;
import java.util.Map;
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;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// Utility to read json data from the existing file to a string
static String readFile(String path, Charset encoding) throws IOException {
// 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);
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
// Saving the Configurations file at server location for config policy.
}
// Saving the Configurations file at server location for config policy.
policyAdapter.setJsonBody(expandedBody);
policyAdapter.setConfigBodyData(expandedBody);
out.close();
policyAdapter.setJsonBody(expandedBody);
policyAdapter.setConfigBodyData(expandedBody);
out.close();
} catch (Exception e) {
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving configuration file");
}
} catch (Exception e) {
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving configuration file");
}
Map<String, String> mapFieldType= new HashMap<>();
if(rule!=null){
try {
Map<String, String> mapFieldType= new HashMap<>();
if(rule!=null){
try {
+ StringBuilder params = new StringBuilder();
Boolean flag = false;
Boolean comment = false;
String lines[] = rule.split("\n");
Boolean flag = false;
Boolean comment = false;
String lines[] = rule.split("\n");
- params = params + 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;
}
}
flag = true;
}
if (line.contains("end") && flag) {
break;
}
}
- params = params.replace("declare Params", "").replace("end", "")
+ String param = params.toString().replace("declare PapParams", "").replace("end", "")
- String[] components = params.split(":");
+ String[] components = param.split(":");
String caption = "";
for (int i = 0; i < components.length; i++) {
String type = "";
String caption = "";
for (int i = 0; i < components.length; i++) {
String type = "";
//Get the type of the UI Fields.
Map<String,String> typeOfUIField=findType(valueFromDictionary);
//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();
- 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.
//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.
if(fieldType.getValue()=="String")
{
//Type is String
if(fieldType.getValue()=="String")
{
//Type is String
- generatedRule = generatedRule + "\n\t\tparams.set"
+ generatedRule.append("\n\t\tparams.set"
- + entry.getValue() + "\");";
+ + entry.getValue() + "\");");
- generatedRule = generatedRule + "\n\t\tparams.set"
+ generatedRule.append("\n\t\tparams.set"
- + 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);
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");
}
} 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");
}
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
// Make sure the filename ends with an extension
- if (policyName.endsWith(".xml") == false) {
+ if (!policyName.endsWith(".xml")) {
policyName = policyName + ".xml";
}
policyName = policyName + ".xml";
}
anyOf.getAllOf().add(allOf);
TargetType target = new TargetType();
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);
// Adding the target to the policy element
configPolicy.setTarget((TargetType) target);
assignment2.setAttributeId("URLID");
assignment2.setCategory(CATEGORY_RESOURCE);
assignment2.setIssuer("");
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);
String content = CONFIG_URL + "/Config/"+ getConfigFile(policyName);
- AttributeValue.getContent().add(content);
+ attributeValue.getContent().add(content);
assignment2.setExpression(new ObjectFactory()
assignment2.setExpression(new ObjectFactory()
- .createAttributeValue(AttributeValue));
+ .createAttributeValue(attributeValue));
advice.getAttributeAssignmentExpression().add(assignment2);
// Policy Name Assignment
advice.getAttributeAssignmentExpression().add(assignment2);
// Policy Name Assignment
// Dynamic Field Config Attributes.
Map<String, String> dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes();
// 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()));
template.setUserCreatedBy(userInfo);
String rule = "package com.sample;\n"
+ "import com.sample.DroolsTest.Message;\n"
template.setUserCreatedBy(userInfo);
String rule = "package com.sample;\n"
+ "import com.sample.DroolsTest.Message;\n"
+ + "declare PapParams\n"
+ "samPoll : int\n"
+ "value : String\n"
+ "end\n"
+ "samPoll : int\n"
+ "value : String\n"
+ "end\n"
if (flag) {
params.append(line);
}
if (flag) {
params.append(line);
}
- if (line.contains("declare Params")) {
+ if (line.contains("declare PapParams")) {
params.append(line);
flag = true;
}
params.append(line);
flag = true;
}
- 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++) {
String[] components = params.toString().split(":");
String caption = "";
for (int i = 0; i < components.length; i++) {
if (flag) {
params.append(line);
}
if (flag) {
params.append(line);
}
- if (line.contains("rule") && line.contains(".Params\"")) {
+ if (line.contains("rule") && line.contains(".PapParams\"")) {
params.append(line);
flag = true;
}
params.append(line);
flag = true;
}
- 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("\\);");
.replace("insert(params);end", "")
.replace("params.set", ""));
String[] components = params.toString().split("\\);");
brmsTemplateVlaue + policyData.getRuleName() + "%$> \n */ \n";
body = body + findRule((String) policyData.getRuleName()) + "\n";
StringBuilder generatedRule = new StringBuilder();
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()){
if(policyData.getRuleData().size() > 0){
for(Object keyValue: policyData.getRuleData().keySet()){
//
// These parameters are required to build the runtime policy
//
//
// These parameters are required to build the runtime policy
//
closedLoopControlName : String
actor : String
aaiURL : String
closedLoopControlName : String
actor : String
aaiURL : String
package com.sample
import com.sample.DroolsTest.Message;
// Declare the Parameters here.
package com.sample
import com.sample.DroolsTest.Message;
// Declare the Parameters here.
samPoll : int
value : String
end
samPoll : int
value : String
end
//
// These parameters are required to build the runtime policy
//
//
// These parameters are required to build the runtime policy
//
closedLoopControlName : String
actor : String
aaiURL : String
closedLoopControlName : String
actor : String
aaiURL : String
public void testBRMSValidate(){
String rule = "package com.sample;\n"
+ "import com.sample.DroolsTest.Message;\n"
public void testBRMSValidate(){
String rule = "package com.sample;\n"
+ "import com.sample.DroolsTest.Message;\n"
+ + "declare PapParams\n"
+ "samPoll : int\n"
+ "value : String\n"
+ "end\n"
+ "samPoll : int\n"
+ "value : String\n"
+ "end\n"