use of org.activiti.bpmn.model.Activity in project Activiti by Activiti.
the class ContinueProcessOperation method executeSynchronous.
protected void executeSynchronous(FlowNode flowNode) {
commandContext.getHistoryManager().recordActivityStart(execution);
// Execution listener: event 'start'
if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) {
executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_START);
}
// Execute any boundary events, sub process boundary events will be executed from the activity behavior
if (!inCompensation && flowNode instanceof Activity) {
// Only activities can have boundary events
List<BoundaryEvent> boundaryEvents = ((Activity) flowNode).getBoundaryEvents();
if (CollectionUtil.isNotEmpty(boundaryEvents)) {
executeBoundaryEvents(boundaryEvents, execution);
}
}
// Execute actual behavior
ActivityBehavior activityBehavior = (ActivityBehavior) flowNode.getBehavior();
if (activityBehavior != null) {
executeActivityBehavior(activityBehavior, flowNode);
} else {
logger.debug("No activityBehavior on activity '{}' with execution {}", flowNode.getId(), execution.getId());
Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(execution, true);
}
}
use of org.activiti.bpmn.model.Activity in project Activiti by Activiti.
the class BoundaryCancelEventActivityBehavior method trigger.
@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);
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);
}
}
}
}
leave(execution);
}
}
use of org.activiti.bpmn.model.Activity in project Activiti by Activiti.
the class BpmnJsonConverter method postProcessElements.
private void postProcessElements(FlowElementsContainer parentContainer, Collection<FlowElement> flowElementList, Map<String, JsonNode> edgeMap, BpmnModel bpmnModel, Map<String, FlowWithContainer> allFlowMap, List<Gateway> gatewayWithOrderList) {
for (FlowElement flowElement : flowElementList) {
if (flowElement instanceof Event) {
Event event = (Event) flowElement;
if (CollectionUtils.isNotEmpty(event.getEventDefinitions())) {
EventDefinition eventDef = event.getEventDefinitions().get(0);
if (eventDef instanceof SignalEventDefinition) {
SignalEventDefinition signalEventDef = (SignalEventDefinition) eventDef;
if (StringUtils.isNotEmpty(signalEventDef.getSignalRef())) {
if (bpmnModel.getSignal(signalEventDef.getSignalRef()) == null) {
bpmnModel.addSignal(new Signal(signalEventDef.getSignalRef(), signalEventDef.getSignalRef()));
}
}
} else if (eventDef instanceof MessageEventDefinition) {
MessageEventDefinition messageEventDef = (MessageEventDefinition) eventDef;
if (StringUtils.isNotEmpty(messageEventDef.getMessageRef())) {
if (bpmnModel.getMessage(messageEventDef.getMessageRef()) == null) {
bpmnModel.addMessage(new Message(messageEventDef.getMessageRef(), messageEventDef.getMessageRef(), null));
}
}
}
}
}
if (flowElement instanceof BoundaryEvent) {
BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
Activity activity = retrieveAttachedRefObject(boundaryEvent.getAttachedToRefId(), parentContainer.getFlowElements());
if (activity == null) {
LOGGER.warn("Boundary event " + boundaryEvent.getId() + " is not attached to any activity");
} else {
boundaryEvent.setAttachedToRef(activity);
activity.getBoundaryEvents().add(boundaryEvent);
}
} else if (flowElement instanceof Gateway) {
if (flowElement.getExtensionElements().containsKey("EDITOR_FLOW_ORDER")) {
gatewayWithOrderList.add((Gateway) flowElement);
}
} else if (flowElement instanceof SubProcess) {
SubProcess subProcess = (SubProcess) flowElement;
postProcessElements(subProcess, subProcess.getFlowElements(), edgeMap, bpmnModel, allFlowMap, gatewayWithOrderList);
} else if (flowElement instanceof SequenceFlow) {
SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
FlowElement sourceFlowElement = parentContainer.getFlowElement(sequenceFlow.getSourceRef());
if (sourceFlowElement != null && sourceFlowElement instanceof FlowNode) {
FlowWithContainer flowWithContainer = new FlowWithContainer(sequenceFlow, parentContainer);
if (sequenceFlow.getExtensionElements().get("EDITOR_RESOURCEID") != null && sequenceFlow.getExtensionElements().get("EDITOR_RESOURCEID").size() > 0) {
allFlowMap.put(sequenceFlow.getExtensionElements().get("EDITOR_RESOURCEID").get(0).getElementText(), flowWithContainer);
sequenceFlow.getExtensionElements().remove("EDITOR_RESOURCEID");
}
((FlowNode) sourceFlowElement).getOutgoingFlows().add(sequenceFlow);
JsonNode edgeNode = edgeMap.get(sequenceFlow.getId());
if (edgeNode != null) {
boolean isDefault = JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_SEQUENCEFLOW_DEFAULT, edgeNode);
if (isDefault) {
if (sourceFlowElement instanceof Activity) {
((Activity) sourceFlowElement).setDefaultFlow(sequenceFlow.getId());
} else if (sourceFlowElement instanceof Gateway) {
((Gateway) sourceFlowElement).setDefaultFlow(sequenceFlow.getId());
}
}
}
}
FlowElement targetFlowElement = parentContainer.getFlowElement(sequenceFlow.getTargetRef());
if (targetFlowElement != null && targetFlowElement instanceof FlowNode) {
((FlowNode) targetFlowElement).getIncomingFlows().add(sequenceFlow);
}
}
}
}
use of org.activiti.bpmn.model.Activity in project Activiti by Activiti.
the class SequenceFlowJsonConverter method convertToJson.
@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);
}
use of org.activiti.bpmn.model.Activity in project Activiti by Activiti.
the class BaseBpmnJsonConverter method convertToJson.
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {
this.model = model;
this.processor = processor;
this.subProcessX = subProcessX;
this.subProcessY = subProcessY;
this.shapesArrayNode = shapesArrayNode;
GraphicInfo graphicInfo = model.getGraphicInfo(baseElement.getId());
String stencilId = null;
if (baseElement instanceof ServiceTask) {
ServiceTask serviceTask = (ServiceTask) baseElement;
if ("mail".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_MAIL;
} else if ("camel".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_CAMEL;
} else if ("mule".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_MULE;
} else if ("dmn".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_DECISION;
} else {
stencilId = getStencilId(baseElement);
}
} else {
stencilId = getStencilId(baseElement);
}
flowElementNode = BpmnJsonConverterUtil.createChildShape(baseElement.getId(), stencilId, graphicInfo.getX() - subProcessX + graphicInfo.getWidth(), graphicInfo.getY() - subProcessY + graphicInfo.getHeight(), graphicInfo.getX() - subProcessX, graphicInfo.getY() - subProcessY);
shapesArrayNode.add(flowElementNode);
ObjectNode propertiesNode = objectMapper.createObjectNode();
propertiesNode.put(PROPERTY_OVERRIDE_ID, baseElement.getId());
if (baseElement instanceof FlowElement) {
FlowElement flowElement = (FlowElement) baseElement;
if (StringUtils.isNotEmpty(flowElement.getName())) {
propertiesNode.put(PROPERTY_NAME, flowElement.getName());
}
if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {
propertiesNode.put(PROPERTY_DOCUMENTATION, flowElement.getDocumentation());
}
}
convertElementToJson(propertiesNode, baseElement);
flowElementNode.set(EDITOR_SHAPE_PROPERTIES, propertiesNode);
ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
if (baseElement instanceof FlowNode) {
FlowNode flowNode = (FlowNode) baseElement;
for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getId()));
}
for (MessageFlow messageFlow : model.getMessageFlows().values()) {
if (messageFlow.getSourceRef().equals(flowNode.getId())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
}
}
}
if (baseElement instanceof Activity) {
Activity activity = (Activity) baseElement;
for (BoundaryEvent boundaryEvent : activity.getBoundaryEvents()) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(boundaryEvent.getId()));
}
propertiesNode.put(PROPERTY_ASYNCHRONOUS, activity.isAsynchronous());
propertiesNode.put(PROPERTY_EXCLUSIVE, !activity.isNotExclusive());
if (activity.getLoopCharacteristics() != null) {
MultiInstanceLoopCharacteristics loopDef = activity.getLoopCharacteristics();
if (StringUtils.isNotEmpty(loopDef.getLoopCardinality()) || StringUtils.isNotEmpty(loopDef.getInputDataItem()) || StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
if (!loopDef.isSequential()) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Parallel");
} else {
propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Sequential");
}
if (StringUtils.isNotEmpty(loopDef.getLoopCardinality())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_CARDINALITY, loopDef.getLoopCardinality());
}
if (StringUtils.isNotEmpty(loopDef.getInputDataItem())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_COLLECTION, loopDef.getInputDataItem());
}
if (StringUtils.isNotEmpty(loopDef.getElementVariable())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_VARIABLE, loopDef.getElementVariable());
}
if (StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_CONDITION, loopDef.getCompletionCondition());
}
}
}
if (activity instanceof UserTask) {
BpmnJsonConverterUtil.convertListenersToJson(((UserTask) activity).getTaskListeners(), false, propertiesNode);
}
if (CollectionUtils.isNotEmpty(activity.getDataInputAssociations())) {
for (DataAssociation dataAssociation : activity.getDataInputAssociations()) {
if (model.getFlowElement(dataAssociation.getSourceRef()) != null) {
createDataAssociation(dataAssociation, true, activity);
}
}
}
if (CollectionUtils.isNotEmpty(activity.getDataOutputAssociations())) {
for (DataAssociation dataAssociation : activity.getDataOutputAssociations()) {
if (model.getFlowElement(dataAssociation.getTargetRef()) != null) {
createDataAssociation(dataAssociation, false, activity);
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(dataAssociation.getId()));
}
}
}
}
if (baseElement instanceof FlowElement) {
BpmnJsonConverterUtil.convertListenersToJson(((FlowElement) baseElement).getExecutionListeners(), true, propertiesNode);
}
for (Artifact artifact : container.getArtifacts()) {
if (artifact instanceof Association) {
Association association = (Association) artifact;
if (StringUtils.isNotEmpty(association.getSourceRef()) && association.getSourceRef().equals(baseElement.getId())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getId()));
}
}
}
if (baseElement instanceof DataStoreReference) {
for (Process process : model.getProcesses()) {
processDataStoreReferences(process, baseElement.getId(), outgoingArrayNode);
}
}
flowElementNode.set("outgoing", outgoingArrayNode);
}
Aggregations