upgrade to 7.25.0.Final and update to new internal API and object of drools

This commit is contained in:
Nicolas Héron 2019-09-03 14:01:04 +02:00
commit cb36a81265
6 changed files with 36 additions and 24 deletions

View file

@ -22,7 +22,9 @@ import org.chtijbug.drools.entity.history.fact.InsertedFactHistoryEvent;
import org.chtijbug.drools.entity.history.fact.UpdatedFactHistoryEvent; import org.chtijbug.drools.entity.history.fact.UpdatedFactHistoryEvent;
import org.chtijbug.drools.runtime.DroolsFactObjectFactory; import org.chtijbug.drools.runtime.DroolsFactObjectFactory;
import org.drools.core.definitions.rule.impl.RuleImpl; import org.drools.core.definitions.rule.impl.RuleImpl;
import org.drools.core.event.rule.impl.RuleRuntimeEventImpl; import org.drools.core.event.rule.impl.ObjectDeletedEventImpl;
import org.drools.core.event.rule.impl.ObjectInsertedEventImpl;
import org.drools.core.event.rule.impl.ObjectUpdatedEventImpl;
import org.drools.core.spi.PropagationContext; import org.drools.core.spi.PropagationContext;
import org.kie.api.event.rule.ObjectDeletedEvent; import org.kie.api.event.rule.ObjectDeletedEvent;
import org.kie.api.event.rule.ObjectInsertedEvent; import org.kie.api.event.rule.ObjectInsertedEvent;
@ -32,6 +34,10 @@ import org.kie.api.runtime.rule.FactHandle;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
//import org.drools.core.definitions.rule.impl.RuleImpl;
//import org.drools.core.event.rule.impl.RuleRuntimeEventImpl;
//import org.drools.core.spi.PropagationContext;
public class FactHandlerListener implements RuleRuntimeEventListener { public class FactHandlerListener implements RuleRuntimeEventListener {
private static Logger logger = LoggerFactory.getLogger(FactHandlerListener.class); private static Logger logger = LoggerFactory.getLogger(FactHandlerListener.class);
@ -53,15 +59,13 @@ public class FactHandlerListener implements RuleRuntimeEventListener {
ruleBaseSession.setData(f, newObject, ff); ruleBaseSession.setData(f, newObject, ff);
//____ Adding the Insert Event from the History Container //____ Adding the Insert Event from the History Container
InsertedFactHistoryEvent insertFactHistoryEvent = new InsertedFactHistoryEvent(this.ruleBaseSession.nextEventId(), ff, this.ruleBaseSession.getRuleBaseID(), this.ruleBaseSession.getSessionId()); InsertedFactHistoryEvent insertFactHistoryEvent = new InsertedFactHistoryEvent(this.ruleBaseSession.nextEventId(), ff, this.ruleBaseSession.getRuleBaseID(), this.ruleBaseSession.getSessionId());
if (insertFactHistoryEvent.getRuleName() == null && event instanceof RuleRuntimeEventImpl) { if (insertFactHistoryEvent.getRuleName() == null && event instanceof ObjectInsertedEventImpl) {
PropagationContext propagationContext = ((RuleRuntimeEventImpl) event).getPropagationContext(); PropagationContext propagationContext = ((ObjectInsertedEventImpl) event).getPropagationContext();
this.updateRuleDetailFromPropagationContext(propagationContext, insertFactHistoryEvent); this.updateRuleDetailFromPropagationContext(propagationContext, insertFactHistoryEvent);
} }
this.ruleBaseSession.addHistoryElement(insertFactHistoryEvent); this.ruleBaseSession.addHistoryElement(insertFactHistoryEvent);
} finally } finally {
{
logger.debug("<<objectInserted"); logger.debug("<<objectInserted");
} }
@ -81,8 +85,8 @@ public class FactHandlerListener implements RuleRuntimeEventListener {
ruleBaseSession.setData(f, newValue, factNewValue); ruleBaseSession.setData(f, newValue, factNewValue);
//____ Adding the Update Event from the History Container //____ Adding the Update Event from the History Container
UpdatedFactHistoryEvent updatedFactHistoryEvent = new UpdatedFactHistoryEvent(this.ruleBaseSession.nextEventId(), factOldValue, factNewValue, this.ruleBaseSession.getRuleBaseID(), this.ruleBaseSession.getSessionId()); UpdatedFactHistoryEvent updatedFactHistoryEvent = new UpdatedFactHistoryEvent(this.ruleBaseSession.nextEventId(), factOldValue, factNewValue, this.ruleBaseSession.getRuleBaseID(), this.ruleBaseSession.getSessionId());
if (updatedFactHistoryEvent.getRuleName() == null && event instanceof RuleRuntimeEventImpl) { if (updatedFactHistoryEvent.getRuleName() == null && event instanceof ObjectUpdatedEventImpl) {
PropagationContext propagationContext = ((RuleRuntimeEventImpl) event).getPropagationContext(); PropagationContext propagationContext = ((ObjectUpdatedEventImpl) event).getPropagationContext();
this.updateRuleDetailFromPropagationContext(propagationContext, updatedFactHistoryEvent); this.updateRuleDetailFromPropagationContext(propagationContext, updatedFactHistoryEvent);
} }
this.ruleBaseSession.addHistoryElement(updatedFactHistoryEvent); this.ruleBaseSession.addHistoryElement(updatedFactHistoryEvent);
@ -103,8 +107,8 @@ public class FactHandlerListener implements RuleRuntimeEventListener {
//____ Adding a Delete Event from the HistoryContainer //____ Adding a Delete Event from the HistoryContainer
DeletedFactHistoryEvent deleteFactEvent = new DeletedFactHistoryEvent(this.ruleBaseSession.nextEventId(), deletedFact, this.ruleBaseSession.getRuleBaseID(), this.ruleBaseSession.getSessionId()); DeletedFactHistoryEvent deleteFactEvent = new DeletedFactHistoryEvent(this.ruleBaseSession.nextEventId(), deletedFact, this.ruleBaseSession.getRuleBaseID(), this.ruleBaseSession.getSessionId());
if (event instanceof RuleRuntimeEventImpl) { if (event instanceof ObjectDeletedEventImpl) {
PropagationContext propagationContext = ((RuleRuntimeEventImpl) event).getPropagationContext(); PropagationContext propagationContext = ((ObjectDeletedEventImpl) event).getPropagationContext();
this.updateRuleDetailFromPropagationContext(propagationContext, deleteFactEvent); this.updateRuleDetailFromPropagationContext(propagationContext, deleteFactEvent);
this.ruleBaseSession.addHistoryElement(deleteFactEvent); this.ruleBaseSession.addHistoryElement(deleteFactEvent);
} }
@ -114,11 +118,13 @@ public class FactHandlerListener implements RuleRuntimeEventListener {
} }
private void updateRuleDetailFromPropagationContext(PropagationContext propagationContext, FactHistoryEvent historyEvent) { private void updateRuleDetailFromPropagationContext(PropagationContext propagationContext, FactHistoryEvent historyEvent) {
if (propagationContext.getRuleOrigin() instanceof RuleImpl) { if (propagationContext.getRuleOrigin() != null
&& propagationContext.getRuleOrigin() instanceof RuleImpl) {
RuleImpl ruleOrigin = (RuleImpl) propagationContext.getRuleOrigin(); RuleImpl ruleOrigin = (RuleImpl) propagationContext.getRuleOrigin();
historyEvent.setRuleName(ruleOrigin.getName()); historyEvent.setRuleName(ruleOrigin.getName());
historyEvent.setRulePackageName(ruleOrigin.getPackageName()); historyEvent.setRulePackageName(ruleOrigin.getPackageName());
historyEvent.setRuleflowGroup(ruleOrigin.getRuleFlowGroup()); historyEvent.setRuleflowGroup(ruleOrigin.getRuleFlowGroup());
} }
} }
} }

View file

@ -46,6 +46,8 @@ import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.*; import java.util.*;
//import org.drools.core.definitions.rule.impl.RuleImpl;
/** /**
* @author nheron * @author nheron
*/ */

View file

@ -23,8 +23,8 @@ import org.chtijbug.drools.entity.history.rule.AfterRuleFlowActivatedHistoryEven
import org.chtijbug.drools.entity.history.rule.AfterRuleFlowDeactivatedHistoryEvent; import org.chtijbug.drools.entity.history.rule.AfterRuleFlowDeactivatedHistoryEvent;
import org.chtijbug.drools.entity.history.rule.BeforeRuleFiredHistoryEvent; import org.chtijbug.drools.entity.history.rule.BeforeRuleFiredHistoryEvent;
import org.chtijbug.drools.entity.history.session.SessionFireAllRulesMaxNumberReachedEvent; import org.chtijbug.drools.entity.history.session.SessionFireAllRulesMaxNumberReachedEvent;
import org.drools.core.common.DefaultFactHandle;
import org.drools.core.common.InternalFactHandle; import org.drools.core.common.InternalFactHandle;
import org.drools.core.reteoo.InitialFactImpl;
import org.kie.api.event.rule.*; import org.kie.api.event.rule.*;
import org.kie.api.runtime.KieRuntime; import org.kie.api.runtime.KieRuntime;
import org.kie.api.runtime.rule.FactHandle; import org.kie.api.runtime.rule.FactHandle;
@ -34,6 +34,9 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
//import org.drools.core.common.InternalFactHandle;
//import org.drools.core.reteoo.InitialFactImpl;
/** /**
* @author nheron * @author nheron
@ -86,16 +89,17 @@ public class RuleHandlerListener extends DefaultAgendaEventListener {
BeforeRuleFiredHistoryEvent newBeforeRuleEvent = new BeforeRuleFiredHistoryEvent(this.ruleBaseSession.nextEventId(), this.nbRuleFired + 1, droolsRuleObject, this.ruleBaseSession.getRuleBaseID(), this.ruleBaseSession.getSessionId()); BeforeRuleFiredHistoryEvent newBeforeRuleEvent = new BeforeRuleFiredHistoryEvent(this.ruleBaseSession.nextEventId(), this.nbRuleFired + 1, droolsRuleObject, this.ruleBaseSession.getRuleBaseID(), this.ruleBaseSession.getSessionId());
//____ Adding all objects info contained in the Activation object into the history Events //____ Adding all objects info contained in the Activation object into the history Events
for (FactHandle h : listFact) { for (FactHandle h : listFact) {
if (h instanceof InternalFactHandle) { if (h instanceof DefaultFactHandle) {
InternalFactHandle defaultFactHandle = (InternalFactHandle) h; InternalFactHandle defaultFactHandle = (InternalFactHandle) h;
//System.out.println(defaultFactHandle.toString()); //System.out.println(defaultFactHandle.toString());
if (defaultFactHandle.getObject() instanceof InitialFactImpl) { Object object = defaultFactHandle.getObject();
// org.drools.reteoo.InitialFactImpl initialFact = (org.drools.reteoo.InitialFactImpl)defaultFactHandle.getObject(); DroolsFactObject sourceFactObject = ruleBaseSession.getLastFactObjectVersionFromFactHandle(h);
//TODO in case of NOT, OR, etc.. newBeforeRuleEvent.getWhenObjects().add(sourceFactObject);
} else { } else {
DroolsFactObject sourceFactObject = ruleBaseSession.getLastFactObjectVersionFromFactHandle(h); DroolsFactObject sourceFactObject = ruleBaseSession.getLastFactObjectVersionFromFactHandle(h);
newBeforeRuleEvent.getWhenObjects().add(sourceFactObject); newBeforeRuleEvent.getWhenObjects().add(sourceFactObject);
}
} }
} }
//_____ Add Event into the History Container //_____ Add Event into the History Container

View file

@ -18,7 +18,7 @@ package org.chtijbug.drools.runtime.test
import org.chtijbug.drools.runtime.test.Fibonacci; import org.chtijbug.drools.runtime.test.Fibonacci;
dialect "mvel" dialect "java"
rule "infiniteLoop" rule "infiniteLoop"
when when

View file

@ -18,7 +18,7 @@ package org.chtijbug.drools.runtime.test
import org.chtijbug.drools.runtime.test.Fibonacci; import org.chtijbug.drools.runtime.test.Fibonacci;
dialect "mvel" dialect "java"
rule Recurse rule Recurse
when when

View file

@ -20,7 +20,7 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<properties> <properties>
<jbpm.version>7.23.0.Final</jbpm.version> <jbpm.version>7.25.0.Final</jbpm.version>
<spring.boot.version>2.1.2.RELEASE</spring.boot.version> <spring.boot.version>2.1.2.RELEASE</spring.boot.version>