cancel
Showing results for 
Search instead for 
Did you mean: 

How to specify activiti:collection variables?

rby
Champ in-the-making
Champ in-the-making
Greetings!

I'd like to know how to work with multi-instance type SubProcesses.

Process consist of 3 transactional subProcesses:Garden,Tree,Fance //as example
Tree subProcess should be done multiple times.

Here is bpmn20.xml process template:


<?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/processdef">
  <process id="newGarden" isExecutable="true">
    <startEvent id="sid-09CAE231-3113-4270-9C78-9078F319D354"></startEvent>
    <transaction id="gardenSubProcess" name="subProcess">
      <serviceTask id="sid-1AB6265D-1EA6-46F2-AB06-815EE5D720F2" name="Create Garden" activiti:expression="${gardenService.createGarden()}"></serviceTask>
      <startEvent id="sid-CB1D2066-33F7-4CEA-BA82-D25787FF35D9"></startEvent>
      <endEvent id="sid-323CAAF9-DE28-4E4F-BEAE-F746B854FD15"></endEvent>
      <sequenceFlow id="sid-AF87DB46-8875-4A81-A0E7-E8D00E62F59D" sourceRef="sid-CB1D2066-33F7-4CEA-BA82-D25787FF35D9" targetRef="sid-1AB6265D-1EA6-46F2-AB06-815EE5D720F2"></sequenceFlow>
      <sequenceFlow id="sid-5BBD31B2-9E61-4C37-9A97-012CE3765967" sourceRef="sid-1AB6265D-1EA6-46F2-AB06-815EE5D720F2" targetRef="sid-323CAAF9-DE28-4E4F-BEAE-F746B854FD15"></sequenceFlow>
    </transaction>
    <sequenceFlow id="sid-897A23C0-B415-44F4-B717-1882BAB4B92B" sourceRef="sid-09CAE231-3113-4270-9C78-9078F319D354" targetRef="gardenSubProcess"></sequenceFlow>
    <transaction id="treeSubProcess" name="subProcess">
      <multiInstanceLoopCharacteristics isSequential="true" activiti:collection="trees" activiti:elementVariable="tree"></multiInstanceLoopCharacteristics>
      <serviceTask id="sid-744FC443-7873-4FA0-8F22-AA4A79E9D4FC" name="Create Tree" activiti:expression="${treeService.createTree()}"></serviceTask>
      <startEvent id="sid-AA2F55AB-C81E-4A2F-883E-E38F6285666A"></startEvent>
      <endEvent id="sid-696B2612-16F8-46C1-9B35-6525F098301B"></endEvent>
      <sequenceFlow id="sid-87968321-5F57-45E9-9D03-1D0BB8C578ED" sourceRef="sid-AA2F55AB-C81E-4A2F-883E-E38F6285666A" targetRef="sid-744FC443-7873-4FA0-8F22-AA4A79E9D4FC"></sequenceFlow>
      <sequenceFlow id="sid-E66A27DD-B1D0-4A21-A7F7-630B537E621C" sourceRef="sid-744FC443-7873-4FA0-8F22-AA4A79E9D4FC" targetRef="sid-696B2612-16F8-46C1-9B35-6525F098301B"></sequenceFlow>
    </transaction>
    <sequenceFlow id="sid-D11B6656-21EA-4DA9-8EA9-74EF1233BA3E" sourceRef="gardenSubProcess" targetRef="treeSubProcess"></sequenceFlow>
    <transaction id="fanceSubProcess" name="subProcess">
      <serviceTask id="sid-377141BD-801D-4739-A575-70E3E7283F22" name="Create Fance" activiti:expression="${fanceService.createFance()}"></serviceTask>
      <startEvent id="sid-F0BBE7D7-03B2-4C82-9B14-9893D9473A77"></startEvent>
      <endEvent id="sid-297608C2-A3A9-4FFA-95C0-C4024229511B"></endEvent>
      <sequenceFlow id="sid-2B0C6FAB-0823-4CBE-94A8-6125073C4A0B" sourceRef="sid-F0BBE7D7-03B2-4C82-9B14-9893D9473A77" targetRef="sid-377141BD-801D-4739-A575-70E3E7283F22"></sequenceFlow>
      <sequenceFlow id="sid-854F9CD9-46BF-4D26-86F8-90BB37C8C505" sourceRef="sid-377141BD-801D-4739-A575-70E3E7283F22" targetRef="sid-297608C2-A3A9-4FFA-95C0-C4024229511B"></sequenceFlow>
    </transaction>
    <endEvent id="sid-29EBC3FE-E2EB-4F4E-BC4D-3B31F75E05D0"></endEvent>
    <sequenceFlow id="sid-45E2887C-EF34-4898-97FC-ABBD644C19F1" sourceRef="fanceSubProcess" targetRef="sid-29EBC3FE-E2EB-4F4E-BC4D-3B31F75E05D0"></sequenceFlow>
    <sequenceFlow id="sid-D78F2D47-3B77-479E-8A41-3F5FC08A8423" sourceRef="treeSubProcess" targetRef="fanceSubProcess"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_newGarden">
    <bpmndi:BPMNPlane bpmnElement="newGarden" id="BPMNPlane_newGarden">
      <bpmndi:BPMNShape bpmnElement="sid-09CAE231-3113-4270-9C78-9078F319D354" id="BPMNShape_sid-09CAE231-3113-4270-9C78-9078F319D354">
        <omgdc:Bounds height="30.0" width="30.0" x="15.0" y="310.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="gardenSubProcess" id="BPMNShape_gardenSubProcess">
        <omgdc:Bounds height="200.00000000000003" width="298.0" x="90.0" y="224.99999999999997"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-1AB6265D-1EA6-46F2-AB06-815EE5D720F2" id="BPMNShape_sid-1AB6265D-1EA6-46F2-AB06-815EE5D720F2">
        <omgdc:Bounds height="79.99999999999997" width="100.0" x="189.0" y="285.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-CB1D2066-33F7-4CEA-BA82-D25787FF35D9" id="BPMNShape_sid-CB1D2066-33F7-4CEA-BA82-D25787FF35D9">
        <omgdc:Bounds height="30.0" width="30.0" x="127.04590469933157" y="310.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-323CAAF9-DE28-4E4F-BEAE-F746B854FD15" id="BPMNShape_sid-323CAAF9-DE28-4E4F-BEAE-F746B854FD15">
        <omgdc:Bounds height="28.0" width="28.0" x="337.0459046993316" y="311.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="treeSubProcess" id="BPMNShape_treeSubProcess">
        <omgdc:Bounds height="195.0" width="261.0" x="450.0" y="227.5"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-744FC443-7873-4FA0-8F22-AA4A79E9D4FC" id="BPMNShape_sid-744FC443-7873-4FA0-8F22-AA4A79E9D4FC">
        <omgdc:Bounds height="80.0" width="100.0" x="530.5" y="285.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-AA2F55AB-C81E-4A2F-883E-E38F6285666A" id="BPMNShape_sid-AA2F55AB-C81E-4A2F-883E-E38F6285666A">
        <omgdc:Bounds height="30.0" width="30.0" x="465.0" y="310.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-696B2612-16F8-46C1-9B35-6525F098301B" id="BPMNShape_sid-696B2612-16F8-46C1-9B35-6525F098301B">
        <omgdc:Bounds height="28.0" width="28.0" x="670.0" y="311.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="fanceSubProcess" id="BPMNShape_fanceSubProcess">
        <omgdc:Bounds height="193.0" width="266.0" x="795.0" y="228.5"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-377141BD-801D-4739-A575-70E3E7283F22" id="BPMNShape_sid-377141BD-801D-4739-A575-70E3E7283F22">
        <omgdc:Bounds height="79.99999999999997" width="100.0" x="878.0" y="282.5"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-F0BBE7D7-03B2-4C82-9B14-9893D9473A77" id="BPMNShape_sid-F0BBE7D7-03B2-4C82-9B14-9893D9473A77">
        <omgdc:Bounds height="30.0" width="30.0" x="810.0" y="307.5"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-297608C2-A3A9-4FFA-95C0-C4024229511B" id="BPMNShape_sid-297608C2-A3A9-4FFA-95C0-C4024229511B">
        <omgdc:Bounds height="28.0" width="28.0" x="1020.0" y="308.5"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-29EBC3FE-E2EB-4F4E-BC4D-3B31F75E05D0" id="BPMNShape_sid-29EBC3FE-E2EB-4F4E-BC4D-3B31F75E05D0">
        <omgdc:Bounds height="28.0" width="28.0" x="1170.0" y="311.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-5BBD31B2-9E61-4C37-9A97-012CE3765967" id="BPMNEdge_sid-5BBD31B2-9E61-4C37-9A97-012CE3765967">
        <omgdi:waypoint x="289.0" y="325.0"></omgdi:waypoint>
        <omgdi:waypoint x="337.0459046993316" y="325.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-45E2887C-EF34-4898-97FC-ABBD644C19F1" id="BPMNEdge_sid-45E2887C-EF34-4898-97FC-ABBD644C19F1">
        <omgdi:waypoint x="1061.0" y="325.0"></omgdi:waypoint>
        <omgdi:waypoint x="1170.0" y="325.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-2B0C6FAB-0823-4CBE-94A8-6125073C4A0B" id="BPMNEdge_sid-2B0C6FAB-0823-4CBE-94A8-6125073C4A0B">
        <omgdi:waypoint x="840.0" y="322.5"></omgdi:waypoint>
        <omgdi:waypoint x="878.0" y="322.5"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-897A23C0-B415-44F4-B717-1882BAB4B92B" id="BPMNEdge_sid-897A23C0-B415-44F4-B717-1882BAB4B92B">
        <omgdi:waypoint x="45.0" y="325.0"></omgdi:waypoint>
        <omgdi:waypoint x="90.0" y="325.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-D78F2D47-3B77-479E-8A41-3F5FC08A8423" id="BPMNEdge_sid-D78F2D47-3B77-479E-8A41-3F5FC08A8423">
        <omgdi:waypoint x="711.0" y="325.0"></omgdi:waypoint>
        <omgdi:waypoint x="795.0" y="325.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-E66A27DD-B1D0-4A21-A7F7-630B537E621C" id="BPMNEdge_sid-E66A27DD-B1D0-4A21-A7F7-630B537E621C">
        <omgdi:waypoint x="630.5" y="325.0"></omgdi:waypoint>
        <omgdi:waypoint x="670.0" y="325.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-D11B6656-21EA-4DA9-8EA9-74EF1233BA3E" id="BPMNEdge_sid-D11B6656-21EA-4DA9-8EA9-74EF1233BA3E">
        <omgdi:waypoint x="388.0" y="325.0"></omgdi:waypoint>
        <omgdi:waypoint x="450.0" y="325.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-AF87DB46-8875-4A81-A0E7-E8D00E62F59D" id="BPMNEdge_sid-AF87DB46-8875-4A81-A0E7-E8D00E62F59D">
        <omgdi:waypoint x="157.04590469933157" y="325.0"></omgdi:waypoint>
        <omgdi:waypoint x="189.0" y="325.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-87968321-5F57-45E9-9D03-1D0BB8C578ED" id="BPMNEdge_sid-87968321-5F57-45E9-9D03-1D0BB8C578ED">
        <omgdi:waypoint x="495.0" y="325.0"></omgdi:waypoint>
        <omgdi:waypoint x="530.5" y="325.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-854F9CD9-46BF-4D26-86F8-90BB37C8C505" id="BPMNEdge_sid-854F9CD9-46BF-4D26-86F8-90BB37C8C505">
        <omgdi:waypoint x="978.0" y="322.5"></omgdi:waypoint>
        <omgdi:waypoint x="1020.0" y="322.5"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>


Here is RestController class:


@RestController
public class GardenProcessRestController {
    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    GardenRepository gardenRepository;

    @Autowired
    TreeRepository treeRepository;

    @Autowired
    FanceRepository fanceRepository;


    @ResponseStatus(value = HttpStatus.OK)
    @RequestMapping(value = "/create-garden-process",method = RequestMethod.POST,
    produces = MediaType.APPLICATION_JSON_VALUE)
    public void createTenantProcess(@RequestBody Map<String,String> data) {

        Garden garden = new Garden(data.get("gardenName"),data.get("gardenRequest"));
        garden.setGardenResponse("gardenResponse");
        gardenRepository.save(garden);

        Tree tree = new Tree("tree", gardenRepository.findOne(garden.getGardenId()).getGardenResponse());
        tree.setTreeResponse("treeResponse");
        ArrayList<Tree> trees = new ArrayList<Tree>();
        trees.add(tree);
        treeRepository.save(trees);
        Map<String,Object> trs = Collections.<String,Object>singletonMap("tree", trees);

        Map<String,Object> vars = Collections.<String, Object>singletonMap("garden", garden);
        runtimeService.startProcessInstanceByKey("newGarden",vars);

    }
}


Here are Service classes(they have the same body,instead of Class/method names):


@Service
@Transactional

public class FanceService {
    public void createFance() {
        System.out.println("Creating Fance …");
    }
}


Entities consist of: id,name,request,response.

Name and request for Garden are set by rest,and it's responce should be a request for Tree entities,such as Tree responses should form Fance request.

Repositories extends JpaRepository.

So here is the trouble,i get 400 error:

"message": "Bad request"
"exception": "Variable trees is not found"





4 REPLIES 4

trademak
Star Contributor
Star Contributor
Is there a specific reason for using the transaction sub process?
Because I don't see any compensation events in the process definition, so you could use a standard subProcess element.
The trees collection is expected to be a variable in the process instance context. And in the code provided, I only see the garden variable being used to start the process instance.

Best regards,

warper
Star Contributor
Star Contributor
You need process variable trees defined/evaluated in process or supplied to it in vars map on process start. Currently you only put 1 variable - garden

rby
Champ in-the-making
Champ in-the-making
At the moment i don't need to use transactions,I may use them in a scale,thank you!

So do i need to specify trees collection before starting and use it to start the process?

I try to integrate with openstack ,so mine task is to create Tenant (Garden), multiple Networks (Trees) and they should form VM (Fance). I can not specify their variables right before starting the Tenant sub process. The result of Tenant sub process should provide some information for Networks ,in the end Networks provide the information for creating VM.

jbarrez
Star Contributor
Star Contributor
you need to provide that collection when the execution arrives at that step in the process instance.
Either by an API call or by it is being set by a JavaDelegate.

Alternatively, you can have a bean (for example with Spring) that uses an expression like ${myBean.determineTrees(execution)}. That bean will be consulted when needed at runtime.