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

The following examples show how to use org.activiti.bpmn.model.Process#findFlowElementsOfType() . 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: IntermediateCatchEventValidator.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
  List<IntermediateCatchEvent> intermediateCatchEvents = process.findFlowElementsOfType(IntermediateCatchEvent.class);
  for (IntermediateCatchEvent intermediateCatchEvent : intermediateCatchEvents) {
    EventDefinition eventDefinition = null;
    if (!intermediateCatchEvent.getEventDefinitions().isEmpty()) {
      eventDefinition = intermediateCatchEvent.getEventDefinitions().get(0);
    }

    if (eventDefinition == null) {
      addError(errors, Problems.INTERMEDIATE_CATCH_EVENT_NO_EVENTDEFINITION, process, intermediateCatchEvent, "No event definition for intermediate catch event ");
    } else {
      if (!(eventDefinition instanceof TimerEventDefinition) && !(eventDefinition instanceof SignalEventDefinition) && !(eventDefinition instanceof MessageEventDefinition)) {
        addError(errors, Problems.INTERMEDIATE_CATCH_EVENT_INVALID_EVENTDEFINITION, process, intermediateCatchEvent, "Unsupported intermediate catch event type");
      }
    }
  }
}
 
Example 2
Source File: JobDefinitionServiceImpl.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts that the first asyncable task in the given model is indeed asynchronous. Only asserts when the configuration is set to true.
 *
 * @param bpmnModel The BPMN model
 */
private void assertFirstTaskIsAsync(BpmnModel bpmnModel)
{
    if (Boolean.TRUE.equals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ASSERT_ASYNC, Boolean.class)))
    {
        Process process = bpmnModel.getMainProcess();
        for (StartEvent startEvent : process.findFlowElementsOfType(StartEvent.class))
        {
            for (SequenceFlow sequenceFlow : startEvent.getOutgoingFlows())
            {
                String targetRef = sequenceFlow.getTargetRef();
                FlowElement targetFlowElement = process.getFlowElement(targetRef);
                if (targetFlowElement instanceof Activity)
                {
                    Assert.isTrue(((Activity) targetFlowElement).isAsynchronous(), "Element with id \"" + targetRef +
                        "\" must be set to activiti:async=true. All tasks which start the workflow must be asynchronous to prevent certain undesired " +
                        "transactional behavior, such as records of workflow not being saved on errors. Please refer to Activiti and herd documentations " +
                        "for details.");
                }
            }
        }
    }
}
 
Example 3
Source File: SubprocessValidator.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
  List<SubProcess> subProcesses = process.findFlowElementsOfType(SubProcess.class);
  for (SubProcess subProcess : subProcesses) {

    if (!(subProcess instanceof EventSubProcess)) {

      // Verify start events
      List<StartEvent> startEvents = process.findFlowElementsInSubProcessOfType(subProcess, StartEvent.class, false);
      if (startEvents.size() > 1) {
        addError(errors, Problems.SUBPROCESS_MULTIPLE_START_EVENTS, process, subProcess, "Multiple start events not supported for subprocess");
      }

      for (StartEvent startEvent : startEvents) {
        if (!startEvent.getEventDefinitions().isEmpty()) {
          addError(errors, Problems.SUBPROCESS_START_EVENT_EVENT_DEFINITION_NOT_ALLOWED, process, startEvent, "event definitions only allowed on start event if subprocess is an event subprocess");
        }
      }

    }

  }

}
 
Example 4
Source File: EventValidator.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
  List<Event> events = process.findFlowElementsOfType(Event.class);
  for (Event event : events) {
    if (event.getEventDefinitions() != null) {
      for (EventDefinition eventDefinition : event.getEventDefinitions()) {

        if (eventDefinition instanceof MessageEventDefinition) {
          handleMessageEventDefinition(bpmnModel, process, event, eventDefinition, errors);
        } else if (eventDefinition instanceof SignalEventDefinition) {
          handleSignalEventDefinition(bpmnModel, process, event, eventDefinition, errors);
        } else if (eventDefinition instanceof TimerEventDefinition) {
          handleTimerEventDefinition(process, event, eventDefinition, errors);
        } else if (eventDefinition instanceof CompensateEventDefinition) {
          handleCompensationEventDefinition(bpmnModel, process, event, eventDefinition, errors);
        }

      }
    }
  }
}
 
Example 5
Source File: EventSubprocessValidator.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
  List<EventSubProcess> eventSubprocesses = process.findFlowElementsOfType(EventSubProcess.class);
  for (EventSubProcess eventSubprocess : eventSubprocesses) {

    List<StartEvent> startEvents = process.findFlowElementsInSubProcessOfType(eventSubprocess, StartEvent.class);
    for (StartEvent startEvent : startEvents) {
      if (startEvent.getEventDefinitions() != null && !startEvent.getEventDefinitions().isEmpty()) {
        EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
        if (!(eventDefinition instanceof org.activiti.bpmn.model.ErrorEventDefinition) && !(eventDefinition instanceof MessageEventDefinition) && !(eventDefinition instanceof SignalEventDefinition)) {
          addError(errors, Problems.EVENT_SUBPROCESS_INVALID_START_EVENT_DEFINITION, process, eventSubprocess, "start event of event subprocess must be of type 'error', 'message' or 'signal'");
        }
      }
    }

  }
}
 
Example 6
Source File: DataObjectValidator.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {

  // Gather data objects
  List<ValuedDataObject> allDataObjects = new ArrayList<ValuedDataObject>();
  allDataObjects.addAll(process.getDataObjects());
  List<SubProcess> subProcesses = process.findFlowElementsOfType(SubProcess.class, true);
  for (SubProcess subProcess : subProcesses) {
    allDataObjects.addAll(subProcess.getDataObjects());
  }

  // Validate
  for (ValuedDataObject dataObject : allDataObjects) {
    if (StringUtils.isEmpty(dataObject.getName())) {
      addError(errors, Problems.DATA_OBJECT_MISSING_NAME, process, dataObject, "Name is mandatory for a data object");
    }
  }

}
 
Example 7
Source File: EndEventValidator.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
  List<EndEvent> endEvents = process.findFlowElementsOfType(EndEvent.class);
  for (EndEvent endEvent : endEvents) {
    if (endEvent.getEventDefinitions() != null && !endEvent.getEventDefinitions().isEmpty()) {

      EventDefinition eventDefinition = endEvent.getEventDefinitions().get(0);

      // Error end event
      if (eventDefinition instanceof CancelEventDefinition) {

        FlowElementsContainer parent = process.findParent(endEvent);
        if (!(parent instanceof Transaction)) {
          addError(errors, Problems.END_EVENT_CANCEL_ONLY_INSIDE_TRANSACTION, process, endEvent, "end event with cancelEventDefinition only supported inside transaction subprocess");
        }

      }

    }
  }
}
 
Example 8
Source File: SendTaskValidator.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) {
  List<SendTask> sendTasks = process.findFlowElementsOfType(SendTask.class);
  for (SendTask sendTask : sendTasks) {

    // Verify implementation
    if (StringUtils.isEmpty(sendTask.getType()) && !ImplementationType.IMPLEMENTATION_TYPE_WEBSERVICE.equalsIgnoreCase(sendTask.getImplementationType())) {
      addError(errors, Problems.SEND_TASK_INVALID_IMPLEMENTATION, process, sendTask, "One of the attributes 'type' or 'operation' is mandatory on sendTask");
    }

    // Verify type
    if (StringUtils.isNotEmpty(sendTask.getType())) {

      if (!sendTask.getType().equalsIgnoreCase("mail") && !sendTask.getType().equalsIgnoreCase("mule") && !sendTask.getType().equalsIgnoreCase("camel")) {
        addError(errors, Problems.SEND_TASK_INVALID_TYPE, process, sendTask, "Invalid or unsupported type for send task");
      }

      if (sendTask.getType().equalsIgnoreCase("mail")) {
        validateFieldDeclarationsForEmail(process, sendTask, sendTask.getFieldExtensions(), errors);
      }

    }

    // Web service
    verifyWebservice(bpmnModel, process, sendTask, errors);
  }
}
 
Example 9
Source File: IntermediateThrowEventValidator.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) {
  List<ThrowEvent> throwEvents = process.findFlowElementsOfType(ThrowEvent.class);
  for (ThrowEvent throwEvent : throwEvents) {
    EventDefinition eventDefinition = null;
    if (!throwEvent.getEventDefinitions().isEmpty()) {
      eventDefinition = throwEvent.getEventDefinitions().get(0);
    }

    if (eventDefinition != null && !(eventDefinition instanceof SignalEventDefinition) && !(eventDefinition instanceof CompensateEventDefinition)) {
      addError(errors, Problems.THROW_EVENT_INVALID_EVENTDEFINITION, process, throwEvent, "Unsupported intermediate throw event type");
    }
  }
}
 
Example 10
Source File: ScriptTaskValidator.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) {
  List<ScriptTask> scriptTasks = process.findFlowElementsOfType(ScriptTask.class);
  for (ScriptTask scriptTask : scriptTasks) {
    if (StringUtils.isEmpty(scriptTask.getScript())) {
      addError(errors, Problems.SCRIPT_TASK_MISSING_SCRIPT, process, scriptTask, "No script provided for script task");
    }
  }
}
 
Example 11
Source File: MultiInstanceActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected Collection<BoundaryEvent> findBoundaryEventsForFlowNode(final String processDefinitionId, final FlowElement flowElement) {
  Process process = getProcessDefinition(processDefinitionId);

  // This could be cached or could be done at parsing time
  List<BoundaryEvent> results = new ArrayList<BoundaryEvent>(1);
  Collection<BoundaryEvent> boundaryEvents = process.findFlowElementsOfType(BoundaryEvent.class, true);
  for (BoundaryEvent boundaryEvent : boundaryEvents) {
    if (boundaryEvent.getAttachedToRefId() != null && boundaryEvent.getAttachedToRefId().equals(flowElement.getId())) {
      results.add(boundaryEvent);
    }
  }
  return results;
}
 
Example 12
Source File: UserTaskValidator.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) {
  List<UserTask> userTasks = process.findFlowElementsOfType(UserTask.class);
  for (UserTask userTask : userTasks) {
    if (userTask.getTaskListeners() != null) {
      for (ActivitiListener listener : userTask.getTaskListeners()) {
        if (listener.getImplementation() == null || listener.getImplementationType() == null) {
          addError(errors, Problems.USER_TASK_LISTENER_IMPLEMENTATION_MISSING, process, userTask, "Element 'class' or 'expression' is mandatory on executionListener");
        }
      }
    }
  }
}
 
Example 13
Source File: ExclusiveGatewayValidator.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) {
  List<ExclusiveGateway> gateways = process.findFlowElementsOfType(ExclusiveGateway.class);
  for (ExclusiveGateway gateway : gateways) {
    validateExclusiveGateway(process, gateway, errors);
  }
}
 
Example 14
Source File: EventGatewayValidator.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) {
  List<EventGateway> eventGateways = process.findFlowElementsOfType(EventGateway.class);
  for (EventGateway eventGateway : eventGateways) {
    for (SequenceFlow sequenceFlow : eventGateway.getOutgoingFlows()) {
      FlowElement flowElement = process.getFlowElement(sequenceFlow.getTargetRef(), true);
      if (flowElement != null && flowElement instanceof IntermediateCatchEvent == false) {
        addError(errors, Problems.EVENT_GATEWAY_ONLY_CONNECTED_TO_INTERMEDIATE_EVENTS, process, eventGateway, "Event based gateway can only be connected to elements of type intermediateCatchEvent");
      }
    }
  }
}
 
Example 15
Source File: ServiceTaskValidator.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) {
  List<ServiceTask> serviceTasks = process.findFlowElementsOfType(ServiceTask.class);
  for (ServiceTask serviceTask : serviceTasks) {
    verifyImplementation(process, serviceTask, errors);
    verifyType(process, serviceTask, errors);
    verifyResultVariableName(process, serviceTask, errors);
    verifyWebservice(bpmnModel, process, serviceTask, errors);
  }

}
 
Example 16
Source File: AbstractBpmnActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected Collection<BoundaryEvent> findBoundaryEventsForFlowNode(final String processDefinitionId, final FlowElement flowElement) {
  Process process = getProcessDefinition(processDefinitionId);

  // This could be cached or could be done at parsing time
  List<BoundaryEvent> results = new ArrayList<BoundaryEvent>(1);
  Collection<BoundaryEvent> boundaryEvents = process.findFlowElementsOfType(BoundaryEvent.class, true);
  for (BoundaryEvent boundaryEvent : boundaryEvents) {
    if (boundaryEvent.getAttachedToRefId() != null && boundaryEvent.getAttachedToRefId().equals(flowElement.getId())) {
      results.add(boundaryEvent);
    }
  }
  return results;
}
 
Example 17
Source File: StartEventValidator.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
  List<StartEvent> startEvents = process.findFlowElementsOfType(StartEvent.class, false);
  validateEventDefinitionTypes(startEvents, process, errors);
  validateMultipleStartEvents(startEvents, process, errors);
}
 
Example 18
Source File: SequenceflowValidator.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
  List<SequenceFlow> sequenceFlows = process.findFlowElementsOfType(SequenceFlow.class);
  for (SequenceFlow sequenceFlow : sequenceFlows) {

    String sourceRef = sequenceFlow.getSourceRef();
    String targetRef = sequenceFlow.getTargetRef();

    if (StringUtils.isEmpty(sourceRef)) {
      addError(errors, Problems.SEQ_FLOW_INVALID_SRC, process, sequenceFlow, "Invalid source for sequenceflow");
    }
    if (StringUtils.isEmpty(targetRef)) {
      addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow");
    }

    // Implicit check: sequence flow cannot cross (sub) process
    // boundaries, hence we check the parent and not the process
    // (could be subprocess for example)
    FlowElement source = process.getFlowElement(sourceRef, true);
    FlowElement target = process.getFlowElement(targetRef, true);

    // Src and target validation
    if (source == null) {
      addError(errors, Problems.SEQ_FLOW_INVALID_SRC, process, sequenceFlow, "Invalid source for sequenceflow");
    }
    if (target == null) {
      addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow");
    }

    if (source != null && target != null) {
      FlowElementsContainer sourceContainer = process.getFlowElementsContainer(source.getId());
      FlowElementsContainer targetContainer = process.getFlowElementsContainer(target.getId());

      if (sourceContainer == null) {
        addError(errors, Problems.SEQ_FLOW_INVALID_SRC, process, sequenceFlow, "Invalid source for sequenceflow");
      }
      if (targetContainer == null) {
        addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow");
      }
      if (sourceContainer != null && targetContainer != null && sourceContainer.equals(targetContainer) == false) {
        addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow, the target isn't defined in the same scope as the source");
      }
    }
  }
}