org.activiti.bpmn.model.StartEvent Java Examples

The following examples show how to use org.activiti.bpmn.model.StartEvent. 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: AddBpmnModelTest.java    From CrazyWorkflowHandoutsActiviti6 with MIT License 7 votes vote down vote up
private static BpmnModel createProcessModel() {
	// 创建BPMN模型
	BpmnModel model = new BpmnModel();
	// 创建一个流程定义
	Process process = new Process();
	model.addProcess(process);
	process.setId("myProcess");
	process.setName("My Process");
	// 开始事件
	StartEvent startEvent = new StartEvent();
	startEvent.setId("startEvent");
	process.addFlowElement(startEvent);
	// 用户任务
	UserTask userTask = new UserTask();
	userTask.setName("User Task");
	userTask.setId("userTask");
	process.addFlowElement(userTask);
	// 结束事件
	EndEvent endEvent = new EndEvent();
	endEvent.setId("endEvent");
	process.addFlowElement(endEvent);		
	// 添加流程顺序
	process.addFlowElement(new SequenceFlow("startEvent", "userTask"));
	process.addFlowElement(new SequenceFlow("userTask", "endEvent"));
	return model;
}
 
Example #2
Source File: DeploymentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void restoreSignalStartEvent(ProcessDefinition previousProcessDefinition, BpmnModel bpmnModel, StartEvent startEvent, EventDefinition eventDefinition) {
  SignalEventDefinition signalEventDefinition = (SignalEventDefinition) eventDefinition;
  SignalEventSubscriptionEntity subscriptionEntity = getEventSubscriptionEntityManager().createSignalEventSubscription();
  Signal signal = bpmnModel.getSignal(signalEventDefinition.getSignalRef());
  if (signal != null) {
    subscriptionEntity.setEventName(signal.getName());
  } else {
    subscriptionEntity.setEventName(signalEventDefinition.getSignalRef());
  }
  subscriptionEntity.setActivityId(startEvent.getId());
  subscriptionEntity.setProcessDefinitionId(previousProcessDefinition.getId());
  if (previousProcessDefinition.getTenantId() != null) {
    subscriptionEntity.setTenantId(previousProcessDefinition.getTenantId());
  }

  getEventSubscriptionEntityManager().insert(subscriptionEntity);
}
 
Example #3
Source File: StartEventParseHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void createProcessDefinitionStartEvent(BpmnParse bpmnParse, ActivityImpl startEventActivity, StartEvent startEvent, ProcessDefinitionEntity processDefinition) {
  if (StringUtils.isNotEmpty(startEvent.getInitiator())) {
    processDefinition.setProperty(PROPERTYNAME_INITIATOR_VARIABLE_NAME, startEvent.getInitiator());
  }

  // all start events share the same behavior:
  startEventActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createNoneStartEventActivityBehavior(startEvent));
  if (!startEvent.getEventDefinitions().isEmpty()) {
    EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
    if (eventDefinition instanceof TimerEventDefinition 
    		|| eventDefinition instanceof MessageEventDefinition
    		|| eventDefinition instanceof SignalEventDefinition) {
      bpmnParse.getBpmnParserHandlers().parseElement(bpmnParse, eventDefinition);
    } else {
      logger.warn("Unsupported event definition on start event", eventDefinition);
    }
  }
}
 
Example #4
Source File: StartEventJsonConverter.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
  StartEvent startEvent = (StartEvent) baseElement;
  if (StringUtils.isNotEmpty(startEvent.getInitiator())) {
    propertiesNode.put(PROPERTY_NONE_STARTEVENT_INITIATOR, startEvent.getInitiator());
  }

  if (StringUtils.isNotEmpty(startEvent.getFormKey())) {
    if (formKeyMap != null && formKeyMap.containsKey(startEvent.getFormKey())) {
      ObjectNode formRefNode = objectMapper.createObjectNode();
      ModelInfo modelInfo = formKeyMap.get(startEvent.getFormKey());
      formRefNode.put("id", modelInfo.getId());
      formRefNode.put("name", modelInfo.getName());
      formRefNode.put("key", modelInfo.getKey());
      propertiesNode.set(PROPERTY_FORM_REFERENCE, formRefNode);

    } else {
      setPropertyValue(PROPERTY_FORMKEY, startEvent.getFormKey(), propertiesNode);
    }
  }

  addFormProperties(startEvent.getFormProperties(), propertiesNode);
  addEventProperties(startEvent, propertiesNode);
}
 
Example #5
Source File: StartEventParseHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void selectInitial(BpmnParse bpmnParse, ActivityImpl startEventActivity, StartEvent startEvent, ProcessDefinitionEntity processDefinition) {
  if (processDefinition.getInitial() == null) {
    processDefinition.setInitial(startEventActivity);
  } else {
    // validate that there is a single none start event / timer start event:
    if (!startEventActivity.getProperty("type").equals("messageStartEvent")
        && !startEventActivity.getProperty("type").equals("signalStartEvent")
        && !startEventActivity.getProperty("type").equals("startTimerEvent")) {
      String currentInitialType = (String) processDefinition.getInitial().getProperty("type");
      if (currentInitialType.equals("messageStartEvent")) {
        processDefinition.setInitial(startEventActivity);
      } else {
        throw new ActivitiException("multiple none start events or timer start events not supported on process definition");
      }
    }
  }
}
 
Example #6
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 #7
Source File: DeploymentServiceImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void processUserTasks(Collection<FlowElement> flowElements, Process process, Map<String, StartEvent> startEventMap) {

    for (FlowElement flowElement : flowElements) {
      if (flowElement instanceof UserTask) {
        UserTask userTask = (UserTask) flowElement;
        if ("$INITIATOR".equals(userTask.getAssignee())) {
          if (startEventMap.get(process.getId()) != null) {
            userTask.setAssignee("${" + startEventMap.get(process.getId()).getInitiator() + "}");
          }
        }

      } else if (flowElement instanceof SubProcess) {
        processUserTasks(((SubProcess) flowElement).getFlowElements(), process, startEventMap);
      }
    }
  }
 
Example #8
Source File: AbstractProcessDefinitionResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected FormDefinition getStartForm(ProcessDefinition processDefinition) {
  FormDefinition formDefinition = null;
  BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
  Process process = bpmnModel.getProcessById(processDefinition.getKey());
  FlowElement startElement = process.getInitialFlowElement();
  if (startElement instanceof StartEvent) {
    StartEvent startEvent = (StartEvent) startElement;
    if (StringUtils.isNotEmpty(startEvent.getFormKey())) {
      formDefinition = formRepositoryService.getFormDefinitionByKeyAndParentDeploymentId(startEvent.getFormKey(), 
          processDefinition.getDeploymentId(), processDefinition.getTenantId());
    }
  }

  if (formDefinition == null) {
    // Definition found, but no form attached
    throw new NotFoundException("Process definition does not have a form defined: " + processDefinition.getId());
  }

  return formDefinition;
}
 
Example #9
Source File: DeploymentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void restoreTimerStartEvent(ProcessDefinition previousProcessDefinition, StartEvent startEvent, EventDefinition eventDefinition) {
  TimerEventDefinition timerEventDefinition = (TimerEventDefinition) eventDefinition;
  TimerJobEntity timer = TimerUtil.createTimerEntityForTimerEventDefinition((TimerEventDefinition) eventDefinition, false, null, TimerStartEventJobHandler.TYPE,
      TimerEventHandler.createConfiguration(startEvent.getId(), timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));
  
  if (timer != null) {
    TimerJobEntity timerJob = getJobManager().createTimerJob((TimerEventDefinition) eventDefinition, false, null, TimerStartEventJobHandler.TYPE,
        TimerEventHandler.createConfiguration(startEvent.getId(), timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));
    
    timerJob.setProcessDefinitionId(previousProcessDefinition.getId());
    
    if (previousProcessDefinition.getTenantId() != null) {
      timerJob.setTenantId(previousProcessDefinition.getTenantId());
    }
    
    getJobManager().scheduleTimerJob(timerJob);
  }
}
 
Example #10
Source File: AddBpmnModelTest.java    From CrazyWorkflowHandoutsActiviti6 with MIT License 6 votes vote down vote up
private static BpmnModel createProcessModel() {
	// 创建BPMN模型
	BpmnModel model = new BpmnModel();
	// 创建一个流程定义
	Process process = new Process();
	model.addProcess(process);
	process.setId("myProcess");
	process.setName("My Process");
	// 开始事件
	StartEvent startEvent = new StartEvent();
	startEvent.setId("startEvent");
	process.addFlowElement(startEvent);
	// 用户任务
	UserTask userTask = new UserTask();
	userTask.setName("User Task");
	userTask.setId("userTask");
	process.addFlowElement(userTask);
	// 结束事件
	EndEvent endEvent = new EndEvent();
	endEvent.setId("endEvent");
	process.addFlowElement(endEvent);		
	// 添加流程顺序
	process.addFlowElement(new SequenceFlow("startEvent", "userTask"));
	process.addFlowElement(new SequenceFlow("userTask", "endEvent"));
	return model;
}
 
Example #11
Source File: DeploymentEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void restoreMessageStartEvent(ProcessDefinition previousProcessDefinition, BpmnModel bpmnModel, StartEvent startEvent, EventDefinition eventDefinition) {
  MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
  if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
    Message message = bpmnModel.getMessage(messageEventDefinition.getMessageRef());
    messageEventDefinition.setMessageRef(message.getName());
  }

  MessageEventSubscriptionEntity newSubscription = getEventSubscriptionEntityManager().createMessageEventSubscription();
  newSubscription.setEventName(messageEventDefinition.getMessageRef());
  newSubscription.setActivityId(startEvent.getId());
  newSubscription.setConfiguration(previousProcessDefinition.getId());
  newSubscription.setProcessDefinitionId(previousProcessDefinition.getId());

  if (previousProcessDefinition.getTenantId() != null) {
    newSubscription.setTenantId(previousProcessDefinition.getTenantId());
  }

  getEventSubscriptionEntityManager().insert(newSubscription);
}
 
Example #12
Source File: FormHandlerUtil.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static StartFormHandler getStartFormHandler(CommandContext commandContext, ProcessDefinition processDefinition) {
  StartFormHandler startFormHandler = new DefaultStartFormHandler();
  org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(processDefinition.getId());
  
  FlowElement initialFlowElement = process.getInitialFlowElement();
  if (initialFlowElement instanceof StartEvent) {
    
    StartEvent startEvent = (StartEvent) initialFlowElement;
    
    List<FormProperty> formProperties = startEvent.getFormProperties();
    String formKey = startEvent.getFormKey();
    DeploymentEntity deploymentEntity = commandContext.getDeploymentEntityManager().findById(processDefinition.getDeploymentId());
    
    startFormHandler.parseConfiguration(formProperties, formKey, deploymentEntity, processDefinition);
    return startFormHandler;
  }
  
  return null;
  
}
 
Example #13
Source File: TestProcessUtil.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static org.activiti.bpmn.model.Process createOneTaskProcess() {
  org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();

  process.setId("oneTaskProcess");
  process.setName("The one task process");

  StartEvent startEvent = new StartEvent();
  startEvent.setId("start");
  process.addFlowElement(startEvent);

  UserTask userTask = new UserTask();
  userTask.setName("The Task");
  userTask.setId("theTask");
  userTask.setAssignee("kermit");
  process.addFlowElement(userTask);

  EndEvent endEvent = new EndEvent();
  endEvent.setId("theEnd");
  process.addFlowElement(endEvent);

  process.addFlowElement(new SequenceFlow("start", "theTask"));
  process.addFlowElement(new SequenceFlow("theTask", "theEnd"));

  return process;
}
 
Example #14
Source File: TestProcessUtil.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static org.activiti.bpmn.model.Process createOneTaskProcess() {
	org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();

	process.setId("oneTaskProcess");
	process.setName("The one task process");

	StartEvent startEvent = new StartEvent();
	startEvent.setId("start");
	process.addFlowElement(startEvent);

	UserTask userTask = new UserTask();
	userTask.setName("The Task");
	userTask.setId("theTask");
	userTask.setAssignee("kermit");
	process.addFlowElement(userTask);

	EndEvent endEvent = new EndEvent();
	endEvent.setId("theEnd");
	process.addFlowElement(endEvent);

	process.addFlowElement(new SequenceFlow("start", "theTask"));
	process.addFlowElement(new SequenceFlow("theTask", "theEnd"));

	return process;
}
 
Example #15
Source File: SyncProcessCmd.java    From lemon with Apache License 2.0 6 votes vote down vote up
/**
 * 配置表单,startEvent.
 */
public void processForm(StartEvent startEvent, BpmConfNode bpmConfNode) {
    if (startEvent.getFormKey() == null) {
        return;
    }

    BpmConfFormManager bpmConfFormManager = getBpmConfFormManager();
    BpmConfForm bpmConfForm = bpmConfFormManager.findUnique(
            "from BpmConfForm where bpmConfNode=?", bpmConfNode);

    if (bpmConfForm == null) {
        bpmConfForm = new BpmConfForm();
        bpmConfForm.setValue(startEvent.getFormKey());
        bpmConfForm.setType(0);
        bpmConfForm.setOriginValue(startEvent.getFormKey());
        bpmConfForm.setOriginType(0);
        bpmConfForm.setStatus(0);
        bpmConfForm.setBpmConfNode(bpmConfNode);
        bpmConfFormManager.save(bpmConfForm);
    }
}
 
Example #16
Source File: SubProcessMultiDiagramConverterNoDITest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
private void validateModel(BpmnModel model) {
  FlowElement flowElement = model.getMainProcess().getFlowElement("start1");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof StartEvent);
  assertEquals("start1", flowElement.getId());

  flowElement = model.getMainProcess().getFlowElement("userTask1");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof UserTask);
  assertEquals("userTask1", flowElement.getId());
  UserTask userTask = (UserTask) flowElement;
  assertTrue(userTask.getCandidateUsers().size() == 1);
  assertTrue(userTask.getCandidateGroups().size() == 1);

  flowElement = model.getMainProcess().getFlowElement("subprocess1");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof SubProcess);
  assertEquals("subprocess1", flowElement.getId());
  SubProcess subProcess = (SubProcess) flowElement;
  assertTrue(subProcess.getFlowElements().size() == 11);
}
 
Example #17
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 #18
Source File: SubProcessMultiDiagramConverterTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
private void validateModel(BpmnModel model) {
  FlowElement flowElement = model.getMainProcess().getFlowElement("start1");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof StartEvent);
  assertEquals("start1", flowElement.getId());

  flowElement = model.getMainProcess().getFlowElement("userTask1");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof UserTask);
  assertEquals("userTask1", flowElement.getId());
  UserTask userTask = (UserTask) flowElement;
  assertTrue(userTask.getCandidateUsers().size() == 1);
  assertTrue(userTask.getCandidateGroups().size() == 1);

  flowElement = model.getMainProcess().getFlowElement("subprocess1");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof SubProcess);
  assertEquals("subprocess1", flowElement.getId());
  SubProcess subProcess = (SubProcess) flowElement;
  assertTrue(subProcess.getFlowElements().size() == 11);
}
 
Example #19
Source File: TimerDefinitionConverterTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
private void validateModel(BpmnModel model) {
  IntermediateCatchEvent timer = (IntermediateCatchEvent) model.getMainProcess().getFlowElement("timer");
  assertNotNull(timer);
  TimerEventDefinition timerEvent = (TimerEventDefinition) timer.getEventDefinitions().get(0);
  assertThat(timerEvent.getCalendarName(), is("custom"));
  assertEquals("PT5M", timerEvent.getTimeDuration());

  StartEvent start = (StartEvent) model.getMainProcess().getFlowElement("theStart");
  assertNotNull(start);
  TimerEventDefinition startTimerEvent = (TimerEventDefinition) start.getEventDefinitions().get(0);
  assertThat(startTimerEvent.getCalendarName(), is("custom"));
  assertEquals("R2/PT5S", startTimerEvent.getTimeCycle());
  assertEquals("${EndDate}", startTimerEvent.getEndDate());

  BoundaryEvent boundaryTimer = (BoundaryEvent) model.getMainProcess().getFlowElement("boundaryTimer");
  assertNotNull(boundaryTimer);
  TimerEventDefinition boundaryTimerEvent = (TimerEventDefinition) boundaryTimer.getEventDefinitions().get(0);
  assertThat(boundaryTimerEvent.getCalendarName(), is("custom"));
  assertEquals("PT10S", boundaryTimerEvent.getTimeDuration());
  assertNull(boundaryTimerEvent.getEndDate());
}
 
Example #20
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 #21
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 #22
Source File: BpmnDeploymentTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml",
    "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg" })
public void testProcessDiagramResource() {
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();

  assertEquals("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml", processDefinition.getResourceName());
  BpmnModel processModel = repositoryService.getBpmnModel(processDefinition.getId());
  List<StartEvent> startEvents = processModel.getMainProcess().findFlowElementsOfType(StartEvent.class);
  assertEquals(1, startEvents.size());
  assertEquals("someFormKey", startEvents.get(0).getFormKey());

  String diagramResourceName = processDefinition.getDiagramResourceName();
  assertEquals("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg", diagramResourceName);

  InputStream diagramStream = repositoryService.getResourceAsStream(deploymentIdFromDeploymentAnnotation,
      "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg");
  byte[] diagramBytes = IoUtil.readInputStream(diagramStream, "diagram stream");
  assertEquals(33343, diagramBytes.length);
}
 
Example #23
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 #24
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 #25
Source File: SubProcessActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
  SubProcess subProcess = getSubProcessFromExecution(execution);

  FlowElement startElement = null;
  if (CollectionUtil.isNotEmpty(subProcess.getFlowElements())) {
    for (FlowElement subElement : subProcess.getFlowElements()) {
      if (subElement instanceof StartEvent) {
        StartEvent startEvent = (StartEvent) subElement;

        // start none event
        if (CollectionUtil.isEmpty(startEvent.getEventDefinitions())) {
          startElement = startEvent;
          break;
        }
      }
    }
  }

  if (startElement == null) {
    throw new ActivitiException("No initial activity found for subprocess " + subProcess.getId());
  }

  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  executionEntity.setScope(true);

  // initialize the template-defined data objects as variables
  Map<String, Object> dataObjectVars = processDataObjects(subProcess.getDataObjects());
  if (dataObjectVars != null) {
    executionEntity.setVariablesLocal(dataObjectVars);
  }

  ExecutionEntity startSubProcessExecution = Context.getCommandContext().getExecutionEntityManager()
      .createChildExecution(executionEntity);
  startSubProcessExecution.setCurrentFlowElement(startElement);
  Context.getAgenda().planContinueProcessOperation(startSubProcessExecution);
}
 
Example #26
Source File: EventSubscriptionManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void addSignalEventSubscriptions(CommandContext commandContext, ProcessDefinitionEntity processDefinition, org.activiti.bpmn.model.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 SignalEventDefinition) {
            SignalEventDefinition signalEventDefinition = (SignalEventDefinition) eventDefinition;
            SignalEventSubscriptionEntity subscriptionEntity = commandContext.getEventSubscriptionEntityManager().createSignalEventSubscription();
            Signal signal = bpmnModel.getSignal(signalEventDefinition.getSignalRef());
            if (signal != null) {
              subscriptionEntity.setEventName(signal.getName());
            } else {
              subscriptionEntity.setEventName(signalEventDefinition.getSignalRef());
            }
            subscriptionEntity.setActivityId(startEvent.getId());
            subscriptionEntity.setProcessDefinitionId(processDefinition.getId());
            if (processDefinition.getTenantId() != null) {
              subscriptionEntity.setTenantId(processDefinition.getTenantId());
            }

            Context.getCommandContext().getEventSubscriptionEntityManager().insert(subscriptionEntity);
          }
        }
      }
    }
  }
}
 
Example #27
Source File: EventSubscriptionManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void insertMessageEvent(MessageEventDefinition messageEventDefinition, StartEvent startEvent, ProcessDefinitionEntity processDefinition, BpmnModel bpmnModel) {
  CommandContext commandContext = Context.getCommandContext();
  if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
    Message message = bpmnModel.getMessage(messageEventDefinition.getMessageRef());
    messageEventDefinition.setMessageRef(message.getName());
  }

  // look for subscriptions for the same name in db:
  List<EventSubscriptionEntity> subscriptionsForSameMessageName = commandContext.getEventSubscriptionEntityManager()
      .findEventSubscriptionsByName(MessageEventHandler.EVENT_HANDLER_TYPE, messageEventDefinition.getMessageRef(), processDefinition.getTenantId());


  for (EventSubscriptionEntity eventSubscriptionEntity : subscriptionsForSameMessageName) {
    // throw exception only if there's already a subscription as start event
    if (eventSubscriptionEntity.getProcessInstanceId() == null || eventSubscriptionEntity.getProcessInstanceId().isEmpty()) { // processInstanceId != null or not empty -> it's a message related to an execution
      // the event subscription has no instance-id, so it's a message start event
      throw new ActivitiException("Cannot deploy process definition '" + processDefinition.getResourceName()
      + "': there already is a message event subscription for the message with name '" + messageEventDefinition.getMessageRef() + "'.");
    }
  }

  MessageEventSubscriptionEntity newSubscription = commandContext.getEventSubscriptionEntityManager().createMessageEventSubscription();
  newSubscription.setEventName(messageEventDefinition.getMessageRef());
  newSubscription.setActivityId(startEvent.getId());
  newSubscription.setConfiguration(processDefinition.getId());
  newSubscription.setProcessDefinitionId(processDefinition.getId());

  if (processDefinition.getTenantId() != null) {
    newSubscription.setTenantId(processDefinition.getTenantId());
  }

  commandContext.getEventSubscriptionEntityManager().insert(newSubscription);
}
 
Example #28
Source File: EventSubProcessMessageStartEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
  CommandContext commandContext = Context.getCommandContext();
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  
  StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement();
  if (startEvent.isInterrupting()) {  
    List<ExecutionEntity> childExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(executionEntity.getParentId());
    for (ExecutionEntity childExecution : childExecutions) {
      if (childExecution.getId().equals(executionEntity.getId()) == false) {
        executionEntityManager.deleteExecutionAndRelatedData(childExecution, 
            DeleteReason.EVENT_SUBPROCESS_INTERRUPTING + "(" + startEvent.getId() + ")", false);
      }
    }
  }
  
  EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
  List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions();
  for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
    if (eventSubscription instanceof MessageEventSubscriptionEntity && eventSubscription.getEventName().equals(messageEventDefinition.getMessageRef())) {

      eventSubscriptionEntityManager.delete(eventSubscription);
    }
  }
  
  executionEntity.setCurrentFlowElement((SubProcess) executionEntity.getCurrentFlowElement().getParentContainer());
  executionEntity.setScope(true);
  
  ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(executionEntity);
  outgoingFlowExecution.setCurrentFlowElement(startEvent);
  
  leave(outgoingFlowExecution);
}
 
Example #29
Source File: StartEventParseHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeParse(BpmnParse bpmnParse, StartEvent element) {
  if (element.getSubProcess() != null && element.getSubProcess() instanceof EventSubProcess) {
    if (CollectionUtil.isNotEmpty(element.getEventDefinitions())) {
      EventDefinition eventDefinition = element.getEventDefinitions().get(0);
      if (eventDefinition instanceof MessageEventDefinition) {
        MessageEventDefinition messageDefinition = (MessageEventDefinition) eventDefinition;
        BpmnModel bpmnModel = bpmnParse.getBpmnModel();
        String messageRef = messageDefinition.getMessageRef();
        if (bpmnModel.containsMessageId(messageRef)) {
          Message message = bpmnModel.getMessage(messageRef);
          messageDefinition.setMessageRef(message.getName());
          messageDefinition.setExtensionElements(message.getExtensionElements());
        }
        element.setBehavior(bpmnParse.getActivityBehaviorFactory().createEventSubProcessMessageStartEventActivityBehavior(element, messageDefinition));
      
      } else if (eventDefinition instanceof ErrorEventDefinition) {
        element.setBehavior(bpmnParse.getActivityBehaviorFactory().createEventSubProcessErrorStartEventActivityBehavior(element));
      }
    }
    
  } else if (CollectionUtil.isEmpty(element.getEventDefinitions())) {
    element.setBehavior(bpmnParse.getActivityBehaviorFactory().createNoneStartEventActivityBehavior(element));
  }
  
  if (element.getSubProcess() == null && (CollectionUtil.isEmpty(element.getEventDefinitions()) || 
      bpmnParse.getCurrentProcess().getInitialFlowElement() == null)) {

    bpmnParse.getCurrentProcess().setInitialFlowElement(element);
  }
}
 
Example #30
Source File: EventSubProcessMessageStartEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
  StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement();
  EventSubProcess eventSubProcess = (EventSubProcess) startEvent.getSubProcess();

  execution.setScope(true);

  // initialize the template-defined data objects as variables
  Map<String, Object> dataObjectVars = processDataObjects(eventSubProcess.getDataObjects());
  if (dataObjectVars != null) {
    execution.setVariablesLocal(dataObjectVars);
  }
}