Process Compilation error : org.drools.lang.descr.ProcessDescr#4c60d6e9
com/sample/Process_com_sample_ruleflowsample.java (21:862) : Type mismatch: cannot convert from int to String
com/sample/Process_com_sample_ruleflowsample.java (29:1151) : Type mismatch: cannot convert from int to String
This is my ruleflowsample.rf under src/main/rules that is throwing the above error.
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
type="RuleFlow" name="ruleflowsample" id="com.sample.ruleflowsample" package-name="com.sample" >
<header>
<imports>
<import name="com.sample.Employee" />
</imports>
<variables>
<variable name="caffeineIntake" >
<type name="org.drools.process.core.datatype.impl.type.FloatDataType" />
</variable>
</variables>
</header>
<nodes>
<start id="1" name="Start" x="12" y="129" width="48" height="48" />
<split id="2" name="Gateway" x="101" y="128" width="49" height="49" type="2" >
<constraints>
<constraint toNodeId="4" toType="DROOLS_DEFAULT" name="Coffee" priority="1" type="code" dialect="java" >return caffeineIntake>0.105F;</constraint>
<constraint toNodeId="5" toType="DROOLS_DEFAULT" name="Tea" priority="1" type="code" dialect="java" >return caffeineIntake>0.04F;</constraint>
</constraints>
</split>
<actionNode id="4" name="Coffee" x="198" y="205" width="80" height="48" >
<action type="expression" dialect="java" >String noOfCups = 1;
System.out.println("No of coffee cups = "+noOfCups);
System.out.println("caffeineIntake");</action>
</actionNode>
<actionNode id="5" name="Tea" x="196" y="61" width="80" height="48" >
<action type="expression" dialect="java" >String noOfCups = 1;
System.out.println("No of tea cups = "+noOfCups);
System.out.println("caffeineIntake");</action>
</actionNode>
<end id="6" name="End" x="386" y="127" width="48" height="48" />
<join id="7" name="Gateway" x="311" y="127" width="49" height="49" type="2" />
</nodes>
<connections>
<connection from="1" to="2" />
<connection from="2" to="4" />
<connection from="2" to="5" />
<connection from="7" to="6" />
<connection from="5" to="7" />
<connection from="4" to="7" />
</connections>
</process>
I know the error is occurring because of this line: System.out.println("caffeineIntake");
I want to access this input variable i.e. caffeineIntake to perform some operation on it.
The error is not occurring because of this line: System.out.println("caffeineIntake");
It is occurring because of the Dialect option selection:
Using this option as mvel rather than java resolved the issue.
Well,
from my point of view
String noOfCups = 1;
is the problem.
perhaps change it to
String noOfCups = "1";
Related
I am having trouble with getting specific information from my xml using stax. Inside my xml I have a current and average which both have a traveltime inside them. But I only want to get the traveltime from the current and not from the average. Here is how my xml looks like:
<allroutes>
<routes>
<route identification="id_1">
<current>
<traveltime time="1187" trustworthy="j" />
<delay time="0" trustworthy="j" />
</current>
<average>
<traveltime time="1187" trustworthy="j" />
<delay time="0" trustworthy="j" />
</average>
</route>
<route identification="id_2">
<current>
<traveltime time="995" trustworthy="j" />
<delay time="0" trustworthy="j" />
</current>
<average>
<traveltime time="995" trustworthy="j" />
<delay time="0" trustworthy="j" />
</average>
</route>
</routes>
<subpaths>
<subpath identification="id_1">
<current>
<traveltime time="0" trustworthy="n" />
<delay time="0" trustworthy="n" />
</current>
<average>
<traveltime time="0" trustworthy="n" />
<delay time="0" trustworthy="n" />
</average>
</subpath>
<subpath identification="id_2">
<current>
<traveltime time="0" trustworthy="n" />
<delay time="0" trustworthy="n" />
</current>
<average>
<traveltime time="0" trustworthy="n" />
<delay time="0" trustworthy="n" />
</average>
</subpath>
</subpaths>
</allroutes>
The code that I have currently looks like this:
try{
while (streamReader.hasNext()) {
streamReader.next();
if (streamReader.getEventType() == XMLStreamReader.START_ELEMENT) {
switch (streamReader.getLocalName()) {
case "route":
//store which type
break;
case "subpath":
//store which type
break;
case "traveltime":
//store traveltime
break;
}
}
if (streamReader.getEventType() == XMLStreamReader.END_ELEMENT && "allroutes".equals(streamReader.getLocalName())) {
//stop the loop and give back the object
}
}
}catch(XMLStreamException ex) {
LOGGER.log(Level.SEVERE, "XMLStreamException: " + ex);
}
What do I need to add / change to only get the traveltime from 'current' inside this reader?
You just have to keep track of where you are in the document. For example, it's common practice to keep a stack of element names: push a name onto the stack when you hit a startElement, pop it off when you hit endElement, and then inspect the stack to discover the context of the element you are currently processing.
I had recently installed java adopt JDK 1.8.0_202 version.
It worked fine for the first time and later when i start hybris server getting the below issue again & again on console :
JVMJ9GC063E Unable to open file '/opt/hybris/log/tomcat/java_gc_ger-d-maa-apsp-001.log' for writing
<allocation-stats totalBytes="223210880" >
<allocated-bytes non-tlh="13688" tlh="223197192" />
<largest-consumer threadName="localhost-startStop-1" threadId="0000000002F7B000" bytes="217285784" />
</allocation-stats>
<gc-op id="2563" type="scavenge" timems="53.990" contextid="2560" timestamp="2019-03-14T15:18:57.791">
<scavenger-info tenureage="14" tenuremask="4000" tiltratio="88" />
<memory-copied type="nursery" objects="394430" bytes="16048744" bytesdiscarded="115760" />
<finalization candidates="204" enqueued="174" />
<ownableSynchronizers candidates="3195" cleared="7" />
<references type="soft" candidates="9645" cleared="0" enqueued="0" dynamicThreshold="32" maxThreshold="32" />
<references type="weak" candidates="6673" cleared="84" enqueued="67" />
</gc-op>
<gc-end id="2564" type="scavenge" contextid="2560" durationms="54.398" usertimems="46.801" systemtimems="0.000" timestamp="2019-03-14T15:18:57.791" activeThreads="2">
<mem-info id="2565" free="564246568" total="1073741824" percent="52">
<mem type="nursery" free="224266520" total="268435456" percent="83">
<mem type="allocate" free="224266520" total="240451584" percent="93" />
<mem type="survivor" free="0" total="27983872" percent="0" />
</mem>
<mem type="tenure" free="339980048" total="805306368" percent="42" macro-fragmented="3110739">
<mem type="soa" free="299715344" total="765041664" percent="39" />
<mem type="loa" free="40264704" total="40264704" percent="100" />
</mem>
<pending-finalizers system="174" default="0" reference="67" classloader="0" />
<remembered-set count="33247" />
</mem-info>
</gc-end>
<cycle-end id="2566" type="scavenge" contextid="2560" timestamp="2019-03-14T15:18:57.792" />
<allocation-satisfied id="2567" threadId="0000000002F7B000" bytesRequested="48" />
<af-end id="2568" timestamp="2019-03-14T15:18:57.792" threadId="0000000002F7B988" success="true" from="nursery"/>
<exclusive-end id="2569" timestamp="2019-03-14T15:18:57.792" durationms="55.438" />
<exclusive-start id="2570" timestamp="2019-03-14T15:19:06.478" intervalms="8740.918">
<response-info timems="0.039" idlems="0.039" threads="0" lastid="0000000002F7B000" lastname="localhost-startStop-1" />
</exclusive-start>
<af-start id="2571" threadId="0000000002F7B988" totalBytesRequested="24" timestamp="2019-03-14T15:19:06.478" intervalms="8740.939" type="nursery" />
<cycle-start id="2572" type="scavenge" contextid="0" timestamp="2019-03-14T15:19:06.478" intervalms="8740.941" />
<gc-start id="2573" type="scavenge" contextid="2572" timestamp="2019-03-14T15:19:06.479">
<mem-info id="2574" free="339975744" total="1073741824" percent="31">
<mem type="nursery" free="0" total="268435456" percent="0">
<mem type="allocate" free="0" total="240451584" percent="0" />
<mem type="survivor" free="0" total="27983872" percent="0" />
</mem>
<mem type="tenure" free="339975744" total="805306368" percent="42">
<mem type="soa" free="299711040" total="765041664" percent="39" />
<mem type="loa" free="40264704" total="40264704" percent="100" />
</mem>
<remembered-set count="34712" />
</mem-info>
</gc-start>
Any help would be appreciated?
Thanks,
Mohammed
This logs produced by -verbose:gc (or similar) JVM option.
You should remove that option if you don't need this logs.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xml>
<Settings version="3" xmlns="urn:Adapter-v3">
<Connections>
<Connection name ="A" description="DEV">
<SaveVersion version="M" siteURL="https://example.com" />
<Save>
<Id>id123</Id>
<Client>hello</Client>
</Save>
</Connection>
<Connection name ="B" description="DEV1">
<SaveVersion version="M" siteURL="https://example.com" />
<Auth>
<UserId>id123</UserId>
<Password>pass</Password>
</Auth>
</Connection>
</Connections>
<Mappings>
<Mapping cont="AA" auction="A1">
<Description>Desc</Description>
<Content
attr1="IO"
attr2="d"
attr3="Information"
attr4="false"
<Element enabled="false" count="200" prefix="DocLib_" itemPrefix="0" />
<Sub enabled="false" count="100" prefix="Folder_" itemPrefix="0" />
<FilenameA auction="N" delay="3" />
</Content>
</Mapping>
<Mapping cont="AB" auction="SharePointOLDev1">
<Description>Desc</Description>
<Content
attr1="IO"
attr2="d"
attr3="Information"
attr4="false"
<Element enabled="false" count="200" prefix="DocLib_" itemPrefix="0" />
<Sub enabled="false" count="100" prefix="1" itemPrefix="0" />
</Content>
</Mapping>
</Mappings>
<TypeMappings>
<TypeMapping Type="rfid" ext="msg" />
</TypeMappings>
</Settings>
Trying to unmarshal the above xml file to java objects.
Generated Settings.java and ObjectFactory.java file using xjc tool.These files are deployed in the src folder(along with other java files.)
WHen i unmarshal i get null valuues for Connections,Mappings and TypeMappings.
Is there any steps that i am missing?
public class JAXBImpl{
public static void main(String args[]){
JAXBContext jaxbContext;
Settings que= null;
jaxbContext = JAXBContext.newInstance(Settings.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
que= (Settings) jaxbUnmarshaller.unmarshal(file);
System.out.println(que.getConnections().getConnection());
}
}
We're going to build a workflow management system and We're embedding the camunda engine Rest API into our Rest Application.
Now I have Inventory defined like this:
public class Inventory {
private String objectName;
private int objectCount;
// getters and setters
}
and this is a sample workflow:
in xml:
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.11.3">
<bpmn:process id="test" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_1v6clcy</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="SequenceFlow_1v6clcy" sourceRef="StartEvent_1" targetRef="testtask" />
<bpmn:userTask id="testtask" name="testtask" camunda:formKey="testform">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="inventories" label="name" type="List<org.example.Inventory>" />
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_1v6clcy</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_07kdfp4</bpmn:outgoing>
</bpmn:userTask>
<bpmn:endEvent id="EndEvent_0vm605w">
<bpmn:incoming>SequenceFlow_07kdfp4</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_07kdfp4" sourceRef="testtask" targetRef="EndEvent_0vm605w" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="test">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="173" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1v6clcy_di" bpmnElement="SequenceFlow_1v6clcy">
<di:waypoint xsi:type="dc:Point" x="209" y="120" />
<di:waypoint xsi:type="dc:Point" x="275" y="120" />
<bpmndi:BPMNLabel>
<dc:Bounds x="242" y="99" width="0" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="UserTask_1s01hea_di" bpmnElement="testtask">
<dc:Bounds x="275" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_0vm605w_di" bpmnElement="EndEvent_0vm605w">
<dc:Bounds x="439" y="109" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="412" y="149" width="90" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_07kdfp4_di" bpmnElement="SequenceFlow_07kdfp4">
<di:waypoint xsi:type="dc:Point" x="375" y="120" />
<di:waypoint xsi:type="dc:Point" x="407" y="120" />
<di:waypoint xsi:type="dc:Point" x="407" y="127" />
<di:waypoint xsi:type="dc:Point" x="439" y="127" />
<bpmndi:BPMNLabel>
<dc:Bounds x="377" y="117.5" width="90" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
I'll eventually have a html form which will submit something like this:
{
"inventories" : [{"name": "banana","count": 3},{"name":"orange","count": 4}]
}
I want to submit this to /task/{id}/submit-form but I don't know what to put as type.
I tried putting the type in modeler as List<org.example.Inventory> but the rest api throws an exception when deploying the process definition like this:
org.camunda.bpm.engine.ProcessEngineException: ENGINE-09005 Could not parse BPMN process. Errors:
* unknown type 'List' | org.example/PM.bpmn | line 65 | column 90
I've seen this example as well but I'm only using the Rest API not the whole bpm platform(besides we prefer to have pure html forms).
So how to do it ? what should I put in type ?
my camunda.cfg.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="processEngineConfiguration" class="org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
<property name="jdbcDriver" value="org.h2.Driver" />
<property name="jdbcUsername" value="sa" />
<property name="jdbcPassword" value="" />
<property name="databaseSchemaUpdate" value="true" />
</bean>
</beans>
my processengineprovider:
public class MyProcessEngineProvider implements ProcessEngineProvider {
#Override
public ProcessEngine getDefaultProcessEngine() {
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = engine.getRepositoryService();
repositoryService.createDeployment()
.addClasspathResource("org.newtech/PM.bpmn")
.deploy();
return engine;
}
#Override
public ProcessEngine getProcessEngine(String s) {
return getDefaultProcessEngine();
}
#Override
public Set<String> getProcessEngineNames() {
Set<String> names = new HashSet<>(1);
names.add("default");
return names;
}
}
I have an xml as shown below.
<?xml version="1.0" encoding="utf-8"?>
<package date-created="11/4/2014" client-version="blah" system-version="blah">
<description />
<system>
<language />
</system>
<res id="blah" name="name" path="path" type="F" mimeType="mimetype-blah">
<description />
<keywords />
<resver id="1690047800" major="50" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
<resver id="1690167421" major="68" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
<resver id="1690176842" major="71" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
</res>
<res id="blah1" name="name1" path="path1" type="F" mimeType="mimetype-blah1">
<description />
<keywords />
<resver id="1690145841" major="34" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
<resver id="1690161885" major="64" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
<resver id="1690165275" major="66" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
<resver id="1690169108" major="69" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
<resver id="1690175442" major="87" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
</res>
</package>
I want to delete all <resver> elements except for the one with highest "major" attribute value.
For example above major="71" is highest in the first resver group and major="87" is the highest in second resver group.
So overall output looks like this:
<?xml version="1.0" encoding="utf-8"?>
<package date-created="11/4/2014" client-version="blah" system-version="blah">
<description />
<system>
<language />
</system>
<res id="blah" name="name" path="path" type="F" mimeType="mimetype-blah">
<description />
<keywords />
<resver id="1690176842" major="71" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
</res>
<res id="blah1" name="name1" path="path1" type="F" mimeType="mimetype-blah1">
<description />
<keywords />
<resver id="1690175442" major="87" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
</res>
</package>
I thought of using JAXB to do the work. Is there a better way to solve this?
Can this be done with Simple Java File api?
Answer
I have written this thing using JAXB to acheive this.
Here is the code
try {
File file = new File(FILE);
JAXBContext jaxbContext = JAXBContext.newInstance(Package.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Package pack = (Package) jaxbUnmarshaller.unmarshal(file);
if (pack.getRes() == null || pack.getRes().size() == 0) {
System.out.println("Size zero - exit");
return;
}
for (Package.Res res : pack.getRes()) {
if (! (res.getResver().size() == 1)) {
Short max = getMaxMajorVersion(res);
List<Package.Res.Resver> resverList = removeNonMaxResver(res, max);
for (Package.Res.Resver resver : resverList)
res.getResver().remove(resver);
}
}
finalPack = pack;
} catch (JAXBException e) {
e.printStackTrace();
}
marshal();
Method: extractNonMaxResver
private static List<Package.Res.Resver> removeNonMaxResver(
Package.Res res, Short max) {
List<Package.Res.Resver> resverList = new ArrayList<Package.Res.Resver>();
for (Package.Res.Resver resver : res.getResver()) {
if (resver.getMajor() != max)
resverList.add(resver);
}
return resverList;
}
Method: getMaxMajorVersion
private static Short getMaxMajorVersion(Package.Res res) {
List<Short> list = new ArrayList<Short>();
for (Package.Res.Resver resver : res.getResver()) {
list.add(resver.getMajor());
}
Short max = Collections.max(list);
System.out.println("Max: " + max);
return max;
}
Method: marshal
public static void marshal() {
try {
File file = new File(FILE_OUT);
JAXBContext jaxbContext = JAXBContext.newInstance(Package.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
// output pretty printed
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
Boolean.TRUE);
jaxbMarshaller.marshal(finalPack, file);
jaxbMarshaller.marshal(finalPack, System.out);
} catch (JAXBException e) {
e.printStackTrace();
}
}
You need to load the XML into either XMLElement or a Java object(using JAXB or other lib). If using XMLEement then you will be iterating through nodes and deleting as per your condition. and in case of Java Model object, just iterate through the list delete them and then persist the same Model as XML file.
Go through the Java Docs :https://docs.oracle.com/javase/7/docs/api/org/w3c/dom/Element.html
It has all API which you can use to manipulate XML.
XML is not a programming language.
you cant add conditions on it, but the same is possible with processing languages such as XSLT.
<xsl:if test="#foo='bar'">
<xsl:text>Hello, world!</xsl:text>
</xsl:if>
I suggest that as the best way to do this kind of operations.
Other possible operations are by parsing the XML String using basic String operations. Its complex and confusing and more error prone.
Ref This