Merge "Updates to policy documentation"
authorPamela Dragosh <pdragosh@research.att.com>
Wed, 11 Oct 2017 14:54:34 +0000 (14:54 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 11 Oct 2017 14:54:34 +0000 (14:54 +0000)
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java
ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java
ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java
ONAP-PDP-REST/src/test/resources/xacml.pdp.properties
ONAP-PDP/pom.xml
POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java
POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt
POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Raw_TestBRMSRawPolicy.1.txt
PolicyEngineClient/testResources/test.drl
PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/PolicyUtilsTest.java
packages/base/src/files/install/servers/pdp/bin/xacml.pdp.properties

index b27dd22..3ed2ee3 100644 (file)
@@ -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
index ba5539f..8208893 100644 (file)
@@ -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"
index efaa5c1..8258aba 100644 (file)
@@ -128,7 +128,7 @@ public class PDPServices {
                 LOGGER.info("Decision not a Permit. "  + result.getDecision().toString());
                 PDPResponse pdpResponse = new PDPResponse();
                 if (decide) {
-                       String indeterminatePropValue = XACMLProperties.getProperty("decision.inStringdeterminate.response");
+                       String indeterminatePropValue = XACMLProperties.getProperty("decision.indeterminate.response");
                        if(result.getDecision().equals(Decision.INDETERMINATE)&& indeterminatePropValue != null){
                                if("PERMIT".equalsIgnoreCase(indeterminatePropValue)){
                                        pdpResponse.setDecision(PolicyDecision.PERMIT);
index 2013a1f..bb174b9 100644 (file)
@@ -42,7 +42,7 @@ aafClient.impl.className=org.onap.policy.utils.AAFPolicyClientImpl
 # AT&T RESTful PDP Implementation Factories
 #
 xacml.pipFinderFactory=org.onap.policy.pdp.rest.impl.XACMLPdpPIPFinderFactory
-xacml.att.policyFinderFactory=org.onap.policy.pdp.rest.impl.XACMLPdpPolicyFinderFactory
+xacml.att.policyFinderFactory=org.onap.policy.pdp.rest.XACMLPdpPolicyFinderFactory
 #
 # When set to true, this flag tells the StdPolicyFinderFactory to combined all the root policy files into
 # into one PolicySet and use the given Policy Algorithm.
index 0310d39..bd05074 100644 (file)
                        <artifactId>httpcore</artifactId>
                        <version>4.4.4</version>
                </dependency>
-               <dependency>
-                       <groupId>org.glassfish</groupId>
-                       <artifactId>javax.json</artifactId>
-                       <version>1.1</version>
-               </dependency>
                <dependency>
                        <groupId>commons-codec</groupId>
                        <artifactId>commons-codec</artifactId>
index fc7cb60..4dc4542 100644 (file)
@@ -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()){ 
index 6ff244e..63f93cb 100644 (file)
@@ -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
index 6924fc3..a3cdb78 100644 (file)
@@ -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
index 7accc63..10cd5b7 100644 (file)
@@ -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
index 586ab35..34ed6b8 100644 (file)
@@ -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"
index f8ec66d..fe5277d 100644 (file)
@@ -42,7 +42,7 @@ aafClient.impl.className=org.onap.policy.utils.AAFPolicyClientImpl
 # AT&T RESTful PDP Implementation Factories
 #
 xacml.pipFinderFactory=org.onap.policy.pdp.rest.impl.XACMLPdpPIPFinderFactory
-xacml.att.policyFinderFactory=org.onap.policy.pdp.rest.impl.XACMLPdpPolicyFinderFactory
+xacml.att.policyFinderFactory=org.onap.policy.pdp.rest.XACMLPdpPolicyFinderFactory
 #
 # When set to true, this flag tells the StdPolicyFinderFactory to combined all the root policy files into
 # into one PolicySet and use the given Policy Algorithm.
@@ -107,7 +107,7 @@ xacml.rest.pap.userid=${{PDP_PAP_PDP_HTTP_USER_ID}}
 # pass PAP
 xacml.rest.pap.password=${{PDP_PAP_PDP_HTTP_PASSWORD}}
 # Delay for Notifications Don't change this. Value in milliSec.  
-xacml.rest.notification.delay=30  
+xacml.rest.notification.delay=30
 # Client interval to ping notification service. 
 CLIENT_INTERVAL=15000
 # Request Buffer Size.