use of org.activiti.bpmn.model.ErrorEventDefinition in project Activiti by Activiti.
the class ErrorEventDefinitionParser method parseChildElement.
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
if (!(parentElement instanceof Event)) {
return;
}
ErrorEventDefinition eventDefinition = new ErrorEventDefinition();
BpmnXMLUtil.addXMLLocation(eventDefinition, xtr);
eventDefinition.setErrorRef(xtr.getAttributeValue(null, ATTRIBUTE_ERROR_REF));
BpmnXMLUtil.parseChildElements(ELEMENT_EVENT_ERRORDEFINITION, eventDefinition, xtr, model);
((Event) parentElement).getEventDefinitions().add(eventDefinition);
}
use of org.activiti.bpmn.model.ErrorEventDefinition 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.ErrorEventDefinition in project Activiti by Activiti.
the class BaseBpmnJsonConverter method addEventProperties.
protected void addEventProperties(Event event, ObjectNode propertiesNode) {
List<EventDefinition> eventDefinitions = event.getEventDefinitions();
if (eventDefinitions.size() == 1) {
EventDefinition eventDefinition = eventDefinitions.get(0);
if (eventDefinition instanceof ErrorEventDefinition) {
ErrorEventDefinition errorDefinition = (ErrorEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(errorDefinition.getErrorRef())) {
propertiesNode.put(PROPERTY_ERRORREF, errorDefinition.getErrorRef());
}
} else if (eventDefinition instanceof SignalEventDefinition) {
SignalEventDefinition signalDefinition = (SignalEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(signalDefinition.getSignalRef())) {
propertiesNode.put(PROPERTY_SIGNALREF, signalDefinition.getSignalRef());
}
} else if (eventDefinition instanceof MessageEventDefinition) {
MessageEventDefinition messageDefinition = (MessageEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(messageDefinition.getMessageRef())) {
propertiesNode.put(PROPERTY_MESSAGEREF, messageDefinition.getMessageRef());
}
} else if (eventDefinition instanceof TimerEventDefinition) {
TimerEventDefinition timerDefinition = (TimerEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(timerDefinition.getTimeDuration())) {
propertiesNode.put(PROPERTY_TIMER_DURATON, timerDefinition.getTimeDuration());
}
if (StringUtils.isNotEmpty(timerDefinition.getTimeCycle())) {
propertiesNode.put(PROPERTY_TIMER_CYCLE, timerDefinition.getTimeCycle());
}
if (StringUtils.isNotEmpty(timerDefinition.getTimeDate())) {
propertiesNode.put(PROPERTY_TIMER_DATE, timerDefinition.getTimeDate());
}
if (StringUtils.isNotEmpty(timerDefinition.getEndDate())) {
propertiesNode.put(PROPERTY_TIMER_CYCLE_END_DATE, timerDefinition.getEndDate());
}
} else if (eventDefinition instanceof TerminateEventDefinition) {
TerminateEventDefinition terminateEventDefinition = (TerminateEventDefinition) eventDefinition;
propertiesNode.put(PROPERTY_TERMINATE_ALL, terminateEventDefinition.isTerminateAll());
propertiesNode.put(PROPERTY_TERMINATE_MULTI_INSTANCE, terminateEventDefinition.isTerminateMultiInstance());
}
}
}
use of org.activiti.bpmn.model.ErrorEventDefinition 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.ErrorEventDefinition in project Activiti by Activiti.
the class BoundaryEventConverterTest method validateModel.
private void validateModel(BpmnModel model) {
BoundaryEvent errorElement = (BoundaryEvent) model.getMainProcess().getFlowElement("errorEvent", true);
ErrorEventDefinition errorEvent = (ErrorEventDefinition) extractEventDefinition(errorElement);
// always true
assertThat(errorElement.isCancelActivity()).isTrue();
assertThat(errorEvent.getErrorRef()).isEqualTo("errorRef");
assertThat(errorElement.getAttachedToRefId()).isEqualTo("sid-F21E9F4D-EA19-44DF-B1D3-14663A809CAE");
BoundaryEvent signalElement = (BoundaryEvent) model.getMainProcess().getFlowElement("signalEvent", true);
SignalEventDefinition signalEvent = (SignalEventDefinition) extractEventDefinition(signalElement);
assertThat(signalElement.isCancelActivity()).isFalse();
assertThat(signalEvent.getSignalRef()).isEqualTo("signalRef");
assertThat(errorElement.getAttachedToRefId()).isEqualTo("sid-F21E9F4D-EA19-44DF-B1D3-14663A809CAE");
BoundaryEvent messageElement = (BoundaryEvent) model.getMainProcess().getFlowElement("messageEvent", true);
MessageEventDefinition messageEvent = (MessageEventDefinition) extractEventDefinition(messageElement);
assertThat(messageElement.isCancelActivity()).isFalse();
assertThat(messageEvent.getMessageRef()).isEqualTo("messageRef");
assertThat(errorElement.getAttachedToRefId()).isEqualTo("sid-F21E9F4D-EA19-44DF-B1D3-14663A809CAE");
BoundaryEvent timerElement = (BoundaryEvent) model.getMainProcess().getFlowElement("timerEvent", true);
TimerEventDefinition timerEvent = (TimerEventDefinition) extractEventDefinition(timerElement);
assertThat(timerElement.isCancelActivity()).isFalse();
assertThat(timerEvent.getTimeDuration()).isEqualTo("PT5M");
assertThat(errorElement.getAttachedToRefId()).isEqualTo("sid-F21E9F4D-EA19-44DF-B1D3-14663A809CAE");
}
Aggregations