Skip to content

Commit

Permalink
JBPM-10112: Expand class name of fundamental java classes if not defi… (
Browse files Browse the repository at this point in the history
#2200)

* JBPM-10112: Expand class name of fundamental java classes if not defined as FQCN to address org.xmlpull.v1.XmlPullParserException in VariableScope.validateVariable

* JBPM-10112: Handle date variable validation

* JBPM-10112: Remove cast to avoid ClassCastException
  • Loading branch information
martinweiler committed Aug 16, 2022
1 parent 2f4ff92 commit 9f1f74d
Show file tree
Hide file tree
Showing 4 changed files with 381 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.Map;

import com.thoughtworks.xstream.XStream;
Expand Down Expand Up @@ -81,15 +85,47 @@ public boolean verifyDataType(final Object value) {
}
try {
Class<?> clazz = Class.forName(className, true, value.getClass().getClassLoader());
if (clazz.isInstance(value)) {
if (clazz.isInstance(value) || isValidDate(value)) {
return true;
}
} catch (ClassNotFoundException e) {
return false;
// check class again
}
// try to expand fundamental classes if it's not a FQCN
if(!className.contains(".")) {
try {
className = "java.lang."+className;
Class<?> clazz = Class.forName(className, true, value.getClass().getClassLoader());
if (clazz.isInstance(value)) {
return true;
}
} catch (ClassNotFoundException e) {
return false;
}
}
return false;
}

private boolean isValidDate(Object value) {
boolean parseable = false;
try{
parseable = LocalDate.parse((String)value)!=null;
} catch(Exception e) {
// ignore parse exception
}
try{
parseable = LocalDateTime.parse((String)value)!=null;
} catch(Exception e) {
// ignore parse exception
}
try{
parseable = ZonedDateTime.parse((String)value)!=null;
} catch(Exception e) {
// ignore parse exception
}
return parseable;
}

public Object readValue(String value) {
return getXStream().fromXML(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public void prepare() {
processes.add("repo/processes/parentProcess/parentWithNotIndepententSubProcess.bpmn");
processes.add("repo/processes/parentProcess/subprocess.bpmn");
processes.add("repo/processes/general/SynchronousProcess.bpmn");
processes.add("repo/processes/general/MIProcess.bpmn");
processes.add("repo/processes/general/DateVariableTestProcess.bpmn");

InternalKieModule kJar1 = createKieJar(ks, releaseId, processes);
File pom = new File("target/kmodule", "pom.xml");
Expand Down Expand Up @@ -150,6 +152,45 @@ public void testStartProcess() {
assertNull(pi);
}

@Test
public void testStartMIProcessWithObjectVariable() {
assertNotNull(deploymentService);

KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);

deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
assertNotNull(processService);

long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "MIProcess");
assertNotNull(processInstanceId);

ProcessInstance pi = processService.getProcessInstance(processInstanceId);
assertNull(pi);
}

@Test
public void testStartProcessInstanceWithDateVariable() {
assertNotNull(deploymentService);

KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);

deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
assertNotNull(processService);

Map<String, Object> params = new HashMap<String, Object>();
params.put("timerIn", "6000000");
params.put("DateIn", "2002-07-08T23:17:00.000Z");


long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "DateVariableTestProcess", params);
assertNotNull(processInstanceId);

ProcessInstance pi = processService.getProcessInstance(processInstanceId);
assertNull(pi);
}

@Test
public void testStartProcessWithParms() {
assertNotNull(deploymentService);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:bpsim="http://www.bpsim.org/schemas/1.0" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:drools="http://www.jboss.org/drools" xmlns:xsi="xsi" id="_WYEpYPsVEDqMLbgzTznQgw" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org/schemas/1.0 bpsim.xsd http://www.omg.org/spec/DD/20100524/DC DC.xsd http://www.omg.org/spec/DD/20100524/DI DI.xsd " exporter="jBPM Process Modeler" exporterVersion="2.0" targetNamespace="http://www.omg.org/bpmn20">
<bpmn2:itemDefinition id="_integerInItem" structureRef="Integer"/>
<bpmn2:itemDefinition id="_booleanInItem" structureRef="Boolean"/>
<bpmn2:itemDefinition id="_stringInItem" structureRef="String"/>
<bpmn2:itemDefinition id="_timerInItem" structureRef="String"/>
<bpmn2:itemDefinition id="_DateInItem" structureRef="java.util.Date"/>
<bpmn2:collaboration id="_DEF1A7E1-4CC2-4924-8B1F-CDD4EF43F1E9" name="Default Collaboration">
<bpmn2:participant id="_B2A78040-3312-40DA-8A0E-515D7A8106EC" name="Pool Participant" processRef="DateVariableTestProcess"/>
</bpmn2:collaboration>
<bpmn2:process id="DateVariableTestProcess" drools:packageName="org.jbpm" drools:version="1.0" drools:adHoc="false" name="DateVariableTestProcess" isExecutable="true" processType="Public">
<bpmn2:property id="integerIn" itemSubjectRef="_integerInItem" name="integerIn"/>
<bpmn2:property id="booleanIn" itemSubjectRef="_booleanInItem" name="booleanIn"/>
<bpmn2:property id="stringIn" itemSubjectRef="_stringInItem" name="stringIn"/>
<bpmn2:property id="timerIn" itemSubjectRef="_timerInItem" name="timerIn"/>
<bpmn2:property id="DateIn" itemSubjectRef="_DateInItem" name="DateIn"/>
<bpmn2:sequenceFlow id="_7D18BF09-4F26-40EA-861C-7ACAB1513C54" sourceRef="processStartEvent" targetRef="_22D8FB9E-239E-4D9C-853C-1347E9C12CE7"/>
<bpmn2:sequenceFlow id="_0758DEB3-CEC9-4949-A667-5D5E00175FB1" sourceRef="_22D8FB9E-239E-4D9C-853C-1347E9C12CE7" targetRef="_83540C34-97AC-4A4D-82EC-9C281E956A71"/>
<bpmn2:startEvent id="processStartEvent" name="Attendre un Timer">
<bpmn2:extensionElements>
<drools:metaData name="elementname">
<drools:metaValue><![CDATA[Attendre un Timer]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
<bpmn2:outgoing>_7D18BF09-4F26-40EA-861C-7ACAB1513C54</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:scriptTask id="_22D8FB9E-239E-4D9C-853C-1347E9C12CE7" name="Script Node 1" scriptFormat="http://www.java.com/java">
<bpmn2:extensionElements>
<drools:metaData name="elementname">
<drools:metaValue><![CDATA[Script Node 1]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
<bpmn2:incoming>_7D18BF09-4F26-40EA-861C-7ACAB1513C54</bpmn2:incoming>
<bpmn2:outgoing>_0758DEB3-CEC9-4949-A667-5D5E00175FB1</bpmn2:outgoing>
<bpmn2:script>System.out.println("Timer Process Phase 1 " + timerIn);</bpmn2:script>
</bpmn2:scriptTask>
<bpmn2:endEvent id="_83540C34-97AC-4A4D-82EC-9C281E956A71" name="Timer Terminé">
<bpmn2:extensionElements>
<drools:metaData name="elementname">
<drools:metaValue><![CDATA[Timer Terminé]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
<bpmn2:incoming>_0758DEB3-CEC9-4949-A667-5D5E00175FB1</bpmn2:incoming>
</bpmn2:endEvent>
</bpmn2:process>
<bpmndi:BPMNDiagram>
<bpmndi:BPMNPlane bpmnElement="DateVariableTestProcess">
<bpmndi:BPMNShape id="shape__83540C34-97AC-4A4D-82EC-9C281E956A71" bpmnElement="_83540C34-97AC-4A4D-82EC-9C281E956A71">
<dc:Bounds height="56" width="56" x="500" y="165"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape__22D8FB9E-239E-4D9C-853C-1347E9C12CE7" bpmnElement="_22D8FB9E-239E-4D9C-853C-1347E9C12CE7">
<dc:Bounds height="79" width="99" x="272.5" y="154"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape_processStartEvent" bpmnElement="processStartEvent">
<dc:Bounds height="56" width="56" x="120" y="165"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="edge_shape__22D8FB9E-239E-4D9C-853C-1347E9C12CE7_to_shape__83540C34-97AC-4A4D-82EC-9C281E956A71" bpmnElement="_0758DEB3-CEC9-4949-A667-5D5E00175FB1">
<di:waypoint x="322" y="193.5"/>
<di:waypoint x="514" y="179"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge_shape_processStartEvent_to_shape__22D8FB9E-239E-4D9C-853C-1347E9C12CE7" bpmnElement="_7D18BF09-4F26-40EA-861C-7ACAB1513C54">
<di:waypoint x="135" y="180"/>
<di:waypoint x="272.5" y="193.5"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
<bpmn2:relationship type="BPSimData">
<bpmn2:extensionElements>
<bpsim:BPSimData>
<bpsim:Scenario id="default" name="Simulationscenario">
<bpsim:ScenarioParameters/>
<bpsim:ElementParameters elementRef="_22D8FB9E-239E-4D9C-853C-1347E9C12CE7">
<bpsim:TimeParameters>
<bpsim:ProcessingTime>
<bpsim:NormalDistribution mean="0" standardDeviation="0"/>
</bpsim:ProcessingTime>
</bpsim:TimeParameters>
<bpsim:ResourceParameters>
<bpsim:Availability>
<bpsim:FloatingParameter value="0"/>
</bpsim:Availability>
<bpsim:Quantity>
<bpsim:FloatingParameter value="0"/>
</bpsim:Quantity>
</bpsim:ResourceParameters>
<bpsim:CostParameters>
<bpsim:UnitCost>
<bpsim:FloatingParameter value="0"/>
</bpsim:UnitCost>
</bpsim:CostParameters>
</bpsim:ElementParameters>
<bpsim:ElementParameters elementRef="processStartEvent">
<bpsim:TimeParameters>
<bpsim:ProcessingTime>
<bpsim:UniformDistribution max="10" min="5"/>
</bpsim:ProcessingTime>
</bpsim:TimeParameters>
</bpsim:ElementParameters>
</bpsim:Scenario>
</bpsim:BPSimData>
</bpmn2:extensionElements>
<bpmn2:source>_WYEpYPsVEDqMLbgzTznQgw</bpmn2:source>
<bpmn2:target>_WYEpYPsVEDqMLbgzTznQgw</bpmn2:target>
</bpmn2:relationship>
</bpmn2:definitions>

0 comments on commit 9f1f74d

Please sign in to comment.