activiti bpmnModel use

bpmnModel objects, it is important activiti bell dynamic deployment of an object, if the object can not bpmnModel-depth understanding, it may, if they need to develop a process designer, appeared to be inadequate, before our own developed a activiti web designer ,As shown below:

 

 

 

When activiti web designer designs, custom storage format is json object that now the question is, how we transform our own json xml file format standard bpmn need it? this point is very important? So this is where the focus needs to explain this lesson, we can draw inferences from the actual development. Flexible use to the project.

1.1.1.  BpmnModel use

Because usually when we use the show flowcharts do not use the default flow generated in this way, the coordinate information here, not this demonstration, the core functionality of the main demonstration and other nodes.

1.1.1.1.  The Eclipse drawing process

To facilitate the presentation, where we first draw a simple process in the eclipse. The specific flowchart is as follows:

 

xml file flowchart is as follows: open the text file directly to bpmn:

 

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="process1" isExecutable="true">
    <startEvent id="start1shareniu" name="start1shareniu"></startEvent>
    <sequenceFlow id="starttouserTask" name="starttouserTask" sourceRef="start1shareniu" targetRef="userTask1shareniu"></sequenceFlow>
    <userTask id="userTask1shareniu" name="userTask1shareniu"></userTask>
    <sequenceFlow id="userTasktoend" name="userTasktoend" sourceRef="userTask1shareniu" targetRef="endEventshareniu"></sequenceFlow>
    <endEvent id="endEventshareniu" name="endEventshareniu"></endEvent>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_process1">
    <bpmndi:BPMNPlane bpmnElement="process1" id="BPMNPlane_process1">
      <bpmndi:BPMNShape bpmnElement="start1shareniu" id="BPMNShape_start1shareniu">
        <omgdc:Bounds height="35.0" width="35.0" x="70.0" y="150.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="userTask1shareniu" id="BPMNShape_userTask1shareniu">
        <omgdc:Bounds height="60.0" width="100.0" x="180.0" y="110.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endEventshareniu" id="BPMNShape_endEventshareniu">
        <omgdc:Bounds height="35.0" width="35.0" x="380.0" y="76.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="starttouserTask" id="BPMNEdge_starttouserTask">
        <omgdi:waypoint x="87.0" y="150.0"></omgdi:waypoint>
        <omgdi:waypoint x="100.0" y="139.0"></omgdi:waypoint>
        <omgdi:waypoint x="180.0" y="140.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="14.0" width="100.0" x="87.0" y="150.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="userTasktoend" id="BPMNEdge_userTasktoend">
        <omgdi:waypoint x="280.0" y="140.0"></omgdi:waypoint>
        <omgdi:waypoint x="324.0" y="129.0"></omgdi:waypoint>
        <omgdi:waypoint x="324.0" y="93.0"></omgdi:waypoint>
        <omgdi:waypoint x="380.0" y="93.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="14.0" width="100.0" x="414.0" y="126.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

 

 

 

 

 

1.1.1.2.  His own generation

The following code is generated bpmnmodel the core code, the code is as follows:

 

//实例化BpmnModel对象
BpmnModel bpmnModel=new BpmnModel();
//开始节点的属性
StartEvent startEvent=new StartEvent();
startEvent.setId("start1shareniu");
startEvent.setName("start1shareniu");
//普通的UserTask节点
UserTask userTask=new UserTask();
userTask.setId("userTask1shareniu");
userTask.setName("userTask1shareniu");
//结束节点属性
EndEvent endEvent=new EndEvent();
endEvent.setId("endEventshareniu");
endEvent.setName("endEventshareniu");
//连线信息
List<SequenceFlow> sequenceFlows=new ArrayList<SequenceFlow>();
List<SequenceFlow> toEnd=new ArrayList<SequenceFlow>();
SequenceFlow s1=new SequenceFlow();
s1.setId("starttouserTask");
s1.setName("starttouserTask");
s1.setSourceRef("start1shareniu");
s1.setTargetRef("userTask1shareniu");
sequenceFlows.add(s1);
SequenceFlow s2=new SequenceFlow();
s2.setId("userTasktoend");
s2.setName("userTasktoend");
s2.setSourceRef("userTask1shareniu");
s2.setTargetRef("endEventshareniu");
toEnd.add(s2);
startEvent.setOutgoingFlows(sequenceFlows);
userTask.setOutgoingFlows(toEnd);
userTask.setIncomingFlows(sequenceFlows);
endEvent.setIncomingFlows(toEnd);
//Process对象
Process process=new Process();
process.setId("process1");
process.addFlowElement(startEvent);
process.addFlowElement(s1);
process.addFlowElement(userTask);
process.addFlowElement(s2);
process.addFlowElement(endEvent);
bpmnModel.addProcess(process);

 

The above code, we've written procedure bpmnmodel draw, then how do we know that right or wrong? Here began our bpmnmodel object into a standard xml file look.

1.1.2.  BpmnModel xml conversion

The above object xml standard is converted to the code as follows:

// bpmnModel into a standard BPMN xml file 

BpmnXMLConverter bpmnXMLConverter=new BpmnXMLConverter();

byte[] convertToXML = bpmnXMLConverter.convertToXML(bpmnModel);

String bytes=new String(convertToXML);

System.out.println(bytes);

Run the program, look at the output of the program are as follows:

 

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="process1" isExecutable="true">
    <startEvent id="start1shareniu" name="start1shareniu"></startEvent>
    <sequenceFlow id="starttouserTask" name="starttouserTask" sourceRef="start1shareniu" targetRef="userTask1shareniu"></sequenceFlow>
    <userTask id="userTask1shareniu" name="userTask1shareniu"></userTask>
    <sequenceFlow id="userTasktoend" name="userTasktoend" sourceRef="userTask1shareniu" targetRef="endEventshareniu"></sequenceFlow>
    <endEvent id="endEventshareniu" name="endEventshareniu"></endEvent>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_process1">
    <bpmndi:BPMNPlane bpmnElement="process1" id="BPMNPlane_process1"></bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

 

We see the xml file conversion, xml eclipse contrast drawing process, in addition to the coordinates no, the other is correct. Then how do we validate our generation of xml is correct? Because the conversion is successful, it can not necessarily be used. Next, look at how bpmnmodel verification.

1.1.3.  BpmnModel verification

Method validation code as follows:

// Verify bpmnModel is correct BPMN xml file 

ProcessValidatorFactory processValidatorFactory=new ProcessValidatorFactory();

ProcessValidator defaultProcessValidator = processValidatorFactory.createDefaultProcessValidator();

// authentication failure information package ValidationError

List<ValidationError> validate = defaultProcessValidator.validate(bpmnModel);

System.out.println(validate.size());

Incidentally: ValidationError package is authentication information, if the size is 0 instructions, bpmnmodel correctly, is greater than 0, indicating custom bpmnmodel is wrong, not usable.

Verification or necessary to use because when the deployment process, we verify the best time, there is no problem in the deployment.

Share cow share, we are happy.

Share bovine original (time respect the original reprint please indicate on the first line, reproduced from the source to share bovine http://blog.csdn.net/qq_30739519)

He published 194 original articles · won praise 569 · Views 1.68 million +

Guess you like

Origin blog.csdn.net/qq_30739519/article/details/51271580