Fix build issues in drools-applications due to changes in policy/models repo 09/90109/2
authorRashmi Pujar <rashmi.pujar@bell.ca>
Tue, 18 Jun 2019 18:53:00 +0000 (14:53 -0400)
committerRashmi Pujar <rashmi.pujar@bell.ca>
Tue, 18 Jun 2019 19:12:36 +0000 (15:12 -0400)
Issue-ID: POLICY-1791
Signed-off-by: Rashmi Pujar <rashmi.pujar@bell.ca>
Change-Id: Ife7cbb07c3bb674257bb1979d80f4f8a7ddfc3a5

controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java
controlloop/common/guard/src/test/java/org/onap/policy/guard/PolicyGuardYamlToXacmlTest.java

index b493fff..a64abca 100644 (file)
@@ -30,6 +30,7 @@ import java.util.regex.Pattern;
 
 import org.onap.policy.controlloop.policy.guard.Constraint;
 import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
+import org.onap.policy.controlloop.policy.guard.GuardPolicy;
 import org.onap.policy.controlloop.policy.guard.MatchParameters;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -50,15 +51,14 @@ public class PolicyGuardYamlToXacml {
      */
     public static void fromYamlToXacml(String yamlFile, String xacmlTemplate, String xacmlPolicyOutput) {
         ControlLoopGuard yamlGuardObject = Util.loadYamlGuard(yamlFile);
-        logger.debug("clname: {}", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getControlLoopName());
-        logger.debug("actor: {}", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getActor());
-        logger.debug("recipe: {}", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getRecipe());
-        logger.debug("num: {}",
-                yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getFreq_limit_per_target());
-        logger.debug("duration: {}",
-                yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window());
-        logger.debug("time_in_range: {}",
-                yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getActive_time_range());
+        GuardPolicy guardPolicy = yamlGuardObject.getGuards().get(0);
+        logger.debug("clname: {}", guardPolicy.getMatch_parameters().getControlLoopName());
+        logger.debug("actor: {}", guardPolicy.getMatch_parameters().getActor());
+        logger.debug("recipe: {}", guardPolicy.getMatch_parameters().getRecipe());
+        Constraint constraint = guardPolicy.getLimit_constraints().get(0);
+        logger.debug("num: {}", constraint.getFreq_limit_per_target());
+        logger.debug("duration: {}", constraint.getTime_window());
+        logger.debug("time_in_range: {}", constraint.getActive_time_range());
 
         Path xacmlTemplatePath = Paths.get(xacmlTemplate);
         String xacmlTemplateContent;
@@ -67,8 +67,7 @@ public class PolicyGuardYamlToXacml {
             xacmlTemplateContent = new String(Files.readAllBytes(xacmlTemplatePath));
 
             String xacmlPolicyContent = generateXacmlGuard(xacmlTemplateContent,
-                    yamlGuardObject.getGuards().getFirst().getMatch_parameters(),
-                    yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst());
+                    guardPolicy.getMatch_parameters(), constraint);
 
             Files.write(Paths.get(xacmlPolicyOutput), xacmlPolicyContent.getBytes());
 
@@ -170,14 +169,13 @@ public class PolicyGuardYamlToXacml {
      */
     public static void fromYamlToXacmlBlacklist(String yamlFile, String xacmlTemplate, String xacmlPolicyOutput) {
         ControlLoopGuard yamlGuardObject = Util.loadYamlGuard(yamlFile);
-        logger.debug("actor: {}", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getActor());
-        logger.debug("recipe: {}", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getRecipe());
-        logger.debug("freq_limit_per_target: {}",
-                yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getFreq_limit_per_target());
-        logger.debug("time_window: {}",
-                yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window());
-        logger.debug("active_time_range: {}",
-                yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getActive_time_range());
+        GuardPolicy guardPolicy = yamlGuardObject.getGuards().get(0);
+        logger.debug("actor: {}", guardPolicy.getMatch_parameters().getActor());
+        logger.debug("recipe: {}", guardPolicy.getMatch_parameters().getRecipe());
+        Constraint constraint = guardPolicy.getLimit_constraints().get(0);
+        logger.debug("freq_limit_per_target: {}", constraint.getFreq_limit_per_target());
+        logger.debug("time_window: {}", constraint.getTime_window());
+        logger.debug("active_time_range: {}", constraint.getActive_time_range());
 
         Path xacmlTemplatePath = Paths.get(xacmlTemplate);
         String xacmlTemplateContent;
@@ -185,8 +183,7 @@ public class PolicyGuardYamlToXacml {
         try {
             xacmlTemplateContent = new String(Files.readAllBytes(xacmlTemplatePath));
             String xacmlPolicyContent = generateXacmlGuardBlacklist(xacmlTemplateContent,
-                    yamlGuardObject.getGuards().getFirst().getMatch_parameters(),
-                    yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst());
+                    guardPolicy.getMatch_parameters(), constraint);
 
             Files.write(Paths.get(xacmlPolicyOutput), xacmlPolicyContent.getBytes());
 
index dced288..a35696d 100644 (file)
@@ -116,10 +116,11 @@ public class PolicyGuardYamlToXacmlTest {
         final File tempXacmlTemplateFile = new File("src/test/resources/frequency_limiter_template.xml");
         final File tempXacmlOutputFile = File.createTempFile("ONAPPF", ".out.xacml");
 
-        clGuard.getGuards().getFirst().getMatch_parameters().setControlLoopName(null);
-        clGuard.getGuards().getFirst().getMatch_parameters().setActor(null);
-        clGuard.getGuards().getFirst().getMatch_parameters().setRecipe(null);
-        clGuard.getGuards().getFirst().getMatch_parameters().setTargets(null);
+        MatchParameters matchParameters = clGuard.getGuards().get(0).getMatch_parameters();
+        matchParameters.setControlLoopName(null);
+        matchParameters.setActor(null);
+        matchParameters.setRecipe(null);
+        matchParameters.setTargets(null);
 
         Yaml clYaml = new Yaml(new Constructor(ControlLoopGuard.class));
         String clYamlString = clYaml.dump(clGuard);
@@ -179,7 +180,7 @@ public class PolicyGuardYamlToXacmlTest {
         List<String> blacklist = new ArrayList<>();
         blacklist.add("WestWitches");
         blacklist.add("EastWitches");
-        clGuard.getGuards().getFirst().getLimit_constraints().getFirst().setBlacklist(blacklist);
+        clGuard.getGuards().get(0).getLimit_constraints().get(0).setBlacklist(blacklist);
 
         Yaml clYaml = new Yaml(new Constructor(ControlLoopGuard.class));
         String clYamlString = clYaml.dump(clGuard);
@@ -210,12 +211,14 @@ public class PolicyGuardYamlToXacmlTest {
         List<String> blacklist = new ArrayList<>();
         blacklist.add("WestWitches");
         blacklist.add("EastWitches");
-        clGuard.getGuards().getFirst().getLimit_constraints().getFirst().setBlacklist(blacklist);
-
-        clGuard.getGuards().getFirst().getMatch_parameters().setControlLoopName(null);
-        clGuard.getGuards().getFirst().getMatch_parameters().setActor(null);
-        clGuard.getGuards().getFirst().getMatch_parameters().setRecipe(null);
-        clGuard.getGuards().getFirst().getMatch_parameters().setTargets(null);
+        GuardPolicy guardPolicy = clGuard.getGuards().get(0);
+        guardPolicy.getLimit_constraints().get(0).setBlacklist(blacklist);
+
+        MatchParameters matchParameters = guardPolicy.getMatch_parameters();
+        matchParameters.setControlLoopName(null);
+        matchParameters.setActor(null);
+        matchParameters.setRecipe(null);
+        matchParameters.setTargets(null);
 
         Yaml clYaml = new Yaml(new Constructor(ControlLoopGuard.class));
         String clYamlString = clYaml.dump(clGuard);