use of org.activiti.bpmn.model.EventDefinition in project Activiti by Activiti.
the class SimpleConverterTest method validateModel.
private void validateModel(BpmnModel model) {
assertEquals("simpleProcess", model.getMainProcess().getId());
assertEquals("Simple process", model.getMainProcess().getName());
assertEquals(true, model.getMainProcess().isExecutable());
FlowElement flowElement = model.getMainProcess().getFlowElement("flow1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof SequenceFlow);
assertEquals("flow1", flowElement.getId());
flowElement = model.getMainProcess().getFlowElement("catchEvent");
assertNotNull(flowElement);
assertTrue(flowElement instanceof IntermediateCatchEvent);
assertEquals("catchEvent", flowElement.getId());
IntermediateCatchEvent catchEvent = (IntermediateCatchEvent) flowElement;
assertTrue(catchEvent.getEventDefinitions().size() == 1);
EventDefinition eventDefinition = catchEvent.getEventDefinitions().get(0);
assertTrue(eventDefinition instanceof TimerEventDefinition);
TimerEventDefinition timerDefinition = (TimerEventDefinition) eventDefinition;
assertEquals("PT5M", timerDefinition.getTimeDuration());
flowElement = model.getMainProcess().getFlowElement("flow1Condition");
assertNotNull(flowElement);
assertTrue(flowElement instanceof SequenceFlow);
assertEquals("flow1Condition", flowElement.getId());
SequenceFlow flow = (SequenceFlow) flowElement;
assertEquals("${number <= 1}", flow.getConditionExpression());
}
use of org.activiti.bpmn.model.EventDefinition in project Activiti by Activiti.
the class BoundaryEventParseHandler method executeParse.
protected void executeParse(BpmnParse bpmnParse, BoundaryEvent boundaryEvent) {
ActivityImpl parentActivity = findActivity(bpmnParse, boundaryEvent.getAttachedToRefId());
if (parentActivity == null) {
logger.warn("Invalid reference in boundary event. Make sure that the referenced activity is defined in the same scope as the boundary event " + boundaryEvent.getId());
return;
}
ActivityImpl nestedActivity = createActivityOnScope(bpmnParse, boundaryEvent, BpmnXMLConstants.ELEMENT_EVENT_BOUNDARY, parentActivity);
bpmnParse.setCurrentActivity(nestedActivity);
EventDefinition eventDefinition = null;
if (!boundaryEvent.getEventDefinitions().isEmpty()) {
eventDefinition = boundaryEvent.getEventDefinitions().get(0);
}
if (eventDefinition instanceof TimerEventDefinition || eventDefinition instanceof org.activiti.bpmn.model.ErrorEventDefinition || eventDefinition instanceof SignalEventDefinition || eventDefinition instanceof CancelEventDefinition || eventDefinition instanceof MessageEventDefinition || eventDefinition instanceof org.activiti.bpmn.model.CompensateEventDefinition) {
bpmnParse.getBpmnParserHandlers().parseElement(bpmnParse, eventDefinition);
} else {
logger.warn("Unsupported boundary event type for boundary event " + boundaryEvent.getId());
}
}
use of org.activiti.bpmn.model.EventDefinition in project Activiti by Activiti.
the class EndEventParseHandler method executeParse.
protected void executeParse(BpmnParse bpmnParse, EndEvent endEvent) {
ActivityImpl endEventActivity = createActivityOnCurrentScope(bpmnParse, endEvent, BpmnXMLConstants.ELEMENT_EVENT_END);
EventDefinition eventDefinition = null;
if (!endEvent.getEventDefinitions().isEmpty()) {
eventDefinition = endEvent.getEventDefinitions().get(0);
}
// Error end event
if (eventDefinition instanceof org.activiti.bpmn.model.ErrorEventDefinition) {
org.activiti.bpmn.model.ErrorEventDefinition errorDefinition = (org.activiti.bpmn.model.ErrorEventDefinition) eventDefinition;
if (bpmnParse.getBpmnModel().containsErrorRef(errorDefinition.getErrorCode())) {
String errorCode = bpmnParse.getBpmnModel().getErrors().get(errorDefinition.getErrorCode());
if (StringUtils.isEmpty(errorCode)) {
logger.warn("errorCode is required for an error event " + endEvent.getId());
}
endEventActivity.setProperty("type", "errorEndEvent");
errorDefinition.setErrorCode(errorCode);
}
endEventActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createErrorEndEventActivityBehavior(endEvent, errorDefinition));
// Cancel end event
} else if (eventDefinition instanceof CancelEventDefinition) {
ScopeImpl scope = bpmnParse.getCurrentScope();
if (scope.getProperty("type") == null || !scope.getProperty("type").equals("transaction")) {
logger.warn("end event with cancelEventDefinition only supported inside transaction subprocess (id=" + endEvent.getId() + ")");
} else {
endEventActivity.setProperty("type", "cancelEndEvent");
endEventActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createCancelEndEventActivityBehavior(endEvent));
}
// Terminate end event
} else if (eventDefinition instanceof TerminateEventDefinition) {
endEventActivity.setAsync(endEvent.isAsynchronous());
endEventActivity.setExclusive(!endEvent.isNotExclusive());
endEventActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createTerminateEndEventActivityBehavior(endEvent));
// None end event
} else if (eventDefinition == null) {
endEventActivity.setAsync(endEvent.isAsynchronous());
endEventActivity.setExclusive(!endEvent.isNotExclusive());
endEventActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createNoneEndEventActivityBehavior(endEvent));
}
}
use of org.activiti.bpmn.model.EventDefinition in project Activiti by Activiti.
the class BoundaryEventXMLConverter method convertXMLToElement.
@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
BoundaryEvent boundaryEvent = new BoundaryEvent();
BpmnXMLUtil.addXMLLocation(boundaryEvent, xtr);
if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_BOUNDARY_CANCELACTIVITY))) {
String cancelActivity = xtr.getAttributeValue(null, ATTRIBUTE_BOUNDARY_CANCELACTIVITY);
if (ATTRIBUTE_VALUE_FALSE.equalsIgnoreCase(cancelActivity)) {
boundaryEvent.setCancelActivity(false);
}
}
boundaryEvent.setAttachedToRefId(xtr.getAttributeValue(null, ATTRIBUTE_BOUNDARY_ATTACHEDTOREF));
parseChildElements(getXMLElementName(), boundaryEvent, model, xtr);
// Explicitly set cancel activity to false for error boundary events
if (boundaryEvent.getEventDefinitions().size() == 1) {
EventDefinition eventDef = boundaryEvent.getEventDefinitions().get(0);
if (eventDef instanceof ErrorEventDefinition) {
boundaryEvent.setCancelActivity(false);
}
}
return boundaryEvent;
}
use of org.activiti.bpmn.model.EventDefinition 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);
}
}
}
}
Aggregations