Skip to content

Commit

Permalink
[DROOLS-1353] contextual conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco committed Nov 11, 2016
1 parent e7ddc92 commit 610518c
Show file tree
Hide file tree
Showing 63 changed files with 492 additions and 505 deletions.
Expand Up @@ -15,21 +15,20 @@
*/
package org.jbpm.process.audit.command;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlTransient;

import org.drools.core.command.impl.FixedKnowledgeCommandContext;
import org.drools.core.command.impl.GenericCommand;
import org.drools.core.command.impl.KnowledgeCommandContext;
import org.drools.core.command.impl.ExecutableCommand;
import org.drools.core.command.impl.RegistryContext;
import org.jbpm.process.audit.AuditLogService;
import org.jbpm.process.audit.JPAAuditLogService;
import org.jbpm.process.audit.strategy.PersistenceStrategyType;
import org.kie.api.runtime.KieSession;
import org.kie.internal.command.Context;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlTransient;

@XmlAccessorType(XmlAccessType.NONE)
public abstract class AuditCommand<T> implements GenericCommand<T> {
public abstract class AuditCommand<T> implements ExecutableCommand<T> {

@XmlTransient
protected AuditLogService auditLogService = null;
Expand All @@ -45,11 +44,10 @@ protected void setLogEnvironment(Context cntxt) {
if( auditLogService != null ) {
return;
}
if( ! (cntxt instanceof KnowledgeCommandContext) ) {
if( ! (cntxt instanceof RegistryContext ) ) {
throw new UnsupportedOperationException("This command must be executed by a " + KieSession.class.getSimpleName() + " instance!");
}
KnowledgeCommandContext realContext = (FixedKnowledgeCommandContext) cntxt;
this.auditLogService = new JPAAuditLogService(realContext.getKieSession().getEnvironment(), PersistenceStrategyType.KIE_SESSION);
this.auditLogService = new JPAAuditLogService( ((RegistryContext) cntxt).lookup( KieSession.class ).getEnvironment(), PersistenceStrategyType.KIE_SESSION);
}

}
13 changes: 7 additions & 6 deletions jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/ActivityTest.java
Expand Up @@ -16,8 +16,8 @@
package org.jbpm.bpmn2;

import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession;
import org.drools.core.command.impl.GenericCommand;
import org.drools.core.command.impl.KnowledgeCommandContext;
import org.drools.core.command.impl.ExecutableCommand;
import org.drools.core.command.impl.RegistryContext;
import org.jbpm.bpmn2.handler.ReceiveTaskHandler;
import org.jbpm.bpmn2.handler.SendTaskHandler;
import org.jbpm.bpmn2.handler.ServiceTaskHandler;
Expand Down Expand Up @@ -421,10 +421,11 @@ public void testRuleTaskWithFactsWithPersistence() throws Exception {
"BPMN2-RuleTask3.drl");
ksession = createKnowledgeSession(kbase);

((KnowledgeCommandContext)
((RegistryContext)
((CommandBasedStatefulKnowledgeSession) ksession)
.getCommandService().getContext())
.getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
.lookup( KieSession.class )
.addEventListener(new TriggerRulesEventListener(ksession));
ksession.addEventListener(new DebugAgendaEventListener());
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "SomeString");
Expand Down Expand Up @@ -507,12 +508,12 @@ public void testUserTaskVerifyParameters() throws Exception {
assertEquals("john", workItem.getParameter("ActorId"));
final long pId = processInstance.getId();

ksession.execute(new GenericCommand<Void>() {
ksession.execute(new ExecutableCommand<Void>() {

@Override
public Void execute(Context context) {

KieSession ksession = ((KnowledgeCommandContext) context).getKieSession();
KieSession ksession = ((RegistryContext) context).lookup( KieSession.class );
ProcessInstance processInstance = ksession.getProcessInstance(pId);
assertNotNull(processInstance);
NodeInstance nodeInstance = ((WorkflowProcessInstance) processInstance)
Expand Down
35 changes: 14 additions & 21 deletions jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/FlowTest.java
Expand Up @@ -15,21 +15,8 @@

package org.jbpm.bpmn2;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.xml.parsers.DocumentBuilderFactory;

import org.drools.core.command.impl.GenericCommand;
import org.drools.core.command.impl.KnowledgeCommandContext;
import org.drools.core.command.impl.ExecutableCommand;
import org.drools.core.command.impl.RegistryContext;
import org.jbpm.bpmn2.objects.TestWorkItemHandler;
import org.jbpm.process.core.context.variable.VariableScope;
import org.jbpm.process.instance.context.variable.VariableScopeInstance;
Expand All @@ -47,11 +34,7 @@
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.kie.api.KieBase;
import org.kie.api.definition.process.Node;
import org.kie.api.event.process.DefaultProcessEventListener;
import org.kie.api.event.process.ProcessEventListener;
import org.kie.api.event.process.ProcessNodeEvent;
import org.kie.api.event.process.ProcessNodeLeftEvent;
import org.kie.api.event.process.ProcessNodeTriggeredEvent;
import org.kie.api.event.process.ProcessStartedEvent;
import org.kie.api.runtime.KieSession;
Expand All @@ -67,6 +50,16 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import javax.xml.parsers.DocumentBuilderFactory;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@RunWith(Parameterized.class)
public class FlowTest extends JbpmBpmn2TestCase {

Expand Down Expand Up @@ -1562,7 +1555,7 @@ public void testTimerAndGateway() throws Exception {
assertProcessInstanceCompleted(instance);
}

private static class GetProcessVariableCommand implements GenericCommand<Object> {
private static class GetProcessVariableCommand implements ExecutableCommand<Object> {

private long processInstanceId;
private String variableName;
Expand All @@ -1575,7 +1568,7 @@ public GetProcessVariableCommand(long processInstanceId, String variableName) {


public Object execute(Context context) {
KieSession ksession = ((KnowledgeCommandContext) context).getKieSession();
KieSession ksession = ((RegistryContext) context).lookup( KieSession.class );

org.jbpm.process.instance.ProcessInstance processInstance =
(org.jbpm.process.instance.ProcessInstance) ksession.getProcessInstance(processInstanceId);
Expand Down
45 changes: 22 additions & 23 deletions jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java
Expand Up @@ -15,21 +15,9 @@

package org.jbpm.bpmn2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession;
import org.drools.core.command.impl.GenericCommand;
import org.drools.core.command.impl.KnowledgeCommandContext;
import org.drools.core.command.impl.ExecutableCommand;
import org.drools.core.command.impl.RegistryContext;
import org.drools.core.common.InternalKnowledgeRuntime;
import org.drools.core.impl.StatefulKnowledgeSessionImpl;
import org.drools.core.process.instance.WorkItemHandler;
Expand Down Expand Up @@ -77,6 +65,17 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

@RunWith(Parameterized.class)
public class IntermediateEventTest extends JbpmBpmn2TestCase {

Expand Down Expand Up @@ -119,8 +118,8 @@ public void dispose() {
private TimerManager getTimerManager(KieSession ksession) {
KieSession internal = ksession;
if (ksession instanceof CommandBasedStatefulKnowledgeSession) {
internal = ((KnowledgeCommandContext) ((CommandBasedStatefulKnowledgeSession) ksession)
.getCommandService().getContext()).getKieSession();
internal = ((RegistryContext) ((CommandBasedStatefulKnowledgeSession) ksession)
.getCommandService().getContext()).lookup( KieSession.class );
}

return ((InternalProcessRuntime)((StatefulKnowledgeSessionImpl)internal).getProcessRuntime()).getTimerManager();
Expand Down Expand Up @@ -1525,10 +1524,10 @@ public void testIntermediateCatchEventTimerCycleWithErrorWithPersistence() throw


final long piId = processInstance.getId();
ksession.execute(new GenericCommand<Void>() {
ksession.execute(new ExecutableCommand<Void>() {

public Void execute(Context context) {
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((KnowledgeCommandContext) context).getKieSession();
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup( KieSession.class );
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.getProcessInstance(piId);
processInstance.setVariable("x", 0);
return null;
Expand All @@ -1539,10 +1538,10 @@ public Void execute(Context context) {
countDownListener.waitTillCompleted();
assertProcessInstanceActive(processInstance);

Integer xValue = ksession.execute(new GenericCommand<Integer>() {
Integer xValue = ksession.execute(new ExecutableCommand<Integer>() {

public Integer execute(Context context) {
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((KnowledgeCommandContext) context).getKieSession();
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup( KieSession.class );
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.getProcessInstance(piId);
return (Integer) processInstance.getVariable("x");

Expand Down Expand Up @@ -1741,7 +1740,7 @@ public void testEventTypesLifeCycle() throws Exception {
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ksession.startProcess("BPMN2-IntermediateCatchSignalBetweenUserTasks");

int signalListSize = ksession.execute(new GenericCommand<Integer>() {
int signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
public Integer execute(Context context) {
SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession)
.getCommandService();
Expand All @@ -1760,7 +1759,7 @@ public Integer execute(Context context) {

ksession.getWorkItemManager().completeWorkItem(1, null);

signalListSize = ksession.execute(new GenericCommand<Integer>() {
signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
public Integer execute(Context context) {
SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession)
.getCommandService();
Expand All @@ -1779,7 +1778,7 @@ public Integer execute(Context context) {

ksession.signalEvent("MySignal", null);

signalListSize = ksession.execute(new GenericCommand<Integer>() {
signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
public Integer execute(Context context) {
SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession)
.getCommandService();
Expand Down
Expand Up @@ -16,8 +16,8 @@
package org.jbpm.bpmn2.persistence;

import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession;
import org.drools.core.command.impl.GenericCommand;
import org.drools.core.command.impl.KnowledgeCommandContext;
import org.drools.core.command.impl.ExecutableCommand;
import org.drools.core.command.impl.RegistryContext;
import org.jbpm.bpmn2.JbpmBpmn2TestCase;
import org.jbpm.compiler.xml.XmlRuleFlowProcessDumper;
import org.jbpm.persistence.session.objects.TestWorkItemHandler;
Expand All @@ -38,6 +38,7 @@
import org.kie.api.event.process.ProcessStartedEvent;
import org.kie.api.event.process.ProcessVariableChangedEvent;
import org.kie.api.io.Resource;
import org.kie.api.runtime.KieSession;
import org.kie.internal.command.Context;
import org.kie.internal.io.ResourceFactory;
import org.kie.internal.runtime.StatefulKnowledgeSession;
Expand Down Expand Up @@ -117,9 +118,9 @@ public void afterNodeLeft(ProcessNodeLeftEvent arg0) {
node.setId(4);
insertNodeInBetween(process, 2, 3, node);

((CommandBasedStatefulKnowledgeSession) ksession).getCommandService().execute(new GenericCommand<Void>() {
((CommandBasedStatefulKnowledgeSession) ksession).getCommandService().execute(new ExecutableCommand<Void>() {
public Void execute(Context context) {
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((KnowledgeCommandContext) context).getKieSession();
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup( KieSession.class );
((ProcessInstanceImpl) ksession.getProcessInstance(processInstance.getId())).updateProcess(process);
return null;
}
Expand Down

0 comments on commit 610518c

Please sign in to comment.