use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.
the class SequenceflowValidator method executeValidation.
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
List<SequenceFlow> sequenceFlows = process.findFlowElementsOfType(SequenceFlow.class);
for (SequenceFlow sequenceFlow : sequenceFlows) {
String sourceRef = sequenceFlow.getSourceRef();
String targetRef = sequenceFlow.getTargetRef();
if (StringUtils.isEmpty(sourceRef)) {
addError(errors, Problems.SEQ_FLOW_INVALID_SRC, process, sequenceFlow, "Invalid source for sequenceflow");
}
if (StringUtils.isEmpty(targetRef)) {
addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow");
}
// Implicit check: sequence flow cannot cross (sub) process boundaries, hence we check the parent and not the process
// (could be subprocess for example)
FlowElement source = process.getFlowElementRecursive(sourceRef);
FlowElement target = process.getFlowElementRecursive(targetRef);
// Src and target validation
if (source == null) {
addError(errors, Problems.SEQ_FLOW_INVALID_SRC, process, sequenceFlow, "Invalid source for sequenceflow");
}
if (target == null) {
addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow");
}
if (source != null && target != null) {
FlowElementsContainer sourceContainer = process.getFlowElementsContainerRecursive(source.getId());
FlowElementsContainer targetContainer = process.getFlowElementsContainerRecursive(target.getId());
if (sourceContainer == null) {
addError(errors, Problems.SEQ_FLOW_INVALID_SRC, process, sequenceFlow, "Invalid source for sequenceflow");
}
if (targetContainer == null) {
addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow");
}
if (sourceContainer != null && targetContainer != null && sourceContainer.equals(targetContainer) == false) {
addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow, the target isn't defined in the same scope as the source");
}
}
}
}
use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.
the class ValuedDataObjectConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("start1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof StartEvent);
assertEquals("start1", flowElement.getId());
// verify main process data objects
List<ValuedDataObject> dataObjects = model.getMainProcess().getDataObjects();
assertEquals(6, dataObjects.size());
for (ValuedDataObject dObj : dataObjects) {
if ("dObj1".equals(dObj.getId())) {
assertEquals(StringDataObject.class, dObj.getClass());
assertEquals("StringTest", dObj.getName());
assertTrue(dObj.getValue() instanceof String);
assertEquals("xsd:string", dObj.getItemSubjectRef().getStructureRef());
assertEquals("Testing123", dObj.getValue());
} else if ("dObj2".equals(dObj.getId())) {
assertEquals(BooleanDataObject.class, dObj.getClass());
assertEquals("BooleanTest", dObj.getName());
assertEquals("xsd:boolean", dObj.getItemSubjectRef().getStructureRef());
assertTrue(dObj.getValue() instanceof Boolean);
assertEquals(new Boolean(true), dObj.getValue());
} else if ("dObj3".equals(dObj.getId())) {
assertEquals(DateDataObject.class, dObj.getClass());
assertEquals("DateTest", dObj.getName());
assertEquals("xsd:datetime", dObj.getItemSubjectRef().getStructureRef());
assertTrue(dObj.getValue() instanceof Date);
GregorianCalendar dateCal = new GregorianCalendar();
dateCal.setTime((Date) dObj.getValue());
assertEquals(2013, dateCal.get(Calendar.YEAR));
assertEquals(8, dateCal.get(Calendar.MONTH));
assertEquals(16, dateCal.get(Calendar.DAY_OF_MONTH));
assertEquals(11, dateCal.get(Calendar.HOUR_OF_DAY));
assertEquals(23, dateCal.get(Calendar.MINUTE));
} else if ("dObj4".equals(dObj.getId())) {
assertEquals(DoubleDataObject.class, dObj.getClass());
assertEquals("DoubleTest", dObj.getName());
assertEquals("xsd:double", dObj.getItemSubjectRef().getStructureRef());
assertTrue(dObj.getValue() instanceof Double);
assertEquals(new Double(123456789), dObj.getValue());
} else if ("dObj5".equals(dObj.getId())) {
assertEquals(IntegerDataObject.class, dObj.getClass());
assertEquals("IntegerTest", dObj.getName());
assertEquals("xsd:int", dObj.getItemSubjectRef().getStructureRef());
assertTrue(dObj.getValue() instanceof Integer);
assertEquals(new Integer(123), dObj.getValue());
} else if ("dObj6".equals(dObj.getId())) {
assertEquals(LongDataObject.class, dObj.getClass());
assertEquals("LongTest", dObj.getName());
assertEquals("xsd:long", dObj.getItemSubjectRef().getStructureRef());
assertTrue(dObj.getValue() instanceof Long);
assertEquals(new Long(-123456), dObj.getValue());
}
}
flowElement = model.getMainProcess().getFlowElement("subprocess1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof SubProcess);
assertEquals("subprocess1", flowElement.getId());
SubProcess subProcess = (SubProcess) flowElement;
assertEquals(11, subProcess.getFlowElements().size());
// verify subprocess data objects
dataObjects = ((SubProcess) flowElement).getDataObjects();
assertEquals(6, dataObjects.size());
for (ValuedDataObject dObj : dataObjects) {
if ("dObj1".equals(dObj.getId())) {
assertEquals(StringDataObject.class, dObj.getClass());
assertEquals("SubStringTest", dObj.getName());
assertTrue(dObj.getValue() instanceof String);
assertEquals("xsd:string", dObj.getItemSubjectRef().getStructureRef());
assertEquals("Testing456", dObj.getValue());
} else if ("dObj2".equals(dObj.getId())) {
assertEquals(BooleanDataObject.class, dObj.getClass());
assertEquals("SubBooleanTest", dObj.getName());
assertEquals("xsd:boolean", dObj.getItemSubjectRef().getStructureRef());
assertTrue(dObj.getValue() instanceof Boolean);
assertEquals(new Boolean(false), dObj.getValue());
} else if ("dObj3".equals(dObj.getId())) {
assertEquals(DateDataObject.class, dObj.getClass());
assertEquals("SubDateTest", dObj.getName());
assertEquals("xsd:datetime", dObj.getItemSubjectRef().getStructureRef());
assertTrue(dObj.getValue() instanceof Date);
GregorianCalendar dateCal = new GregorianCalendar();
dateCal.setTime((Date) dObj.getValue());
assertEquals(2013, dateCal.get(Calendar.YEAR));
assertEquals(10, dateCal.get(Calendar.MONTH));
assertEquals(11, dateCal.get(Calendar.DAY_OF_MONTH));
} else if ("dObj4".equals(dObj.getId())) {
assertEquals(DoubleDataObject.class, dObj.getClass());
assertEquals("SubDoubleTest", dObj.getName());
assertEquals("xsd:double", dObj.getItemSubjectRef().getStructureRef());
assertTrue(dObj.getValue() instanceof Double);
assertEquals(new Double(678912345), dObj.getValue());
} else if ("dObj5".equals(dObj.getId())) {
assertEquals(IntegerDataObject.class, dObj.getClass());
assertEquals("SubIntegerTest", dObj.getName());
assertEquals("xsd:int", dObj.getItemSubjectRef().getStructureRef());
assertTrue(dObj.getValue() instanceof Integer);
assertEquals(new Integer(45), dObj.getValue());
} else if ("dObj6".equals(dObj.getId())) {
assertEquals(LongDataObject.class, dObj.getClass());
assertEquals("SubLongTest", dObj.getName());
assertEquals("xsd:long", dObj.getItemSubjectRef().getStructureRef());
assertTrue(dObj.getValue() instanceof Long);
assertEquals(new Long(456123), dObj.getValue());
assertEquals(1, dObj.getExtensionElements().size());
}
}
}
use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.
the class ResourceParser method parse.
public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {
String resourceId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
String resourceName = xtr.getAttributeValue(null, ATTRIBUTE_NAME);
Resource resource;
if (model.containsResourceId(resourceId)) {
resource = model.getResource(resourceId);
resource.setName(resourceName);
for (org.activiti.bpmn.model.Process process : model.getProcesses()) {
for (FlowElement fe : process.getFlowElements()) {
if (fe instanceof UserTask && ((UserTask) fe).getCandidateGroups().contains(resourceId)) {
((UserTask) fe).getCandidateGroups().remove(resourceId);
((UserTask) fe).getCandidateGroups().add(resourceName);
}
}
}
} else {
resource = new Resource(resourceId, resourceName);
model.addResource(resource);
}
BpmnXMLUtil.addXMLLocation(resource, xtr);
}
use of org.activiti.bpmn.model.FlowElement 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.FlowElement in project Activiti by Activiti.
the class ServiceTaskConverterTest method validateModel.
private void validateModel(BpmnModel model) {
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 = fields.get(0);
assertEquals("testField", field.getFieldName());
assertEquals("test", field.getStringValue());
field = fields.get(1);
assertEquals("testField2", field.getFieldName());
assertEquals("${test}", field.getExpression());
List<ActivitiListener> listeners = serviceTask.getExecutionListeners();
assertEquals(3, listeners.size());
ActivitiListener listener = listeners.get(0);
assertTrue(ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(listener.getImplementationType()));
assertEquals("org.test.TestClass", listener.getImplementation());
assertEquals("start", listener.getEvent());
listener = listeners.get(1);
assertTrue(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equals(listener.getImplementationType()));
assertEquals("${testExpression}", listener.getImplementation());
assertEquals("end", listener.getEvent());
listener = listeners.get(2);
assertTrue(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equals(listener.getImplementationType()));
assertEquals("${delegateExpression}", listener.getImplementation());
assertEquals("start", listener.getEvent());
assertEquals("R5/PT5M", serviceTask.getFailedJobRetryTimeCycleValue());
}
Aggregations