org.activiti.bpmn.model.Activity Java Examples

The following examples show how to use org.activiti.bpmn.model.Activity. 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: AbstractBpmnParseHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public ActivityImpl createActivityOnScope(BpmnParse bpmnParse, FlowElement flowElement, String xmlLocalName, ScopeImpl scopeElement) {
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Parsing activity {}", flowElement.getId());
  }
  
  ActivityImpl activity = scopeElement.createActivity(flowElement.getId());
  bpmnParse.setCurrentActivity(activity);

  activity.setProperty("name", flowElement.getName());
  activity.setProperty("documentation", flowElement.getDocumentation());
  if (flowElement instanceof Activity) {
    Activity modelActivity = (Activity) flowElement;
    activity.setProperty("default", modelActivity.getDefaultFlow());
    if(modelActivity.isForCompensation()) {
      activity.setProperty(PROPERTYNAME_IS_FOR_COMPENSATION, true);        
    }
  } else if (flowElement instanceof Gateway) {
    activity.setProperty("default", ((Gateway) flowElement).getDefaultFlow());
  }
  activity.setProperty("type", xmlLocalName);
  
  return activity;
}
 
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: ActivitiMapExceptionParser.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
  if (!(parentElement instanceof Activity))
    return;

  String errorCode = xtr.getAttributeValue(null, MAP_EXCEPTION_ERRORCODE);
  String andChildren = xtr.getAttributeValue(null, MAP_EXCEPTION_ANDCHILDREN);
  String exceptionClass = xtr.getElementText();
  boolean hasChildrenBool = false;

  if (StringUtils.isEmpty(andChildren) || andChildren.toLowerCase().equals("false")) {
    hasChildrenBool = false;
  } else if (andChildren.toLowerCase().equals("true")) {
    hasChildrenBool = true;
  } else {
    throw new XMLException("'" + andChildren + "' is not valid boolean in mapException with errorCode=" + errorCode + " and class=" + exceptionClass);
  }
  
  if (StringUtils.isEmpty(errorCode) || StringUtils.isEmpty(errorCode.trim())) {
    throw new XMLException("No errorCode defined mapException with errorCode=" + errorCode + " and class=" + exceptionClass);
  }

  ((Activity) parentElement).getMapExceptions().add(new MapExceptionEntry(errorCode, exceptionClass, hasChildrenBool));
}
 
Example #4
Source File: ParallelGatewayActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected DelegateExecution findMultiInstanceParentExecution(DelegateExecution execution) {
  DelegateExecution multiInstanceExecution = null;
  DelegateExecution parentExecution = execution.getParent();
  if (parentExecution != null && parentExecution.getCurrentFlowElement() != null) {
    FlowElement flowElement = parentExecution.getCurrentFlowElement();
    if (flowElement instanceof Activity) {
      Activity activity = (Activity) flowElement;
      if (activity.getLoopCharacteristics() != null) {
        multiInstanceExecution = parentExecution;
      }
    }

    if (multiInstanceExecution == null) {
      DelegateExecution potentialMultiInstanceExecution = findMultiInstanceParentExecution(parentExecution);
      if (potentialMultiInstanceExecution != null) {
        multiInstanceExecution = potentialMultiInstanceExecution;
      }
    }
  }

  return multiInstanceExecution;
}
 
Example #5
Source File: BaseBpmnJsonConverter.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void processDataStoreReferences(FlowElementsContainer container, String dataStoreReferenceId, ArrayNode outgoingArrayNode) {
  for (FlowElement flowElement : container.getFlowElements()) {
    if (flowElement instanceof Activity) {
      Activity activity = (Activity) flowElement;

      if (CollectionUtils.isNotEmpty(activity.getDataInputAssociations())) {
        for (DataAssociation dataAssociation : activity.getDataInputAssociations()) {
          if (dataStoreReferenceId.equals(dataAssociation.getSourceRef())) {
            outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(dataAssociation.getId()));
          }
        }
      }

    } else if (flowElement instanceof SubProcess) {
      processDataStoreReferences((SubProcess) flowElement, dataStoreReferenceId, outgoingArrayNode);
    }
  }
}
 
Example #6
Source File: CamelBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected boolean isASync(DelegateExecution execution) {
  boolean async = false;
  if (execution.getCurrentFlowElement() instanceof Activity) {
    async = ((Activity) execution.getCurrentFlowElement()).isAsynchronous();
  }
  return async;
}
 
Example #7
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 #8
Source File: FlowElementValidator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void handleMultiInstanceLoopCharacteristics(Process process, Activity activity, List<ValidationError> errors) {
	MultiInstanceLoopCharacteristics multiInstanceLoopCharacteristics = activity.getLoopCharacteristics();
	if (multiInstanceLoopCharacteristics != null) {

		if (StringUtils.isEmpty(multiInstanceLoopCharacteristics.getLoopCardinality())
    		&& StringUtils.isEmpty(multiInstanceLoopCharacteristics.getInputDataItem())) {
    	
		  addError(errors, Problems.MULTI_INSTANCE_MISSING_COLLECTION, process, activity,
    			"Either loopCardinality or loopDataInputRef/activiti:collection must been set");
    }

	}
}
 
Example #9
Source File: BpmnXMLConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void processFlowElements(Collection<FlowElement> flowElementList, BaseElement parentScope) {
  for (FlowElement flowElement : flowElementList) {
    if (flowElement instanceof SequenceFlow) {
      SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
      FlowNode sourceNode = getFlowNodeFromScope(sequenceFlow.getSourceRef(), parentScope);
      if (sourceNode != null) {
        sourceNode.getOutgoingFlows().add(sequenceFlow);
        sequenceFlow.setSourceFlowElement(sourceNode);
      }
      
      FlowNode targetNode = getFlowNodeFromScope(sequenceFlow.getTargetRef(), parentScope);
      if (targetNode != null) {
        targetNode.getIncomingFlows().add(sequenceFlow);
        sequenceFlow.setTargetFlowElement(targetNode);
      }
      
    } else if (flowElement instanceof BoundaryEvent) {
      BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
      FlowElement attachedToElement = getFlowNodeFromScope(boundaryEvent.getAttachedToRefId(), parentScope);
      if (attachedToElement instanceof Activity) {
        Activity attachedActivity = (Activity) attachedToElement;
        boundaryEvent.setAttachedToRef(attachedActivity);
        attachedActivity.getBoundaryEvents().add(boundaryEvent);
      }
      
    } else if (flowElement instanceof SubProcess) {
      SubProcess subProcess = (SubProcess) flowElement;
      processFlowElements(subProcess.getFlowElements(), subProcess);
    }
  }
}
 
Example #10
Source File: FailedJobRetryCountExport.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static void writeFailedJobRetryCount(Activity activity, XMLStreamWriter xtw) throws Exception {
  String failedJobRetryCycle = activity.getFailedJobRetryTimeCycleValue();
  if (failedJobRetryCycle != null) {

    if (StringUtils.isNotEmpty(failedJobRetryCycle)) {
      xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, FAILED_JOB_RETRY_TIME_CYCLE, ACTIVITI_EXTENSIONS_NAMESPACE);
      xtw.writeCharacters(failedJobRetryCycle);
      xtw.writeEndElement();
    }
  }
}
 
Example #11
Source File: MultiInstanceExport.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static void writeMultiInstance(Activity activity, XMLStreamWriter xtw) throws Exception {
  if (activity.getLoopCharacteristics() != null) {
    MultiInstanceLoopCharacteristics multiInstanceObject = activity.getLoopCharacteristics();
    if (StringUtils.isNotEmpty(multiInstanceObject.getLoopCardinality()) || StringUtils.isNotEmpty(multiInstanceObject.getInputDataItem())
        || StringUtils.isNotEmpty(multiInstanceObject.getCompletionCondition())) {

      xtw.writeStartElement(ELEMENT_MULTIINSTANCE);
      BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_MULTIINSTANCE_SEQUENTIAL, String.valueOf(multiInstanceObject.isSequential()).toLowerCase(), xtw);
      if (StringUtils.isNotEmpty(multiInstanceObject.getInputDataItem())) {
        BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_MULTIINSTANCE_COLLECTION, multiInstanceObject.getInputDataItem(), xtw);
      }
      if (StringUtils.isNotEmpty(multiInstanceObject.getElementVariable())) {
        BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_MULTIINSTANCE_VARIABLE, multiInstanceObject.getElementVariable(), xtw);
      }
      if (StringUtils.isNotEmpty(multiInstanceObject.getLoopCardinality())) {
        xtw.writeStartElement(ELEMENT_MULTIINSTANCE_CARDINALITY);
        xtw.writeCharacters(multiInstanceObject.getLoopCardinality());
        xtw.writeEndElement();
      }
      if (StringUtils.isNotEmpty(multiInstanceObject.getCompletionCondition())) {
        xtw.writeStartElement(ELEMENT_MULTIINSTANCE_CONDITION);
        xtw.writeCharacters(multiInstanceObject.getCompletionCondition());
        xtw.writeEndElement();
      }
      xtw.writeEndElement();
    }
  }
}
 
Example #12
Source File: DataInputAssociationParser.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {

    if (parentElement instanceof Activity == false)
      return;

    DataAssociation dataAssociation = new DataAssociation();
    BpmnXMLUtil.addXMLLocation(dataAssociation, xtr);
    DataAssociationParser.parseDataAssociation(dataAssociation, getElementName(), xtr);

    ((Activity) parentElement).getDataInputAssociations().add(dataAssociation);
  }
 
Example #13
Source File: AbstractActivityBpmnParseHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void parse(BpmnParse bpmnParse, BaseElement element) {
  super.parse(bpmnParse, element);

  if (element instanceof Activity && ((Activity) element).getLoopCharacteristics() != null) {
    createMultiInstanceLoopCharacteristics(bpmnParse, (Activity) element);
  }
}
 
Example #14
Source File: AbstractActivityBpmnParseHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void parse(BpmnParse bpmnParse, BaseElement element) {
  super.parse(bpmnParse, element);
  
  if (element instanceof Activity
          && ((Activity) element).getLoopCharacteristics() != null) {
    createMultiInstanceLoopCharacteristics(bpmnParse, (Activity) element);
  }
}
 
Example #15
Source File: MultiInstanceParser.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
  if (parentElement instanceof Activity == false)
    return;

  MultiInstanceLoopCharacteristics multiInstanceDef = new MultiInstanceLoopCharacteristics();
  BpmnXMLUtil.addXMLLocation(multiInstanceDef, xtr);
  if (xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_SEQUENTIAL) != null) {
    multiInstanceDef.setSequential(Boolean.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_SEQUENTIAL)));
  }
  multiInstanceDef.setInputDataItem(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_MULTIINSTANCE_COLLECTION));
  multiInstanceDef.setElementVariable(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_MULTIINSTANCE_VARIABLE));
  multiInstanceDef.setElementIndexVariable(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_MULTIINSTANCE_INDEX_VARIABLE));

  boolean readyWithMultiInstance = false;
  try {
    while (readyWithMultiInstance == false && xtr.hasNext()) {
      xtr.next();
      if (xtr.isStartElement() && ELEMENT_MULTIINSTANCE_CARDINALITY.equalsIgnoreCase(xtr.getLocalName())) {
        multiInstanceDef.setLoopCardinality(xtr.getElementText());

      } else if (xtr.isStartElement() && ELEMENT_MULTIINSTANCE_DATAINPUT.equalsIgnoreCase(xtr.getLocalName())) {
        multiInstanceDef.setInputDataItem(xtr.getElementText());

      } else if (xtr.isStartElement() && ELEMENT_MULTIINSTANCE_DATAITEM.equalsIgnoreCase(xtr.getLocalName())) {
        if (xtr.getAttributeValue(null, ATTRIBUTE_NAME) != null) {
          multiInstanceDef.setElementVariable(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
        }

      } else if (xtr.isStartElement() && ELEMENT_MULTIINSTANCE_CONDITION.equalsIgnoreCase(xtr.getLocalName())) {
        multiInstanceDef.setCompletionCondition(xtr.getElementText());

      } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
        readyWithMultiInstance = true;
      }
    }
  } catch (Exception e) {
    LOGGER.warn("Error parsing multi instance definition", e);
  }
  ((Activity) parentElement).setLoopCharacteristics(multiInstanceDef);
}
 
Example #16
Source File: DataOutputAssociationParser.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {

    if (parentElement instanceof Activity == false)
      return;

    DataAssociation dataAssociation = new DataAssociation();
    BpmnXMLUtil.addXMLLocation(dataAssociation, xtr);
    DataAssociationParser.parseDataAssociation(dataAssociation, getElementName(), xtr);

    ((Activity) parentElement).getDataOutputAssociations().add(dataAssociation);
  }
 
Example #17
Source File: ActivitiFailedjobRetryParser.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
  if (!(parentElement instanceof Activity))
    return;
  String cycle = xtr.getElementText();
  if (cycle == null || cycle.isEmpty()) {
    return;
  }
  ((Activity) parentElement).setFailedJobRetryTimeCycleValue(cycle);
}
 
Example #18
Source File: AbstractInfoMapper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ArrayNode map(Object element) {
	propertiesNode = objectMapper.createArrayNode();
	if (element instanceof FlowElement) {
	    FlowElement flowElement = (FlowElement) element;
	    if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {
            createPropertyNode("Documentation", flowElement.getDocumentation());
        }
	    
	    if (element instanceof Activity) {
	        Activity activity = (Activity) element;
	        if (activity.getLoopCharacteristics() != null) {
	            MultiInstanceLoopCharacteristics multiInstanceDef = activity.getLoopCharacteristics();
	            createPropertyNode("Multi-instance activity", "");
	            createPropertyNode("Sequential", multiInstanceDef.isSequential());
	            if (StringUtils.isNotEmpty(multiInstanceDef.getInputDataItem())) {
	                createPropertyNode("Collection", multiInstanceDef.getInputDataItem());
	            }
	            if (StringUtils.isNotEmpty(multiInstanceDef.getElementVariable())) {
                       createPropertyNode("Element variable", multiInstanceDef.getElementVariable());
                   }
	            if (StringUtils.isNotEmpty(multiInstanceDef.getLoopCardinality())) {
                       createPropertyNode("Loop cardinality", multiInstanceDef.getLoopCardinality());
                   }
	            if (StringUtils.isNotEmpty(multiInstanceDef.getCompletionCondition())) {
                       createPropertyNode("Completion condition", multiInstanceDef.getCompletionCondition());
                   }
	            createPropertyNode("", "");
               }
   		    if (StringUtils.isNotEmpty(activity.getDefaultFlow())) {
                   createPropertyNode("Default flow", activity.getDefaultFlow());
               }
	    }
	}
	mapProperties(element);
	return propertiesNode;
}
 
Example #19
Source File: DefaultProcessDiagramGenerator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * This method returns shape type of base element.<br>
 * Each element can be presented as rectangle, rhombus, or ellipse.
 * @param baseElement
 * @return DefaultProcessDiagramCanvas.SHAPE_TYPE
 */
protected static DefaultProcessDiagramCanvas.SHAPE_TYPE getShapeType(BaseElement baseElement) {
  if (baseElement instanceof Task || baseElement instanceof Activity || baseElement instanceof TextAnnotation) {
      return DefaultProcessDiagramCanvas.SHAPE_TYPE.Rectangle;
  } else if (baseElement instanceof Gateway) {
      return DefaultProcessDiagramCanvas.SHAPE_TYPE.Rhombus;
  } else if (baseElement instanceof Event) {
      return DefaultProcessDiagramCanvas.SHAPE_TYPE.Ellipse;
  } else {
      // unknown source element, just do not correct coordinates
  }
  return null;
}
 
Example #20
Source File: FlowElementValidator.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected void handleConstraints(Process process, Activity activity, List<ValidationError> errors) {
	if (activity.getId() != null && activity.getId().length() > ID_MAX_LENGTH) {
		addError(errors, Problems.FLOW_ELEMENT_ID_TOO_LONG, process, activity,
				"The id of a flow element must not contain more than " + ID_MAX_LENGTH + " characters");
	}
}
 
Example #21
Source File: BoundaryCancelEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
  BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement();
  
  CommandContext commandContext = Context.getCommandContext();
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
  
  ExecutionEntity subProcessExecution = null;
  // TODO: this can be optimized. A full search in the all executions shouldn't be needed
  List<ExecutionEntity> processInstanceExecutions = executionEntityManager.findChildExecutionsByProcessInstanceId(execution.getProcessInstanceId());
  for (ExecutionEntity childExecution : processInstanceExecutions) {
    if (childExecution.getCurrentFlowElement() != null 
        && childExecution.getCurrentFlowElement().getId().equals(boundaryEvent.getAttachedToRefId())) {
      subProcessExecution = childExecution;
      break;
    }
  }
  
  if (subProcessExecution == null) {
    throw new ActivitiException("No execution found for sub process of boundary cancel event " + boundaryEvent.getId());
  }
  
  EventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.getEventSubscriptionEntityManager();
  List<CompensateEventSubscriptionEntity> eventSubscriptions = eventSubscriptionEntityManager.findCompensateEventSubscriptionsByExecutionId(subProcessExecution.getParentId());

  if (eventSubscriptions.isEmpty()) {
    leave(execution);
  } else {
    
    String deleteReason = DeleteReason.BOUNDARY_EVENT_INTERRUPTING + "(" + boundaryEvent.getId() + ")";
    
    // cancel boundary is always sync
    ScopeUtil.throwCompensationEvent(eventSubscriptions, execution, false);
    executionEntityManager.deleteExecutionAndRelatedData(subProcessExecution, deleteReason, false);
    if (subProcessExecution.getCurrentFlowElement() instanceof Activity) {
      Activity activity = (Activity) subProcessExecution.getCurrentFlowElement();
      if (activity.getLoopCharacteristics() != null) {
        ExecutionEntity miExecution = subProcessExecution.getParent();
        List<ExecutionEntity> miChildExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(miExecution.getId());
        for (ExecutionEntity miChildExecution : miChildExecutions) {
          if (subProcessExecution.getId().equals(miChildExecution.getId()) == false && activity.getId().equals(miChildExecution.getCurrentActivityId())) {
            executionEntityManager.deleteExecutionAndRelatedData(miChildExecution, deleteReason, false);
          }
        }
      }
    }
    leave(execution);
  }
}
 
Example #22
Source File: TestActivityBehaviorFactory.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public ParallelMultiInstanceBehavior createParallelMultiInstanceBehavior(Activity activity, AbstractBpmnActivityBehavior innerActivityBehavior) {
  return wrappedActivityBehaviorFactory.createParallelMultiInstanceBehavior(activity, innerActivityBehavior);
}
 
Example #23
Source File: TestActivityBehaviorFactory.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public SequentialMultiInstanceBehavior createSequentialMultiInstanceBehavior(Activity activity, AbstractBpmnActivityBehavior innerActivityBehavior) {
  return wrappedActivityBehaviorFactory.createSequentialMultiInstanceBehavior(activity, innerActivityBehavior);
}
 
Example #24
Source File: SequenceFlowJsonConverter.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {

  SequenceFlow sequenceFlow = (SequenceFlow) baseElement;
  ObjectNode flowNode = BpmnJsonConverterUtil.createChildShape(sequenceFlow.getId(), STENCIL_SEQUENCE_FLOW, 172, 212, 128, 212);
  ArrayNode dockersArrayNode = objectMapper.createArrayNode();
  ObjectNode dockNode = objectMapper.createObjectNode();
  dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(sequenceFlow.getSourceRef()).getWidth() / 2.0);
  dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(sequenceFlow.getSourceRef()).getHeight() / 2.0);
  dockersArrayNode.add(dockNode);

  if (model.getFlowLocationGraphicInfo(sequenceFlow.getId()).size() > 2) {
    for (int i = 1; i < model.getFlowLocationGraphicInfo(sequenceFlow.getId()).size() - 1; i++) {
      GraphicInfo graphicInfo = model.getFlowLocationGraphicInfo(sequenceFlow.getId()).get(i);
      dockNode = objectMapper.createObjectNode();
      dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX());
      dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY());
      dockersArrayNode.add(dockNode);
    }
  }

  dockNode = objectMapper.createObjectNode();
  dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(sequenceFlow.getTargetRef()).getWidth() / 2.0);
  dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(sequenceFlow.getTargetRef()).getHeight() / 2.0);
  dockersArrayNode.add(dockNode);
  flowNode.set("dockers", dockersArrayNode);
  ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
  outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getTargetRef()));
  flowNode.set("outgoing", outgoingArrayNode);
  flowNode.set("target", BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getTargetRef()));

  ObjectNode propertiesNode = objectMapper.createObjectNode();
  propertiesNode.put(PROPERTY_OVERRIDE_ID, sequenceFlow.getId());
  if (StringUtils.isNotEmpty(sequenceFlow.getName())) {
    propertiesNode.put(PROPERTY_NAME, sequenceFlow.getName());
  }

  if (StringUtils.isNotEmpty(sequenceFlow.getDocumentation())) {
    propertiesNode.put(PROPERTY_DOCUMENTATION, sequenceFlow.getDocumentation());
  }

  if (StringUtils.isNotEmpty(sequenceFlow.getConditionExpression())) {
    propertiesNode.put(PROPERTY_SEQUENCEFLOW_CONDITION, sequenceFlow.getConditionExpression());
  }

  if (StringUtils.isNotEmpty(sequenceFlow.getSourceRef())) {

    FlowElement sourceFlowElement = container.getFlowElement(sequenceFlow.getSourceRef());
    if (sourceFlowElement != null) {
      String defaultFlowId = null;
      if (sourceFlowElement instanceof ExclusiveGateway) {
        ExclusiveGateway parentExclusiveGateway = (ExclusiveGateway) sourceFlowElement;
        defaultFlowId = parentExclusiveGateway.getDefaultFlow();
      } else if (sourceFlowElement instanceof Activity) {
        Activity parentActivity = (Activity) sourceFlowElement;
        defaultFlowId = parentActivity.getDefaultFlow();
      }

      if (defaultFlowId != null && defaultFlowId.equals(sequenceFlow.getId())) {
        propertiesNode.put(PROPERTY_SEQUENCEFLOW_DEFAULT, true);
      }

    }
  }

  if (sequenceFlow.getExecutionListeners().size() > 0) {
    BpmnJsonConverterUtil.convertListenersToJson(sequenceFlow.getExecutionListeners(), true, propertiesNode);
  }

  flowNode.set(EDITOR_SHAPE_PROPERTIES, propertiesNode);
  shapesArrayNode.add(flowNode);
}
 
Example #25
Source File: ParallelMultiInstanceBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ParallelMultiInstanceBehavior(Activity activity, AbstractBpmnActivityBehavior originalActivityBehavior) {
  super(activity, originalActivityBehavior);
}
 
Example #26
Source File: SequentialMultiInstanceBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public SequentialMultiInstanceBehavior(Activity activity, AbstractBpmnActivityBehavior innerActivityBehavior) {
  super(activity, innerActivityBehavior);
}
 
Example #27
Source File: BoundaryCompensateEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement();
  
  Process process = ProcessDefinitionUtil.getProcess(execution.getProcessDefinitionId());
  if (process == null) {
    throw new ActivitiException("Process model (id = " + execution.getId() + ") could not be found");
  }
  
  Activity compensationActivity = null;
  List<Association> associations = process.findAssociationsWithSourceRefRecursive(boundaryEvent.getId());
  for (Association association : associations) {
    FlowElement targetElement = process.getFlowElement(association.getTargetRef(), true);
    if (targetElement instanceof Activity) {
      Activity activity = (Activity) targetElement;
      if (activity.isForCompensation()) {
        compensationActivity = activity;
        break;
      }
    }
  }
  
  if (compensationActivity == null) {
    throw new ActivitiException("Compensation activity could not be found (or it is missing 'isForCompensation=\"true\"'");
  }
  
  // find SubProcess or Process instance execution
  ExecutionEntity scopeExecution = null;
  ExecutionEntity parentExecution = executionEntity.getParent();
  while (scopeExecution == null && parentExecution != null) {
    if (parentExecution.getCurrentFlowElement() instanceof SubProcess) {
      scopeExecution = parentExecution;
      
    } else if (parentExecution.isProcessInstanceType()) {
      scopeExecution = parentExecution;
    } else {
      parentExecution = parentExecution.getParent();
    }
  }
  
  if (scopeExecution == null) {
    throw new ActivitiException("Could not find a scope execution for compensation boundary event " + boundaryEvent.getId());
  }
  
  Context.getCommandContext().getEventSubscriptionEntityManager().insertCompensationEvent(
      scopeExecution, compensationActivity.getId());
}
 
Example #28
Source File: AbstractActivityBpmnParseHandler.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected void createMultiInstanceLoopCharacteristics(BpmnParse bpmnParse, Activity modelActivity) {
  
  MultiInstanceLoopCharacteristics loopCharacteristics = modelActivity.getLoopCharacteristics();
  
  // Activity Behavior
  MultiInstanceActivityBehavior miActivityBehavior = null;
  ActivityImpl activity = bpmnParse.getCurrentScope().findActivity(modelActivity.getId());
  if (activity == null) {
    throw new ActivitiException("Activity " + modelActivity.getId() + " needed for multi instance cannot bv found");
  }
          
  if (loopCharacteristics.isSequential()) {
    miActivityBehavior = bpmnParse.getActivityBehaviorFactory().createSequentialMultiInstanceBehavior(
            activity, (AbstractBpmnActivityBehavior) activity.getActivityBehavior()); 
  } else {
    miActivityBehavior = bpmnParse.getActivityBehaviorFactory().createParallelMultiInstanceBehavior(
            activity, (AbstractBpmnActivityBehavior) activity.getActivityBehavior());
  }
  
  // ActivityImpl settings
  activity.setScope(true);
  activity.setProperty("multiInstance", loopCharacteristics.isSequential() ? "sequential" : "parallel");
  activity.setActivityBehavior(miActivityBehavior);
  
  ExpressionManager expressionManager = bpmnParse.getExpressionManager();
  BpmnModel bpmnModel = bpmnParse.getBpmnModel();
  
  // loopcardinality
  if (StringUtils.isNotEmpty(loopCharacteristics.getLoopCardinality())) {
    miActivityBehavior.setLoopCardinalityExpression(expressionManager.createExpression(loopCharacteristics.getLoopCardinality()));
  }
  
  // completion condition
  if (StringUtils.isNotEmpty(loopCharacteristics.getCompletionCondition())) {
    miActivityBehavior.setCompletionConditionExpression(expressionManager.createExpression(loopCharacteristics.getCompletionCondition()));
  }
  
  // activiti:collection
  if (StringUtils.isNotEmpty(loopCharacteristics.getInputDataItem())) {
    if (loopCharacteristics.getInputDataItem().contains("{")) {
      miActivityBehavior.setCollectionExpression(expressionManager.createExpression(loopCharacteristics.getInputDataItem()));
    } else {
      miActivityBehavior.setCollectionVariable(loopCharacteristics.getInputDataItem());
    }
  }

  // activiti:elementVariable
  if (StringUtils.isNotEmpty(loopCharacteristics.getElementVariable())) {
    miActivityBehavior.setCollectionElementVariable(loopCharacteristics.getElementVariable());
  }

  // activiti:elementIndexVariable
  if (StringUtils.isNotEmpty(loopCharacteristics.getElementIndexVariable())) {
    miActivityBehavior.setCollectionElementIndexVariable(loopCharacteristics.getElementIndexVariable());
  }

}
 
Example #29
Source File: IntermediateThrowCompensationEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
  ThrowEvent throwEvent = (ThrowEvent) execution.getCurrentFlowElement();
  
  /*
   * From the BPMN 2.0 spec:
   * 
   * The Activity to be compensated MAY be supplied.
   *  
   * If an Activity is not supplied, then the compensation is broadcast to all completed Activities in 
   * the current Sub- Process (if present), or the entire Process instance (if at the global level). This “throws” the compensation.
   */
  final String activityRef = compensateEventDefinition.getActivityRef();
  
  CommandContext commandContext = Context.getCommandContext();
  EventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.getEventSubscriptionEntityManager();
  
  List<CompensateEventSubscriptionEntity> eventSubscriptions = new ArrayList<CompensateEventSubscriptionEntity>();
  if (StringUtils.isNotEmpty(activityRef)) {
    
    // If an activity ref is provided, only that activity is compensated
    eventSubscriptions.addAll(eventSubscriptionEntityManager
        .findCompensateEventSubscriptionsByProcessInstanceIdAndActivityId(execution.getProcessInstanceId(), activityRef));
    
  } else {
    
    // If no activity ref is provided, it is broadcast to the current sub process / process instance
    Process process = ProcessDefinitionUtil.getProcess(execution.getProcessDefinitionId());
    
    FlowElementsContainer flowElementsContainer = null;
    if (throwEvent.getSubProcess() == null) {
      flowElementsContainer = process;
    } else {
      flowElementsContainer = throwEvent.getSubProcess();
    }
    
    for (FlowElement flowElement : flowElementsContainer.getFlowElements()) {
      if (flowElement instanceof Activity) {
        eventSubscriptions.addAll(eventSubscriptionEntityManager
            .findCompensateEventSubscriptionsByProcessInstanceIdAndActivityId(execution.getProcessInstanceId(), flowElement.getId()));
      }
    }
    
  }
  
  if (eventSubscriptions.isEmpty()) {
    leave(execution);
  } else {
    // TODO: implement async (waitForCompletion=false in bpmn)
    ScopeUtil.throwCompensationEvent(eventSubscriptions, execution, false);
    leave(execution);
  }
}
 
Example #30
Source File: AbstractActivityBpmnParseHandler.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected void createMultiInstanceLoopCharacteristics(BpmnParse bpmnParse, Activity modelActivity) {

    MultiInstanceLoopCharacteristics loopCharacteristics = modelActivity.getLoopCharacteristics();

    // Activity Behavior
    MultiInstanceActivityBehavior miActivityBehavior = null;

    if (loopCharacteristics.isSequential()) {
      miActivityBehavior = bpmnParse.getActivityBehaviorFactory().createSequentialMultiInstanceBehavior(modelActivity, (AbstractBpmnActivityBehavior) modelActivity.getBehavior());
    } else {
      miActivityBehavior = bpmnParse.getActivityBehaviorFactory().createParallelMultiInstanceBehavior(modelActivity, (AbstractBpmnActivityBehavior) modelActivity.getBehavior());
    }

    modelActivity.setBehavior(miActivityBehavior);

    ExpressionManager expressionManager = Context.getProcessEngineConfiguration().getExpressionManager();

    // loop cardinality
    if (StringUtils.isNotEmpty(loopCharacteristics.getLoopCardinality())) {
      miActivityBehavior.setLoopCardinalityExpression(expressionManager.createExpression(loopCharacteristics.getLoopCardinality()));
    }

    // completion condition
    if (StringUtils.isNotEmpty(loopCharacteristics.getCompletionCondition())) {
      miActivityBehavior.setCompletionConditionExpression(expressionManager.createExpression(loopCharacteristics.getCompletionCondition()));
    }

    // activiti:collection
    if (StringUtils.isNotEmpty(loopCharacteristics.getInputDataItem())) {
      if (loopCharacteristics.getInputDataItem().contains("{")) {
        miActivityBehavior.setCollectionExpression(expressionManager.createExpression(loopCharacteristics.getInputDataItem()));
      } else {
        miActivityBehavior.setCollectionVariable(loopCharacteristics.getInputDataItem());
      }
    }

    // activiti:elementVariable
    if (StringUtils.isNotEmpty(loopCharacteristics.getElementVariable())) {
      miActivityBehavior.setCollectionElementVariable(loopCharacteristics.getElementVariable());
    }

    // activiti:elementIndexVariable
    if (StringUtils.isNotEmpty(loopCharacteristics.getElementIndexVariable())) {
      miActivityBehavior.setCollectionElementIndexVariable(loopCharacteristics.getElementIndexVariable());
    }

  }