use of org.activiti.bpmn.model.EventDefinition 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.EventDefinition 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.EventDefinition in project Activiti by Activiti.
the class SimpleConverterTest method validateModel.
private void validateModel(BpmnModel model) {
assertThat(model.getDefinitionsAttributes()).hasSize(2);
assertThat(model.getDefinitionsAttributeValue("http://activiti.com/modeler", "version")).isEqualTo("2.2A");
assertThat(model.getDefinitionsAttributeValue("http://activiti.com/modeler", "exportDate")).isEqualTo("20140312T10:45:23");
assertThat(model.getMainProcess().getId()).isEqualTo("simpleProcess");
assertThat(model.getMainProcess().getName()).isEqualTo("Simple process");
assertThat(model.getMainProcess().getDocumentation()).isEqualTo("simple doc");
assertThat(model.getMainProcess().isExecutable()).isEqualTo(true);
FlowElement flowElement = model.getMainProcess().getFlowElement("flow1");
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(SequenceFlow.class);
assertThat(flowElement.getId()).isEqualTo("flow1");
flowElement = model.getMainProcess().getFlowElement("catchEvent");
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(IntermediateCatchEvent.class);
assertThat(flowElement.getId()).isEqualTo("catchEvent");
IntermediateCatchEvent catchEvent = (IntermediateCatchEvent) flowElement;
assertThat(catchEvent.getEventDefinitions().size() == 1).isTrue();
EventDefinition eventDefinition = catchEvent.getEventDefinitions().get(0);
assertThat(eventDefinition).isInstanceOf(TimerEventDefinition.class);
TimerEventDefinition timerDefinition = (TimerEventDefinition) eventDefinition;
assertThat(timerDefinition.getTimeDuration()).isEqualTo("PT5M");
flowElement = model.getMainProcess().getFlowElement("userTask1");
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(UserTask.class);
UserTask task = (UserTask) flowElement;
assertThat(task.getDocumentation()).isEqualTo("task doc");
flowElement = model.getMainProcess().getFlowElement("flow1Condition");
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(SequenceFlow.class);
assertThat(flowElement.getId()).isEqualTo("flow1Condition");
SequenceFlow flow = (SequenceFlow) flowElement;
assertThat(flow.getConditionExpression()).isEqualTo("${number <= 1}");
flowElement = model.getMainProcess().getFlowElement("gateway1");
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(ExclusiveGateway.class);
}
use of org.activiti.bpmn.model.EventDefinition 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.EventDefinition in project Activiti by Activiti.
the class EventSubscriptionManager method addSignalEventSubscriptions.
protected void addSignalEventSubscriptions(CommandContext commandContext, ProcessDefinitionEntity processDefinition, Process process, BpmnModel bpmnModel) {
if (CollectionUtil.isNotEmpty(process.getFlowElements())) {
for (FlowElement element : process.getFlowElements()) {
if (element instanceof StartEvent) {
StartEvent startEvent = (StartEvent) element;
if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions())) {
EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
if (eventDefinition instanceof SignalEventDefinition) {
SignalEventDefinition signalEventDefinition = (SignalEventDefinition) eventDefinition;
SignalEventSubscriptionEntity subscriptionEntity = commandContext.getEventSubscriptionEntityManager().createSignalEventSubscription();
Signal signal = bpmnModel.getSignal(signalEventDefinition.getSignalRef());
if (signal != null) {
subscriptionEntity.setEventName(signal.getName());
} else {
subscriptionEntity.setEventName(signalEventDefinition.getSignalRef());
}
subscriptionEntity.setActivityId(startEvent.getId());
subscriptionEntity.setProcessDefinitionId(processDefinition.getId());
if (processDefinition.getTenantId() != null) {
subscriptionEntity.setTenantId(processDefinition.getTenantId());
}
Context.getCommandContext().getEventSubscriptionEntityManager().insert(subscriptionEntity);
}
}
}
}
}
}
Aggregations