use of org.activiti.bpmn.model.ValuedDataObject in project Activiti by Activiti.
the class ValuedDataObjectWithExtensionsConverterTest 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.getMainProcess().getDataObjects();
assertThat(dataObjects).hasSize(1);
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("Testing123");
/*
* Verify DataObject attributes extension
*/
Map<String, String> attributes = getDataObjectAttributes(dataObj);
assertThat(attributes).hasSize(2);
assertThat(attributes).containsOnlyKeys("Attr1", "Attr2");
assertThat(attributes.get("Attr1")).isEqualTo("1");
assertThat(attributes.get("Attr2")).isEqualTo("2");
/*
* Verify DataObject localization extension
*/
Localization localization = getLocalization(dataObj);
assertThat(localization.getResourceBundleKeyForName()).isEqualTo("rbkfn-1");
assertThat(localization.getResourceBundleKeyForDescription()).isEqualTo("rbkfd-1");
assertThat(localization.getLabeledEntityIdForName()).isEqualTo("leifn-1");
assertThat(localization.getLabeledEntityIdForDescription()).isEqualTo("leifd-1");
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(6);
// verify the sub process data objects
dataObjects = subProcess.getDataObjects();
assertThat(dataObjects).hasSize(1);
objectMap = new HashMap<String, ValuedDataObject>();
for (ValuedDataObject valueObj : dataObjects) {
objectMap.put(valueObj.getId(), valueObj);
}
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);
/*
* Verify DataObject attributes extension
*/
attributes = getDataObjectAttributes(dataObj);
assertThat(attributes).hasSize(2);
assertThat(attributes).containsOnlyKeys("Attr3", "Attr4");
assertThat(attributes.get("Attr3")).isEqualTo("3");
assertThat(attributes.get("Attr4")).isEqualTo("4");
/*
* Verify DataObject localization extension
*/
localization = getLocalization(dataObj);
assertThat(localization.getResourceBundleKeyForName()).isEqualTo("rbkfn-2");
assertThat(localization.getResourceBundleKeyForDescription()).isEqualTo("rbkfd-2");
assertThat(localization.getLabeledEntityIdForName()).isEqualTo("leifn-2");
assertThat(localization.getLabeledEntityIdForDescription()).isEqualTo("leifd-2");
}
use of org.activiti.bpmn.model.ValuedDataObject in project Activiti by Activiti.
the class BpmnJsonConverterUtil method convertDataPropertiesToJson.
public static void convertDataPropertiesToJson(List<ValuedDataObject> dataObjects, ObjectNode propertiesNode) {
ObjectNode dataPropertiesNode = objectMapper.createObjectNode();
ArrayNode itemsNode = objectMapper.createArrayNode();
for (ValuedDataObject dObj : dataObjects) {
ObjectNode propertyItemNode = objectMapper.createObjectNode();
propertyItemNode.put(PROPERTY_DATA_ID, dObj.getId());
propertyItemNode.put(PROPERTY_DATA_NAME, dObj.getName());
String itemSubjectRefQName = dObj.getItemSubjectRef().getStructureRef();
// remove namespace prefix
String dataType = itemSubjectRefQName.substring(itemSubjectRefQName.indexOf(':') + 1);
propertyItemNode.put(PROPERTY_DATA_TYPE, dataType);
Object dObjValue = dObj.getValue();
String value = new String();
if (null == dObjValue) {
propertyItemNode.put(PROPERTY_DATA_VALUE, "");
} else {
if ("datetime".equals(dataType)) {
value = new DateTime(dObjValue).toString("yyyy-MM-dd'T'hh:mm:ss");
} else {
value = new String(dObjValue.toString());
}
propertyItemNode.put(PROPERTY_DATA_VALUE, value.toString());
}
itemsNode.add(propertyItemNode);
}
dataPropertiesNode.set(EDITOR_PROPERTIES_GENERAL_ITEMS, itemsNode);
propertiesNode.set("dataproperties", dataPropertiesNode);
}
use of org.activiti.bpmn.model.ValuedDataObject 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;
}
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", true);
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(StartEvent.class);
assertThat(flowElement.getId()).isEqualTo("start1");
// verify main process data objects
List<ValuedDataObject> dataObjects = model.getMainProcess().getDataObjects();
assertThat(dataObjects).hasSize(6);
for (ValuedDataObject dObj : dataObjects) {
if ("dObj1".equals(dObj.getId())) {
assertThat(dObj.getClass()).isEqualTo(StringDataObject.class);
assertThat(dObj.getName()).isEqualTo("StringTest");
assertThat(dObj.getValue()).isInstanceOf(String.class);
assertThat(dObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:string");
assertThat(dObj.getValue()).isEqualTo("Testing123");
} else if ("dObj2".equals(dObj.getId())) {
assertThat(dObj.getClass()).isEqualTo(BooleanDataObject.class);
assertThat(dObj.getName()).isEqualTo("BooleanTest");
assertThat(dObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:boolean");
assertThat(dObj.getValue()).isInstanceOf(Boolean.class);
assertThat(dObj.getValue()).isEqualTo(Boolean.TRUE);
} else if ("dObj3".equals(dObj.getId())) {
assertThat(dObj.getClass()).isEqualTo(DateDataObject.class);
assertThat(dObj.getName()).isEqualTo("DateTest");
assertThat(dObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:datetime");
assertThat(dObj.getValue()).isInstanceOf(Date.class);
GregorianCalendar dateCal = new GregorianCalendar();
dateCal.setTime((Date) dObj.getValue());
assertThat(dateCal.get(Calendar.YEAR)).isEqualTo(2013);
assertThat(dateCal.get(Calendar.MONTH)).isEqualTo(8);
assertThat(dateCal.get(Calendar.DAY_OF_MONTH)).isEqualTo(16);
assertThat(dateCal.get(Calendar.HOUR_OF_DAY)).isEqualTo(11);
assertThat(dateCal.get(Calendar.MINUTE)).isEqualTo(23);
} else if ("dObj4".equals(dObj.getId())) {
assertThat(dObj.getClass()).isEqualTo(DoubleDataObject.class);
assertThat(dObj.getName()).isEqualTo("DoubleTest");
assertThat(dObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:double");
assertThat(dObj.getValue()).isInstanceOf(Double.class);
assertThat(dObj.getValue()).isEqualTo(new Double(123456789));
} else if ("dObj5".equals(dObj.getId())) {
assertThat(dObj.getClass()).isEqualTo(IntegerDataObject.class);
assertThat(dObj.getName()).isEqualTo("IntegerTest");
assertThat(dObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:int");
assertThat(dObj.getValue()).isInstanceOf(Integer.class);
assertThat(dObj.getValue()).isEqualTo(Integer.valueOf(123));
} else if ("dObj6".equals(dObj.getId())) {
assertThat(dObj.getClass()).isEqualTo(LongDataObject.class);
assertThat(dObj.getName()).isEqualTo("LongTest");
assertThat(dObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:long");
assertThat(dObj.getValue()).isInstanceOf(Long.class);
assertThat(dObj.getValue()).isEqualTo(new Long(-123456));
}
}
flowElement = model.getMainProcess().getFlowElement("subprocess1", true);
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(SubProcess.class);
assertThat(flowElement.getId()).isEqualTo("subprocess1");
SubProcess subProcess = (SubProcess) flowElement;
assertThat(subProcess.getFlowElements()).hasSize(11);
// verify subprocess data objects
dataObjects = ((SubProcess) flowElement).getDataObjects();
assertThat(dataObjects).hasSize(6);
for (ValuedDataObject dObj : dataObjects) {
if ("dObj1".equals(dObj.getId())) {
assertThat(dObj.getClass()).isEqualTo(StringDataObject.class);
assertThat(dObj.getName()).isEqualTo("SubStringTest");
assertThat(dObj.getValue()).isInstanceOf(String.class);
assertThat(dObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:string");
assertThat(dObj.getValue()).isEqualTo("Testing456");
} else if ("dObj2".equals(dObj.getId())) {
assertThat(dObj.getClass()).isEqualTo(BooleanDataObject.class);
assertThat(dObj.getName()).isEqualTo("SubBooleanTest");
assertThat(dObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:boolean");
assertThat(dObj.getValue()).isInstanceOf(Boolean.class);
assertThat(dObj.getValue()).isEqualTo(Boolean.FALSE);
} else if ("dObj3".equals(dObj.getId())) {
assertThat(dObj.getClass()).isEqualTo(DateDataObject.class);
assertThat(dObj.getName()).isEqualTo("SubDateTest");
assertThat(dObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:datetime");
assertThat(dObj.getValue()).isInstanceOf(Date.class);
GregorianCalendar dateCal = new GregorianCalendar();
dateCal.setTime((Date) dObj.getValue());
assertThat(dateCal.get(Calendar.YEAR)).isEqualTo(2013);
assertThat(dateCal.get(Calendar.MONTH)).isEqualTo(10);
assertThat(dateCal.get(Calendar.DAY_OF_MONTH)).isEqualTo(11);
} else if ("dObj4".equals(dObj.getId())) {
assertThat(dObj.getClass()).isEqualTo(DoubleDataObject.class);
assertThat(dObj.getName()).isEqualTo("SubDoubleTest");
assertThat(dObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:double");
assertThat(dObj.getValue()).isInstanceOf(Double.class);
assertThat(dObj.getValue()).isEqualTo(new Double(678912345));
} else if ("dObj5".equals(dObj.getId())) {
assertThat(dObj.getClass()).isEqualTo(IntegerDataObject.class);
assertThat(dObj.getName()).isEqualTo("SubIntegerTest");
assertThat(dObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:int");
assertThat(dObj.getValue()).isInstanceOf(Integer.class);
assertThat(dObj.getValue()).isEqualTo(Integer.valueOf(45));
} else if ("dObj6".equals(dObj.getId())) {
assertThat(dObj.getClass()).isEqualTo(LongDataObject.class);
assertThat(dObj.getName()).isEqualTo("SubLongTest");
assertThat(dObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:long");
assertThat(dObj.getValue()).isInstanceOf(Long.class);
assertThat(dObj.getValue()).isEqualTo(new Long(456123));
assertThat(dObj.getExtensionElements()).hasSize(1);
}
}
}
use of org.activiti.bpmn.model.ValuedDataObject 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) {
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;
}
Aggregations