org.activiti.bpmn.model.SequenceFlow Java Examples

The following examples show how to use org.activiti.bpmn.model.SequenceFlow. 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: ModelImageService.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void scaleFlowElements(Collection<FlowElement> elementList, BpmnModel bpmnModel, double scaleFactor) {
  for (FlowElement flowElement : elementList) {
    List<GraphicInfo> graphicInfoList = new ArrayList<GraphicInfo>();
    if (flowElement instanceof SequenceFlow) {
      List<GraphicInfo> flowList = bpmnModel.getFlowLocationGraphicInfo(flowElement.getId());
      if (flowList != null) {
        graphicInfoList.addAll(flowList);
      }
    } else {
      graphicInfoList.add(bpmnModel.getGraphicInfo(flowElement.getId()));
    }

    scaleGraphicInfoList(graphicInfoList, scaleFactor);

    if (flowElement instanceof SubProcess) {
      SubProcess subProcess = (SubProcess) flowElement;
      scaleFlowElements(subProcess.getFlowElements(), bpmnModel, scaleFactor);
    }
  }
}
 
Example #3
Source File: DisplayJsonClientResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected List<String> gatherCompletedFlows(List<String> completedActivityInstances,
    List<String> currentActivityinstances, BpmnModel pojoModel) {

List<String> completedFlows = new ArrayList<String>();
List<String> activities = new ArrayList<String>(completedActivityInstances);
activities.addAll(currentActivityinstances);

// TODO: not a robust way of checking when parallel paths are active, should be revisited
// Go over all activities and check if it's possible to match any outgoing paths against the activities
  for (FlowElement activity : pojoModel.getMainProcess().getFlowElements()) {
  	if(activity instanceof FlowNode) {
  		int index = activities.indexOf(activity.getId());
  		if (index >= 0 && index + 1 < activities.size()) {
  			List<SequenceFlow> outgoingFlows = ((FlowNode) activity).getOutgoingFlows();
  			for (SequenceFlow flow : outgoingFlows) {
  				String destinationFlowId = flow.getTargetRef();
  				if (destinationFlowId.equals(activities.get(index + 1))) {
  					completedFlows.add(flow.getId());
  				}
  			}
  		}
  	}
  }
 return completedFlows;
}
 
Example #4
Source File: SequenceFlowJsonConverter.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void setFieldConditionExpression(SequenceFlow flow, JsonNode expressionNode) {
  String fieldId = null;
  if (expressionNode.get("fieldId") != null && expressionNode.get("fieldId").isNull() == false) {
    fieldId = expressionNode.get("fieldId").asText();
  }

  String operator = null;
  if (expressionNode.get("operator") != null && expressionNode.get("operator").isNull() == false) {
    operator = expressionNode.get("operator").asText();
  }

  String value = null;
  if (expressionNode.get("value") != null && expressionNode.get("value").isNull() == false) {
    value = expressionNode.get("value").asText();
  }

  if (fieldId != null && operator != null && value != null) {
    flow.setConditionExpression("${" + fieldId + " " + operator + " " + value + "}");
    addExtensionElement("conditionFieldId", fieldId, flow);
    addExtensionElement("conditionOperator", operator, flow);
    addExtensionElement("conditionValue", value, flow);
  }
}
 
Example #5
Source File: SequenceFlowJsonConverter.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void setOutcomeConditionExpression(SequenceFlow flow, JsonNode expressionNode) {
  Long formId = null;
  if (expressionNode.get("outcomeFormId") != null && expressionNode.get("outcomeFormId").isNull() == false) {
    formId = expressionNode.get("outcomeFormId").asLong();
  }

  String operator = null;
  if (expressionNode.get("operator") != null && expressionNode.get("operator").isNull() == false) {
    operator = expressionNode.get("operator").asText();
  }

  String outcomeName = null;
  if (expressionNode.get("outcomeName") != null && expressionNode.get("outcomeName").isNull() == false) {
    outcomeName = expressionNode.get("outcomeName").asText();
  }

  if (formId != null && operator != null && outcomeName != null) {
    flow.setConditionExpression("${form" + formId + "outcome " + operator + " " + outcomeName + "}");
    addExtensionElement("conditionFormId", String.valueOf(formId), flow);
    addExtensionElement("conditionOperator", operator, flow);
    addExtensionElement("conditionOutcomeName", outcomeName, flow);
  }
}
 
Example #6
Source File: ModelImageService.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void calculateWidthForFlowElements(Collection<FlowElement> elementList, BpmnModel bpmnModel, GraphicInfo diagramInfo) {
  for (FlowElement flowElement : elementList) {
    List<GraphicInfo> graphicInfoList = new ArrayList<GraphicInfo>();
    if (flowElement instanceof SequenceFlow) {
      List<GraphicInfo> flowGraphics = bpmnModel.getFlowLocationGraphicInfo(flowElement.getId());
      if (flowGraphics != null && flowGraphics.size() > 0) {
        graphicInfoList.addAll(flowGraphics);
      }
    } else {
      GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowElement.getId());
      if (graphicInfo != null) {
        graphicInfoList.add(graphicInfo);
      }
    }

    processGraphicInfoList(graphicInfoList, diagramInfo);
  }
}
 
Example #7
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 #8
Source File: RuntimeDisplayJsonClientResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected List<String> gatherCompletedFlows(Set<String> completedActivityInstances, Set<String> currentActivityinstances, BpmnModel pojoModel) {

    List<String> completedFlows = new ArrayList<String>();
    List<String> activities = new ArrayList<String>(completedActivityInstances);
    activities.addAll(currentActivityinstances);

    // TODO: not a robust way of checking when parallel paths are active, should be revisited
    // Go over all activities and check if it's possible to match any outgoing paths against the activities
    for (FlowElement activity : pojoModel.getMainProcess().getFlowElements()) {
      if (activity instanceof FlowNode) {
        int index = activities.indexOf(activity.getId());
        if (index >= 0 && index + 1 < activities.size()) {
          List<SequenceFlow> outgoingFlows = ((FlowNode) activity).getOutgoingFlows();
          for (SequenceFlow flow : outgoingFlows) {
            String destinationFlowId = flow.getTargetRef();
            if (destinationFlowId.equals(activities.get(index + 1))) {
              completedFlows.add(flow.getId());
            }
          }
        }
      }
    }
    return completedFlows;
  }
 
Example #9
Source File: BpmnImageTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void scaleFlowElements(Collection<FlowElement> elementList, BpmnModel bpmnModel, double scaleFactor) {
    for (FlowElement flowElement : elementList) {
    	List<GraphicInfo> graphicInfoList = new ArrayList<GraphicInfo>();
    	if (flowElement instanceof SequenceFlow) {
    		graphicInfoList.addAll(bpmnModel.getFlowLocationGraphicInfo(flowElement.getId()));
    	} else {
    		graphicInfoList.add(bpmnModel.getGraphicInfo(flowElement.getId()));
    	}
    	
    	scaleGraphicInfoList(graphicInfoList, scaleFactor);
    	
    	if (flowElement instanceof SubProcess) {
    		SubProcess subProcess = (SubProcess) flowElement;
    		scaleFlowElements(subProcess.getFlowElements(), bpmnModel, scaleFactor);
    	}
    }
}
 
Example #10
Source File: ConditionUtil.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static boolean hasTrueCondition(SequenceFlow sequenceFlow, DelegateExecution execution) {
  String conditionExpression = null;
  if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
    ObjectNode elementProperties = Context.getBpmnOverrideElementProperties(sequenceFlow.getId(), execution.getProcessDefinitionId());
    conditionExpression = getActiveValue(sequenceFlow.getConditionExpression(), DynamicBpmnConstants.SEQUENCE_FLOW_CONDITION, elementProperties);
  } else {
    conditionExpression = sequenceFlow.getConditionExpression();
  }
  
  if (StringUtils.isNotEmpty(conditionExpression)) {

    Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(conditionExpression);
    Condition condition = new UelExpressionCondition(expression);
    if (condition.evaluate(sequenceFlow.getId(), execution)) {
      return true;
    }

    return false;

  } else {
    return true;
  }

}
 
Example #11
Source File: BpmnParse.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void createBPMNEdge(String key, List<GraphicInfo> graphicList) {
  FlowElement flowElement = bpmnModel.getFlowElement(key);
  if (flowElement instanceof SequenceFlow) {
    SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
    List<Integer> waypoints = new ArrayList<Integer>();
    for (GraphicInfo waypointInfo : graphicList) {
      waypoints.add((int) waypointInfo.getX());
      waypoints.add((int) waypointInfo.getY());
    }
    sequenceFlow.setWaypoints(waypoints);
    
  } else if (bpmnModel.getArtifact(key) != null) {
    // it's an association, so nothing to do
  } else {
    LOGGER.warn("Invalid reference in 'bpmnElement' attribute, sequenceFlow " + key + " not found");
  }
}
 
Example #12
Source File: DefaultHistoryManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public HistoricActivityInstanceEntity findActivityInstance(ExecutionEntity execution, boolean createOnNotFound, boolean endTimeMustBeNull) {
  String activityId = null;
  if (execution.getCurrentFlowElement() instanceof FlowNode) {
    activityId = execution.getCurrentFlowElement().getId();
  } else if (execution.getCurrentFlowElement() instanceof SequenceFlow
      && execution.getCurrentActivitiListener() == null) { // while executing sequence flow listeners, we don't want historic activities
    activityId = ( (SequenceFlow) (execution.getCurrentFlowElement())).getSourceFlowElement().getId();
  } 
  
  if (activityId != null) {
    return findActivityInstance(execution, activityId, createOnNotFound, endTimeMustBeNull);
  }
  
  return null;
}
 
Example #13
Source File: MyPostParseHandler.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
@Override
public void parse(BpmnParse bpmnParse, BaseElement element) {
    if (element instanceof Process) {
        ProcessDefinitionEntity processDefinition = bpmnParse.getCurrentProcessDefinition();
        String key = processDefinition.getKey();
        processDefinition.setKey(key + "-modified-by-post-parse-handler");
    } else if (element instanceof UserTask) {
        UserTask userTask = (UserTask) element;
        List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
        System.out.println("UserTask:[" + userTask.getName() + "]的输出流:");
        for (SequenceFlow outgoingFlow : outgoingFlows) {
            System.out.println("\t" + outgoingFlow.getTargetRef());
        }
        System.out.println();
    }
}
 
Example #14
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 #15
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 #16
Source File: CustomSequenceFlowBpmnParseHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void executeParse(BpmnParse bpmnParse, SequenceFlow flow) {
  
  // Do the regular stuff
  super.executeParse(bpmnParse, flow);
  
  // Add extension element conditions
  Map<String, List<ExtensionElement>> extensionElements = flow.getExtensionElements();
  if (extensionElements.containsKey("activiti_custom_condition")) {
    List<ExtensionElement> conditionsElements = extensionElements.get("activiti_custom_condition");
    CustomSetConditionsExecutionListener customFlowListener = new CustomSetConditionsExecutionListener();
    customFlowListener.setFlowId(flow.getId());
    for (ExtensionElement conditionElement : conditionsElements) {
      customFlowListener.addCondition(conditionElement.getElementText());
    }
    ActivityImpl activity = findActivity(bpmnParse, flow.getSourceRef());
    activity.addExecutionListener("start", customFlowListener);
  }
}
 
Example #17
Source File: PoolsConverterTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
private void validateModel(BpmnModel model) {
  assertEquals(1, model.getPools().size());
  Pool pool = model.getPools().get(0);
  assertEquals("pool1", pool.getId());
  assertEquals("Pool", pool.getName());
  Process process = model.getProcess(pool.getId());
  assertNotNull(process);
  assertEquals(2, process.getLanes().size());
  Lane lane = process.getLanes().get(0);
  assertEquals("lane1", lane.getId());
  assertEquals("Lane 1", lane.getName());
  assertEquals(2, lane.getFlowReferences().size());
  lane = process.getLanes().get(1);
  assertEquals("lane2", lane.getId());
  assertEquals("Lane 2", lane.getName());
  assertEquals(2, lane.getFlowReferences().size());
  FlowElement flowElement = process.getFlowElement("flow1");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof SequenceFlow);
}
 
Example #18
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 #19
Source File: CustomSequenceFlowBpmnParseHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void executeParse(BpmnParse bpmnParse, SequenceFlow flow) {

    // Do the regular stuff
    super.executeParse(bpmnParse, flow);

    // Add extension element conditions
    Map<String, List<ExtensionElement>> extensionElements = flow.getExtensionElements();
    if (extensionElements.containsKey("activiti_custom_condition")) {
      List<ExtensionElement> conditionsElements = extensionElements.get("activiti_custom_condition");
      
      CustomSetConditionsExecutionListener customFlowListener = new CustomSetConditionsExecutionListener();
      customFlowListener.setFlowId(flow.getId());
      for (ExtensionElement conditionElement : conditionsElements) {
        customFlowListener.addCondition(conditionElement.getElementText());
      }
      
      ActivitiListener activitiListener = new ActivitiListener();
      activitiListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_INSTANCE);
      activitiListener.setInstance(customFlowListener);
      activitiListener.setEvent("start");
      flow.getSourceFlowElement().getExecutionListeners().add(activitiListener);
      
    }
  }
 
Example #20
Source File: IntermediateCatchEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected EventGateway getPrecedingEventBasedGateway(DelegateExecution execution) {
  FlowElement currentFlowElement = execution.getCurrentFlowElement();
  if (currentFlowElement instanceof IntermediateCatchEvent) {
    IntermediateCatchEvent intermediateCatchEvent = (IntermediateCatchEvent) currentFlowElement;
    List<SequenceFlow> incomingSequenceFlow = intermediateCatchEvent.getIncomingFlows();
    
    // If behind an event based gateway, there is only one incoming sequence flow that originates from said gateway
    if (incomingSequenceFlow != null && incomingSequenceFlow.size() == 1) {
      SequenceFlow sequenceFlow = incomingSequenceFlow.get(0);
      FlowElement sourceFlowElement = sequenceFlow.getSourceFlowElement();
      if (sourceFlowElement instanceof EventGateway) {
        return (EventGateway) sourceFlowElement;
      }
    }
    
  }
  return null;
}
 
Example #21
Source File: SequenceFlowXMLConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeAdditionalChildElements(BaseElement element, BpmnModel model, XMLStreamWriter xtw) throws Exception {
  SequenceFlow sequenceFlow = (SequenceFlow) element;

  if (StringUtils.isNotEmpty(sequenceFlow.getConditionExpression())) {
    xtw.writeStartElement(ELEMENT_FLOW_CONDITION);
    xtw.writeAttribute(XSI_PREFIX, XSI_NAMESPACE, "type", "tFormalExpression");
    xtw.writeCData(sequenceFlow.getConditionExpression());
    xtw.writeEndElement();
  }
}
 
Example #22
Source File: IntermediateCatchEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void deleteOtherEventsRelatedToEventBasedGateway(DelegateExecution execution, EventGateway eventGateway) {
  
  // To clean up the other events behind the event based gateway, we must gather the 
  // activity ids of said events and check the _sibling_ executions of the incoming execution.
  // Note that it can happen that there are multiple such execution in those activity ids,
  // (for example a parallel gw going twice to the event based gateway, kinda silly, but valid)
  // so we only take _one_ result of such a query for deletion.
  
  // Gather all activity ids for the events after the event based gateway that need to be destroyed
  List<SequenceFlow> outgoingSequenceFlows = eventGateway.getOutgoingFlows();
  Set<String> eventActivityIds = new HashSet<String>(outgoingSequenceFlows.size() - 1); // -1, the event being triggered does not need to be deleted
  for (SequenceFlow outgoingSequenceFlow : outgoingSequenceFlows) {
    if (outgoingSequenceFlow.getTargetFlowElement() != null
        && !outgoingSequenceFlow.getTargetFlowElement().getId().equals(execution.getCurrentActivityId())) {
      eventActivityIds.add(outgoingSequenceFlow.getTargetFlowElement().getId());
    }
  }
  
  CommandContext commandContext = Context.getCommandContext();
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
  
  // Find the executions
  List<ExecutionEntity> executionEntities = executionEntityManager
      .findExecutionsByParentExecutionAndActivityIds(execution.getParentId(), eventActivityIds);
  
  // Execute the cancel behaviour of the IntermediateCatchEvent
  for (ExecutionEntity executionEntity : executionEntities) {
    if (eventActivityIds.contains(executionEntity.getActivityId()) && execution.getCurrentFlowElement() instanceof IntermediateCatchEvent) {
      IntermediateCatchEvent intermediateCatchEvent = (IntermediateCatchEvent) execution.getCurrentFlowElement();
      if (intermediateCatchEvent.getBehavior() instanceof IntermediateCatchEventActivityBehavior) {
        ((IntermediateCatchEventActivityBehavior) intermediateCatchEvent.getBehavior()).eventCancelledByEventGateway(executionEntity);
        eventActivityIds.remove(executionEntity.getActivityId()); // We only need to delete ONE execution at the event.
      }
    }
  }
}
 
Example #23
Source File: ProcessDefinitionPersistenceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testProcessDefinitionIntrospection() {
  String deploymentId = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/db/processOne.bpmn20.xml").deploy().getId();

  String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
  ProcessDefinition processDefinition = ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(procDefId);

  assertEquals(procDefId, processDefinition.getId());
  assertEquals("Process One", processDefinition.getName());
  
  Process process = repositoryService.getBpmnModel(processDefinition.getId()).getMainProcess();
  StartEvent startElement = (StartEvent) process.getFlowElement("start");
  assertNotNull(startElement);
  assertEquals("start", startElement.getId());
  assertEquals("S t a r t", startElement.getName());
  assertEquals("the start event", startElement.getDocumentation());
  List<SequenceFlow> outgoingFlows = startElement.getOutgoingFlows();
  assertEquals(1, outgoingFlows.size());
  assertEquals("${a == b}", outgoingFlows.get(0).getConditionExpression());

  EndEvent endElement = (EndEvent) process.getFlowElement("end");
  assertNotNull(endElement);
  assertEquals("end", endElement.getId());

  assertEquals("flow1", outgoingFlows.get(0).getId());
  assertEquals("Flow One", outgoingFlows.get(0).getName());
  assertEquals("The only transitions in the process", outgoingFlows.get(0).getDocumentation());
  assertSame(startElement, outgoingFlows.get(0).getSourceFlowElement());
  assertSame(endElement, outgoingFlows.get(0).getTargetFlowElement());

  repositoryService.deleteDeployment(deploymentId);
}
 
Example #24
Source File: TestProcessUtil.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static BpmnModel createTwoTasksBpmnModel() {
  BpmnModel model = new BpmnModel();
  org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();
  model.addProcess(process);
  process.setId("twoTasksProcess");
  process.setName("The two tasks process");

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

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

  UserTask userTask2 = new UserTask();
  userTask2.setName("The Second Task");
  userTask2.setId("task2");
  userTask2.setAssignee("kermit");
  process.addFlowElement(userTask2);

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

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

  return model;
}
 
Example #25
Source File: BpmnDeploymentTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testDiagramCreationDisabled() {
  // disable diagram generation
  processEngineConfiguration.setCreateDiagramOnDeploy(false);

  try {
    repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/bpmn/parse/BpmnParseTest.testParseDiagramInterchangeElements.bpmn20.xml").deploy();

    // Graphical information is not yet exposed publicly, so we need to
    // do some plumbing
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    ProcessDefinition processDefinition = commandExecutor.execute(new Command<ProcessDefinition>() {
      public ProcessDefinition execute(CommandContext commandContext) {
        return Context.getProcessEngineConfiguration().getDeploymentManager().findDeployedLatestProcessDefinitionByKey("myProcess");
      }
    });

    assertNotNull(processDefinition);
    BpmnModel processModel = repositoryService.getBpmnModel(processDefinition.getId());
    assertEquals(14, processModel.getMainProcess().getFlowElements().size());
    assertEquals(7, processModel.getMainProcess().findFlowElementsOfType(SequenceFlow.class).size());

    // Check that no diagram has been created
    List<String> resourceNames = repositoryService.getDeploymentResourceNames(processDefinition.getDeploymentId());
    assertEquals(1, resourceNames.size());

    repositoryService.deleteDeployment(repositoryService.createDeploymentQuery().singleResult().getId(), true);
  } finally {
    processEngineConfiguration.setCreateDiagramOnDeploy(true);
  }
}
 
Example #26
Source File: EventJavaTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testStartEventWithExecutionListener() throws Exception {
  BpmnModel bpmnModel = new BpmnModel();
  Process process = new Process();
  process.setId("simpleProcess");
  process.setName("Very simple process");
  bpmnModel.getProcesses().add(process);
  StartEvent startEvent = new StartEvent();
  startEvent.setId("startEvent1");
  TimerEventDefinition timerDef = new TimerEventDefinition();
  timerDef.setTimeDuration("PT5M");
  startEvent.getEventDefinitions().add(timerDef);
  ActivitiListener listener = new ActivitiListener();
  listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
  listener.setImplementation("${test}");
  listener.setEvent("end");
  startEvent.getExecutionListeners().add(listener);
  process.addFlowElement(startEvent);
  UserTask task = new UserTask();
  task.setId("reviewTask");
  task.setAssignee("kermit");
  process.addFlowElement(task);
  SequenceFlow flow1 = new SequenceFlow();
  flow1.setId("flow1");
  flow1.setSourceRef("startEvent1");
  flow1.setTargetRef("reviewTask");
  process.addFlowElement(flow1);
  EndEvent endEvent = new EndEvent();
  endEvent.setId("endEvent1");
  process.addFlowElement(endEvent);

  byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);

  new BpmnXMLConverter().validateModel(new InputStreamSource(new ByteArrayInputStream(xml)));

  Deployment deployment = repositoryService.createDeployment().name("test").addString("test.bpmn20.xml", new String(xml)).deploy();
  repositoryService.deleteDeployment(deployment.getId());
}
 
Example #27
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 #28
Source File: ExclusiveGatewayValidator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void validateExclusiveGateway(Process process, ExclusiveGateway exclusiveGateway, List<ValidationError> errors) {
  if (exclusiveGateway.getOutgoingFlows().isEmpty()) {
    addError(errors, Problems.EXCLUSIVE_GATEWAY_NO_OUTGOING_SEQ_FLOW, process, exclusiveGateway, "Exclusive gateway has no outgoing sequence flow");
  } else if (exclusiveGateway.getOutgoingFlows().size() == 1) {
    SequenceFlow sequenceFlow = exclusiveGateway.getOutgoingFlows().get(0);
    if (StringUtils.isNotEmpty(sequenceFlow.getConditionExpression())) {
      addError(errors, Problems.EXCLUSIVE_GATEWAY_CONDITION_NOT_ALLOWED_ON_SINGLE_SEQ_FLOW, process, exclusiveGateway,
          "Exclusive gateway has only one outgoing sequence flow. This is not allowed to have a condition.");
    }
  } else {
    String defaultSequenceFlow = exclusiveGateway.getDefaultFlow();

    List<SequenceFlow> flowsWithoutCondition = new ArrayList<SequenceFlow>();
    for (SequenceFlow flow : exclusiveGateway.getOutgoingFlows()) {
      String condition = flow.getConditionExpression();
      boolean isDefaultFlow = flow.getId() != null && flow.getId().equals(defaultSequenceFlow);
      boolean hasConditon = StringUtils.isNotEmpty(condition);

      if (!hasConditon && !isDefaultFlow) {
        flowsWithoutCondition.add(flow);
      }
      if (hasConditon && isDefaultFlow) {
        addError(errors, Problems.EXCLUSIVE_GATEWAY_CONDITION_ON_DEFAULT_SEQ_FLOW, process, exclusiveGateway, "Default sequenceflow has a condition, which is not allowed");
      }
    }

    if (!flowsWithoutCondition.isEmpty()) {
      addWarning(errors, Problems.EXCLUSIVE_GATEWAY_SEQ_FLOW_WITHOUT_CONDITIONS, process, exclusiveGateway,
          "Exclusive gateway has at least one outgoing sequence flow without a condition (which isn't the default one)");
    }

  }
}
 
Example #29
Source File: SequenceFlowXMLConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
  SequenceFlow sequenceFlow = new SequenceFlow();
  BpmnXMLUtil.addXMLLocation(sequenceFlow, xtr);
  sequenceFlow.setSourceRef(xtr.getAttributeValue(null, ATTRIBUTE_FLOW_SOURCE_REF));
  sequenceFlow.setTargetRef(xtr.getAttributeValue(null, ATTRIBUTE_FLOW_TARGET_REF));
  sequenceFlow.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
  sequenceFlow.setSkipExpression(xtr.getAttributeValue(null, ATTRIBUTE_FLOW_SKIP_EXPRESSION));

  parseChildElements(getXMLElementName(), sequenceFlow, model, xtr);

  return sequenceFlow;
}
 
Example #30
Source File: TestProcessUtil.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static BpmnModel createTwoTasksBpmnModel() {
	BpmnModel model = new BpmnModel();
	org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();
	model.addProcess(process);
	process.setId("twoTasksProcess");
	process.setName("The two tasks process");

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

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

	UserTask userTask2 = new UserTask();
	userTask2.setName("The Second Task");
	userTask2.setId("task2");
	userTask2.setAssignee("kermit");
	process.addFlowElement(userTask2);

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

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

	return model;
}