@RequestMapping(value = "/rest/admin/process-definitions/{processDefinitionId}/model-json", method = RequestMethod.GET, produces = "application/json") public JsonNode getProcessDefinitionModelJSON(@PathVariable String processDefinitionId) { ServerConfig config = retrieveServerConfig(EndpointType.PROCESS); ObjectNode displayNode = objectMapper.createObjectNode(); BpmnModel pojoModel = clientService.getProcessDefinitionModel(config, processDefinitionId); if (!pojoModel.getLocationMap().isEmpty()) { try { GraphicInfo diagramInfo = new GraphicInfo(); processProcessElements(config, pojoModel, displayNode, diagramInfo, null, null); displayNode.put("diagramBeginX", diagramInfo.getX()); displayNode.put("diagramBeginY", diagramInfo.getY()); displayNode.put("diagramWidth", diagramInfo.getWidth()); displayNode.put("diagramHeight", diagramInfo.getHeight()); } catch (Exception e) { LOGGER.error("Error creating model JSON", e); } } return displayNode; }
public ObjectNode getSummary() { ObjectNode summary = objectMapper.createObjectNode(); for (Process process : bpmnModel.getProcesses()) { for (FlowElement flowElement : process.getFlowElements()) { summary.set(flowElement.getId(), getElement(flowElement.getId())); } } return summary; }
protected String parseOperationRef(String operationRef, BpmnModel model) { String result = null; if (StringUtils.isNotEmpty(operationRef)) { int indexOfP = operationRef.indexOf(':'); if (indexOfP != -1) { String prefix = operationRef.substring(0, indexOfP); String resolvedNamespace = model.getNamespace(prefix); result = resolvedNamespace + ":" + operationRef.substring(indexOfP + 1); } else { result = model.getTargetNamespace() + ":" + operationRef; } } return result; }
public Process getMainProcess() { if (!getPools().isEmpty()) { return getProcess(getPools().get(0).getId()); } else { return getProcess(null); } }
protected FlowElement resolveFlowElementFromBpmnModel(BpmnModel bpmnModel, String activityId) { FlowElement flowElement = bpmnModel.getFlowElement(activityId); if (flowElement == null) { throw new FlowableException("Cannot find activity '" + activityId + "' in process definition with id '" + bpmnModel.getMainProcess().getId() + "'"); } return flowElement; } //-- Move container preparation section end
ArrayNode dockersArrayNode = objectMapper.createArrayNode(); ObjectNode dockNode = objectMapper.createObjectNode(); dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(messageFlow.getSourceRef()).getWidth() / 2.0); dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(messageFlow.getSourceRef()).getHeight() / 2.0); dockersArrayNode.add(dockNode); if (model.getFlowLocationGraphicInfo(messageFlow.getId()).size() > 2) { for (int i = 1; i < model.getFlowLocationGraphicInfo(messageFlow.getId()).size() - 1; i++) { GraphicInfo graphicInfo = model.getFlowLocationGraphicInfo(messageFlow.getId()).get(i); dockNode = objectMapper.createObjectNode(); dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX()); dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY()); dockersArrayNode.add(dockNode); dockNode = objectMapper.createObjectNode(); dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(messageFlow.getTargetRef()).getWidth() / 2.0); dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(messageFlow.getTargetRef()).getHeight() / 2.0); dockersArrayNode.add(dockNode); flowNode.set("dockers", dockersArrayNode); ObjectNode propertiesNode = objectMapper.createObjectNode(); propertiesNode.put(PROPERTY_OVERRIDE_ID, messageFlow.getId()); if (StringUtils.isNotEmpty(messageFlow.getName())) { propertiesNode.put(PROPERTY_NAME, messageFlow.getName());
interfaceObject.setId(model.getTargetNamespace() + ":" + xtr.getAttributeValue(null, ATTRIBUTE_ID)); interfaceObject.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME)); interfaceObject.setImplementationRef(parseMessageRef(xtr.getAttributeValue(null, ATTRIBUTE_IMPLEMENTATION_REF), model)); operation = new Operation(); BpmnXMLUtil.addXMLLocation(operation, xtr); operation.setId(model.getTargetNamespace() + ":" + xtr.getAttributeValue(null, ATTRIBUTE_ID)); operation.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME)); operation.setImplementationRef(parseMessageRef(xtr.getAttributeValue(null, ATTRIBUTE_IMPLEMENTATION_REF), model)); } else if (xtr.isStartElement() && ELEMENT_IN_MESSAGE.equals(xtr.getLocalName())) { String inMessageRef = xtr.getElementText(); if (operation != null && StringUtils.isNotEmpty(inMessageRef)) { operation.setInMessageRef(parseMessageRef(inMessageRef.trim(), model)); } else if (xtr.isStartElement() && ELEMENT_OUT_MESSAGE.equals(xtr.getLocalName())) { String outMessageRef = xtr.getElementText(); if (operation != null && StringUtils.isNotEmpty(outMessageRef)) { operation.setOutMessageRef(parseMessageRef(outMessageRef.trim(), model)); } else if (xtr.isEndElement() && ELEMENT_OPERATION.equalsIgnoreCase(xtr.getLocalName())) { if (operation != null && StringUtils.isNotEmpty(operation.getImplementationRef())) { interfaceObject.getOperations().add(operation); model.getInterfaces().add(interfaceObject);
public BpmnModel convertToBpmnModel(XMLStreamReader xtr) { BpmnModel model = new BpmnModel(); model.setStartEventFormTypes(startEventFormTypes); model.setUserTaskFormTypes(userTaskFormTypes); try { Process activeProcess = null; List<SubProcess> activeSubProcessList = new ArrayList<>(); while (xtr.hasNext()) { try { xtr.next(); } catch (Exception e) { LOGGER.debug("Error reading XML document", e); if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) { model.addError(xtr.getAttributeValue(null, ATTRIBUTE_ID), xtr.getAttributeValue(null, ATTRIBUTE_ERROR_CODE)); TextAnnotation textAnnotation = (TextAnnotation) new TextAnnotationXMLConverter().convertXMLToElement(xtr, model); textAnnotation.setId(elementId); model.getGlobalArtifacts().add(textAnnotation); Association association = (Association) new AssociationXMLConverter().convertXMLToElement(xtr, model); association.setId(elementId); model.getGlobalArtifacts().add(association); for (Process process : model.getProcesses()) { for (Pool pool : model.getPools()) { if (process.getId().equals(pool.getProcessRef())) { pool.setExecutable(process.isExecutable());
public ObjectNode convertToJson(BpmnModel model, Map<String, ModelInfo> formKeyMap, Map<String, ModelInfo> decisionTableKeyMap) { ObjectNode modelNode = objectMapper.createObjectNode(); double maxX = 0.0; double maxY = 0.0; for (GraphicInfo flowInfo : model.getLocationMap().values()) { if ((flowInfo.getX() + flowInfo.getWidth()) > maxX) { maxX = flowInfo.getX() + flowInfo.getWidth(); if (model.getPools().size() > 0) { mainProcess = model.getProcess(model.getPools().get(0).getId()); } else { mainProcess = model.getMainProcess(); if (StringUtils.isNoneEmpty(model.getTargetNamespace())) { propertiesNode.put(PROPERTY_PROCESS_NAMESPACE, model.getTargetNamespace()); BpmnJsonConverterUtil.convertMessagesToJson(model.getMessages(), propertiesNode); if (model.getPools().size() > 0) { for (Pool pool : model.getPools()) { GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId()); if (graphicInfo != null) { poolHasDI = true; if (model.getPools().size() > 0 && poolHasDI) { for (Pool pool : model.getPools()) { GraphicInfo poolGraphicInfo = model.getGraphicInfo(pool.getId()); if (poolGraphicInfo == null) continue;
eventDefinition.setMessageRef(xtr.getAttributeValue(null, ATTRIBUTE_MESSAGE_REF)); eventDefinition.setMessageExpression(BpmnXMLUtil.getAttributeValue(ATTRIBUTE_MESSAGE_EXPRESSION, xtr)); if (!StringUtils.isEmpty(eventDefinition.getMessageRef())) { String resolvedNamespace = model.getNamespace(prefix); String messageRef = eventDefinition.getMessageRef().substring(indexOfP + 1); } else if (!resolvedNamespace.equalsIgnoreCase(model.getTargetNamespace())) {
this.subProcessY = subProcessY; this.shapesArrayNode = shapesArrayNode; GraphicInfo graphicInfo = model.getGraphicInfo(baseElement.getId()); if (StringUtils.isNotEmpty(flowElement.getName())) { propertiesNode.put(PROPERTY_NAME, flowElement.getName()); for (MessageFlow messageFlow : model.getMessageFlows().values()) { if (messageFlow.getSourceRef().equals(flowNode.getId())) { outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId())); for (Artifact artifact : model.getMainProcess().getArtifacts()) { if (artifact instanceof Association){ Association association= (Association) artifact; if (StringUtils.isNotEmpty(loopDef.getLoopCardinality()) || StringUtils.isNotEmpty(loopDef.getInputDataItem()) || StringUtils.isNotEmpty(loopDef.getCompletionCondition())) { if (model.getFlowElement(dataAssociation.getSourceRef()) != null) { createDataAssociation(dataAssociation, true, activity); if (model.getFlowElement(dataAssociation.getTargetRef()) != null) { createDataAssociation(dataAssociation, false, activity); outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(dataAssociation.getId())); for (Process process : model.getProcesses()) { processDataStoreReferences(process, baseElement.getId(), outgoingArrayNode);
@Override protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) { SubProcess subProcess = (SubProcess) baseElement; propertiesNode.put("activitytype", "Event-Sub-Process"); propertiesNode.put("subprocesstype", "Embedded"); ArrayNode subProcessShapesArrayNode = objectMapper.createArrayNode(); GraphicInfo graphicInfo = model.getGraphicInfo(subProcess.getId()); processor.processFlowElements(subProcess, model, subProcessShapesArrayNode, formKeyMap, decisionTableKeyMap, graphicInfo.getX(), graphicInfo.getY()); flowElementNode.set("childShapes", subProcessShapesArrayNode); }
ObjectNode elementNode = objectMapper.createObjectNode(); if (completedElements != null) { elementNode.put("completed", completedElements.contains(element.getId())); elementNode.put("current", currentElements.contains(element.getId())); elementNode.put("id", flow.getId()); elementNode.put("type", "sequenceFlow"); elementNode.put("sourceRef", flow.getSourceRef()); elementNode.put("name", flow.getName()); List<GraphicInfo> flowInfo = model.getFlowLocationGraphicInfo(flow.getId()); ArrayNode waypointArray = objectMapper.createArrayNode(); for (GraphicInfo graphicInfo : flowInfo) { ObjectNode pointNode = objectMapper.createObjectNode(); fillGraphicInfo(pointNode, graphicInfo, false); waypointArray.add(pointNode); GraphicInfo graphicInfo = model.getGraphicInfo(element.getId()); if (graphicInfo != null) { fillGraphicInfo(elementNode, graphicInfo, true); if (graphicInfo != null && graphicInfo.getExpanded() != null && !graphicInfo.getExpanded()) { elementNode.put("collapsed", "true"); newCollapsedNode = objectMapper.createObjectNode();
public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception { if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) { String itemDefinitionId = model.getTargetNamespace() + ":" + xtr.getAttributeValue(null, ATTRIBUTE_ID); String structureRef = xtr.getAttributeValue(null, ATTRIBUTE_STRUCTURE_REF); if (StringUtils.isNotEmpty(structureRef)) { ItemDefinition item = new ItemDefinition(); item.setId(itemDefinitionId); BpmnXMLUtil.addXMLLocation(item, xtr); int indexOfP = structureRef.indexOf(':'); if (indexOfP != -1) { String prefix = structureRef.substring(0, indexOfP); String resolvedNamespace = model.getNamespace(prefix); structureRef = resolvedNamespace + ":" + structureRef.substring(indexOfP + 1); } else { structureRef = model.getTargetNamespace() + ":" + structureRef; } item.setStructureRef(structureRef); item.setItemKind(xtr.getAttributeValue(null, ATTRIBUTE_ITEM_KIND)); BpmnXMLUtil.parseChildElements(ELEMENT_ITEM_DEFINITION, item, xtr, model); model.addItemDefinition(itemDefinitionId, item); } } } }
public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception { if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) { Pool pool = new Pool(); pool.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID)); pool.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME)); pool.setProcessRef(xtr.getAttributeValue(null, ATTRIBUTE_PROCESS_REF)); BpmnXMLUtil.parseChildElements(ELEMENT_PARTICIPANT, pool, xtr, model); model.getPools().add(pool); } } }
public Process parse(XMLStreamReader xtr, BpmnModel model) throws Exception { Process process = null; if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) { String processId = xtr.getAttributeValue(null, ATTRIBUTE_ID); process = new Process(); process.setId(processId); BpmnXMLUtil.addXMLLocation(process, xtr); process.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME)); if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_PROCESS_EXECUTABLE))) { process.setExecutable(Boolean.parseBoolean(xtr.getAttributeValue(null, ATTRIBUTE_PROCESS_EXECUTABLE))); if (StringUtils.isNotEmpty(candidateUsersString)) { List<String> candidateUsers = BpmnXMLUtil.parseDelimitedList(candidateUsersString); process.setCandidateStarterUsers(candidateUsers); model.getProcesses().add(process);
protected void processProcessElements(ServerConfig config, BpmnModel pojoModel, ObjectNode displayNode, GraphicInfo diagramInfo, Set<String> completedElements, Set<String> currentElements) throws Exception { if (pojoModel.getLocationMap().isEmpty()) return; if (CollectionUtils.isNotEmpty(pojoModel.getPools())) { for (Pool pool : pojoModel.getPools()) { ObjectNode poolNode = objectMapper.createObjectNode(); poolNode.put("id", pool.getId()); poolNode.put("name", pool.getName()); GraphicInfo poolInfo = pojoModel.getGraphicInfo(pool.getId()); fillGraphicInfo(poolNode, poolInfo, true); org.flowable.bpmn.model.Process process = pojoModel.getProcess(pool.getId()); if (process != null && CollectionUtils.isNotEmpty(process.getLanes())) { ArrayNode laneArray = objectMapper.createArrayNode(); for (Lane lane : process.getLanes()) { ObjectNode laneNode = objectMapper.createObjectNode(); laneNode.put("id", lane.getId()); laneNode.put("name", lane.getName()); fillGraphicInfo(laneNode, pojoModel.getGraphicInfo(lane.getId()), true); laneArray.add(laneNode); double rightX = poolInfo.getX() + poolInfo.getWidth(); double bottomY = poolInfo.getY() + poolInfo.getHeight(); for (org.flowable.bpmn.model.Process process : pojoModel.getProcesses()) { processElements(process.getFlowElements(), pojoModel, elementArray, flowArray, collapsedArray, diagramInfo, completedElements, currentElements, null);
public void createMessages() { for (Message messageElement : bpmnModel.getMessages()) { MessageDefinition messageDefinition = new MessageDefinition(messageElement.getId()); if (StringUtils.isNotEmpty(messageElement.getItemRef())) { if (this.itemDefinitions.containsKey(messageElement.getItemRef())) { ItemDefinition itemDefinition = this.itemDefinitions.get(messageElement.getItemRef()); messageDefinition.setItemDefinition(itemDefinition); } } this.messages.put(messageDefinition.getId(), messageDefinition); } }
@Override public void validate(BpmnModel bpmnModel, List<ValidationError> errors) { if (bpmnModel.getMessages() != null && !bpmnModel.getMessages().isEmpty()) { for (Message message : bpmnModel.getMessages()) { // Item ref if (StringUtils.isNotEmpty(message.getItemRef())) { if (!bpmnModel.getItemDefinitions().containsKey(message.getItemRef())) { addError(errors, Problems.MESSAGE_INVALID_ITEM_REF, null, message, "Item reference is invalid: not found"); } } } } }
@SuppressWarnings("unchecked") public static void writeRootElement(BpmnModel model, XMLStreamWriter xtw, String encoding) throws Exception { xtw.writeStartDocument(encoding, "1.0"); // start definitions root element xtw.writeStartElement(ELEMENT_DEFINITIONS); xtw.setDefaultNamespace(BPMN2_NAMESPACE); xtw.writeDefaultNamespace(BPMN2_NAMESPACE); xtw.writeNamespace(XSI_PREFIX, XSI_NAMESPACE); xtw.writeNamespace(XSD_PREFIX, SCHEMA_NAMESPACE); xtw.writeNamespace(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE); xtw.writeNamespace(BPMNDI_PREFIX, BPMNDI_NAMESPACE); xtw.writeNamespace(OMGDC_PREFIX, OMGDC_NAMESPACE); xtw.writeNamespace(OMGDI_PREFIX, OMGDI_NAMESPACE); for (String prefix : model.getNamespaces().keySet()) { if (!defaultNamespaces.contains(prefix) && StringUtils.isNotEmpty(prefix)) xtw.writeNamespace(prefix, model.getNamespaces().get(prefix)); } xtw.writeAttribute(TYPE_LANGUAGE_ATTRIBUTE, SCHEMA_NAMESPACE); xtw.writeAttribute(EXPRESSION_LANGUAGE_ATTRIBUTE, XPATH_NAMESPACE); if (StringUtils.isNotEmpty(model.getTargetNamespace())) { xtw.writeAttribute(TARGET_NAMESPACE_ATTRIBUTE, model.getTargetNamespace()); } else { xtw.writeAttribute(TARGET_NAMESPACE_ATTRIBUTE, PROCESS_NAMESPACE); } BpmnXMLUtil.writeCustomAttributes(model.getDefinitionsAttributes().values(), xtw, model.getNamespaces(), defaultAttributes); } }