aboutsummaryrefslogtreecommitdiffstats
path: root/POLICY-SDK-APP/src
diff options
context:
space:
mode:
authorpa834y <pa834y@att.com>2018-03-02 17:14:47 -0500
committerpa834y <pa834y@att.com>2018-03-05 11:28:37 -0500
commit23c1e146852b43841c666aca584123dec896167e (patch)
tree9a095809efcc49c1b3f869e7aaa47a70e941519b /POLICY-SDK-APP/src
parent44a296f53e8faf2b458c59355e5a2506ad46aca5 (diff)
Remove auto generated rule to the drl
Issue-ID: POLICY-488 Change-Id: Id6915407a6f030b77ae2d18ad3665af9d0feb34b Signed-off-by: pa834y <pa834y@att.com>
Diffstat (limited to 'POLICY-SDK-APP/src')
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java61
-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
3 files changed, 35 insertions, 30 deletions
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 df1ca6a9f..40cceead5 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
- * 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.
@@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -175,7 +176,7 @@ public class CreateBRMSParamController extends RestrictedBaseController {
if (flag) {
params.append(line);
}
- if (line.contains("declare PapParams")) {
+ if (line.contains("declare Params")) {
params.append(line);
flag = true;
}
@@ -183,7 +184,7 @@ public class CreateBRMSParamController extends RestrictedBaseController {
break;
}
}
- params = new StringBuilder(params.toString().replace("declare PapParams", "").replace("end", "").replaceAll("\\s+", ""));
+ params = new StringBuilder(params.toString().replace("declare Params", "").replace("end", "").replaceAll("\\s+", ""));
String[] components = params.toString().split(":");
String caption = "";
for (int i = 0; i < components.length; i++) {
@@ -363,6 +364,17 @@ public class CreateBRMSParamController extends RestrictedBaseController {
value = value.replace(brmsTemplateVlaue, "");
policyAdapter.setRuleName(value);
}
+ if(line.contains("<%$Values=")) {
+ String value = line.substring(line.indexOf("<%$"), line.indexOf("$%>"));
+ value = value.replaceAll("<%\\$Values=", "");
+ for( String keyValue : value.split(":\\|:")) {
+ String[] pair = keyValue.split(":-:");
+ if (pair != null && pair.length > 0) {
+ dynamicLayoutMap.put(pair[0], (pair.length > 1) ? pair[1] : "");
+ }
+ }
+ return;
+ }
if (line.startsWith("/*")) {
comment = true;
continue;
@@ -402,7 +414,7 @@ public class CreateBRMSParamController extends RestrictedBaseController {
if (flag) {
params.append(line);
}
- if (line.contains("rule") && line.contains(".PapParams\"")) {
+ if (line.contains("rule") && line.contains(".Params\"")) {
params.append(line);
flag = true;
}
@@ -410,8 +422,8 @@ public class CreateBRMSParamController extends RestrictedBaseController {
break;
}
}
- params = new StringBuilder(params.substring(params.indexOf(".PapParams\"")+ 11));
- params = new StringBuilder(params.toString().replaceAll("\\s+", "").replace("salience1000whenthenPapParamsparams=newPapParams();","")
+ params = new StringBuilder(params.substring(params.indexOf(".Params\"")+ 11));
+ params = new StringBuilder(params.toString().replaceAll("\\s+", "").replace("salience1000whenthenParamsparams=newParams();","")
.replace("insert(params);end", "")
.replace("params.set", ""));
String[] components = params.toString().split("\\);");
@@ -459,30 +471,23 @@ public class CreateBRMSParamController extends RestrictedBaseController {
}
String body;
+ body = findRule((String) policyData.getRuleName()) + "\n";
+ StringBuilder generatedMetadata = new StringBuilder();
+ generatedMetadata.append("/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose. \n\t " +
+ brmsTemplateVlaue + policyData.getRuleName() + "%$> \n */ \n");
- body = "/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose. \n\t " +
- 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()+".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()){
- String key = keyValue.toString().substring(0, 1).toUpperCase() + keyValue.toString().substring(1);
- if (string.equals(keyValue)) {
- generatedRule.append("\n\t\tparams.set"
- + key + "(\""
- + policyData.getRuleData().get(keyValue).toString() + "\");");
- } else {
- generatedRule.append("\n\t\tparams.set"
- + key + "("
- + policyData.getRuleData().get(keyValue).toString() + ");");
- }
- }
+ if(policyData.getDynamicLayoutMap().size() > 0){
+ generatedMetadata.append("/* <%$Values=");
+ for (Entry<?, ?> entry : policyData.getRuleData().entrySet()) {
+ String uiKey = (String) entry.getKey();
+ if(!"templateName".equals(uiKey)) {
+ generatedMetadata.append(uiKey+":-:"+entry.getValue()+":|:");
+ }
+ }
+ generatedMetadata.append("$%> \n*/ \n");
}
- generatedRule.append("\n\t\tinsert(params);\nend");
- policyLogger.info("New rule generated with :" + generatedRule.toString());
- body = body + generatedRule.toString();
+ policyLogger.info("Metadata generated with :" + generatedMetadata.toString());
+ body = generatedMetadata.toString() + body;
// Expand the body.
Map<String,String> copyMap=new HashMap<>();
copyMap.putAll((Map<? extends String, ? extends String>) policyData.getRuleData());
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 63f93cbe2..6ff244ea4 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 PapParams
+declare Params
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 a3cdb7851..6924fc3a9 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 PapParams
+declare Params
samPoll : int
value : String
end