private void handleGeneralTaskDtoProperties(KickstartTask baseTaskDto, Task task) {
    // task id
    baseTaskDto.setId(task.getId());

    // task name
    baseTaskDto.setName(task.getName());

    // task description
    if (!task.getDocumentation().isEmpty()) {
      baseTaskDto.setDescription(task.getDocumentation().get(0).getText());
    }
  }
  public KickstartWorkflow convertToKickstartWorkflow(Definitions definitions) {
    KickstartWorkflow adhocWorkflow = new KickstartWorkflow();

    for (BaseElement baseElement : definitions.getRootElement()) {
      if (baseElement instanceof org.activiti.kickstart.bpmn20.model.Process) {

        org.activiti.kickstart.bpmn20.model.Process process =
            (org.activiti.kickstart.bpmn20.model.Process) baseElement;

        // Process name and description
        adhocWorkflow.setName(process.getName());
        if (!process.getDocumentation().isEmpty()) {
          adhocWorkflow.setDescription(process.getDocumentation().get(0).getText());
        }

        // user tasks
        Map<String, Task> tasks = new HashMap<String, Task>();
        Map<String, ParallelGateway> gateways = new HashMap<String, ParallelGateway>();
        Map<String, List<SequenceFlow>> sequenceFlows = new HashMap<String, List<SequenceFlow>>();
        for (FlowElement flowElement : process.getFlowElement()) {
          if (flowElement instanceof Task) {
            tasks.put(flowElement.getId(), (Task) flowElement);
          }
          if (flowElement instanceof ParallelGateway) {
            gateways.put(flowElement.getId(), (ParallelGateway) flowElement);
          }
          if (flowElement instanceof SequenceFlow) {
            SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
            String sourceRef = sequenceFlow.getSourceRef().getId();
            if (!sequenceFlows.containsKey(sourceRef)) {
              sequenceFlows.put(sourceRef, new ArrayList<SequenceFlow>());
            }
            sequenceFlows.get(sourceRef).add(sequenceFlow);
          }
        }

        // Follow sequence flow to discover sequence of tasks
        SequenceFlow currentSequenceFlow =
            sequenceFlows.get(KickstartWorkflow.START_NAME).get(0); // Can be only one
        while (!currentSequenceFlow.getTargetRef().getId().equals(KickstartWorkflow.END_NAME)) {

          String targetRef = currentSequenceFlow.getTargetRef().getId();
          KickstartTask taskDto = null;
          if (tasks.containsKey(targetRef)) {

            taskDto = convertToKickstartTask((Task) currentSequenceFlow.getTargetRef());
            currentSequenceFlow =
                sequenceFlows
                    .get(currentSequenceFlow.getTargetRef().getId())
                    .get(0); // Can be only one
            adhocWorkflow.addTask(taskDto);

          } else if (gateways.containsKey(targetRef)) {

            Task task = null;
            for (int i = 0; i < sequenceFlows.get(targetRef).size(); i++) {
              SequenceFlow seqFlowOutOfGateway = sequenceFlows.get(targetRef).get(i);
              task = (Task) seqFlowOutOfGateway.getTargetRef();
              taskDto = convertToKickstartTask(task);
              if (i > 0) {
                taskDto.setStartWithPrevious(true);
              }
              adhocWorkflow.addTask(taskDto);
            }

            String parallelJoinId =
                sequenceFlows.get(task.getId()).get(0).getTargetRef().getId(); // any seqflow is ok
            currentSequenceFlow = sequenceFlows.get(parallelJoinId).get(0); // can be only one
          }
        } // end while
      }
    }

    return adhocWorkflow;
  }