use of org.activiti.bpmn.model.ExtensionElement 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));
}
use of org.activiti.bpmn.model.ExtensionElement in project Activiti by Activiti.
the class ExtensionElementsParser method parse.
public void parse(XMLStreamReader xtr, List<SubProcess> activeSubProcessList, Process activeProcess, BpmnModel model) throws Exception {
BaseElement parentElement = null;
if (!activeSubProcessList.isEmpty()) {
parentElement = activeSubProcessList.get(activeSubProcessList.size() - 1);
} else {
parentElement = activeProcess;
}
boolean readyWithChildElements = false;
while (readyWithChildElements == false && xtr.hasNext()) {
xtr.next();
if (xtr.isStartElement()) {
if (ELEMENT_EXECUTION_LISTENER.equals(xtr.getLocalName())) {
new ExecutionListenerParser().parseChildElement(xtr, parentElement, model);
} else if (ELEMENT_EVENT_LISTENER.equals(xtr.getLocalName())) {
new ActivitiEventListenerParser().parseChildElement(xtr, parentElement, model);
} else if (ELEMENT_POTENTIAL_STARTER.equals(xtr.getLocalName())) {
new PotentialStarterParser().parse(xtr, activeProcess);
} else {
ExtensionElement extensionElement = BpmnXMLUtil.parseExtensionElement(xtr);
parentElement.addExtensionElement(extensionElement);
}
} else if (xtr.isEndElement()) {
if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
readyWithChildElements = true;
}
}
}
}
use of org.activiti.bpmn.model.ExtensionElement in project Activiti by Activiti.
the class UserTaskJsonConverter method addExtensionElement.
protected void addExtensionElement(String name, String elementText, UserTask task) {
ExtensionElement extensionElement = new ExtensionElement();
extensionElement.setNamespace(NAMESPACE);
extensionElement.setNamespacePrefix("modeler");
extensionElement.setName(name);
extensionElement.setElementText(elementText);
task.addExtensionElement(extensionElement);
}
use of org.activiti.bpmn.model.ExtensionElement in project Activiti by Activiti.
the class BpmnJsonConverter method convertToBpmnModel.
public BpmnModel convertToBpmnModel(JsonNode modelNode, Map<String, String> formKeyMap, Map<String, String> decisionTableKeyMap) {
BpmnModel bpmnModel = new BpmnModel();
bpmnModel.setTargetNamespace("http://activiti.org/test");
Map<String, JsonNode> shapeMap = new HashMap<String, JsonNode>();
Map<String, JsonNode> sourceRefMap = new HashMap<String, JsonNode>();
Map<String, JsonNode> edgeMap = new HashMap<String, JsonNode>();
Map<String, List<JsonNode>> sourceAndTargetMap = new HashMap<String, List<JsonNode>>();
readShapeDI(modelNode, 0, 0, shapeMap, sourceRefMap, bpmnModel);
filterAllEdges(modelNode, edgeMap, sourceAndTargetMap, shapeMap, sourceRefMap);
readEdgeDI(edgeMap, sourceAndTargetMap, bpmnModel);
ArrayNode shapesArrayNode = (ArrayNode) modelNode.get(EDITOR_CHILD_SHAPES);
if (shapesArrayNode == null || shapesArrayNode.size() == 0) {
return bpmnModel;
}
boolean nonEmptyPoolFound = false;
Map<String, Lane> elementInLaneMap = new HashMap<String, Lane>();
// first create the pool structure
for (JsonNode shapeNode : shapesArrayNode) {
String stencilId = BpmnJsonConverterUtil.getStencilId(shapeNode);
if (STENCIL_POOL.equals(stencilId)) {
Pool pool = new Pool();
pool.setId(BpmnJsonConverterUtil.getElementId(shapeNode));
pool.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, shapeNode));
pool.setProcessRef(JsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, shapeNode));
pool.setExecutable(JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, shapeNode, true));
bpmnModel.getPools().add(pool);
Process process = new Process();
process.setId(pool.getProcessRef());
process.setName(pool.getName());
process.setExecutable(pool.isExecutable());
bpmnModel.addProcess(process);
ArrayNode laneArrayNode = (ArrayNode) shapeNode.get(EDITOR_CHILD_SHAPES);
for (JsonNode laneNode : laneArrayNode) {
// should be a lane, but just check to be certain
String laneStencilId = BpmnJsonConverterUtil.getStencilId(laneNode);
if (STENCIL_LANE.equals(laneStencilId)) {
nonEmptyPoolFound = true;
Lane lane = new Lane();
lane.setId(BpmnJsonConverterUtil.getElementId(laneNode));
lane.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, laneNode));
lane.setParentProcess(process);
process.getLanes().add(lane);
processJsonElements(laneNode.get(EDITOR_CHILD_SHAPES), modelNode, lane, shapeMap, formKeyMap, decisionTableKeyMap, bpmnModel);
if (CollectionUtils.isNotEmpty(lane.getFlowReferences())) {
for (String elementRef : lane.getFlowReferences()) {
elementInLaneMap.put(elementRef, lane);
}
}
}
}
}
}
// Signal Definitions exist on the root level
JsonNode signalDefinitionNode = BpmnJsonConverterUtil.getProperty(PROPERTY_SIGNAL_DEFINITIONS, modelNode);
signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode);
// no idea why this needs to be done twice ..
signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode);
if (signalDefinitionNode != null) {
if (signalDefinitionNode instanceof ArrayNode) {
ArrayNode signalDefinitionArrayNode = (ArrayNode) signalDefinitionNode;
Iterator<JsonNode> signalDefinitionIterator = signalDefinitionArrayNode.iterator();
while (signalDefinitionIterator.hasNext()) {
JsonNode signalDefinitionJsonNode = signalDefinitionIterator.next();
String signalId = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_ID).asText();
String signalName = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_NAME).asText();
String signalScope = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_SCOPE).asText();
if (StringUtils.isNotEmpty(signalId) && StringUtils.isNotEmpty(signalName)) {
Signal signal = new Signal();
signal.setId(signalId);
signal.setName(signalName);
signal.setScope((signalScope.toLowerCase().equals("processinstance")) ? Signal.SCOPE_PROCESS_INSTANCE : Signal.SCOPE_GLOBAL);
bpmnModel.addSignal(signal);
}
}
}
}
if (!nonEmptyPoolFound) {
Process process = new Process();
bpmnModel.getProcesses().add(process);
process.setId(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, modelNode));
process.setName(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, modelNode));
String namespace = BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_NAMESPACE, modelNode);
if (StringUtils.isNotEmpty(namespace)) {
bpmnModel.setTargetNamespace(namespace);
}
process.setDocumentation(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_DOCUMENTATION, modelNode));
JsonNode processExecutableNode = JsonConverterUtil.getProperty(PROPERTY_PROCESS_EXECUTABLE, modelNode);
if (processExecutableNode != null && StringUtils.isNotEmpty(processExecutableNode.asText())) {
process.setExecutable(JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, modelNode));
}
BpmnJsonConverterUtil.convertJsonToMessages(modelNode, bpmnModel);
BpmnJsonConverterUtil.convertJsonToListeners(modelNode, process);
JsonNode eventListenersNode = BpmnJsonConverterUtil.getProperty(PROPERTY_EVENT_LISTENERS, modelNode);
if (eventListenersNode != null) {
eventListenersNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(eventListenersNode);
BpmnJsonConverterUtil.parseEventListeners(eventListenersNode.get(PROPERTY_EVENTLISTENER_VALUE), process);
}
JsonNode processDataPropertiesNode = modelNode.get(EDITOR_SHAPE_PROPERTIES).get(PROPERTY_DATA_PROPERTIES);
if (processDataPropertiesNode != null) {
List<ValuedDataObject> dataObjects = BpmnJsonConverterUtil.convertJsonToDataProperties(processDataPropertiesNode, process);
process.setDataObjects(dataObjects);
process.getFlowElements().addAll(dataObjects);
}
processJsonElements(shapesArrayNode, modelNode, process, shapeMap, formKeyMap, decisionTableKeyMap, bpmnModel);
} else {
// sequence flows are on root level so need additional parsing for pools
for (JsonNode shapeNode : shapesArrayNode) {
if (STENCIL_SEQUENCE_FLOW.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode)) || STENCIL_ASSOCIATION.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode))) {
String sourceRef = BpmnJsonConverterUtil.lookForSourceRef(shapeNode.get(EDITOR_SHAPE_ID).asText(), modelNode.get(EDITOR_CHILD_SHAPES));
if (sourceRef != null) {
Lane lane = elementInLaneMap.get(sourceRef);
SequenceFlowJsonConverter flowConverter = new SequenceFlowJsonConverter();
if (lane != null) {
flowConverter.convertToBpmnModel(shapeNode, modelNode, this, lane, shapeMap, bpmnModel);
} else {
flowConverter.convertToBpmnModel(shapeNode, modelNode, this, bpmnModel.getProcesses().get(0), shapeMap, bpmnModel);
}
}
}
}
}
// sequence flows are now all on root level
Map<String, SubProcess> subShapesMap = new HashMap<String, SubProcess>();
for (Process process : bpmnModel.getProcesses()) {
for (FlowElement flowElement : process.findFlowElementsOfType(SubProcess.class)) {
SubProcess subProcess = (SubProcess) flowElement;
fillSubShapes(subShapesMap, subProcess);
}
if (subShapesMap.size() > 0) {
List<String> removeSubFlowsList = new ArrayList<String>();
for (FlowElement flowElement : process.findFlowElementsOfType(SequenceFlow.class)) {
SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
if (subShapesMap.containsKey(sequenceFlow.getSourceRef())) {
SubProcess subProcess = subShapesMap.get(sequenceFlow.getSourceRef());
if (subProcess.getFlowElement(sequenceFlow.getId()) == null) {
subProcess.addFlowElement(sequenceFlow);
removeSubFlowsList.add(sequenceFlow.getId());
}
}
}
for (String flowId : removeSubFlowsList) {
process.removeFlowElement(flowId);
}
}
}
Map<String, FlowWithContainer> allFlowMap = new HashMap<String, FlowWithContainer>();
List<Gateway> gatewayWithOrderList = new ArrayList<Gateway>();
// post handling of process elements
for (Process process : bpmnModel.getProcesses()) {
postProcessElements(process, process.getFlowElements(), edgeMap, bpmnModel, allFlowMap, gatewayWithOrderList);
}
// sort the sequence flows
for (Gateway gateway : gatewayWithOrderList) {
List<ExtensionElement> orderList = gateway.getExtensionElements().get("EDITOR_FLOW_ORDER");
if (CollectionUtils.isNotEmpty(orderList)) {
for (ExtensionElement orderElement : orderList) {
String flowValue = orderElement.getElementText();
if (StringUtils.isNotEmpty(flowValue)) {
if (allFlowMap.containsKey(flowValue)) {
FlowWithContainer flowWithContainer = allFlowMap.get(flowValue);
flowWithContainer.getFlowContainer().removeFlowElement(flowWithContainer.getSequenceFlow().getId());
flowWithContainer.getFlowContainer().addFlowElement(flowWithContainer.getSequenceFlow());
}
}
}
}
gateway.getExtensionElements().remove("EDITOR_FLOW_ORDER");
}
return bpmnModel;
}
use of org.activiti.bpmn.model.ExtensionElement in project Activiti by Activiti.
the class StartEventJsonConverter method addExtensionElement.
protected void addExtensionElement(String name, String elementText, Event event) {
ExtensionElement extensionElement = new ExtensionElement();
extensionElement.setNamespace(NAMESPACE);
extensionElement.setNamespacePrefix("modeler");
extensionElement.setName(name);
extensionElement.setElementText(elementText);
event.addExtensionElement(extensionElement);
}
Aggregations