use of org.activiti.bpmn.model.Process in project Activiti by Activiti.
the class ActivitiEventListenerParser method parseChildElement.
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
EventListener listener = new EventListener();
BpmnXMLUtil.addXMLLocation(listener, xtr);
if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CLASS))) {
listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_CLASS));
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
} else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_DELEGATEEXPRESSION))) {
listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_DELEGATEEXPRESSION));
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
} else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_THROW_EVENT_TYPE))) {
String eventType = xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_THROW_EVENT_TYPE);
if (ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_SIGNAL.equals(eventType)) {
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_THROW_SIGNAL_EVENT);
listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_THROW_SIGNAL_EVENT_NAME));
} else if (ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_GLOBAL_SIGNAL.equals(eventType)) {
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_THROW_GLOBAL_SIGNAL_EVENT);
listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_THROW_SIGNAL_EVENT_NAME));
} else if (ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_MESSAGE.equals(eventType)) {
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_THROW_MESSAGE_EVENT);
listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_THROW_MESSAGE_EVENT_NAME));
} else if (ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_ERROR.equals(eventType)) {
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_THROW_ERROR_EVENT);
listener.setImplementation(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_THROW_ERROR_EVENT_CODE));
} else {
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_INVALID_THROW_EVENT);
}
}
listener.setEvents(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_EVENTS));
listener.setEntityType(xtr.getAttributeValue(null, ATTRIBUTE_LISTENER_ENTITY_TYPE));
Process parentProcess = (Process) parentElement;
parentProcess.getEventListeners().add(listener);
}
use of org.activiti.bpmn.model.Process 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.Process in project Activiti by Activiti.
the class CustomExtensionsConverterTest method validateModel.
private void validateModel(BpmnModel model) {
Process process = model.getMainProcess();
assertNotNull(process.getAttributes());
assertEquals(1, process.getAttributes().size());
List<ExtensionAttribute> attributes = process.getAttributes().get("version");
assertNotNull(attributes);
assertEquals(1, attributes.size());
ExtensionAttribute attribute = attributes.get(0);
//custom:version = "9"
assertNotNull(attribute);
assertEquals("http://custom.org/bpmn", attribute.getNamespace());
assertEquals("custom", attribute.getNamespacePrefix());
assertEquals("version", attribute.getName());
assertEquals("9", attribute.getValue());
List<ActivitiListener> listeners = model.getMainProcess().getExecutionListeners();
validateExecutionListeners(listeners);
Map<String, List<ExtensionElement>> extensionElementMap = model.getMainProcess().getExtensionElements();
validateExtensionElements(extensionElementMap);
FlowElement flowElement = model.getMainProcess().getFlowElement("servicetask");
assertNotNull(flowElement);
assertTrue(flowElement instanceof ServiceTask);
assertEquals("servicetask", flowElement.getId());
ServiceTask serviceTask = (ServiceTask) flowElement;
assertEquals("servicetask", serviceTask.getId());
assertEquals("Service task", serviceTask.getName());
List<FieldExtension> fields = serviceTask.getFieldExtensions();
assertEquals(2, fields.size());
FieldExtension field = (FieldExtension) fields.get(0);
assertEquals("testField", field.getFieldName());
assertEquals("test", field.getStringValue());
field = (FieldExtension) fields.get(1);
assertEquals("testField2", field.getFieldName());
assertEquals("${test}", field.getExpression());
listeners = serviceTask.getExecutionListeners();
validateExecutionListeners(listeners);
extensionElementMap = serviceTask.getExtensionElements();
validateExtensionElements(extensionElementMap);
assertEquals(1, serviceTask.getBoundaryEvents().size());
BoundaryEvent boundaryEvent = serviceTask.getBoundaryEvents().get(0);
assertEquals("timerEvent", boundaryEvent.getId());
assertEquals(1, boundaryEvent.getEventDefinitions().size());
assertTrue(boundaryEvent.getEventDefinitions().get(0) instanceof TimerEventDefinition);
extensionElementMap = boundaryEvent.getEventDefinitions().get(0).getExtensionElements();
validateExtensionElements(extensionElementMap);
}
use of org.activiti.bpmn.model.Process in project Activiti by Activiti.
the class CustomNamespaceAttributeConverterTest method validateModel.
private void validateModel(BpmnModel model) {
Process process = model.getMainProcess();
assertNotNull(process.getAttributes());
assertEquals(1, process.getAttributes().size());
List<ExtensionAttribute> attributes = process.getAttributes().get("version");
assertNotNull(attributes);
assertEquals(1, attributes.size());
ExtensionAttribute attribute = attributes.get(0);
//custom:version = "9"
assertNotNull(attribute);
assertEquals("http://custom.org/bpmn", attribute.getNamespace());
assertEquals("custom", attribute.getNamespacePrefix());
assertEquals("version", attribute.getName());
assertEquals("9", attribute.getValue());
FlowElement flowElement = model.getMainProcess().getFlowElement("usertask");
assertNotNull(flowElement);
assertTrue(flowElement instanceof UserTask);
assertEquals("usertask", flowElement.getId());
UserTask userTask = (UserTask) flowElement;
assertEquals("usertask", userTask.getId());
assertEquals("User Task", userTask.getName());
Map<String, List<ExtensionAttribute>> attributesMap = userTask.getAttributes();
assertNotNull(attributesMap);
assertEquals(2, attributesMap.size());
attributes = attributesMap.get("id");
assertNotNull(attributes);
assertEquals(1, attributes.size());
ExtensionAttribute a = attributes.get(0);
assertNotNull(a);
assertEquals("id", a.getName());
assertEquals("test", a.getValue());
assertEquals("custom2", a.getNamespacePrefix());
assertEquals("http://custom2.org/bpmn", a.getNamespace());
attributes = attributesMap.get("attr");
assertNotNull(attributes);
assertEquals(1, attributes.size());
a = attributes.get(0);
assertNotNull(a);
assertEquals("attr", a.getName());
assertEquals("attrValue", a.getValue());
assertEquals("custom2", a.getNamespacePrefix());
assertEquals("http://custom2.org/bpmn", a.getNamespace());
}
use of org.activiti.bpmn.model.Process in project Activiti by Activiti.
the class EventJavaTest method testStartEventWithExecutionListener.
public void testStartEventWithExecutionListener() throws Exception {
BpmnModel bpmnModel = new BpmnModel();
Process process = new Process();
process.setId("simpleProcess");
process.setName("Very simple process");
bpmnModel.getProcesses().add(process);
StartEvent startEvent = new StartEvent();
startEvent.setId("startEvent1");
TimerEventDefinition timerDef = new TimerEventDefinition();
timerDef.setTimeDuration("PT5M");
startEvent.getEventDefinitions().add(timerDef);
ActivitiListener listener = new ActivitiListener();
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
listener.setImplementation("${test}");
listener.setEvent("end");
startEvent.getExecutionListeners().add(listener);
process.addFlowElement(startEvent);
UserTask task = new UserTask();
task.setId("reviewTask");
task.setAssignee("kermit");
process.addFlowElement(task);
SequenceFlow flow1 = new SequenceFlow();
flow1.setId("flow1");
flow1.setSourceRef("startEvent1");
flow1.setTargetRef("reviewTask");
process.addFlowElement(flow1);
EndEvent endEvent = new EndEvent();
endEvent.setId("endEvent1");
process.addFlowElement(endEvent);
byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);
new BpmnXMLConverter().validateModel(new InputStreamSource(new ByteArrayInputStream(xml)));
Deployment deployment = repositoryService.createDeployment().name("test").addString("test.bpmn20.xml", new String(xml)).deploy();
repositoryService.deleteDeployment(deployment.getId());
}
Aggregations