use of org.activiti.bpmn.model.CompensateEventDefinition 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.CompensateEventDefinition 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) {
// 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.CompensateEventDefinition in project Activiti by Activiti.
the class AbstractBpmnActivityBehavior method executeCompensateBoundaryEvents.
protected void executeCompensateBoundaryEvents(Collection<BoundaryEvent> boundaryEvents, DelegateExecution execution) {
// The parent execution becomes a scope, and a child execution is created for each of the boundary events
for (BoundaryEvent boundaryEvent : boundaryEvents) {
if (CollectionUtil.isEmpty(boundaryEvent.getEventDefinitions())) {
continue;
}
if (boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition == false) {
continue;
}
ExecutionEntity childExecutionEntity = Context.getCommandContext().getExecutionEntityManager().createChildExecution((ExecutionEntity) execution);
childExecutionEntity.setParentId(execution.getId());
childExecutionEntity.setCurrentFlowElement(boundaryEvent);
childExecutionEntity.setScope(false);
ActivityBehavior boundaryEventBehavior = ((ActivityBehavior) boundaryEvent.getBehavior());
boundaryEventBehavior.execute(childExecutionEntity);
}
}
use of org.activiti.bpmn.model.CompensateEventDefinition in project Activiti by Activiti.
the class ContinueProcessOperation method executeBoundaryEvents.
protected void executeBoundaryEvents(Collection<BoundaryEvent> boundaryEvents, ExecutionEntity execution) {
// The parent execution becomes a scope, and a child execution is created for each of the boundary events
for (BoundaryEvent boundaryEvent : boundaryEvents) {
if (CollectionUtil.isEmpty(boundaryEvent.getEventDefinitions()) || (boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition)) {
continue;
}
// A Child execution of the current execution is created to represent the boundary event being active
ExecutionEntity childExecutionEntity = commandContext.getExecutionEntityManager().createChildExecution((ExecutionEntity) execution);
childExecutionEntity.setParentId(execution.getId());
childExecutionEntity.setCurrentFlowElement(boundaryEvent);
childExecutionEntity.setScope(false);
ActivityBehavior boundaryEventBehavior = ((ActivityBehavior) boundaryEvent.getBehavior());
logger.debug("Executing boundary event activityBehavior {} with execution {}", boundaryEventBehavior.getClass(), childExecutionEntity.getId());
boundaryEventBehavior.execute(childExecutionEntity);
}
}
use of org.activiti.bpmn.model.CompensateEventDefinition in project Activiti by Activiti.
the class MultiInstanceActivityBehavior method executeCompensationBoundaryEvents.
protected void executeCompensationBoundaryEvents(FlowElement flowElement, DelegateExecution execution) {
// Execute compensation boundary events
Collection<BoundaryEvent> boundaryEvents = findBoundaryEventsForFlowNode(execution.getProcessDefinitionId(), flowElement);
if (CollectionUtil.isNotEmpty(boundaryEvents)) {
// The parent execution becomes a scope, and a child execution is created for each of the boundary events
for (BoundaryEvent boundaryEvent : boundaryEvents) {
if (CollectionUtil.isEmpty(boundaryEvent.getEventDefinitions())) {
continue;
}
if (boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition) {
ExecutionEntity childExecutionEntity = Context.getCommandContext().getExecutionEntityManager().createChildExecution((ExecutionEntity) execution);
childExecutionEntity.setParentId(execution.getId());
childExecutionEntity.setCurrentFlowElement(boundaryEvent);
childExecutionEntity.setScope(false);
ActivityBehavior boundaryEventBehavior = ((ActivityBehavior) boundaryEvent.getBehavior());
boundaryEventBehavior.execute(childExecutionEntity);
}
}
}
}
Aggregations