use of org.activiti.bpmn.model.CancelEventDefinition in project Activiti by Activiti.
the class BoundaryEventValidator method executeValidation.
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
List<BoundaryEvent> boundaryEvents = process.findFlowElementsOfType(BoundaryEvent.class);
// Only one boundary event of type 'cancel' can be attached to the same element, so we store the count temporarily here
HashMap<String, Integer> cancelBoundaryEventsCounts = new HashMap<String, Integer>();
// Only one boundary event of type 'compensate' can be attached to the same element, so we store the count temporarily here
HashMap<String, Integer> compensateBoundaryEventsCounts = new HashMap<String, Integer>();
for (int i = 0; i < boundaryEvents.size(); i++) {
BoundaryEvent boundaryEvent = boundaryEvents.get(i);
if (boundaryEvent.getEventDefinitions() != null && !boundaryEvent.getEventDefinitions().isEmpty()) {
EventDefinition eventDefinition = boundaryEvent.getEventDefinitions().get(0);
if (!(eventDefinition instanceof TimerEventDefinition) && !(eventDefinition instanceof ErrorEventDefinition) && !(eventDefinition instanceof SignalEventDefinition) && !(eventDefinition instanceof CancelEventDefinition) && !(eventDefinition instanceof MessageEventDefinition) && !(eventDefinition instanceof CompensateEventDefinition)) {
addError(errors, Problems.BOUNDARY_EVENT_INVALID_EVENT_DEFINITION, process, boundaryEvent, "Invalid or unsupported event definition");
}
if (eventDefinition instanceof CancelEventDefinition) {
FlowElement attachedToFlowElement = bpmnModel.getFlowElement(boundaryEvent.getAttachedToRefId());
if (!(attachedToFlowElement instanceof Transaction)) {
addError(errors, Problems.BOUNDARY_EVENT_CANCEL_ONLY_ON_TRANSACTION, process, boundaryEvent, "boundary event with cancelEventDefinition only supported on transaction subprocesses");
} else {
if (!cancelBoundaryEventsCounts.containsKey(attachedToFlowElement.getId())) {
cancelBoundaryEventsCounts.put(attachedToFlowElement.getId(), new Integer(0));
}
cancelBoundaryEventsCounts.put(attachedToFlowElement.getId(), new Integer(cancelBoundaryEventsCounts.get(attachedToFlowElement.getId()) + 1));
}
} else if (eventDefinition instanceof CompensateEventDefinition) {
if (!compensateBoundaryEventsCounts.containsKey(boundaryEvent.getAttachedToRefId())) {
compensateBoundaryEventsCounts.put(boundaryEvent.getAttachedToRefId(), new Integer(0));
}
compensateBoundaryEventsCounts.put(boundaryEvent.getAttachedToRefId(), compensateBoundaryEventsCounts.get(boundaryEvent.getAttachedToRefId()) + 1);
} else if (eventDefinition instanceof MessageEventDefinition) {
// Check if other message boundary events with same message id
for (int j = 0; j < boundaryEvents.size(); j++) {
if (j != i) {
BoundaryEvent otherBoundaryEvent = boundaryEvents.get(j);
if (otherBoundaryEvent.getAttachedToRefId() != null && otherBoundaryEvent.getAttachedToRefId().equals(boundaryEvent.getAttachedToRefId())) {
if (otherBoundaryEvent.getEventDefinitions() != null && !otherBoundaryEvent.getEventDefinitions().isEmpty()) {
EventDefinition otherEventDefinition = otherBoundaryEvent.getEventDefinitions().get(0);
if (otherEventDefinition instanceof MessageEventDefinition) {
MessageEventDefinition currentMessageEventDefinition = (MessageEventDefinition) eventDefinition;
MessageEventDefinition otherMessageEventDefinition = (MessageEventDefinition) otherEventDefinition;
if (otherMessageEventDefinition.getMessageRef() != null && otherMessageEventDefinition.getMessageRef().equals(currentMessageEventDefinition.getMessageRef())) {
addError(errors, Problems.MESSAGE_EVENT_MULTIPLE_ON_BOUNDARY_SAME_MESSAGE_ID, process, boundaryEvent, "Multiple message events with same message id not supported");
}
}
}
}
}
}
}
} else {
addError(errors, Problems.BOUNDARY_EVENT_NO_EVENT_DEFINITION, process, boundaryEvent, "Event definition is missing from boundary event");
}
}
for (String elementId : cancelBoundaryEventsCounts.keySet()) {
if (cancelBoundaryEventsCounts.get(elementId) > 1) {
addError(errors, Problems.BOUNDARY_EVENT_MULTIPLE_CANCEL_ON_TRANSACTION, process, bpmnModel.getFlowElement(elementId), "multiple boundary events with cancelEventDefinition not supported on same transaction subprocess.");
}
}
for (String elementId : compensateBoundaryEventsCounts.keySet()) {
if (compensateBoundaryEventsCounts.get(elementId) > 1) {
addError(errors, Problems.COMPENSATE_EVENT_MULTIPLE_ON_BOUNDARY, process, bpmnModel.getFlowElement(elementId), "Multiple boundary events of type 'compensate' is invalid");
}
}
}
use of org.activiti.bpmn.model.CancelEventDefinition in project Activiti by Activiti.
the class BoundaryEventJsonConverter method getStencilId.
protected String getStencilId(BaseElement baseElement) {
BoundaryEvent boundaryEvent = (BoundaryEvent) baseElement;
List<EventDefinition> eventDefinitions = boundaryEvent.getEventDefinitions();
if (eventDefinitions.size() != 1) {
// return timer event as default;
return STENCIL_EVENT_BOUNDARY_TIMER;
}
EventDefinition eventDefinition = eventDefinitions.get(0);
if (eventDefinition instanceof ErrorEventDefinition) {
return STENCIL_EVENT_BOUNDARY_ERROR;
} else if (eventDefinition instanceof SignalEventDefinition) {
return STENCIL_EVENT_BOUNDARY_SIGNAL;
} else if (eventDefinition instanceof MessageEventDefinition) {
return STENCIL_EVENT_BOUNDARY_MESSAGE;
} else if (eventDefinition instanceof CancelEventDefinition) {
return STENCIL_EVENT_BOUNDARY_CANCEL;
} else if (eventDefinition instanceof CompensateEventDefinition) {
return STENCIL_EVENT_BOUNDARY_COMPENSATION;
} else {
return STENCIL_EVENT_BOUNDARY_TIMER;
}
}
use of org.activiti.bpmn.model.CancelEventDefinition in project Activiti by Activiti.
the class BoundaryEventJsonConverter method convertJsonToElement.
protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) {
BoundaryEvent boundaryEvent = new BoundaryEvent();
String stencilId = BpmnJsonConverterUtil.getStencilId(elementNode);
if (STENCIL_EVENT_BOUNDARY_TIMER.equals(stencilId)) {
convertJsonToTimerDefinition(elementNode, boundaryEvent);
boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));
} else if (STENCIL_EVENT_BOUNDARY_ERROR.equals(stencilId)) {
convertJsonToErrorDefinition(elementNode, boundaryEvent);
} else if (STENCIL_EVENT_BOUNDARY_SIGNAL.equals(stencilId)) {
convertJsonToSignalDefinition(elementNode, boundaryEvent);
boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));
} else if (STENCIL_EVENT_BOUNDARY_MESSAGE.equals(stencilId)) {
convertJsonToMessageDefinition(elementNode, boundaryEvent);
boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));
} else if (STENCIL_EVENT_BOUNDARY_CANCEL.equals(stencilId)) {
CancelEventDefinition cancelEventDefinition = new CancelEventDefinition();
boundaryEvent.getEventDefinitions().add(cancelEventDefinition);
boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));
} else if (STENCIL_EVENT_BOUNDARY_COMPENSATION.equals(stencilId)) {
CompensateEventDefinition compensateEventDefinition = new CompensateEventDefinition();
boundaryEvent.getEventDefinitions().add(compensateEventDefinition);
boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));
}
boundaryEvent.setAttachedToRefId(lookForAttachedRef(elementNode.get(EDITOR_SHAPE_ID).asText(), modelNode.get(EDITOR_CHILD_SHAPES)));
return boundaryEvent;
}
use of org.activiti.bpmn.model.CancelEventDefinition 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.CancelEventDefinition 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));
}
}
Aggregations