use of org.activiti.bpmn.model.MessageEventDefinition in project Activiti by Activiti.
the class StartEventParseHandler method createScopeStartEvent.
protected void createScopeStartEvent(BpmnParse bpmnParse, ActivityImpl startEventActivity, StartEvent startEvent) {
ScopeImpl scope = bpmnParse.getCurrentScope();
Object triggeredByEvent = scope.getProperty("triggeredByEvent");
boolean isTriggeredByEvent = triggeredByEvent != null && ((Boolean) triggeredByEvent == true);
if (isTriggeredByEvent) {
// event subprocess
// all start events of an event subprocess share common behavior
EventSubProcessStartEventActivityBehavior activityBehavior = bpmnParse.getActivityBehaviorFactory().createEventSubProcessStartEventActivityBehavior(startEvent, startEventActivity.getId());
startEventActivity.setActivityBehavior(activityBehavior);
if (!startEvent.getEventDefinitions().isEmpty()) {
EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
if (eventDefinition instanceof org.activiti.bpmn.model.ErrorEventDefinition || eventDefinition instanceof MessageEventDefinition || eventDefinition instanceof SignalEventDefinition) {
bpmnParse.getBpmnParserHandlers().parseElement(bpmnParse, eventDefinition);
} else {
logger.warn("start event of event subprocess must be of type 'error', 'message' or 'signal' for start event " + startEvent.getId());
}
}
} else {
if (!startEvent.getEventDefinitions().isEmpty()) {
logger.warn("event definitions only allowed on start event if subprocess is an event subprocess " + bpmnParse.getCurrentSubProcess().getId());
}
if (scope.getProperty(PROPERTYNAME_INITIAL) == null) {
scope.setProperty(PROPERTYNAME_INITIAL, startEventActivity);
startEventActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createNoneStartEventActivityBehavior(startEvent));
} else {
logger.warn("multiple start events not supported for subprocess", bpmnParse.getCurrentSubProcess().getId());
}
}
}
use of org.activiti.bpmn.model.MessageEventDefinition in project Activiti by Activiti.
the class IntermediateCatchEventParseHandler method executeParse.
protected void executeParse(BpmnParse bpmnParse, IntermediateCatchEvent event) {
ActivityImpl nestedActivity = null;
EventDefinition eventDefinition = null;
if (!event.getEventDefinitions().isEmpty()) {
eventDefinition = event.getEventDefinitions().get(0);
}
if (eventDefinition == null) {
nestedActivity = createActivityOnCurrentScope(bpmnParse, event, BpmnXMLConstants.ELEMENT_EVENT_CATCH);
nestedActivity.setAsync(event.isAsynchronous());
nestedActivity.setExclusive(!event.isNotExclusive());
} else {
ScopeImpl scope = bpmnParse.getCurrentScope();
String eventBasedGatewayId = getPrecedingEventBasedGateway(bpmnParse, event);
if (eventBasedGatewayId != null) {
ActivityImpl gatewayActivity = scope.findActivity(eventBasedGatewayId);
nestedActivity = createActivityOnScope(bpmnParse, event, BpmnXMLConstants.ELEMENT_EVENT_CATCH, gatewayActivity);
} else {
nestedActivity = createActivityOnScope(bpmnParse, event, BpmnXMLConstants.ELEMENT_EVENT_CATCH, scope);
}
nestedActivity.setAsync(event.isAsynchronous());
nestedActivity.setExclusive(!event.isNotExclusive());
// Catch event behavior is the same for all types
nestedActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateCatchEventActivityBehavior(event));
if (eventDefinition instanceof TimerEventDefinition || eventDefinition instanceof SignalEventDefinition || eventDefinition instanceof MessageEventDefinition) {
bpmnParse.getBpmnParserHandlers().parseElement(bpmnParse, eventDefinition);
} else {
logger.warn("Unsupported intermediate catch event type for event " + event.getId());
}
}
}
use of org.activiti.bpmn.model.MessageEventDefinition 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())) {
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())) {
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(BPMN2_PREFIX, ELEMENT_MESSAGE, BPMN2_NAMESPACE);
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.MessageEventDefinition in project Activiti by Activiti.
the class IntermediateThrowEventParseHandler method executeParse.
protected void executeParse(BpmnParse bpmnParse, ThrowEvent intermediateEvent) {
EventDefinition eventDefinition = null;
if (!intermediateEvent.getEventDefinitions().isEmpty()) {
eventDefinition = intermediateEvent.getEventDefinitions().get(0);
}
if (eventDefinition instanceof SignalEventDefinition) {
SignalEventDefinition signalEventDefinition = (SignalEventDefinition) eventDefinition;
intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowSignalEventActivityBehavior(intermediateEvent, signalEventDefinition, bpmnParse.getBpmnModel().getSignal(signalEventDefinition.getSignalRef())));
} else if (eventDefinition instanceof CompensateEventDefinition) {
CompensateEventDefinition compensateEventDefinition = (CompensateEventDefinition) eventDefinition;
intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowCompensationEventActivityBehavior(intermediateEvent, compensateEventDefinition));
} else if (eventDefinition instanceof MessageEventDefinition) {
MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
Message message = bpmnParse.getBpmnModel().getMessage(messageEventDefinition.getMessageRef());
BpmnModel bpmnModel = bpmnParse.getBpmnModel();
if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
messageEventDefinition.setMessageRef(message.getName());
messageEventDefinition.setExtensionElements(message.getExtensionElements());
}
intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createThrowMessageEventActivityBehavior(intermediateEvent, messageEventDefinition, message));
} else if (eventDefinition == null) {
intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowNoneEventActivityBehavior(intermediateEvent));
} else {
logger.warn("Unsupported intermediate throw event type for throw event " + intermediateEvent.getId());
}
}
use of org.activiti.bpmn.model.MessageEventDefinition 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);
}
Aggregations