use of org.activiti.bpmn.model.TimerEventDefinition in project Activiti by Activiti.
the class BoundaryEventValidator method executeValidation.
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
List<BoundaryEvent> boundaryEvents = process.findFlowElementsOfType(BoundaryEvent.class);
// Only one boundary event of type 'cancel' can be attached to the same element, so we store the count temporarily here
HashMap<String, Integer> cancelBoundaryEventsCounts = new HashMap<String, Integer>();
// Only one boundary event of type 'compensate' can be attached to the same element, so we store the count temporarily here
HashMap<String, Integer> compensateBoundaryEventsCounts = new HashMap<String, Integer>();
for (int i = 0; i < boundaryEvents.size(); i++) {
BoundaryEvent boundaryEvent = boundaryEvents.get(i);
if (boundaryEvent.getEventDefinitions() != null && !boundaryEvent.getEventDefinitions().isEmpty()) {
EventDefinition eventDefinition = boundaryEvent.getEventDefinitions().get(0);
if (!(eventDefinition instanceof TimerEventDefinition) && !(eventDefinition instanceof ErrorEventDefinition) && !(eventDefinition instanceof SignalEventDefinition) && !(eventDefinition instanceof CancelEventDefinition) && !(eventDefinition instanceof MessageEventDefinition) && !(eventDefinition instanceof CompensateEventDefinition)) {
addError(errors, Problems.BOUNDARY_EVENT_INVALID_EVENT_DEFINITION, process, boundaryEvent, "Invalid or unsupported event definition");
}
if (eventDefinition instanceof CancelEventDefinition) {
FlowElement attachedToFlowElement = bpmnModel.getFlowElement(boundaryEvent.getAttachedToRefId());
if (!(attachedToFlowElement instanceof Transaction)) {
addError(errors, Problems.BOUNDARY_EVENT_CANCEL_ONLY_ON_TRANSACTION, process, boundaryEvent, "boundary event with cancelEventDefinition only supported on transaction subprocesses");
} else {
if (!cancelBoundaryEventsCounts.containsKey(attachedToFlowElement.getId())) {
cancelBoundaryEventsCounts.put(attachedToFlowElement.getId(), new Integer(0));
}
cancelBoundaryEventsCounts.put(attachedToFlowElement.getId(), new Integer(cancelBoundaryEventsCounts.get(attachedToFlowElement.getId()) + 1));
}
} else if (eventDefinition instanceof CompensateEventDefinition) {
if (!compensateBoundaryEventsCounts.containsKey(boundaryEvent.getAttachedToRefId())) {
compensateBoundaryEventsCounts.put(boundaryEvent.getAttachedToRefId(), new Integer(0));
}
compensateBoundaryEventsCounts.put(boundaryEvent.getAttachedToRefId(), compensateBoundaryEventsCounts.get(boundaryEvent.getAttachedToRefId()) + 1);
} else if (eventDefinition instanceof MessageEventDefinition) {
// Check if other message boundary events with same message id
for (int j = 0; j < boundaryEvents.size(); j++) {
if (j != i) {
BoundaryEvent otherBoundaryEvent = boundaryEvents.get(j);
if (otherBoundaryEvent.getAttachedToRefId() != null && otherBoundaryEvent.getAttachedToRefId().equals(boundaryEvent.getAttachedToRefId())) {
if (otherBoundaryEvent.getEventDefinitions() != null && !otherBoundaryEvent.getEventDefinitions().isEmpty()) {
EventDefinition otherEventDefinition = otherBoundaryEvent.getEventDefinitions().get(0);
if (otherEventDefinition instanceof MessageEventDefinition) {
MessageEventDefinition currentMessageEventDefinition = (MessageEventDefinition) eventDefinition;
MessageEventDefinition otherMessageEventDefinition = (MessageEventDefinition) otherEventDefinition;
if (otherMessageEventDefinition.getMessageRef() != null && otherMessageEventDefinition.getMessageRef().equals(currentMessageEventDefinition.getMessageRef())) {
addError(errors, Problems.MESSAGE_EVENT_MULTIPLE_ON_BOUNDARY_SAME_MESSAGE_ID, process, boundaryEvent, "Multiple message events with same message id not supported");
}
}
}
}
}
}
}
} else {
addError(errors, Problems.BOUNDARY_EVENT_NO_EVENT_DEFINITION, process, boundaryEvent, "Event definition is missing from boundary event");
}
}
for (String elementId : cancelBoundaryEventsCounts.keySet()) {
if (cancelBoundaryEventsCounts.get(elementId) > 1) {
addError(errors, Problems.BOUNDARY_EVENT_MULTIPLE_CANCEL_ON_TRANSACTION, process, bpmnModel.getFlowElement(elementId), "multiple boundary events with cancelEventDefinition not supported on same transaction subprocess.");
}
}
for (String elementId : compensateBoundaryEventsCounts.keySet()) {
if (compensateBoundaryEventsCounts.get(elementId) > 1) {
addError(errors, Problems.COMPENSATE_EVENT_MULTIPLE_ON_BOUNDARY, process, bpmnModel.getFlowElement(elementId), "Multiple boundary events of type 'compensate' is invalid");
}
}
}
use of org.activiti.bpmn.model.TimerEventDefinition in project Activiti by Activiti.
the class TimeDurationParser method parseChildElement.
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
if (parentElement instanceof TimerEventDefinition == false)
return;
TimerEventDefinition eventDefinition = (TimerEventDefinition) parentElement;
eventDefinition.setTimeDuration(xtr.getElementText());
}
use of org.activiti.bpmn.model.TimerEventDefinition in project Activiti by Activiti.
the class TimerEventDefinitionParser method parseChildElement.
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
if (parentElement instanceof Event == false)
return;
TimerEventDefinition eventDefinition = new TimerEventDefinition();
String calendarName = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_CALENDAR_NAME);
if (StringUtils.isNotEmpty(calendarName)) {
eventDefinition.setCalendarName(calendarName);
}
BpmnXMLUtil.addXMLLocation(eventDefinition, xtr);
BpmnXMLUtil.parseChildElements(ELEMENT_EVENT_TIMERDEFINITION, eventDefinition, xtr, model);
((Event) parentElement).getEventDefinitions().add(eventDefinition);
}
use of org.activiti.bpmn.model.TimerEventDefinition in project Activiti by Activiti.
the class SimpleConverterTest method validateModel.
private void validateModel(BpmnModel model) {
assertEquals(2, model.getDefinitionsAttributes().size());
assertEquals("2.2A", model.getDefinitionsAttributeValue("http://activiti.com/modeler", "version"));
assertEquals("20140312T10:45:23", model.getDefinitionsAttributeValue("http://activiti.com/modeler", "exportDate"));
assertEquals("simpleProcess", model.getMainProcess().getId());
assertEquals("Simple process", model.getMainProcess().getName());
assertEquals("simple doc", model.getMainProcess().getDocumentation());
assertEquals(true, model.getMainProcess().isExecutable());
FlowElement flowElement = model.getMainProcess().getFlowElement("flow1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof SequenceFlow);
assertEquals("flow1", flowElement.getId());
flowElement = model.getMainProcess().getFlowElement("catchEvent");
assertNotNull(flowElement);
assertTrue(flowElement instanceof IntermediateCatchEvent);
assertEquals("catchEvent", flowElement.getId());
IntermediateCatchEvent catchEvent = (IntermediateCatchEvent) flowElement;
assertTrue(catchEvent.getEventDefinitions().size() == 1);
EventDefinition eventDefinition = catchEvent.getEventDefinitions().get(0);
assertTrue(eventDefinition instanceof TimerEventDefinition);
TimerEventDefinition timerDefinition = (TimerEventDefinition) eventDefinition;
assertEquals("PT5M", timerDefinition.getTimeDuration());
flowElement = model.getMainProcess().getFlowElement("userTask1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof UserTask);
UserTask task = (UserTask) flowElement;
assertEquals("task doc", task.getDocumentation());
flowElement = model.getMainProcess().getFlowElement("flow1Condition");
assertNotNull(flowElement);
assertTrue(flowElement instanceof SequenceFlow);
assertEquals("flow1Condition", flowElement.getId());
SequenceFlow flow = (SequenceFlow) flowElement;
assertEquals("${number <= 1}", flow.getConditionExpression());
flowElement = model.getMainProcess().getFlowElement("gateway1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof ExclusiveGateway);
}
use of org.activiti.bpmn.model.TimerEventDefinition 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);
}
Aggregations