Skip to content

Commit

Permalink
fix miscelanea stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian committed Jun 10, 2024
1 parent 11e44e1 commit 359ad7f
Show file tree
Hide file tree
Showing 23 changed files with 306 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.jbpm.bpmn2.core.Lane;
import org.jbpm.bpmn2.core.SequenceFlow;
import org.jbpm.bpmn2.core.Signal;
import org.jbpm.compiler.canonical.builtin.ReturnValueEvaluatorBuilderService;
import org.jbpm.compiler.xml.Handler;
import org.jbpm.compiler.xml.Parser;
import org.jbpm.compiler.xml.ProcessBuildData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ protected Expression toTransformation(NodeImpl node, DataAssociationType type, L
}

Expression lang = new StringLiteralExpr(transformation.getLanguage());
Expression expression = new StringLiteralExpr(transformation.getExpression());
Expression expression = new StringLiteralExpr(sanitizeString(transformation.getExpression()));

ContextResolver contextResolver = type.equals(DataAssociationType.INPUT) ? node : wrapContextResolver(node, inputs);

Expand Down Expand Up @@ -396,7 +396,7 @@ public static LambdaExpr buildCompensationLambdaExpr(String compensationRef) {
}

protected ObjectCreationExpr buildProducerAction(Node node, ProcessMetaData metadata) {
TriggerMetaData trigger = TriggerMetaData.of(node);
TriggerMetaData trigger = TriggerMetaData.of(node, (String) node.getMetaData().get(Metadata.MAPPING_VARIABLE_INPUT));
return buildProducerAction(parseClassOrInterfaceType(ProduceEventAction.class.getCanonicalName()).setTypeArguments(NodeList.nodeList(parseClassOrInterfaceType(trigger.getDataType()))),
trigger, metadata);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public Object eval(Function<String, Object> resolver) {

@Override
public boolean isResolveable(String name) {
return resolver.apply("#{" + name + "}") != null;
return resolver.apply(name) != null;
};

@Override
public VariableResolver getVariableResolver(String name) {
return new SimpleValueResolver(resolver.apply("#{" + name + "}"));
return new SimpleValueResolver(resolver.apply(name));
};
};
return MVEL.eval(expression, factory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
package org.jbpm.process.instance.impl.actions;

import java.io.Serializable;
import java.util.Map;
import java.util.function.Supplier;

import org.drools.core.common.InternalKnowledgeRuntime;
import org.jbpm.process.instance.InternalProcessRuntime;
import org.jbpm.process.instance.impl.Action;
import org.jbpm.workflow.core.impl.NodeIoHelper;
import org.jbpm.workflow.instance.impl.NodeInstanceImpl;
import org.kie.kogito.event.impl.MessageProducer;
import org.kie.kogito.internal.process.runtime.KogitoProcessContext;
import org.kie.kogito.internal.process.runtime.KogitoProcessInstance;
Expand All @@ -44,7 +47,8 @@ public ProduceEventAction(String triggerName, String varName, Supplier<MessagePr

@Override
public void execute(KogitoProcessContext context) throws Exception {
Object object = context.getVariable(varName);
Map<String, Object> inputs = NodeIoHelper.processInputs((NodeInstanceImpl) context.getNodeInstance(), var -> context.getVariable(var));
Object object = inputs.get(varName);
KogitoProcessInstance pi = context.getProcessInstance();
InternalKnowledgeRuntime runtime = (InternalKnowledgeRuntime) context.getKieRuntime();
InternalProcessRuntime process = (InternalProcessRuntime) runtime.getProcessRuntime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<bpmn2:scriptTask id="_4" name="Event">
<bpmn2:incoming>_3-_4</bpmn2:incoming>
<bpmn2:outgoing>_4-_5</bpmn2:outgoing>
<bpmn2:script>kcontext.getKieRuntime().getGlobal(&quot;TestOK&quot;).toString();
</bpmn2:script>
<bpmn2:script>kcontext.setVariable("TestOK", Boolean.TRUE);
</bpmn2:script>
</bpmn2:scriptTask>
<bpmn2:endEvent id="_5" name="EndProcess">
<bpmn2:incoming>_4-_5</bpmn2:incoming>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
<startEvent id="_1" name="StartProcess" />
<serviceTask id="_2" name="Hello" operationRef="_2_ServiceOperation" implementation="Other" >
<ioSpecification>
<dataInput id="_2_param" name="Parameter" />
<dataOutput id="_2_result" name="Result" />
<dataInput id="_2_param" name="Parameter" itemSubjectRef="_sItem"/>
<dataOutput id="_2_result" name="Result" itemSubjectRef="_sItem"/>
<inputSet>
<dataInputRefs>_2_param</dataInputRefs>
</inputSet>
Expand All @@ -70,7 +70,7 @@
<dataOutputAssociation>
<sourceRef>_2_result</sourceRef>
<targetRef>list</targetRef>
<transformation language="http://www.mvel.org/2.0">Arrays.asList(Result.split(","))</transformation>
<transformation language="http://www.mvel.org/2.0">java.util.Arrays.asList(Result.split(","))</transformation>
</dataOutputAssociation>
</serviceTask>
<endEvent id="_3" name="EndProcess" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<serviceTask id="_2" name="Hello" operationRef="_2_ServiceOperation" implementation="Other" >
<ioSpecification>
<dataInput id="_2_param" name="Parameter" />
<dataOutput id="_2_result" name="Result" />
<dataOutput id="_2_result" name="Result" itemSubjectRef="_2_InMessageType"/>
<inputSet>
<dataInputRefs>_2_param</dataInputRefs>
</inputSet>
Expand All @@ -67,18 +67,28 @@
<dataInputAssociation>
<sourceRef>s</sourceRef>
<targetRef>_2_param</targetRef>
<transformation language="http://www.mvel.org/2.0"><![CDATA[
<transformation language="java"><![CDATA[
try {
StringWriter result = new java.io.StringWriter();
JAXBContext.newInstance(Person, Address).createMarshaller().marshal(s, result);
return result.toString();]]>
JAXBContext.newInstance(Person.class, Address.class).createMarshaller().marshal(s, result);
return result.toString();
} catch(Throwable th) {
throw new RuntimeException(th);
}
]]>
</transformation>
</dataInputAssociation>
<dataOutputAssociation>
<sourceRef>_2_result</sourceRef>
<targetRef>s</targetRef>
<transformation language="http://www.mvel.org/2.0"><![CDATA[
StringReader result = new java.io.StringReader(Result);
return JAXBContext.newInstance(Person, Address).createUnmarshaller().unmarshal(result);]]>
<transformation language="java"><![CDATA[
try {
StringReader result = new java.io.StringReader(Result);
return JAXBContext.newInstance(Person.class, Address.class).createUnmarshaller().unmarshal(result);
} catch(Throwable th) {
throw new RuntimeException(th);
}
]]>
</transformation>
</dataOutputAssociation>
</serviceTask>
Expand Down
79 changes: 46 additions & 33 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
import org.jbpm.bpmn2.objects.HelloService;
import org.jbpm.bpmn2.objects.Person;
import org.jbpm.bpmn2.objects.TestWorkItemHandler;
import org.jbpm.bpmn2.service.ServiceProcessWithMvelCollectionTransformationModel;
import org.jbpm.bpmn2.service.ServiceProcessWithMvelCollectionTransformationProcess;
import org.jbpm.bpmn2.service.ServiceProcessWithMvelJaxbTransformationModel;
import org.jbpm.bpmn2.service.ServiceProcessWithMvelJaxbTransformationProcess;
import org.jbpm.bpmn2.service.ServiceProcessWithMvelTransformationModel;
import org.jbpm.bpmn2.service.ServiceProcessWithMvelTransformationProcess;
import org.jbpm.bpmn2.subprocess.AssignmentProcessModel;
import org.jbpm.bpmn2.subprocess.AssignmentProcessProcess;
import org.jbpm.bpmn2.subprocess.AssignmentSubProcessModel;
Expand Down Expand Up @@ -136,6 +142,8 @@
import org.kie.api.runtime.process.NodeInstance;
import org.kie.kogito.Application;
import org.kie.kogito.auth.SecurityPolicy;
import org.kie.kogito.handlers.HelloService_hello__2_Handler;
import org.kie.kogito.handlers.HelloService_validate__2_Handler;
import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener;
import org.kie.kogito.internal.process.runtime.KogitoNode;
import org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer;
Expand Down Expand Up @@ -829,20 +837,6 @@ public void executeWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkIt
assertThat(processInstance.getVariable("s")).isEqualTo("Hello john!");
}

@Test
public void testServiceTaskWithMvelTransformation() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcessWithMvelTransformation.bpmn2");

kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task",
new ServiceTaskHandler());
Map<String, Object> params = new HashMap<>();
params.put("s", "JoHn");
KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime
.startProcess("ServiceProcessWithMvelTransformation", params);
assertProcessInstanceFinished(processInstance, kruntime);
assertThat(processInstance.getVariable("s")).isEqualTo("hello john!");
}

@Test
public void testServiceTaskNoInterfaceName() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-ServiceTask-web-service.bpmn2");
Expand Down Expand Up @@ -1197,39 +1191,58 @@ public void beforeProcessStarted(ProcessStartedEvent event) {
assertThat(((KogitoWorkflowProcessInstance) instances.get(1)).getVariable("subY")).isEqualTo("new value");
}

@Test
public void testServiceTaskWithMvelTransformation() throws Exception {
Application app = ProcessTestHelper.newApplication();
ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.HelloService_hello__2_Handler", new HelloService_hello__2_Handler());
org.kie.kogito.process.Process<ServiceProcessWithMvelTransformationModel> definition = ServiceProcessWithMvelTransformationProcess.newProcess(app);
ServiceProcessWithMvelTransformationModel model = definition.createModel();

model.setS("JoHn");

org.kie.kogito.process.ProcessInstance<ServiceProcessWithMvelTransformationModel> instance = definition.createInstance(model);
instance.start();

assertThat(instance.variables().getS()).isEqualTo("hello john!");

}

@Test
public void testServiceTaskWithMvelCollectionTransformation() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2");

kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task",
new ServiceTaskHandler());
Map<String, Object> params = new HashMap<>();
params.put("s", "john,poul,mary");
KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime
.startProcess("ServiceProcess", params);
assertProcessInstanceFinished(processInstance, kruntime);
@SuppressWarnings("unchecked")
List<String> result = (List<String>) processInstance.getVariable("list");
Application app = ProcessTestHelper.newApplication();
ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.HelloService_hello__2_Handler", new HelloService_hello__2_Handler());
org.kie.kogito.process.Process<ServiceProcessWithMvelCollectionTransformationModel> definition = ServiceProcessWithMvelCollectionTransformationProcess.newProcess(app);
ServiceProcessWithMvelCollectionTransformationModel model = definition.createModel();

model.setS("john,poul,mary");

org.kie.kogito.process.ProcessInstance<ServiceProcessWithMvelCollectionTransformationModel> instance = definition.createInstance(model);
instance.start();

List<String> result = (List<String>) instance.variables().getList();
assertThat(result).hasSize(3);

}

@Test
public void testServiceTaskWithMvelJaxbTransformation() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2");
HelloService.VALIDATE_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><person><id>123</id><name>john</name></person>";

Application app = ProcessTestHelper.newApplication();
ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.HelloService_validate__2_Handler", new HelloService_validate__2_Handler());
org.kie.kogito.process.Process<ServiceProcessWithMvelJaxbTransformationModel> definition = ServiceProcessWithMvelJaxbTransformationProcess.newProcess(app);
ServiceProcessWithMvelJaxbTransformationModel model = definition.createModel();

kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task",
new ServiceTaskHandler());
Map<String, Object> params = new HashMap<>();
Person person = new Person();
person.setId(123);
person.setName("john");
params.put("s", person);
model.setS(person);

HelloService.VALIDATE_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><person><id>123</id><name>john</name></person>";
org.kie.kogito.process.ProcessInstance<ServiceProcessWithMvelJaxbTransformationModel> instance = definition.createInstance(model);
instance.start();

KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime
.startProcess("ServiceProcessWithMvelJaxbTransformation", params);
assertProcessInstanceFinished(processInstance, kruntime);
assertThat(instance.status()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED);

}

Expand Down
Loading

0 comments on commit 359ad7f

Please sign in to comment.