private void validateModel(BpmnModel model) { BoundaryEvent errorElement = (BoundaryEvent) model.getMainProcess().getFlowElement("errorEvent"); ErrorEventDefinition errorEvent = (ErrorEventDefinition) extractEventDefinition(errorElement); assertTrue(errorElement.isCancelActivity()); // always true assertEquals("errorRef", errorEvent.getErrorCode()); BoundaryEvent signalElement = (BoundaryEvent) model.getMainProcess().getFlowElement("signalEvent"); SignalEventDefinition signalEvent = (SignalEventDefinition) extractEventDefinition(signalElement); assertFalse(signalElement.isCancelActivity()); assertEquals("signalRef", signalEvent.getSignalRef()); BoundaryEvent messageElement = (BoundaryEvent) model.getMainProcess().getFlowElement("messageEvent"); MessageEventDefinition messageEvent = (MessageEventDefinition) extractEventDefinition(messageElement); assertFalse(messageElement.isCancelActivity()); assertEquals("messageRef", messageEvent.getMessageRef()); BoundaryEvent timerElement = (BoundaryEvent) model.getMainProcess().getFlowElement("timerEvent"); TimerEventDefinition timerEvent = (TimerEventDefinition) extractEventDefinition(timerElement); assertFalse(timerElement.isCancelActivity()); assertEquals("PT5M", timerEvent.getTimeDuration()); }
public static void writeSignalsAndMessages(BpmnModel model, XMLStreamWriter xtw) throws Exception { for (Process process : model.getProcesses()) { for (FlowElement flowElement : process.getFlowElements()) { if (flowElement instanceof Event) { Event event = (Event) flowElement; if (event.getEventDefinitions().size() > 0) { EventDefinition eventDefinition = event.getEventDefinitions().get(0); if (eventDefinition instanceof SignalEventDefinition) { SignalEventDefinition signalEvent = (SignalEventDefinition) eventDefinition; 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 (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()); 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 (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); xtw.writeAttribute(ATTRIBUTE_NAME, message.getName()); xtw.writeEndElement(); } }
@Override public void refresh() { cancelActivityCombo.removeFocusListener(listener); messageCombo.removeFocusListener(listener); PictogramElement pe = getSelectedPictogramElement(); if (pe != null) { Object bo = getBusinessObject(pe); if (bo == null) return; final Bpmn2MemoryModel model = ModelHandler.getModel(EcoreUtil.getURI(getDiagram())); if (model == null) { return; } boolean cancelActivity = ((BoundaryEvent) bo).isCancelActivity(); if (cancelActivity == false) { cancelActivityCombo.select(1); } else { cancelActivityCombo.select(0); } String messageRef = null; if (bo instanceof BoundaryEvent) { BoundaryEvent boundaryEvent = (BoundaryEvent) bo; if (boundaryEvent.getEventDefinitions().get(0) != null) { MessageEventDefinition messageDefinition = (MessageEventDefinition) boundaryEvent.getEventDefinitions().get(0); if (StringUtils.isNotEmpty(messageDefinition.getMessageRef())) { messageRef = messageDefinition.getMessageRef(); } } } String[] items = new String[model.getBpmnModel().getMessages().size() + 1]; items[0] = ""; int counter = 1; int selectedCounter = 0; for (Message message : model.getBpmnModel().getMessages()) { items[counter] = message.getId() + " / " + message.getName(); if (message.getId().equals(messageRef)) { selectedCounter = counter; } counter++; } messageCombo.setItems(items); messageCombo.select(selectedCounter); } cancelActivityCombo.addFocusListener(listener); messageCombo.addFocusListener(listener); }
protected void writeMessageDefinition( Event parentEvent, MessageEventDefinition messageDefinition, BpmnModel model, XMLStreamWriter xtw) throws Exception { xtw.writeStartElement(ELEMENT_EVENT_MESSAGEDEFINITION); String messageRef = messageDefinition.getMessageRef(); if (StringUtils.isNotEmpty(messageRef)) { // remove the namespace from the message id if set if (messageRef.startsWith(model.getTargetNamespace())) { messageRef = messageRef.replace(model.getTargetNamespace(), ""); messageRef = messageRef.replaceFirst(":", ""); } else { for (String prefix : model.getNamespaces().keySet()) { String namespace = model.getNamespace(prefix); if (messageRef.startsWith(namespace)) { messageRef = messageRef.replace(model.getTargetNamespace(), ""); messageRef = prefix + messageRef; } } } } writeDefaultAttribute(ATTRIBUTE_MESSAGE_REF, messageRef, xtw); boolean didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(messageDefinition, false, xtw); if (didWriteExtensionStartElement) { xtw.writeEndElement(); } xtw.writeEndElement(); }
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()); } } }
protected void convertJsonToMessageDefinition(JsonNode objectNode, Event event) { String messageRef = getPropertyValueAsString(PROPERTY_MESSAGEREF, objectNode); MessageEventDefinition eventDefinition = new MessageEventDefinition(); eventDefinition.setMessageRef(messageRef); event.getEventDefinitions().add(eventDefinition); }
protected void writeMessageDefinition( MessageEventDefinition messageDefinition, XMLStreamWriter xtw) throws Exception { xtw.writeStartElement(ELEMENT_EVENT_MESSAGEDEFINITION); writeDefaultAttribute(ATTRIBUTE_MESSAGE_REF, messageDefinition.getMessageRef(), xtw); xtw.writeEndElement(); }