如何为camunda rest api创建List <inventory>类型的表单字段

时间:2018-01-23 11:38:11

标签: java forms camunda

我们将构建一个工作流管理系统,我们将camunda引擎Rest API嵌入到Rest应用程序中。

现在我的库存定义如下:

public class Inventory {
    private String objectName;
    private int objectCount;

    // getters and setters
}

这是一个示例工作流程: enter image description here

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&#60;org.example.Inventory&#62;" />
        </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>

我最终会有一个html表单,它会提交这样的内容:

{ 
    "inventories" : [{"name": "banana","count": 3},{"name":"orange","count": 4}]
}

我想将此内容提交到/ task / {id} / submit-form,但我不知道要输入什么类型。

我尝试将模型中的类型设置为List<org.example.Inventory>,但是在部署流程定义时,其余的api会抛出异常:

  

org.camunda.bpm.engine.ProcessEngineException:ENGINE-09005无法解析BPMN流程。错误:   *未知类型'列表'| org.example / PM.bpmn |第65行|第90栏

我也见过this示例,但我只使用Rest API而不是整个bpm平台(此外我们更喜欢使用纯html表单)。

那怎么办?我应该把什么类型放入?

我的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>  

我的processsengine提供者:

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;
    }
}

0 个答案:

没有答案