summaryrefslogtreecommitdiffstats
path: root/policy-management/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'policy-management/src/main')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java10
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java24
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java10
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java10
4 files changed, 51 insertions, 3 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java
index 78a2f4e8..4347614f 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java
@@ -243,6 +243,16 @@ public interface DroolsController extends Startable, Lockable {
<T> boolean delete(@NonNull T fact);
/**
+ * Deletes all facts from a given class from a session.
+ */
+ <T> boolean delete(@NonNull String sessionName, @NonNull Class<T> fact);
+
+ /**
+ * Deletes all facts from a given class from all sessions.
+ */
+ <T> boolean delete(@NonNull Class<T> fact);
+
+ /**
* halts and permanently releases all resources.
*
*/
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
index a9ab212b..140d6769 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
@@ -920,6 +920,30 @@ public class MavenDroolsController implements DroolsController {
}
@Override
+ public <T> boolean delete(@NonNull String sessionName, @NonNull Class<T> fact) {
+ PolicySession session = getSession(sessionName);
+ KieSession kieSession = session.getKieSession();
+
+ boolean success = true;
+ Collection<FactHandle> factHandles = kieSession.getFactHandles(new ClassObjectFilter(fact));
+ for (FactHandle factHandle : factHandles) {
+ try {
+ kieSession.delete(factHandle);
+ } catch (Exception e) {
+ logger.warn("Object cannot be retrieved from fact {}", factHandle, e);
+ success = false;
+ }
+ }
+ return success;
+ }
+
+ @Override
+ public <T> boolean delete(@NonNull Class<T> fact) {
+ return this.getSessionNames().stream().map((ss) -> delete(ss, fact)).reduce(false, Boolean::logicalOr);
+ }
+
+
+ @Override
public Class<?> fetchModelClass(String className) {
return ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className);
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java
index 5bf51efa..3595f91a 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java
@@ -203,6 +203,16 @@ public class NullDroolsController implements DroolsController {
return false;
}
+ @Override
+ public <T> boolean delete(@NonNull String sessionName, @NonNull Class<T> fact) {
+ return false;
+ }
+
+ @Override
+ public <T> boolean delete(@NonNull Class<T> fact) {
+ return false;
+ }
+
private String makeInvokeMsg() {
return this.getClass().getCanonicalName() + " invoked";
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java
index aac92505..d926bed6 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java
@@ -1699,6 +1699,7 @@ public class RestManager {
@ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm
) {
List<TopicSource> sources = new ArrayList<>();
+ Status status = Status.OK;
switch (CommInfrastructure.valueOf(comm.toUpperCase())) {
case UEB:
sources.addAll(TopicEndpoint.manager.getUebTopicSources());
@@ -1710,10 +1711,11 @@ public class RestManager {
sources.addAll(TopicEndpoint.manager.getNoopTopicSources());
break;
default:
+ status = Status.BAD_REQUEST;
logger.debug("Invalid communication mechanism parameter: {}", comm);
break;
}
- return Response.status(Response.Status.OK).entity(sources).build();
+ return Response.status(status).entity(sources).build();
}
/**
@@ -1727,6 +1729,7 @@ public class RestManager {
@ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm
) {
List<TopicSink> sinks = new ArrayList<>();
+ Status status = Status.OK;
switch (CommInfrastructure.valueOf(comm.toUpperCase())) {
case UEB:
sinks.addAll(TopicEndpoint.manager.getUebTopicSinks());
@@ -1738,10 +1741,11 @@ public class RestManager {
sinks.addAll(TopicEndpoint.manager.getNoopTopicSinks());
break;
default:
+ status = Status.BAD_REQUEST;
logger.debug("Invalid communication mechanism parameter: {}", comm);
break;
}
- return Response.status(Response.Status.OK).entity(sinks).build();
+ return Response.status(status).entity(sinks).build();
}
@@ -1992,7 +1996,7 @@ public class RestManager {
}
/**
- * Offers and event to a topic in a communication infrastructure.
+ * Offers an event to a topic in a communication infrastructure.
*
* @return response object
*/