use of org.activiti.bpmn.model.ExtensionElement in project Activiti by Activiti.
the class BpmnXMLUtil method writeExtensionElement.
protected static void writeExtensionElement(ExtensionElement extensionElement, Map<String, String> namespaceMap, XMLStreamWriter xtw) throws Exception {
if (StringUtils.isNotEmpty(extensionElement.getName())) {
Map<String, String> localNamespaceMap = new HashMap<String, String>();
if (StringUtils.isNotEmpty(extensionElement.getNamespace())) {
if (StringUtils.isNotEmpty(extensionElement.getNamespacePrefix())) {
xtw.writeStartElement(extensionElement.getNamespacePrefix(), extensionElement.getName(), extensionElement.getNamespace());
if (namespaceMap.containsKey(extensionElement.getNamespacePrefix()) == false || namespaceMap.get(extensionElement.getNamespacePrefix()).equals(extensionElement.getNamespace()) == false) {
xtw.writeNamespace(extensionElement.getNamespacePrefix(), extensionElement.getNamespace());
namespaceMap.put(extensionElement.getNamespacePrefix(), extensionElement.getNamespace());
localNamespaceMap.put(extensionElement.getNamespacePrefix(), extensionElement.getNamespace());
}
} else {
xtw.writeStartElement(extensionElement.getNamespace(), extensionElement.getName());
}
} else {
xtw.writeStartElement(extensionElement.getName());
}
for (List<ExtensionAttribute> attributes : extensionElement.getAttributes().values()) {
for (ExtensionAttribute attribute : attributes) {
if (StringUtils.isNotEmpty(attribute.getName()) && attribute.getValue() != null) {
if (StringUtils.isNotEmpty(attribute.getNamespace())) {
if (StringUtils.isNotEmpty(attribute.getNamespacePrefix())) {
if (namespaceMap.containsKey(attribute.getNamespacePrefix()) == false || namespaceMap.get(attribute.getNamespacePrefix()).equals(attribute.getNamespace()) == false) {
xtw.writeNamespace(attribute.getNamespacePrefix(), attribute.getNamespace());
namespaceMap.put(attribute.getNamespacePrefix(), attribute.getNamespace());
}
xtw.writeAttribute(attribute.getNamespacePrefix(), attribute.getNamespace(), attribute.getName(), attribute.getValue());
} else {
xtw.writeAttribute(attribute.getNamespace(), attribute.getName(), attribute.getValue());
}
} else {
xtw.writeAttribute(attribute.getName(), attribute.getValue());
}
}
}
}
if (extensionElement.getElementText() != null) {
xtw.writeCData(extensionElement.getElementText());
} else {
for (List<ExtensionElement> childElements : extensionElement.getChildElements().values()) {
for (ExtensionElement childElement : childElements) {
writeExtensionElement(childElement, namespaceMap, xtw);
}
}
}
for (String prefix : localNamespaceMap.keySet()) {
namespaceMap.remove(prefix);
}
xtw.writeEndElement();
}
}
use of org.activiti.bpmn.model.ExtensionElement in project Activiti by Activiti.
the class BpmnXMLUtil method parseExtensionElement.
public static ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception {
ExtensionElement extensionElement = new ExtensionElement();
extensionElement.setName(xtr.getLocalName());
if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) {
extensionElement.setNamespace(xtr.getNamespaceURI());
}
if (StringUtils.isNotEmpty(xtr.getPrefix())) {
extensionElement.setNamespacePrefix(xtr.getPrefix());
}
for (int i = 0; i < xtr.getAttributeCount(); i++) {
ExtensionAttribute extensionAttribute = new ExtensionAttribute();
extensionAttribute.setName(xtr.getAttributeLocalName(i));
extensionAttribute.setValue(xtr.getAttributeValue(i));
if (StringUtils.isNotEmpty(xtr.getAttributeNamespace(i))) {
extensionAttribute.setNamespace(xtr.getAttributeNamespace(i));
}
if (StringUtils.isNotEmpty(xtr.getAttributePrefix(i))) {
extensionAttribute.setNamespacePrefix(xtr.getAttributePrefix(i));
}
extensionElement.addAttribute(extensionAttribute);
}
boolean readyWithExtensionElement = false;
while (readyWithExtensionElement == false && xtr.hasNext()) {
xtr.next();
if (xtr.isCharacters() || XMLStreamReader.CDATA == xtr.getEventType()) {
if (StringUtils.isNotEmpty(xtr.getText().trim())) {
extensionElement.setElementText(xtr.getText().trim());
}
} else if (xtr.isStartElement()) {
ExtensionElement childExtensionElement = parseExtensionElement(xtr);
extensionElement.addChildElement(childExtensionElement);
} else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) {
readyWithExtensionElement = true;
}
}
return extensionElement;
}
use of org.activiti.bpmn.model.ExtensionElement in project Activiti by Activiti.
the class BpmnJsonConverter method convertToBpmnModel.
public BpmnModel convertToBpmnModel(JsonNode modelNode) {
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, 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();
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 == false) {
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, 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 CustomExtensionsConverterTest method validateExtensionElements.
protected void validateExtensionElements(Map<String, List<ExtensionElement>> extensionElementMap) {
assertThat(extensionElementMap).hasSize(1);
List<ExtensionElement> extensionElements = extensionElementMap.get("test");
assertThat(extensionElements).hasSize(2);
ExtensionElement extensionElement = extensionElements.get(0);
assertThat(extensionElement).isNotNull();
assertThat(extensionElement.getName()).isEqualTo("test");
assertThat(extensionElement.getNamespacePrefix()).isEqualTo("custom");
assertThat(extensionElement.getNamespace()).isEqualTo("http://custom.org/bpmn");
assertThat(extensionElement.getAttributes()).hasSize(2);
List<ExtensionAttribute> attributes = extensionElement.getAttributes().get("id");
assertThat(attributes).hasSize(1);
ExtensionAttribute attribute = attributes.get(0);
assertThat(attribute).isNotNull();
assertThat(attribute.getName()).isEqualTo("id");
assertThat(attribute.getValue()).isEqualTo("test");
assertThat(attribute.getNamespace()).isNull();
assertThat(attribute.getNamespacePrefix()).isNull();
attributes = extensionElement.getAttributes().get("name");
assertThat(attributes).hasSize(1);
attribute = attributes.get(0);
assertThat(attribute).isNotNull();
assertThat(attribute.getName()).isEqualTo("name");
assertThat(attribute.getValue()).isEqualTo("test");
assertThat(extensionElement.getChildElements()).hasSize(2);
List<ExtensionElement> childExtensions = extensionElement.getChildElements().get("name");
assertThat(childExtensions).hasSize(2);
ExtensionElement childExtension = childExtensions.get(0);
assertThat(childExtension).isNotNull();
assertThat(childExtension.getName()).isEqualTo("name");
assertThat(childExtension.getNamespacePrefix()).isEqualTo("custom");
assertThat(childExtension.getNamespace()).isEqualTo("http://custom.org/bpmn");
assertThat(childExtension.getAttributes()).hasSize(0);
assertThat(childExtension.getChildElements()).hasSize(1);
List<ExtensionElement> subChildExtensions = childExtension.getChildElements().get("test");
assertThat(subChildExtensions).hasSize(1);
childExtension = subChildExtensions.get(0);
assertThat(childExtension).isNotNull();
assertThat(childExtension.getName()).isEqualTo("test");
assertThat(childExtension.getNamespacePrefix()).isEqualTo("custom");
assertThat(childExtension.getNamespace()).isEqualTo("http://custom.org/bpmn");
assertThat(childExtension.getAttributes()).hasSize(0);
assertThat(childExtension.getChildElements()).hasSize(0);
assertThat(childExtension.getElementText()).isEqualTo("test");
childExtensions = extensionElement.getChildElements().get("description");
assertThat(childExtensions).hasSize(1);
childExtension = childExtensions.get(0);
assertThat(childExtension).isNotNull();
assertThat(childExtension.getName()).isEqualTo("description");
assertThat(childExtension.getAttributes()).hasSize(1);
attributes = childExtension.getAttributes().get("id");
attribute = attributes.get(0);
assertThat(attribute).isNotNull();
assertThat(attribute.getName()).isEqualTo("id");
assertThat(attribute.getValue()).isEqualTo("test");
assertThat(attribute.getNamespacePrefix()).isEqualTo("custom2");
assertThat(attribute.getNamespace()).isEqualTo("http://custom2.org/bpmn");
extensionElement = extensionElements.get(1);
assertThat(extensionElement).isNotNull();
assertThat(extensionElement.getName()).isEqualTo("test");
assertThat(extensionElement.getNamespacePrefix()).isEqualTo("custom");
assertThat(extensionElement.getNamespace()).isEqualTo("http://custom.org/bpmn");
assertThat(extensionElement.getAttributes()).hasSize(2);
attributes = extensionElement.getAttributes().get("id");
assertThat(attributes).hasSize(1);
attribute = attributes.get(0);
assertThat(attribute).isNotNull();
assertThat(attribute.getName()).isEqualTo("id");
assertThat(attribute.getValue()).isEqualTo("test2");
assertThat(attribute.getNamespace()).isNull();
assertThat(attribute.getNamespacePrefix()).isNull();
attributes = extensionElement.getAttributes().get("name");
assertThat(attributes).hasSize(1);
attribute = attributes.get(0);
assertThat(attribute).isNotNull();
assertThat(attribute.getName()).isEqualTo("name");
assertThat(attribute.getValue()).isEqualTo("test2");
}
use of org.activiti.bpmn.model.ExtensionElement in project Activiti by Activiti.
the class SubProcessWithExtensionsConverterTest method getSubprocessAttributes.
protected Map<String, String> getSubprocessAttributes(BaseElement bObj) {
Map<String, String> attributes = null;
if (null != bObj) {
List<ExtensionElement> attributesExtension = bObj.getExtensionElements().get(ELEMENT_ATTRIBUTES);
if (null != attributesExtension && !attributesExtension.isEmpty()) {
attributes = new HashMap<String, String>();
List<ExtensionElement> attributeExtensions = attributesExtension.get(0).getChildElements().get(ELEMENT_ATTRIBUTE);
for (ExtensionElement attributeExtension : attributeExtensions) {
attributes.put(attributeExtension.getAttributeValue(YOURCO_EXTENSIONS_NAMESPACE, ATTRIBUTE_NAME), attributeExtension.getAttributeValue(YOURCO_EXTENSIONS_NAMESPACE, ATTRIBUTE_VALUE));
}
}
}
return attributes;
}
Aggregations