Search in sources :

Example 11 with FlowElement

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");
            }
        }
    }
}
Also used : SequenceFlow(org.activiti.bpmn.model.SequenceFlow) FlowElement(org.activiti.bpmn.model.FlowElement) FlowElementsContainer(org.activiti.bpmn.model.FlowElementsContainer)

Example 12 with FlowElement

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());
        }
    }
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) GregorianCalendar(java.util.GregorianCalendar) BooleanDataObject(org.activiti.bpmn.model.BooleanDataObject) Date(java.util.Date) DoubleDataObject(org.activiti.bpmn.model.DoubleDataObject) FlowElement(org.activiti.bpmn.model.FlowElement) StartEvent(org.activiti.bpmn.model.StartEvent) LongDataObject(org.activiti.bpmn.model.LongDataObject)

Example 13 with FlowElement

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);
}
Also used : FlowElement(org.activiti.bpmn.model.FlowElement) Resource(org.activiti.bpmn.model.Resource) UserTask(org.activiti.bpmn.model.UserTask)

Example 14 with FlowElement

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();
    }
}
Also used : Signal(org.activiti.bpmn.model.Signal) Message(org.activiti.bpmn.model.Message) FlowElement(org.activiti.bpmn.model.FlowElement) Event(org.activiti.bpmn.model.Event) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) Process(org.activiti.bpmn.model.Process) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition)

Example 15 with FlowElement

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());
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) FlowElement(org.activiti.bpmn.model.FlowElement) FieldExtension(org.activiti.bpmn.model.FieldExtension) ActivitiListener(org.activiti.bpmn.model.ActivitiListener)

Aggregations

FlowElement (org.activiti.bpmn.model.FlowElement)75 SubProcess (org.activiti.bpmn.model.SubProcess)27 UserTask (org.activiti.bpmn.model.UserTask)25 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)24 StartEvent (org.activiti.bpmn.model.StartEvent)14 Process (org.activiti.bpmn.model.Process)13 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)9 Activity (org.activiti.bpmn.model.Activity)9 ServiceTask (org.activiti.bpmn.model.ServiceTask)9 Gateway (org.activiti.bpmn.model.Gateway)8 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)7 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)7 Artifact (org.activiti.bpmn.model.Artifact)6 FlowNode (org.activiti.bpmn.model.FlowNode)6 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)6 EventDefinition (org.activiti.bpmn.model.EventDefinition)5 ExclusiveGateway (org.activiti.bpmn.model.ExclusiveGateway)5