use of org.activiti.bpmn.model.Message in project Activiti by Activiti.
the class BpmnParse method createMessages.
public void createMessages() {
for (Message messageElement : bpmnModel.getMessages()) {
MessageDefinition messageDefinition = new MessageDefinition(messageElement.getId(), name);
if (StringUtils.isNotEmpty(messageElement.getItemRef())) {
if (this.itemDefinitions.containsKey(messageElement.getItemRef())) {
ItemDefinition itemDefinition = this.itemDefinitions.get(messageElement.getItemRef());
messageDefinition.setItemDefinition(itemDefinition);
}
}
this.messages.put(messageDefinition.getId(), messageDefinition);
}
}
use of org.activiti.bpmn.model.Message in project Activiti by Activiti.
the class MessageEventDefinitionWithExtensionElementsTest method testParseMessagedDefinitionWithExtension.
@Test
public void testParseMessagedDefinitionWithExtension() {
BpmnParse bpmnParseMock = Mockito.mock(BpmnParse.class);
MessageEventDefinition messageEventDefinitionMock = Mockito.mock(MessageEventDefinition.class);
BpmnModel bpmnModelMock = Mockito.mock(BpmnModel.class);
Message messageMock = Mockito.mock(Message.class);
@SuppressWarnings("unchecked") Map<String, List<ExtensionElement>> extensionElementMap = Mockito.mock(Map.class);
Mockito.when(bpmnParseMock.getBpmnModel()).thenReturn(bpmnModelMock);
Mockito.when(messageEventDefinitionMock.getMessageRef()).thenReturn("messageId");
Mockito.when(bpmnModelMock.containsMessageId("messageId")).thenReturn(true);
Mockito.when(bpmnModelMock.getMessage("messageId")).thenReturn(messageMock);
Mockito.when(messageMock.getName()).thenReturn("MessageWithExtensionElements");
Mockito.when(messageMock.getExtensionElements()).thenReturn(extensionElementMap);
MessageEventDefinitionParseHandler handler = new MessageEventDefinitionParseHandler();
handler.parse(bpmnParseMock, messageEventDefinitionMock);
Mockito.verify(messageEventDefinitionMock).setMessageRef("MessageWithExtensionElements");
Mockito.verify(messageEventDefinitionMock).setExtensionElements(extensionElementMap);
}
use of org.activiti.bpmn.model.Message 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.Message in project Activiti by Activiti.
the class MessageParser method parse.
public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {
if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) {
String messageId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
String messageName = xtr.getAttributeValue(null, ATTRIBUTE_NAME);
String itemRef = parseItemRef(xtr.getAttributeValue(null, ATTRIBUTE_ITEM_REF), model);
Message message = new Message(messageId, messageName, itemRef);
BpmnXMLUtil.addXMLLocation(message, xtr);
BpmnXMLUtil.parseChildElements(ELEMENT_MESSAGE, message, xtr, model);
model.addMessage(message);
}
}
use of org.activiti.bpmn.model.Message in project Activiti by Activiti.
the class BpmnJsonConverterUtil method convertMessagesToJson.
public static void convertMessagesToJson(Collection<Message> messages, ObjectNode propertiesNode) {
String propertyName = "messages";
ArrayNode messagesNode = objectMapper.createArrayNode();
for (Message message : messages) {
ObjectNode propertyItemNode = objectMapper.createObjectNode();
propertyItemNode.put(PROPERTY_MESSAGE_ID, message.getId());
propertyItemNode.put(PROPERTY_MESSAGE_NAME, message.getName());
propertyItemNode.put(PROPERTY_MESSAGE_ITEM_REF, message.getItemRef());
messagesNode.add(propertyItemNode);
}
propertiesNode.put(propertyName, messagesNode);
}
Aggregations