aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src/main
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2017-07-19 18:54:02 -0500
committerJorge Hernandez <jh1730@att.com>2017-07-20 08:56:24 -0500
commite10845684c65f2a1e99d31615df141cd318562bc (patch)
tree32dcb4f698cd726ff56bb379834a06262e20b900 /policy-management/src/main
parent6d015d1f3f8ecc09bfcd74dcaacb56048cd84a47 (diff)
[POLICY-88] validation of query pre-execution
Change-Id: Ie02de9aca434c3d80b9e34126990e3b9995747bb Signed-off-by: Jorge Hernandez <jh1730@att.com>
Diffstat (limited to 'policy-management/src/main')
-rw-r--r--policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsController.java6
-rw-r--r--policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java19
-rw-r--r--policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/NullDroolsController.java14
3 files changed, 33 insertions, 6 deletions
diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsController.java b/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsController.java
index 5a5f3123..251cef11 100644
--- a/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsController.java
+++ b/policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsController.java
@@ -23,6 +23,7 @@ package org.openecomp.policy.drools.controller;
import java.util.List;
import java.util.Map;
+import org.openecomp.policy.drools.core.PolicyContainer;
import org.openecomp.policy.drools.event.comm.TopicSink;
import org.openecomp.policy.drools.properties.Lockable;
import org.openecomp.policy.drools.properties.Startable;
@@ -122,6 +123,11 @@ public interface DroolsController extends Startable, Lockable {
public String[] getRecentSinkEvents();
/**
+ * @return the underlying policy container
+ */
+ public PolicyContainer getContainer();
+
+ /**
* Supports this encoder?
*
* @param encodedObject
diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java
index bc577649..4eacbd1c 100644
--- a/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java
+++ b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java
@@ -28,6 +28,8 @@ import java.util.Map;
import org.apache.commons.collections4.queue.CircularFifoQueue;
import org.drools.core.ClassObjectFilter;
+import org.kie.api.definition.KiePackage;
+import org.kie.api.definition.rule.Query;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;
import org.kie.api.runtime.rule.QueryResults;
@@ -649,11 +651,10 @@ public class MavenDroolsController implements DroolsController {
}
/**
- * gets the policy container
- * @return the underlying container
+ * {@inheritDoc}
*/
@JsonIgnore
- protected PolicyContainer getContainer() {
+ public PolicyContainer getContainer() {
return this.policyContainer;
}
@@ -824,6 +825,18 @@ public class MavenDroolsController implements DroolsController {
PolicySession session = getSession(sessionName);
KieSession kieSession = session.getKieSession();
+ boolean found = false;
+ for (KiePackage kiePackage : kieSession.getKieBase().getKiePackages()) {
+ for (Query q : kiePackage.getQueries()) {
+ if (q.getName() != null && q.getName().equals(queryName)) {
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ throw new IllegalArgumentException("Invalid Query Name: " + queryName);
+
List<Object> factObjects = new ArrayList<>();
QueryResults queryResults = kieSession.getQueryResults(queryName, queryParams);
diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/NullDroolsController.java b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/NullDroolsController.java
index 4019beef..7f5d4665 100644
--- a/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/NullDroolsController.java
+++ b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/NullDroolsController.java
@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Map;
import org.openecomp.policy.drools.controller.DroolsController;
+import org.openecomp.policy.drools.core.PolicyContainer;
import org.openecomp.policy.drools.event.comm.TopicSink;
import org.openecomp.policy.drools.protocol.coders.TopicCoderFilterConfiguration;
@@ -152,7 +153,7 @@ public class NullDroolsController implements DroolsController {
@Override
public boolean deliver(TopicSink sink, Object event)
throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException {
- throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked");
+ throw new IllegalStateException(this.getClass().getCanonicalName() + " invoked");
}
/**
@@ -162,6 +163,14 @@ public class NullDroolsController implements DroolsController {
public Object[] getRecentSourceEvents() {
return new String[0];
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public PolicyContainer getContainer() {
+ return null;
+ }
/**
* {@inheritDoc}
@@ -176,7 +185,7 @@ public class NullDroolsController implements DroolsController {
*/
@Override
public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) throws IllegalStateException {
- throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked");
+ throw new IllegalStateException(this.getClass().getCanonicalName() + " invoked");
}
/**
@@ -250,5 +259,4 @@ public class NullDroolsController implements DroolsController {
boolean delete, Object... queryParams) {
return new ArrayList<Object>();
}
-
}