use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.
the class BpmnXMLConverter method createXML.
private void createXML(FlowElement flowElement, BpmnModel model, XMLStreamWriter xtw) throws Exception {
if (flowElement instanceof SubProcess) {
SubProcess subProcess = (SubProcess) flowElement;
if (flowElement instanceof Transaction) {
xtw.writeStartElement(ELEMENT_TRANSACTION);
} else {
xtw.writeStartElement(ELEMENT_SUBPROCESS);
}
xtw.writeAttribute(ATTRIBUTE_ID, subProcess.getId());
if (StringUtils.isNotEmpty(subProcess.getName())) {
xtw.writeAttribute(ATTRIBUTE_NAME, subProcess.getName());
} else {
xtw.writeAttribute(ATTRIBUTE_NAME, "subProcess");
}
if (subProcess instanceof EventSubProcess) {
xtw.writeAttribute(ATTRIBUTE_TRIGGERED_BY, ATTRIBUTE_VALUE_TRUE);
} else if (subProcess instanceof Transaction == false) {
if (subProcess.isAsynchronous()) {
BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
if (subProcess.isNotExclusive()) {
BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
}
}
}
if (StringUtils.isNotEmpty(subProcess.getDocumentation())) {
xtw.writeStartElement(ELEMENT_DOCUMENTATION);
xtw.writeCharacters(subProcess.getDocumentation());
xtw.writeEndElement();
}
boolean didWriteExtensionStartElement = ActivitiListenerExport.writeListeners(subProcess, false, xtw);
didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(subProcess, didWriteExtensionStartElement, model.getNamespaces(), xtw);
if (didWriteExtensionStartElement) {
// closing extensions element
xtw.writeEndElement();
}
MultiInstanceExport.writeMultiInstance(subProcess, xtw);
for (FlowElement subElement : subProcess.getFlowElements()) {
createXML(subElement, model, xtw);
}
for (Artifact artifact : subProcess.getArtifacts()) {
createXML(artifact, model, xtw);
}
xtw.writeEndElement();
} else {
BaseBpmnXMLConverter converter = convertersToXMLMap.get(flowElement.getClass());
if (converter == null) {
throw new XMLException("No converter for " + flowElement.getClass() + " found");
}
converter.convertToXML(xtw, flowElement, model);
}
}
use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.
the class BpmnXMLConverter method processFlowElements.
private void processFlowElements(Collection<FlowElement> flowElementList, BaseElement parentScope) {
for (FlowElement flowElement : flowElementList) {
if (flowElement instanceof SequenceFlow) {
SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
FlowNode sourceNode = getFlowNodeFromScope(sequenceFlow.getSourceRef(), parentScope);
if (sourceNode != null) {
sourceNode.getOutgoingFlows().add(sequenceFlow);
}
FlowNode targetNode = getFlowNodeFromScope(sequenceFlow.getTargetRef(), parentScope);
if (targetNode != null) {
targetNode.getIncomingFlows().add(sequenceFlow);
}
} else if (flowElement instanceof BoundaryEvent) {
BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
FlowElement attachedToElement = getFlowNodeFromScope(boundaryEvent.getAttachedToRefId(), parentScope);
if (attachedToElement != null) {
boundaryEvent.setAttachedToRef((Activity) attachedToElement);
((Activity) attachedToElement).getBoundaryEvents().add(boundaryEvent);
}
} else if (flowElement instanceof SubProcess) {
SubProcess subProcess = (SubProcess) flowElement;
processFlowElements(subProcess.getFlowElements(), subProcess);
}
}
}
use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.
the class BPMNDIExport method writeBPMNDI.
public static void writeBPMNDI(BpmnModel model, XMLStreamWriter xtw) throws Exception {
// BPMN DI information
xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_DIAGRAM, BPMNDI_NAMESPACE);
String processId = null;
if (!model.getPools().isEmpty()) {
processId = "Collaboration";
} else {
processId = model.getMainProcess().getId();
}
xtw.writeAttribute(ATTRIBUTE_ID, "BPMNDiagram_" + processId);
xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_PLANE, BPMNDI_NAMESPACE);
xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, processId);
xtw.writeAttribute(ATTRIBUTE_ID, "BPMNPlane_" + processId);
for (String elementId : model.getLocationMap().keySet()) {
if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null || model.getPool(elementId) != null || model.getLane(elementId) != null) {
xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_SHAPE, BPMNDI_NAMESPACE);
xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
xtw.writeAttribute(ATTRIBUTE_ID, "BPMNShape_" + elementId);
GraphicInfo graphicInfo = model.getGraphicInfo(elementId);
FlowElement flowElement = model.getFlowElement(elementId);
if (flowElement instanceof SubProcess && graphicInfo.getExpanded() != null) {
xtw.writeAttribute(ATTRIBUTE_DI_IS_EXPANDED, String.valueOf(graphicInfo.getExpanded()));
}
xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + graphicInfo.getHeight());
xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + graphicInfo.getWidth());
xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
xtw.writeEndElement();
xtw.writeEndElement();
}
}
for (String elementId : model.getFlowLocationMap().keySet()) {
if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null || model.getMessageFlow(elementId) != null) {
xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_EDGE, BPMNDI_NAMESPACE);
xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
xtw.writeAttribute(ATTRIBUTE_ID, "BPMNEdge_" + elementId);
List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(elementId);
for (GraphicInfo graphicInfo : graphicInfoList) {
xtw.writeStartElement(OMGDI_PREFIX, ELEMENT_DI_WAYPOINT, OMGDI_NAMESPACE);
xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
xtw.writeEndElement();
}
GraphicInfo labelGraphicInfo = model.getLabelGraphicInfo(elementId);
FlowElement flowElement = model.getFlowElement(elementId);
MessageFlow messageFlow = null;
if (flowElement == null) {
messageFlow = model.getMessageFlow(elementId);
}
boolean hasName = false;
if (flowElement != null && StringUtils.isNotEmpty(flowElement.getName())) {
hasName = true;
} else if (messageFlow != null && StringUtils.isNotEmpty(messageFlow.getName())) {
hasName = true;
}
if (labelGraphicInfo != null && hasName) {
xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_LABEL, BPMNDI_NAMESPACE);
xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + labelGraphicInfo.getHeight());
xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + labelGraphicInfo.getWidth());
xtw.writeAttribute(ATTRIBUTE_DI_X, "" + labelGraphicInfo.getX());
xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + labelGraphicInfo.getY());
xtw.writeEndElement();
xtw.writeEndElement();
}
xtw.writeEndElement();
}
}
// end BPMN DI elements
xtw.writeEndElement();
xtw.writeEndElement();
}
use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.
the class BpmnDeployer method localizeFlowElements.
protected boolean localizeFlowElements(Collection<FlowElement> flowElements, ObjectNode infoNode) {
boolean localizationValuesChanged = false;
if (flowElements == null)
return localizationValuesChanged;
CommandContext commandContext = Context.getCommandContext();
DynamicBpmnService dynamicBpmnService = commandContext.getProcessEngineConfiguration().getDynamicBpmnService();
for (FlowElement flowElement : flowElements) {
if (flowElement instanceof UserTask || flowElement instanceof SubProcess) {
List<ExtensionElement> localizationElements = flowElement.getExtensionElements().get("localization");
if (localizationElements != null) {
for (ExtensionElement localizationElement : localizationElements) {
if (BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX.equals(localizationElement.getNamespacePrefix())) {
String locale = localizationElement.getAttributeValue(null, "locale");
String name = localizationElement.getAttributeValue(null, "name");
String documentation = null;
List<ExtensionElement> documentationElements = localizationElement.getChildElements().get("documentation");
if (documentationElements != null) {
for (ExtensionElement documentationElement : documentationElements) {
documentation = StringUtils.trimToNull(documentationElement.getElementText());
break;
}
}
String flowElementId = flowElement.getId();
if (isEqualToCurrentLocalizationValue(locale, flowElementId, "name", name, infoNode) == false) {
dynamicBpmnService.changeLocalizationName(locale, flowElementId, name, infoNode);
localizationValuesChanged = true;
}
if (documentation != null && isEqualToCurrentLocalizationValue(locale, flowElementId, "description", documentation, infoNode) == false) {
dynamicBpmnService.changeLocalizationDescription(locale, flowElementId, documentation, infoNode);
localizationValuesChanged = true;
}
break;
}
}
}
if (flowElement instanceof SubProcess) {
SubProcess subprocess = (SubProcess) flowElement;
boolean isFlowElementLocalizationChanged = localizeFlowElements(subprocess.getFlowElements(), infoNode);
boolean isDataObjectLocalizationChanged = localizeDataObjectElements(subprocess.getDataObjects(), infoNode);
if (isFlowElementLocalizationChanged || isDataObjectLocalizationChanged) {
localizationValuesChanged = true;
}
}
}
}
return localizationValuesChanged;
}
use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.
the class DelegateHelper method getFlowElement.
/**
* Returns the current {@link FlowElement} where the {@link DelegateExecution} is currently at.
*/
public static FlowElement getFlowElement(DelegateExecution execution) {
BpmnModel bpmnModel = getBpmnModel(execution);
FlowElement flowElement = bpmnModel.getFlowElement(execution.getCurrentActivityId());
if (flowElement == null) {
throw new ActivitiException("Could not find a FlowElement for activityId " + execution.getCurrentActivityId());
}
return flowElement;
}
Aggregations