Java Code Examples for org.activiti.bpmn.model.Process#getFlowElements()

The following examples show how to use org.activiti.bpmn.model.Process#getFlowElements() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeploymentServiceImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected Map<String, StartEvent> processNoneStartEvents(BpmnModel bpmnModel) {
  Map<String, StartEvent> startEventMap = new HashMap<String, StartEvent>();
  for (Process process : bpmnModel.getProcesses()) {
    for (FlowElement flowElement : process.getFlowElements()) {
      if (flowElement instanceof StartEvent) {
        StartEvent startEvent = (StartEvent) flowElement;
        if (CollectionUtils.isEmpty(startEvent.getEventDefinitions())) {
          if (StringUtils.isEmpty(startEvent.getInitiator())) {
            startEvent.setInitiator("initiator");
          }
          startEventMap.put(process.getId(), startEvent);
          break;
        }
      }
    }
  }
  return startEventMap;
}
 
Example 2
Source File: EventSubscriptionManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void addMessageEventSubscriptions(ProcessDefinitionEntity processDefinition, Process process, BpmnModel bpmnModel) {
  if (CollectionUtil.isNotEmpty(process.getFlowElements())) {
    for (FlowElement element : process.getFlowElements()) {
      if (element instanceof StartEvent) {
        StartEvent startEvent = (StartEvent) element;
        if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions())) {
          EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
          if (eventDefinition instanceof MessageEventDefinition) {
            MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
            insertMessageEvent(messageEventDefinition, startEvent, processDefinition, bpmnModel);
          }
        }
      } 
    }
  }
}
 
Example 3
Source File: BpmnAutoLayout.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Since subprocesses are autolayouted independently (see {@link #handleSubProcess(FlowElement)}), the elements have x and y coordinates relative to the bounds of the subprocess (thinking the
 * subprocess is on (0,0). This however, does not work for nested subprocesses, as they need to take in account the x and y coordinates for each of the parent subproceses.
 * 
 * This method is to be called after fully layouting one process, since ALL elements need to have x and y.
 */
protected void translateNestedSubprocesses(Process process) {
     for (FlowElement flowElement : process.getFlowElements()) {
          if (flowElement instanceof SubProcess) {
            translateNestedSubprocessElements((SubProcess) flowElement);
          }
     }
}
 
Example 4
Source File: TimerManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected List<TimerJobEntity> getTimerDeclarations(ProcessDefinitionEntity processDefinition, Process process) {
  JobManager jobManager = Context.getCommandContext().getJobManager();
  List<TimerJobEntity> timers = new ArrayList<TimerJobEntity>();
  if (CollectionUtil.isNotEmpty(process.getFlowElements())) {
    for (FlowElement element : process.getFlowElements()) {
      if (element instanceof StartEvent) {
        StartEvent startEvent = (StartEvent) element;
        if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions())) {
          EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
          if (eventDefinition instanceof TimerEventDefinition) {
            TimerEventDefinition timerEventDefinition = (TimerEventDefinition) eventDefinition;
            TimerJobEntity timerJob = jobManager.createTimerJob(timerEventDefinition, false, null, TimerStartEventJobHandler.TYPE,
                TimerEventHandler.createConfiguration(startEvent.getId(), timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));

            if (timerJob != null) {
              timerJob.setProcessDefinitionId(processDefinition.getId());

              if (processDefinition.getTenantId() != null) {
                timerJob.setTenantId(processDefinition.getTenantId());
              }
              timers.add(timerJob);
            }

          }
        }
      }
    }
  }

  return timers;
}
 
Example 5
Source File: ActivitiTestCaseProcessValidator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeParse(BpmnModel bpmnModel, Process element) {
  for (FlowElement flowElement : element.getFlowElements()) {
    if (!ServiceTask.class.isAssignableFrom(flowElement.getClass())) {
      continue;
    }
    ServiceTask serviceTask = (ServiceTask) flowElement;
    validateAsyncAttribute(serviceTask, bpmnModel, flowElement);
  }
}
 
Example 6
Source File: FlowElementValidator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
	for (FlowElement flowElement : process.getFlowElements()) {
		
		if (flowElement instanceof Activity) {
			Activity activity = (Activity) flowElement;
			handleConstraints(process, activity, errors);
			handleMultiInstanceLoopCharacteristics(process, activity, errors);
			handleDataAssociations(process, activity, errors);
		}
		
	}
	
}
 
Example 7
Source File: ExecutionListenerValidator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {

  validateListeners(process, process, process.getExecutionListeners(), errors);

  for (FlowElement flowElement : process.getFlowElements()) {
    validateListeners(process, flowElement, flowElement.getExecutionListeners(), errors);
  }
}
 
Example 8
Source File: ActivitiTestCaseProcessValidator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeParse(BpmnModel bpmnModel, Process element) {
  for (FlowElement flowElement : element.getFlowElements()) {
    if (!ServiceTask.class.isAssignableFrom(flowElement.getClass())) {
      continue;
    }
    ServiceTask serviceTask = (ServiceTask) flowElement;
    validateAsyncAttribute(serviceTask, bpmnModel, flowElement);
  }
}
 
Example 9
Source File: ProcessInstanceHelper.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ProcessInstance createAndStartProcessInstanceByMessage(ProcessDefinition processDefinition, String messageName,
    Map<String, Object> variables, Map<String, Object> transientVariables) {

  CommandContext commandContext = Context.getCommandContext();
  if (processDefinition.getEngineVersion() != null) {
    if (Activiti5CompatibilityHandler.ACTIVITI_5_ENGINE_TAG.equals(processDefinition.getEngineVersion())) {
      Activiti5CompatibilityHandler activiti5CompatibilityHandler = commandContext.getProcessEngineConfiguration().getActiviti5CompatibilityHandler();

      if (activiti5CompatibilityHandler == null) {
        throw new ActivitiException("Found Activiti 5 process definition, but no compatibility handler on the classpath");
      }

      return activiti5CompatibilityHandler.startProcessInstanceByMessage(messageName, variables, null, processDefinition.getTenantId());

    } else {
      throw new ActivitiException("Invalid 'engine' for process definition " + processDefinition.getId() + " : " + processDefinition.getEngineVersion());
    }
  }

  // Do not start process a process instance if the process definition is suspended
  if (ProcessDefinitionUtil.isProcessDefinitionSuspended(processDefinition.getId())) {
    throw new ActivitiException("Cannot start process instance. Process definition " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") is suspended");
  }

  // Get model from cache
  Process process = ProcessDefinitionUtil.getProcess(processDefinition.getId());
  if (process == null) {
    throw new ActivitiException("Cannot start process instance. Process model " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") could not be found");
  }

  FlowElement initialFlowElement = null;
  for (FlowElement flowElement : process.getFlowElements()) {
    if (flowElement instanceof StartEvent) {
      StartEvent startEvent = (StartEvent) flowElement;
      if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions()) && startEvent.getEventDefinitions().get(0) instanceof MessageEventDefinition) {

        MessageEventDefinition messageEventDefinition = (MessageEventDefinition) startEvent.getEventDefinitions().get(0);
        if (messageEventDefinition.getMessageRef().equals(messageName)) {
          initialFlowElement = flowElement;
          break;
        }
      }
    }
  }
  if (initialFlowElement == null) {
    throw new ActivitiException("No message start event found for process definition " + processDefinition.getId() + " and message name " + messageName);
  }

  return createAndStartProcessInstanceWithInitialFlowElement(processDefinition, null, null, initialFlowElement, process, variables, transientVariables, true);
}
 
Example 10
Source File: ProcessInstanceHelper.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void startProcessInstance(ExecutionEntity processInstance, CommandContext commandContext, Map<String, Object> variables) {

      Process process = ProcessDefinitionUtil.getProcess(processInstance.getProcessDefinitionId());


    // Event sub process handling
      List<MessageEventSubscriptionEntity> messageEventSubscriptions = new LinkedList<>();
    for (FlowElement flowElement : process.getFlowElements()) {
      if (flowElement instanceof EventSubProcess) {
        EventSubProcess eventSubProcess = (EventSubProcess) flowElement;
        for (FlowElement subElement : eventSubProcess.getFlowElements()) {
          if (subElement instanceof StartEvent) {
            StartEvent startEvent = (StartEvent) subElement;
            if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions())) {
              EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
              if (eventDefinition instanceof MessageEventDefinition) {
                MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
                BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(processInstance.getProcessDefinitionId());
                if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
                  messageEventDefinition.setMessageRef(bpmnModel.getMessage(messageEventDefinition.getMessageRef()).getName());
                }
                ExecutionEntity messageExecution = commandContext.getExecutionEntityManager().createChildExecution(processInstance);
                messageExecution.setCurrentFlowElement(startEvent);
                messageExecution.setEventScope(true);
                messageEventSubscriptions
                .add(commandContext.getEventSubscriptionEntityManager().insertMessageEvent(messageEventDefinition.getMessageRef(), messageExecution));
              }
            }
          }
        }
      }
    }
    
    ExecutionEntity execution = processInstance.getExecutions().get(0); // There will always be one child execution created
    commandContext.getAgenda().planContinueProcessOperation(execution);

    if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
    	ActivitiEventDispatcher eventDispatcher = Context.getProcessEngineConfiguration().getEventDispatcher();
        eventDispatcher.dispatchEvent(ActivitiEventBuilder.createProcessStartedEvent(execution, variables, false));
        
        for (MessageEventSubscriptionEntity messageEventSubscription : messageEventSubscriptions) {
            commandContext.getProcessEngineConfiguration().getEventDispatcher()
                    .dispatchEvent(ActivitiEventBuilder.createMessageEvent(ActivitiEventType.ACTIVITY_MESSAGE_WAITING, messageEventSubscription.getActivityId(),
                            messageEventSubscription.getEventName(), null, messageEventSubscription.getExecution().getId(),
                            messageEventSubscription.getProcessInstanceId(), messageEventSubscription.getProcessDefinitionId()));
          }
    }
  }
 
Example 11
Source File: SubprocessXMLConverter.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] convertToXML(BpmnModel model, String encoding) {
  try {

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding);

    XMLStreamWriter writer = xof.createXMLStreamWriter(out);
    XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer);

    DefinitionsRootExport.writeRootElement(model, xtw, encoding);
    CollaborationExport.writePools(model, xtw);
    DataStoreExport.writeDataStores(model, xtw);
    SignalAndMessageDefinitionExport.writeSignalsAndMessages(model, xtw);

    for (Process process : model.getProcesses()) {

      if (process.getFlowElements().isEmpty() && process.getLanes().isEmpty()) {
        // empty process, ignore it
        continue;
      }

      ProcessExport.writeProcess(process, xtw);

      for (FlowElement flowElement : process.getFlowElements()) {
        createXML(flowElement, model, xtw);
      }

      for (Artifact artifact : process.getArtifacts()) {
        createXML(artifact, model, xtw);
      }

      // end process element
      xtw.writeEndElement();
    }

    // refactor each subprocess into a separate Diagram
    List<BpmnModel> subModels = parseSubModels(model);
    for (BpmnModel tempModel : subModels) {
      if (!tempModel.getFlowLocationMap().isEmpty() || !tempModel.getLocationMap().isEmpty()) {
        BPMNDIExport.writeBPMNDI(tempModel, xtw);
      }
    }

    // end definitions root element
    xtw.writeEndElement();
    xtw.writeEndDocument();

    xtw.flush();
    byte[] bytes = outputStream.toByteArray().clone();

    // cleanup
    outputStream.close();
    xtw.close();

    return bytes;
  } catch (Exception e) {
    LOGGER.error("Error writing BPMN XML", e);
    throw new XMLException("Error writing BPMN XML", e);
  }
}
 
Example 12
Source File: BpmnXMLConverter.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public byte[] convertToXML(BpmnModel model, String encoding) {
  try {

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding);

    XMLStreamWriter writer = xof.createXMLStreamWriter(out);
    XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer);

    DefinitionsRootExport.writeRootElement(model, xtw, encoding);
    CollaborationExport.writePools(model, xtw);
    DataStoreExport.writeDataStores(model, xtw);
    SignalAndMessageDefinitionExport.writeSignalsAndMessages(model, xtw);

    for (Process process : model.getProcesses()) {

      if (process.getFlowElements().isEmpty() && process.getLanes().isEmpty()) {
        // empty process, ignore it
        continue;
      }

      ProcessExport.writeProcess(process, xtw);

      for (FlowElement flowElement : process.getFlowElements()) {
        createXML(flowElement, model, xtw);
      }

      for (Artifact artifact : process.getArtifacts()) {
        createXML(artifact, model, xtw);
      }

      // end process element
      xtw.writeEndElement();
    }

    BPMNDIExport.writeBPMNDI(model, xtw);

    // end definitions root element
    xtw.writeEndElement();
    xtw.writeEndDocument();

    xtw.flush();

    outputStream.close();

    xtw.close();

    return outputStream.toByteArray();

  } catch (Exception e) {
    LOGGER.error("Error writing BPMN XML", e);
    throw new XMLException("Error writing BPMN XML", e);
  }
}