use of org.activiti.bpmn.model.SignalEventDefinition 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.SignalEventDefinition in project Activiti by Activiti.
the class SignalAndMessageDefinitionExport method writeSignalsAndMessages.
public static void writeSignalsAndMessages(BpmnModel model, XMLStreamWriter xtw) throws Exception {
for (Process process : model.getProcesses()) {
for (FlowElement flowElement : process.findFlowElementsOfType(Event.class)) {
Event event = (Event) flowElement;
if (!event.getEventDefinitions().isEmpty()) {
EventDefinition eventDefinition = event.getEventDefinitions().get(0);
if (eventDefinition instanceof SignalEventDefinition) {
SignalEventDefinition signalEvent = (SignalEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(signalEvent.getSignalRef())) {
if (model.containsSignalId(signalEvent.getSignalRef()) == false) {
Signal signal = new Signal(signalEvent.getSignalRef(), signalEvent.getSignalRef());
model.addSignal(signal);
}
}
} else if (eventDefinition instanceof MessageEventDefinition) {
MessageEventDefinition messageEvent = (MessageEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(messageEvent.getMessageRef())) {
if (model.containsMessageId(messageEvent.getMessageRef()) == false) {
Message message = new Message(messageEvent.getMessageRef(), messageEvent.getMessageRef(), null);
model.addMessage(message);
}
}
}
}
}
}
for (Signal signal : model.getSignals()) {
xtw.writeStartElement(ELEMENT_SIGNAL);
xtw.writeAttribute(ATTRIBUTE_ID, signal.getId());
xtw.writeAttribute(ATTRIBUTE_NAME, signal.getName());
if (signal.getScope() != null) {
xtw.writeAttribute(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_SCOPE, signal.getScope());
}
xtw.writeEndElement();
}
for (Message message : model.getMessages()) {
xtw.writeStartElement(ELEMENT_MESSAGE);
String messageId = message.getId();
// remove the namespace from the message id if set
if (model.getTargetNamespace() != null && messageId.startsWith(model.getTargetNamespace())) {
messageId = messageId.replace(model.getTargetNamespace(), "");
messageId = messageId.replaceFirst(":", "");
} else {
for (String prefix : model.getNamespaces().keySet()) {
String namespace = model.getNamespace(prefix);
if (messageId.startsWith(namespace)) {
messageId = messageId.replace(model.getTargetNamespace(), "");
messageId = prefix + messageId;
}
}
}
xtw.writeAttribute(ATTRIBUTE_ID, messageId);
if (StringUtils.isNotEmpty(message.getName())) {
xtw.writeAttribute(ATTRIBUTE_NAME, message.getName());
}
if (StringUtils.isNotEmpty(message.getItemRef())) {
// replace the namespace by the right prefix
String itemRef = message.getItemRef();
for (String prefix : model.getNamespaces().keySet()) {
String namespace = model.getNamespace(prefix);
if (itemRef.startsWith(namespace)) {
if (prefix.isEmpty()) {
itemRef = itemRef.replace(namespace + ":", "");
} else {
itemRef = itemRef.replace(namespace, prefix);
}
break;
}
}
xtw.writeAttribute(ATTRIBUTE_ITEM_REF, itemRef);
}
xtw.writeEndElement();
}
}
use of org.activiti.bpmn.model.SignalEventDefinition 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.getErrorCode())) {
propertiesNode.put(PROPERTY_ERRORREF, errorDefinition.getErrorCode());
}
} 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());
}
}
}
use of org.activiti.bpmn.model.SignalEventDefinition in project Activiti by Activiti.
the class BaseBpmnJsonConverter method convertJsonToSignalDefinition.
protected void convertJsonToSignalDefinition(JsonNode objectNode, Event event) {
String signalRef = getPropertyValueAsString(PROPERTY_SIGNALREF, objectNode);
SignalEventDefinition eventDefinition = new SignalEventDefinition();
eventDefinition.setSignalRef(signalRef);
event.getEventDefinitions().add(eventDefinition);
}
use of org.activiti.bpmn.model.SignalEventDefinition 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;
}
}
Aggregations