Search in sources :

Example 11 with ValuedDataObject

use of org.activiti.bpmn.model.ValuedDataObject in project Activiti by Activiti.

the class ValuedDataObjectXMLConverter method convertXMLToElement.

@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
    ValuedDataObject dataObject = null;
    ItemDefinition itemSubjectRef = new ItemDefinition();
    String structureRef = xtr.getAttributeValue(null, ATTRIBUTE_DATA_ITEM_REF);
    if (StringUtils.isNotEmpty(structureRef) && structureRef.contains(":")) {
        String dataType = structureRef.substring(structureRef.indexOf(':') + 1);
        if (dataType.equals("string")) {
            dataObject = new StringDataObject();
        } else if (dataType.equals("int")) {
            dataObject = new IntegerDataObject();
        } else if (dataType.equals("long")) {
            dataObject = new LongDataObject();
        } else if (dataType.equals("double")) {
            dataObject = new DoubleDataObject();
        } else if (dataType.equals("boolean")) {
            dataObject = new BooleanDataObject();
        } else if (dataType.equals("datetime")) {
            dataObject = new DateDataObject();
        } else {
            LOGGER.error("Error converting {}, invalid data type: " + dataType, xtr.getAttributeValue(null, ATTRIBUTE_DATA_NAME));
        }
    } else {
        // use String as default type
        dataObject = new StringDataObject();
        structureRef = "xsd:string";
    }
    if (dataObject != null) {
        dataObject.setId(xtr.getAttributeValue(null, ATTRIBUTE_DATA_ID));
        dataObject.setName(xtr.getAttributeValue(null, ATTRIBUTE_DATA_NAME));
        BpmnXMLUtil.addXMLLocation(dataObject, xtr);
        itemSubjectRef.setStructureRef(structureRef);
        dataObject.setItemSubjectRef(itemSubjectRef);
        parseChildElements(getXMLElementName(), dataObject, model, xtr);
        List<ExtensionElement> valuesElement = dataObject.getExtensionElements().get("value");
        if (valuesElement != null && !valuesElement.isEmpty()) {
            ExtensionElement valueElement = valuesElement.get(0);
            if (StringUtils.isNotEmpty(valueElement.getElementText())) {
                if (dataObject instanceof DateDataObject) {
                    try {
                        dataObject.setValue(sdf.parse(valueElement.getElementText()));
                    } catch (Exception e) {
                        LOGGER.error("Error converting {}", dataObject.getName(), e.getMessage());
                    }
                } else {
                    dataObject.setValue(valueElement.getElementText());
                }
            }
            // remove value element
            dataObject.getExtensionElements().remove("value");
        }
    }
    return dataObject;
}
Also used : ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) StringDataObject(org.activiti.bpmn.model.StringDataObject) DoubleDataObject(org.activiti.bpmn.model.DoubleDataObject) DateDataObject(org.activiti.bpmn.model.DateDataObject) ItemDefinition(org.activiti.bpmn.model.ItemDefinition) ExtensionElement(org.activiti.bpmn.model.ExtensionElement) IntegerDataObject(org.activiti.bpmn.model.IntegerDataObject) LongDataObject(org.activiti.bpmn.model.LongDataObject) BooleanDataObject(org.activiti.bpmn.model.BooleanDataObject)

Example 12 with ValuedDataObject

use of org.activiti.bpmn.model.ValuedDataObject in project Activiti by Activiti.

the class ValuedDataObjectConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    FlowElement flowElement = model.getMainProcess().getFlowElement("start1");
    assertThat(flowElement).isNotNull();
    assertThat(flowElement).isInstanceOf(StartEvent.class);
    assertThat(flowElement.getId()).isEqualTo("start1");
    // verify the main process data objects
    List<ValuedDataObject> dataObjects = model.getProcess(null).getDataObjects();
    assertThat(dataObjects).hasSize(7);
    Map<String, ValuedDataObject> objectMap = new HashMap<String, ValuedDataObject>();
    for (ValuedDataObject valueObj : dataObjects) {
        objectMap.put(valueObj.getId(), valueObj);
    }
    ValuedDataObject dataObj = objectMap.get("dObj1");
    assertThat(dataObj.getId()).isEqualTo("dObj1");
    assertThat(dataObj.getName()).isEqualTo("StringTest");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:string");
    assertThat(dataObj.getValue()).isInstanceOf(String.class);
    assertThat(dataObj.getValue()).isEqualTo("Testing1&2&3");
    dataObj = objectMap.get("dObj2");
    assertThat(dataObj.getId()).isEqualTo("dObj2");
    assertThat(dataObj.getName()).isEqualTo("BooleanTest");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:boolean");
    assertThat(dataObj.getValue()).isInstanceOf(Boolean.class);
    assertThat(dataObj.getValue()).isEqualTo(Boolean.TRUE);
    dataObj = objectMap.get("dObj3");
    assertThat(dataObj.getId()).isEqualTo("dObj3");
    assertThat(dataObj.getName()).isEqualTo("DateTest");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:datetime");
    assertThat(dataObj.getValue()).isInstanceOf(Date.class);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    assertThat(sdf.format(dataObj.getValue())).isEqualTo("2013-09-16T11:23:00");
    dataObj = objectMap.get("dObj4");
    assertThat(dataObj.getId()).isEqualTo("dObj4");
    assertThat(dataObj.getName()).isEqualTo("DoubleTest");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:double");
    assertThat(dataObj.getValue()).isInstanceOf(Double.class);
    assertThat(dataObj.getValue()).isEqualTo(new Double(123456789));
    dataObj = objectMap.get("dObj5");
    assertThat(dataObj.getId()).isEqualTo("dObj5");
    assertThat(dataObj.getName()).isEqualTo("IntegerTest");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:int");
    assertThat(dataObj.getValue()).isInstanceOf(Integer.class);
    assertThat(dataObj.getValue()).isEqualTo(Integer.valueOf(123));
    dataObj = objectMap.get("dObj6");
    assertThat(dataObj.getId()).isEqualTo("dObj6");
    assertThat(dataObj.getName()).isEqualTo("LongTest");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:long");
    assertThat(dataObj.getValue()).isInstanceOf(Long.class);
    assertThat(dataObj.getValue()).isEqualTo(new Long(-123456));
    assertThat(dataObj.getExtensionElements()).hasSize(1);
    List<ExtensionElement> testValues = dataObj.getExtensionElements().get("testvalue");
    assertThat(testValues).isNotNull();
    assertThat(testValues).hasSize(1);
    assertThat(testValues.get(0).getName()).isEqualTo("testvalue");
    assertThat(testValues.get(0).getElementText()).isEqualTo("test");
    dataObj = objectMap.get("NoData");
    assertThat(dataObj.getId()).isEqualTo("NoData");
    assertThat(dataObj.getName()).isEqualTo("NoData");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:datetime");
    assertThat(dataObj.getValue()).isNull();
    flowElement = model.getMainProcess().getFlowElement("userTask1");
    assertThat(flowElement).isNotNull();
    assertThat(flowElement).isInstanceOf(UserTask.class);
    assertThat(flowElement.getId()).isEqualTo("userTask1");
    UserTask userTask = (UserTask) flowElement;
    assertThat(userTask.getAssignee()).isEqualTo("kermit");
    flowElement = model.getMainProcess().getFlowElement("subprocess1");
    assertThat(flowElement).isNotNull();
    assertThat(flowElement).isInstanceOf(SubProcess.class);
    assertThat(flowElement.getId()).isEqualTo("subprocess1");
    SubProcess subProcess = (SubProcess) flowElement;
    assertThat(subProcess.getFlowElements()).hasSize(11);
    // verify the sub process data objects
    dataObjects = subProcess.getDataObjects();
    assertThat(dataObjects).hasSize(6);
    objectMap = new HashMap<String, ValuedDataObject>();
    for (ValuedDataObject valueObj : dataObjects) {
        objectMap.put(valueObj.getId(), valueObj);
    }
    dataObj = objectMap.get("dObj7");
    assertThat(dataObj.getId()).isEqualTo("dObj7");
    assertThat(dataObj.getName()).isEqualTo("StringSubTest");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:string");
    assertThat(dataObj.getValue()).isInstanceOf(String.class);
    assertThat(dataObj.getValue()).isEqualTo("Testing456");
    dataObj = objectMap.get("dObj8");
    assertThat(dataObj.getId()).isEqualTo("dObj8");
    assertThat(dataObj.getName()).isEqualTo("BooleanSubTest");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:boolean");
    assertThat(dataObj.getValue()).isInstanceOf(Boolean.class);
    assertThat(dataObj.getValue()).isEqualTo(Boolean.FALSE);
    dataObj = objectMap.get("dObj9");
    assertThat(dataObj.getId()).isEqualTo("dObj9");
    assertThat(dataObj.getName()).isEqualTo("DateSubTest");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:datetime");
    assertThat(dataObj.getValue()).isInstanceOf(Date.class);
    assertThat(sdf.format(dataObj.getValue())).isEqualTo("2013-11-11T22:00:00");
    dataObj = objectMap.get("dObj10");
    assertThat(dataObj.getId()).isEqualTo("dObj10");
    assertThat(dataObj.getName()).isEqualTo("DoubleSubTest");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:double");
    assertThat(dataObj.getValue()).isInstanceOf(Double.class);
    assertThat(dataObj.getValue()).isEqualTo(new Double(678912345));
    dataObj = objectMap.get("dObj11");
    assertThat(dataObj.getId()).isEqualTo("dObj11");
    assertThat(dataObj.getName()).isEqualTo("IntegerSubTest");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:int");
    assertThat(dataObj.getValue()).isInstanceOf(Integer.class);
    assertThat(dataObj.getValue()).isEqualTo(Integer.valueOf(45));
    dataObj = objectMap.get("dObj12");
    assertThat(dataObj.getId()).isEqualTo("dObj12");
    assertThat(dataObj.getName()).isEqualTo("LongSubTest");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:long");
    assertThat(dataObj.getValue()).isInstanceOf(Long.class);
    assertThat(dataObj.getValue()).isEqualTo(new Long(456123));
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) HashMap(java.util.HashMap) ExtensionElement(org.activiti.bpmn.model.ExtensionElement) UserTask(org.activiti.bpmn.model.UserTask) FlowElement(org.activiti.bpmn.model.FlowElement) SimpleDateFormat(java.text.SimpleDateFormat)

Example 13 with ValuedDataObject

use of org.activiti.bpmn.model.ValuedDataObject in project Activiti by Activiti.

the class GetDataObjectsCmd method execute.

public Map<String, DataObject> execute(CommandContext commandContext) {
    // Verify existance of execution
    if (executionId == null) {
        throw new ActivitiIllegalArgumentException("executionId is null");
    }
    ExecutionEntity execution = commandContext.getExecutionEntityManager().findById(executionId);
    if (execution == null) {
        throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
    }
    Map<String, VariableInstance> variables = null;
    if (dataObjectNames == null || dataObjectNames.isEmpty()) {
        // Fetch all
        if (isLocal) {
            variables = execution.getVariableInstancesLocal();
        } else {
            variables = execution.getVariableInstances();
        }
    } else {
        // Fetch specific collection of variables
        if (isLocal) {
            variables = execution.getVariableInstancesLocal(dataObjectNames, false);
        } else {
            variables = execution.getVariableInstances(dataObjectNames, false);
        }
    }
    Map<String, DataObject> dataObjects = null;
    if (variables != null) {
        dataObjects = new HashMap<>(variables.size());
        for (Entry<String, VariableInstance> entry : variables.entrySet()) {
            String name = entry.getKey();
            VariableInstance variableEntity = (VariableInstance) entry.getValue();
            ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(variableEntity.getExecutionId());
            while (!executionEntity.isScope()) {
                executionEntity = executionEntity.getParent();
            }
            BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(execution.getProcessDefinitionId());
            ValuedDataObject foundDataObject = null;
            if (executionEntity.getParentId() == null) {
                for (ValuedDataObject dataObject : bpmnModel.getMainProcess().getDataObjects()) {
                    if (dataObject.getName().equals(variableEntity.getName())) {
                        foundDataObject = dataObject;
                        break;
                    }
                }
            } else {
                SubProcess subProcess = (SubProcess) bpmnModel.getFlowElement(execution.getActivityId());
                for (ValuedDataObject dataObject : subProcess.getDataObjects()) {
                    if (dataObject.getName().equals(variableEntity.getName())) {
                        foundDataObject = dataObject;
                        break;
                    }
                }
            }
            String localizedName = null;
            String localizedDescription = null;
            if (locale != null && foundDataObject != null) {
                ObjectNode languageNode = Context.getLocalizationElementProperties(locale, foundDataObject.getId(), execution.getProcessDefinitionId(), withLocalizationFallback);
                if (languageNode != null) {
                    JsonNode nameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
                    if (nameNode != null) {
                        localizedName = nameNode.asText();
                    }
                    JsonNode descriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
                    if (descriptionNode != null) {
                        localizedDescription = descriptionNode.asText();
                    }
                }
            }
            if (foundDataObject != null) {
                dataObjects.put(name, new DataObjectImpl(variableEntity.getName(), variableEntity.getValue(), foundDataObject.getDocumentation(), foundDataObject.getType(), localizedName, localizedDescription, foundDataObject.getId()));
            }
        }
    }
    return dataObjects;
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) BpmnModel(org.activiti.bpmn.model.BpmnModel) DataObjectImpl(org.activiti.engine.impl.DataObjectImpl) DataObject(org.activiti.engine.runtime.DataObject) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance)

Example 14 with ValuedDataObject

use of org.activiti.bpmn.model.ValuedDataObject in project Activiti by Activiti.

the class BaseBpmnXMLConverter method convertToBpmnModel.

public void convertToBpmnModel(XMLStreamReader xtr, BpmnModel model, Process activeProcess, List<SubProcess> activeSubProcessList) throws Exception {
    String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
    String elementName = xtr.getAttributeValue(null, ATTRIBUTE_NAME);
    boolean async = parseAsync(xtr);
    boolean notExclusive = parseNotExclusive(xtr);
    String defaultFlow = xtr.getAttributeValue(null, ATTRIBUTE_DEFAULT);
    boolean isForCompensation = parseForCompensation(xtr);
    BaseElement parsedElement = convertXMLToElement(xtr, model);
    if (parsedElement instanceof Artifact) {
        Artifact currentArtifact = (Artifact) parsedElement;
        currentArtifact.setId(elementId);
        if (!activeSubProcessList.isEmpty()) {
            activeSubProcessList.get(activeSubProcessList.size() - 1).addArtifact(currentArtifact);
        } else {
            activeProcess.addArtifact(currentArtifact);
        }
    }
    if (parsedElement instanceof FlowElement) {
        FlowElement currentFlowElement = (FlowElement) parsedElement;
        currentFlowElement.setId(elementId);
        currentFlowElement.setName(elementName);
        if (currentFlowElement instanceof FlowNode) {
            FlowNode flowNode = (FlowNode) currentFlowElement;
            flowNode.setAsynchronous(async);
            flowNode.setNotExclusive(notExclusive);
            if (currentFlowElement instanceof Activity) {
                Activity activity = (Activity) currentFlowElement;
                activity.setForCompensation(isForCompensation);
                if (StringUtils.isNotEmpty(defaultFlow)) {
                    activity.setDefaultFlow(defaultFlow);
                }
            }
            if (currentFlowElement instanceof Gateway) {
                Gateway gateway = (Gateway) currentFlowElement;
                if (StringUtils.isNotEmpty(defaultFlow)) {
                    gateway.setDefaultFlow(defaultFlow);
                }
            }
        }
        if (currentFlowElement instanceof DataObject) {
            if (!activeSubProcessList.isEmpty()) {
                SubProcess subProcess = activeSubProcessList.get(activeSubProcessList.size() - 1);
                subProcess.getDataObjects().add((ValuedDataObject) parsedElement);
            } else {
                activeProcess.getDataObjects().add((ValuedDataObject) parsedElement);
            }
        }
        if (!activeSubProcessList.isEmpty()) {
            SubProcess subProcess = activeSubProcessList.get(activeSubProcessList.size() - 1);
            subProcess.addFlowElement(currentFlowElement);
        } else {
            activeProcess.addFlowElement(currentFlowElement);
        }
    }
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) BaseElement(org.activiti.bpmn.model.BaseElement) DataObject(org.activiti.bpmn.model.DataObject) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) FlowElement(org.activiti.bpmn.model.FlowElement) Gateway(org.activiti.bpmn.model.Gateway) Activity(org.activiti.bpmn.model.Activity) Artifact(org.activiti.bpmn.model.Artifact) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 15 with ValuedDataObject

use of org.activiti.bpmn.model.ValuedDataObject in project Activiti by Activiti.

the class SubProcessJsonConverter method convertJsonToElement.

protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) {
    SubProcess subProcess = null;
    if (getPropertyValueAsBoolean("istransaction", elementNode)) {
        subProcess = new Transaction();
    } else {
        subProcess = new SubProcess();
    }
    JsonNode childShapesArray = elementNode.get(EDITOR_CHILD_SHAPES);
    processor.processJsonElements(childShapesArray, modelNode, subProcess, shapeMap, formMap, decisionTableMap, model);
    JsonNode processDataPropertiesNode = elementNode.get(EDITOR_SHAPE_PROPERTIES).get(PROPERTY_DATA_PROPERTIES);
    if (processDataPropertiesNode != null) {
        List<ValuedDataObject> dataObjects = BpmnJsonConverterUtil.convertJsonToDataProperties(processDataPropertiesNode, subProcess);
        subProcess.setDataObjects(dataObjects);
        subProcess.getFlowElements().addAll(dataObjects);
    }
    return subProcess;
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) Transaction(org.activiti.bpmn.model.Transaction) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

ValuedDataObject (org.activiti.bpmn.model.ValuedDataObject)21 SubProcess (org.activiti.bpmn.model.SubProcess)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 FlowElement (org.activiti.bpmn.model.FlowElement)8 BpmnModel (org.activiti.bpmn.model.BpmnModel)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 HashMap (java.util.HashMap)5 ExtensionElement (org.activiti.bpmn.model.ExtensionElement)5 ArrayList (java.util.ArrayList)4 BooleanDataObject (org.activiti.bpmn.model.BooleanDataObject)4 DateDataObject (org.activiti.bpmn.model.DateDataObject)4 DoubleDataObject (org.activiti.bpmn.model.DoubleDataObject)4 LongDataObject (org.activiti.bpmn.model.LongDataObject)4 StringDataObject (org.activiti.bpmn.model.StringDataObject)4 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)4 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)4 DataObjectImpl (org.activiti.engine.impl.DataObjectImpl)4 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)4 VariableInstance (org.activiti.engine.impl.persistence.entity.VariableInstance)4 DataObject (org.activiti.engine.runtime.DataObject)4