Search in sources :

Example 1 with StringDataObject

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

the class BpmnJsonConverterUtil method convertJsonToDataProperties.

public static List<ValuedDataObject> convertJsonToDataProperties(JsonNode objectNode, BaseElement element) {
    List<ValuedDataObject> dataObjects = new ArrayList<ValuedDataObject>();
    if (objectNode != null) {
        if (objectNode.isValueNode() && StringUtils.isNotEmpty(objectNode.asText())) {
            try {
                objectNode = objectMapper.readTree(objectNode.asText());
            } catch (Exception e) {
                logger.info("Data properties node cannot be read", e);
            }
        }
        JsonNode itemsArrayNode = objectNode.get(EDITOR_PROPERTIES_GENERAL_ITEMS);
        if (itemsArrayNode != null) {
            for (JsonNode dataNode : itemsArrayNode) {
                JsonNode dataIdNode = dataNode.get(PROPERTY_DATA_ID);
                if (dataIdNode != null && StringUtils.isNotEmpty(dataIdNode.asText())) {
                    ValuedDataObject dataObject = null;
                    ItemDefinition itemSubjectRef = new ItemDefinition();
                    String dataType = dataNode.get(PROPERTY_DATA_TYPE).asText();
                    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 {}", dataIdNode.asText());
                    }
                    if (null != dataObject) {
                        dataObject.setId(dataIdNode.asText());
                        dataObject.setName(dataNode.get(PROPERTY_DATA_NAME).asText());
                        itemSubjectRef.setStructureRef("xsd:" + dataType);
                        dataObject.setItemSubjectRef(itemSubjectRef);
                        if (dataObject instanceof DateDataObject) {
                            try {
                                dataObject.setValue(dateTimeFormatter.parseDateTime(dataNode.get(PROPERTY_DATA_VALUE).asText()).toDate());
                            } catch (Exception e) {
                                logger.error("Error converting {}", dataObject.getName(), e);
                            }
                        } else {
                            dataObject.setValue(dataNode.get(PROPERTY_DATA_VALUE).asText());
                        }
                        dataObjects.add(dataObject);
                    }
                }
            }
        }
    }
    return dataObjects;
}
Also used : ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) ArrayList(java.util.ArrayList) ItemDefinition(org.activiti.bpmn.model.ItemDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) IntegerDataObject(org.activiti.bpmn.model.IntegerDataObject) BooleanDataObject(org.activiti.bpmn.model.BooleanDataObject) StringDataObject(org.activiti.bpmn.model.StringDataObject) DoubleDataObject(org.activiti.bpmn.model.DoubleDataObject) DateDataObject(org.activiti.bpmn.model.DateDataObject) LongDataObject(org.activiti.bpmn.model.LongDataObject)

Example 2 with StringDataObject

use of org.activiti.bpmn.model.StringDataObject 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 3 with StringDataObject

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

the class ValuedDataObjectXMLConverter method writeExtensionChildElements.

@Override
protected boolean writeExtensionChildElements(BaseElement element, boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {
    ValuedDataObject dataObject = (ValuedDataObject) element;
    if (StringUtils.isNotEmpty(dataObject.getId()) && dataObject.getValue() != null) {
        if (didWriteExtensionStartElement == false) {
            xtw.writeStartElement(ELEMENT_EXTENSIONS);
            didWriteExtensionStartElement = true;
        }
        xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_DATA_VALUE, ACTIVITI_EXTENSIONS_NAMESPACE);
        if (dataObject.getValue() != null) {
            String value = null;
            if (dataObject instanceof DateDataObject) {
                value = sdf.format(dataObject.getValue());
            } else {
                value = dataObject.getValue().toString();
            }
            if (dataObject instanceof StringDataObject && xmlChars.matcher(value).find()) {
                xtw.writeCData(value);
            } else {
                xtw.writeCharacters(value);
            }
        }
        xtw.writeEndElement();
    }
    return didWriteExtensionStartElement;
}
Also used : ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) StringDataObject(org.activiti.bpmn.model.StringDataObject) DateDataObject(org.activiti.bpmn.model.DateDataObject)

Aggregations

DateDataObject (org.activiti.bpmn.model.DateDataObject)3 StringDataObject (org.activiti.bpmn.model.StringDataObject)3 ValuedDataObject (org.activiti.bpmn.model.ValuedDataObject)3 BooleanDataObject (org.activiti.bpmn.model.BooleanDataObject)2 DoubleDataObject (org.activiti.bpmn.model.DoubleDataObject)2 IntegerDataObject (org.activiti.bpmn.model.IntegerDataObject)2 ItemDefinition (org.activiti.bpmn.model.ItemDefinition)2 LongDataObject (org.activiti.bpmn.model.LongDataObject)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 ExtensionElement (org.activiti.bpmn.model.ExtensionElement)1