package com.vci.client.workflow.editor; import java.awt.Color; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.imageio.ImageIO; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.commons.lang3.StringUtils; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; import org.w3c.dom.Node; import com.mxgraph.io.mxCodec; import com.mxgraph.model.mxCell; import com.mxgraph.model.mxICell; import com.mxgraph.model.mxIGraphModel; import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.util.mxUtils; import com.mxgraph.view.mxGraph; import com.vci.client.LogonApplication; import com.vci.client.ui.locale.LocaleDisplay; import com.vci.client.workflow.delegate.EventConfClientDelegate; import com.vci.client.workflow.delegate.ProcessCustomClientDelegate; import com.vci.client.workflow.editor.ui.DecisionPanel; import com.vci.client.workflow.editor.ui.FlowInfoPanel; import com.vci.client.workflow.editor.ui.IProcessProperty; import com.vci.client.workflow.editor.ui.MailPanel; import com.vci.client.workflow.editor.ui.PropertyObject; import com.vci.client.workflow.editor.ui.StartEndPanel; import com.vci.client.workflow.editor.ui.SubProcesslPanel; import com.vci.client.workflow.editor.ui.TaskPanel; import com.vci.client.workflow.editor.ui.TransitionPanel; import com.vci.client.workflow.template.object.ProcessCategoryObject; import com.vci.client.workflow.template.object.ProcessDefinitionObject; import com.vci.common.resource.CommonProperties; import com.vci.corba.common.VCIError; import com.vci.corba.workflow.data.CustomInfo; import com.vci.corba.workflow.data.ProcessTaskInfo; import com.vci.corba.workflow.data.PropertyInfo; import com.vci.corba.workflow.data.SubprocessTemInfo; import com.vci.corba.workflow.data.TaskRevokeInfo; public class FlowDeployPanel extends JPanel { private static final long serialVersionUID = -2304467530018557819L; private BasicGraphEditor designer; private ProcessCategoryObject flowCategory; private ProcessDefinitionObject processDefinition; //导入时任务对应的对象 private ProcessTaskInfo importProcessTaskInfo; private TaskDescCObject[] importTaskDescCObjects; private Document importObjectXmlDoc; private String fileSeparator = System.getProperty("file.separator"); //记录路由XML信息 private List trainsitionXmllist = null; // private PhaseObject[] phaseObjects; private String jbpmDeploymentId; private boolean flag = false; public FlowDeployPanel(final BasicGraphEditor designer) { setLayout(new FlowLayout(FlowLayout.LEFT, 2, 2)); this.designer = designer; JButton deployBtn = new JButton("部署"); deployBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { deployFlow(); } }); add(deployBtn); checkDeployDir(); /* JButton updateBtn = new JButton("更新"); updateBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { updateFlow(); } }); add(updateBtn);*/ } public boolean isEdit(boolean flag){ this.flag = flag; return flag; } private void deployFlow() { if(processNameIsEmpty()){ JOptionPane.showMessageDialog(this, "流程名不能为空,请确认"); return; } // if(keyIsEmpty()){ // JOptionPane.showMessageDialog(this, "key名称不能为空,请确认"); // return; // } if(!isEdit(flag)){ if(checkKey()){ JOptionPane.showMessageDialog(this, "流程名或key名称已存在,请确认"); return; } } if(!checkTask()){ JOptionPane.showMessageDialog(this, "流程任务不能重名,请确认"); return; } if(!checkJoin()){ JOptionPane.showMessageDialog(this, "合并节点不能重名,请确认"); return; } if(!checkFork()){ JOptionPane.showMessageDialog(this, "分支节点不能重名,请确认"); return; } if(!checkDecision()){ JOptionPane.showMessageDialog(this, "判断节点不能重名,请确认"); return; } if(!checkEdge()){ JOptionPane.showMessageDialog(this, "路由名称和节点名称重名,请确认"); return; } // if(!isNullEdge()){ // JOptionPane.showMessageDialog(this, "路由名称不能为空,请确认"); // return; // } EditorCreateXmlToJbpm getXml = new EditorCreateXmlToJbpm(designer); String jbpmXml = getXml.getsXml(); mxCodec codec = new mxCodec(); mxIGraphModel model = designer.getGraphComponent().getGraph().getModel(); Node encode = codec.encode(model); String graphXml = mxUtils.getXml(encode); mxGraphComponent graphComponent = designer.getGraphComponent(); try { mxGraph graph = designer.getGraphComponent().getGraph(); BufferedImage image = FlowCellRenderer.createBufferedImage(graph, null, 1, Color.decode("#FFFBFF"), graphComponent.isAntiAlias(), graphComponent.getCanvas()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "png", baos); byte[] jbpmImage = baos.toByteArray(); ProcessTaskInfo[] processTaskInfos = getTaskPropertyByGraph(); boolean result = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).deployProcess(jbpmImage, jbpmXml, graphXml, flowCategory.getId(), processTaskInfos); SubprocessTemInfo[] subprocessTemInfos = getSubprocessTemInfoByGraph(); if(subprocessTemInfos!=null&&subprocessTemInfos.length>0){ new ProcessCustomClientDelegate().saveSubProcess(subprocessTemInfos); } if(result) { JOptionPane.showMessageDialog(this, "流程部署成功"); //探出的对话框消失 this.designer.getParent().getParent().getParent().setVisible(false); }else{ JOptionPane.showMessageDialog(this, "流程部署失败"); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "流程部署失败"); } } private void updateFlow() { if(processNameIsEmpty()){ JOptionPane.showMessageDialog(this, "流程名不能为空,请确认"); return; } // if(keyIsEmpty()){ // JOptionPane.showMessageDialog(this, "key名称不能为空,请确认"); // return; // } if(!isEdit(flag)){ if(checkKey()){ JOptionPane.showMessageDialog(this, "流程名或key名称已存在,请确认"); return; } } if(!checkTask()){ JOptionPane.showMessageDialog(this, "流程任务不能重名,请确认"); return; } if(!checkJoin()){ JOptionPane.showMessageDialog(this, "合并节点不能重名,请确认"); return; } if(!checkFork()){ JOptionPane.showMessageDialog(this, "分支节点不能重名,请确认"); return; } if(!checkDecision()){ JOptionPane.showMessageDialog(this, "判断节点不能重名,请确认"); return; } if(!checkEdge()){ JOptionPane.showMessageDialog(this, "路由名称和节点名称重名,请确认"); return; } // if(!isNullEdge()){ // JOptionPane.showMessageDialog(this, "路由名称不能为空,请确认"); // return; // } EditorCreateXmlToJbpm getXml = new EditorCreateXmlToJbpm(designer); String jbpmXml = getXml.getsXml(); mxCodec codec = new mxCodec(); mxIGraphModel model = designer.getGraphComponent().getGraph().getModel(); Node encode = codec.encode(model); String graphXml = mxUtils.getXml(encode); mxGraphComponent graphComponent = designer.getGraphComponent(); try { mxGraph graph = designer.getGraphComponent().getGraph(); BufferedImage image = FlowCellRenderer.createBufferedImage(graph, null, 1, Color.decode("#FFFBFF"), graphComponent.isAntiAlias(), graphComponent.getCanvas()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "png", baos); byte[] jbpmImage = baos.toByteArray(); ProcessTaskInfo[] processTaskInfos = getTaskPropertyByGraph(); boolean result = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).updateProcess(jbpmImage, jbpmXml, graphXml, flowCategory.getId(), processTaskInfos,jbpmDeploymentId); SubprocessTemInfo[] subprocessTemInfos = getSubprocessTemInfoByGraph(); if(subprocessTemInfos!=null&&subprocessTemInfos.length>0){ new ProcessCustomClientDelegate().saveSubProcess(subprocessTemInfos); } if(result) { JOptionPane.showMessageDialog(this, "流程部署成功"); //探出的对话框消失 this.designer.getParent().getParent().getParent().setVisible(false); }else{ JOptionPane.showMessageDialog(this, "流程部署失败"); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "流程部署失败"); } } /** * 判断key是否重复 */ private boolean checkKey() { mxGraph graph = designer.getGraphComponent().getGraph(); mxCell rootCell = (mxCell)graph.getModel().getRoot(); String nameAndkey = rootCell.getValue().toString().trim(); String[] splieKey = nameAndkey.split(","); String keyValue = ""; String name = ""; if(splieKey.length==2){ name = splieKey[0]; keyValue = splieKey[1]; try { return new ProcessCustomClientDelegate().checkKey(name, keyValue); } catch (VCIError e) { e.printStackTrace(); } } return false; } // private boolean keyIsEmpty() { // mxGraph graph = designer.getGraphComponent().getGraph(); // mxCell rootCell = (mxCell)graph.getModel().getRoot(); // String nameAndkey = rootCell.getValue().toString().trim(); // String[] splieKey = nameAndkey.split(","); // if(splieKey.length==2){ // if(splieKey[1] == null||"".equals(splieKey[1])) { // return true; // } // } // return false; // } private boolean processNameIsEmpty() { mxGraph graph = designer.getGraphComponent().getGraph(); mxCell rootCell = (mxCell)graph.getModel().getRoot(); String nameAndkey = rootCell.getValue().toString().trim(); String[] splieKey = nameAndkey.split(","); if(splieKey.length==0){ return true; }else{ if(splieKey[0] == null||"".equals(splieKey[0] )) { return true; } } return false; } private boolean checkTask() { mxGraph graph = designer.getGraphComponent().getGraph(); Object parent = graph.getDefaultParent(); Object[] ocjectCells = graph.getChildCells(parent); List taskNames = new ArrayList(); for (Object objectCell : ocjectCells) { if (objectCell instanceof mxCell) { mxCell cell = (mxCell) objectCell; if (!cell.isEdge() && cell.getStyle().equals(FlowConstants.XMLTASK)) { String taskName = cell.getValue().toString(); if (taskNames.contains(taskName)) { return false; }else{ taskNames.add(taskName); } } } } return true; } private boolean checkJoin() { mxGraph graph = designer.getGraphComponent().getGraph(); Object parent = graph.getDefaultParent(); Object[] ocjectCells = graph.getChildCells(parent); List joins = new ArrayList(); for (Object objectCell : ocjectCells) { if (objectCell instanceof mxCell) { mxCell cell = (mxCell) objectCell; if (!cell.isEdge() && cell.getStyle().equals(FlowConstants.XMLJOIN)) { String joinName = cell.getValue().toString(); if (joins.contains(joinName)) { return false; }else{ joins.add(joinName); } } } } return true; } private boolean checkFork() { mxGraph graph = designer.getGraphComponent().getGraph(); Object parent = graph.getDefaultParent(); Object[] ocjectCells = graph.getChildCells(parent); List forks = new ArrayList(); for (Object objectCell : ocjectCells) { if (objectCell instanceof mxCell) { mxCell cell = (mxCell) objectCell; if (!cell.isEdge() && cell.getStyle().equals(FlowConstants.XMLFORK)) { String forkName = cell.getValue().toString(); if (forks.contains(forkName)) { return false; }else{ forks.add(forkName); } } } } return true; } private boolean checkDecision() { mxGraph graph = designer.getGraphComponent().getGraph(); Object parent = graph.getDefaultParent(); Object[] ocjectCells = graph.getChildCells(parent); List forks = new ArrayList(); for (Object objectCell : ocjectCells) { if (objectCell instanceof mxCell) { mxCell cell = (mxCell) objectCell; if (!cell.isEdge() && cell.getStyle().equals(FlowConstants.DECISION)) { String forkName = cell.getValue().toString(); if (forks.contains(forkName)) { return false; }else{ forks.add(forkName); } } } } return true; } private boolean isNullEdge() { mxGraph graph = designer.getGraphComponent().getGraph(); Object parent = graph.getDefaultParent(); Object[] ocjectCells = graph.getChildCells(parent); for (Object objectCell : ocjectCells) { if (objectCell instanceof mxCell) { mxCell cell = (mxCell) objectCell; if (cell.isEdge()) { String edgeName = cell.getValue().toString(); if ("".equals(edgeName)) { return false; } } } } return true; } private boolean checkEdge() { mxGraph graph = designer.getGraphComponent().getGraph(); Object parent = graph.getDefaultParent(); Object[] ocjectCells = graph.getChildCells(parent); List nodes = new ArrayList(); List edges = new ArrayList(); for (Object objectCell : ocjectCells) { if (objectCell instanceof mxCell) { mxCell cell = (mxCell) objectCell; String eleValues = ""; if(cell.getValue()!=null){ eleValues =cell.getValue().toString(); } if (!cell.isEdge()) { nodes.add(eleValues); }else{ edges.add(eleValues); } } } for(String node : nodes){ for(String edge : edges){ if(node.equals(edge)){ return false; } } } return true; } private ProcessTaskInfo[] getTaskPropertyByGraph() { mxGraph graph = designer.getGraphComponent().getGraph(); Object parent = graph.getDefaultParent(); Object[] ocjectCells = graph.getChildCells(parent); List list = new ArrayList(); for (Object objectCell : ocjectCells) { if (objectCell instanceof mxCell) { mxCell cell = (mxCell) objectCell; if (cell.getValue() != null && cell.getValue() instanceof IProcessProperty && !cell.isEdge()) { IProcessProperty object = (IProcessProperty) cell.getValue(); String nodeType = object.getNodeType(); if (nodeType.equals(FlowConstants.XMLTASK)) { TaskPanel task = (TaskPanel) object; list.add(task.getProcessTaskInfo()); } } } } return list.toArray(new ProcessTaskInfo[0]); } private SubprocessTemInfo[] getSubprocessTemInfoByGraph() { mxGraph graph = designer.getGraphComponent().getGraph(); Object parent = graph.getDefaultParent(); Object[] ocjectCells = graph.getChildCells(parent); List list = new ArrayList(); for (Object objectCell : ocjectCells) { if (objectCell instanceof mxCell) { mxCell cell = (mxCell) objectCell; if (cell.getValue() instanceof IProcessProperty && !cell.isEdge()) { IProcessProperty object = (IProcessProperty) cell.getValue(); String nodeType = object.getNodeType(); if (nodeType.equals(FlowConstants.SUBPROCESS)) { SubProcesslPanel spp = (SubProcesslPanel) object; mxCell rootCell = (mxCell)graph.getModel().getRoot(); String nameAndkey = rootCell.getValue().toString().trim(); String[] splieKey = nameAndkey.split(","); spp.getSubprocessTemInfo().parentTemName=splieKey[0]; list.add(spp.getSubprocessTemInfo()); } } } } return list.toArray(new SubprocessTemInfo[0]); } private void checkDeployDir() { String path = System.getProperty("user.home") + fileSeparator + ".flow"; File deployDir = new File(path); if (!deployDir.exists()) { deployDir.mkdir(); } } public void setFlowCategory(ProcessCategoryObject flowCategory) { this.flowCategory = flowCategory; } public void setProcessDefinition(ProcessDefinitionObject pd) throws Exception { try { processDefinition = pd; jbpmDeploymentId = pd.getJbpmDeploymentId(); byte[] graphXml = new ProcessCustomClientDelegate().getProcessGraphXml(jbpmDeploymentId); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = factory.newDocumentBuilder(); InputStream gin = new ByteArrayInputStream(graphXml); org.w3c.dom.Document document = docBuilder.parse(gin); mxCodec codec = new mxCodec(document); codec.decode(document.getDocumentElement(), designer .getGraphComponent().getGraph().getModel()); byte[] processXml = new ProcessCustomClientDelegate().getProcessXml(jbpmDeploymentId); InputStream in = new ByteArrayInputStream(processXml); BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8")); SAXReader saxr = new SAXReader(); Document doc = saxr.read(reader); updateGraph(doc); resetDesigner(designer); // mxGraph graph = designer.getGraphComponent().getGraph(); // graph.refresh(); } catch (Exception e) { e.printStackTrace(); throw e; } } public void setProcessDefinition(byte[] graphXml, byte[] processXml,ProcessDefinitionObject pd,byte[] objectXml ) throws Exception { try { processDefinition = pd; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = factory.newDocumentBuilder(); InputStream gin = new ByteArrayInputStream(graphXml); org.w3c.dom.Document document = docBuilder.parse(gin); mxCodec codec = new mxCodec(document); codec.decode(document.getDocumentElement(), designer .getGraphComponent().getGraph().getModel()); InputStream in = new ByteArrayInputStream(processXml); BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8")); SAXReader saxr = new SAXReader(); Document doc = saxr.read(reader); //对象xml解析 InputStream objectXmlIn = new ByteArrayInputStream(objectXml); BufferedReader objectXmlReader = new BufferedReader(new InputStreamReader(objectXmlIn, "utf-8")); SAXReader objectXmlSaxr = new SAXReader(); Document objectXmlDoc = objectXmlSaxr.read(objectXmlReader); importObjectXmlDoc = objectXmlDoc; updateGraph(doc); resetDesigner(designer); // mxGraph graph = designer.getGraphComponent().getGraph(); // graph.refresh(); } catch (Exception e) { e.printStackTrace(); throw e; } } private void resetDesigner(BasicGraphEditor editor) { editor.setModified(false); editor.getUndoManager().clear(); } private void updateGraph(Document doc) throws Exception{ mxGraph graph = designer.getGraphComponent().getGraph(); Object parent = graph.getDefaultParent(); graph.getModel().beginUpdate(); try { Element root = doc.getRootElement(); mxCell rootCell = (mxCell)graph.getModel().getRoot(); //遍历根process节点的属性 FlowInfoPanel flowInfo = new FlowInfoPanel(graph); flowInfo.setValue(processDefinition.getName()); flowInfo.setKey(processDefinition.getKey()); rootCell.setValue(flowInfo); //XML元素的遍历 for (Iterator a = root.elementIterator(); a.hasNext();) { Element next = (Element) a.next(); String cellType = next.getName(); if(cellType.equals(FlowConstants.GLOBAL)){ ProcessTaskInfo processTaskInfo = new ProcessTaskInfo(); List processTypeProperties = new ArrayList(); // Element globalElement = next.element(FlowConstants.GLOBAL); for (Iterator b = next.elementIterator(); b.hasNext();) { Element fieldElement = (Element)b.next();//多个field element if(fieldElement.getName().equals(FlowConstants.EVENT_FIELD)){ PropertyInfo propertyInfo = new PropertyInfo(); propertyInfo.property = fieldElement.attributeValue(FlowConstants.XMLNAME); for (Iterator c = fieldElement.elementIterator(); c.hasNext();) { Element stringElement = (Element)c.next(); if(stringElement.getName().equals(FlowConstants.EVENT_STRING)){ propertyInfo.value = stringElement.attributeValue(FlowConstants.EVENT_VALUE); } } processTypeProperties.add(propertyInfo); } } processTaskInfo.taskTypeProperties = processTypeProperties.toArray(new PropertyInfo[0]); flowInfo.setPropertyInfo(processTaskInfo.taskTypeProperties); }else{ if(cellType.equalsIgnoreCase(FlowConstants.EVENT_ON)){ if(next.getName().equalsIgnoreCase(FlowConstants.EVENT_ON)) { setProcessEvent(flowInfo, next); } }else{ parseJpdl(next, graph, parent); } } } //记录路由XML信息 trainsitionElInfo(root); //处理transition updateEdge(graph); } catch (Exception e) { e.printStackTrace(); throw e; } finally { graph.getModel().endUpdate(); } } private void updateEdge(mxGraph graph) throws VCIError { Object parent = graph.getDefaultParent(); Object[] cells = graph.getChildCells(parent); int trainsitionXmlInfoIndex = 0; for (int i = 0; i < cells.length; i++) { if (cells[i] instanceof mxCell) { mxCell cell = (mxCell) cells[i]; if(cell.isEdge() && cell.getValue() instanceof String) { String style = (cell.getStyle()==null?"":cell.getStyle()).trim(); if(style.length() == 0) { style = "transition_horizontal"; } FlowNode flowNode = new FlowNode(style, (String)cell.getValue()); cell.setValue(flowNode); JComponent component = ProcessComponentFactory.getComponent(graph, cell); cell.setValue(component); mxICell source = cell.getSource(); mxICell target = cell.getTarget(); if(source !=null && target !=null){ Object value = source.getValue(); Object value2 = target.getValue(); String sourceName = ""; String targetName =""; if(value instanceof StartEndPanel){ sourceName = ((StartEndPanel) value).toString(); } if(value2 instanceof StartEndPanel){ targetName = ((StartEndPanel) value2).toString(); } if(value instanceof TaskPanel){ sourceName = ((TaskPanel) value).toString(); } if(value2 instanceof TaskPanel){ targetName = ((TaskPanel) value2).toString(); } String fromto = sourceName+"->"+flowNode.getName()+"->"+targetName; System.out.println("setTrainstion==" + fromto); List elements = trainsitonMap.get(fromto); TransitionPanel transitionPanel = (TransitionPanel)component; if(elements!=null){ if(elements!=null){ // for(Element element: elements){ // if(element!=null){ setTransitionEvent(transitionPanel, elements); // } // } } } transitionPanel.setTrainsitionDescPanel(trainsitionUrlMap.get(fromto)); // if(trainsitionXmllist!=null){ // Element element = trainsitionXmllist.get(trainsitionXmlInfoIndex); // TransitionPanel transitionPanel = (TransitionPanel)component; // if(element!=null){ // setTransitionEvent(transitionPanel, element); // } // trainsitionXmlInfoIndex++; // } } } } } } /** * 记录路由XML信息 * @param root * @return */ private Map> trainsitonMap = new HashMap>(); private Map trainsitionUrlMap = new HashMap(); private List trainsitionElInfo(Element root) { String name = ""; for (Iterator a = root.elementIterator(); a.hasNext();) { String fromTo = ""; //存储路由事件信息 trainsitionXmllist = new ArrayList(); Element next = (Element)a.next(); System.out.println("next.getName()="+next.getName()); if(next.getName().equalsIgnoreCase(FlowConstants.XMLSTART)){ name = next.attribute(FlowConstants.XMLNAME)==null?"":next.attribute(FlowConstants.XMLNAME).getValue(); } else if(next.getName().equalsIgnoreCase(FlowConstants.XMLTASK)){ name = next.attribute(FlowConstants.XMLNAME)==null?"":next.attribute(FlowConstants.XMLNAME).getValue(); } else if(next.getName().equalsIgnoreCase(FlowConstants.XMLEND)){ name = next.attribute(FlowConstants.XMLNAME)==null?"":next.attribute(FlowConstants.XMLNAME).getValue(); } else if(next.getName().equalsIgnoreCase(FlowConstants.XMLFORK)){ name = next.attribute(FlowConstants.XMLNAME)==null?"":next.attribute(FlowConstants.XMLNAME).getValue(); } else if(next.getName().equalsIgnoreCase(FlowConstants.XMLJOIN)){ name = next.attribute(FlowConstants.XMLNAME)==null?"":next.attribute(FlowConstants.XMLNAME).getValue(); } else if(next.getName().equalsIgnoreCase(FlowConstants.DECISION)){ name = next.attribute(FlowConstants.XMLNAME)==null?"":next.attribute(FlowConstants.XMLNAME).getValue(); } for (Iterator trainsitionIt = next.elementIterator(); trainsitionIt.hasNext();) { trainsitionXmllist = new ArrayList(); Element trainsitionNext = (Element) trainsitionIt.next(); if(trainsitionNext.getName().equalsIgnoreCase(FlowConstants.TRANSITION)) { // Element trainsitonEl = trainsitionNext.element(FlowConstants.TRANSITION); Attribute attribute = trainsitionNext.attribute(FlowConstants.URL_PATH); if(attribute!= null){ String transitionName = trainsitionNext.attribute(FlowConstants.XMLNAME)==null?"":trainsitionNext.attribute(FlowConstants.XMLNAME).getValue(); String to = trainsitionNext.attribute(FlowConstants.XMLTARGET)==null?"":trainsitionNext.attribute(FlowConstants.XMLTARGET).getValue(); String trainsitionUrlfromTo = name + "->" + transitionName + "->" + to; trainsitionUrlMap.put(trainsitionUrlfromTo, attribute.getText()); } for(Iterator trainsitonElIt = trainsitionNext.elementIterator(); trainsitonElIt.hasNext();){ Element trainsitioListener = (Element) trainsitonElIt.next(); String transitionName = trainsitionNext.attribute(FlowConstants.XMLNAME)==null?"":trainsitionNext.attribute(FlowConstants.XMLNAME).getValue(); String to = trainsitionNext.attribute(FlowConstants.XMLTARGET)==null?"":trainsitionNext.attribute(FlowConstants.XMLTARGET).getValue(); fromTo = name + "->" + transitionName + "->" + to; System.out.println("getTrainstion=="+fromTo+"/////Listener=="+trainsitioListener); trainsitionXmllist.add(trainsitioListener); trainsitonMap.put(fromTo, trainsitionXmllist); } } } } return trainsitionXmllist; } private mxCell getCell(mxGraph graph, String name){ if(name != null) { Object parent = graph.getDefaultParent(); Object[] cells = graph.getChildCells(parent); for (int i = 0; i < cells.length; i++) { if (cells[i] instanceof mxCell) { mxCell cell = (mxCell) cells[i]; if(!cell.isEdge() && name.equals(cell.getValue().toString())) { return cell; } } } } return null; } private void parseJpdl(Element element, mxGraph graph, Object parent) throws VCIError { String cellType = element.getName(); FlowNode flowNode = new FlowNode(cellType); String cellName = element.attributeValue(FlowConstants.XMLNAME); mxCell cell = getCell(graph, cellName); Object value = cell.getValue(); if(value != null) { flowNode.setName(value.toString()); } cell.setValue(flowNode); if(cellType.equalsIgnoreCase(FlowConstants.XMLSTART) || cellType.equalsIgnoreCase(FlowConstants.XMLEND) || cellType.equalsIgnoreCase(FlowConstants.XMLFORK) || cellType.equalsIgnoreCase(FlowConstants.XMLJOIN)){ JComponent component = ProcessComponentFactory.getComponent(graph, cell); cell.setValue(component); } else if(cellType.equalsIgnoreCase(FlowConstants.XMLTASK)) { JComponent component = ProcessComponentFactory.getComponent(graph, cell); cell.setValue(component); TaskPanel taskPanel = (TaskPanel)component; try { if(jbpmDeploymentId!=null&&!"".equals(jbpmDeploymentId)){ ProcessTaskInfo processTaskInfo = new ProcessCustomClientDelegate().findById(jbpmDeploymentId, taskPanel.toString()); taskPanel.setProcessTaskInfo(processTaskInfo); }else{ if(importObjectXmlDoc!=null){ ProcessTaskInfo processTaskInfo = new ProcessTaskInfo(); Element root = importObjectXmlDoc.getRootElement(); // Element taskEle = root.element(taskPanel.toString()); //获取流程任务信息 Element processTaskInfoEle = root.element("ProcessTaskInfo"); if(processTaskInfoEle!=null){ processTaskInfo.id = processTaskInfoEle.attribute("id").getValue(); processTaskInfo.deploymentId = processTaskInfoEle.attribute("deploymentId").getValue(); processTaskInfo.taskName = processTaskInfoEle.attribute("taskName").getValue(); processTaskInfo.taskType = processTaskInfoEle.attribute("taskType").getValue(); processTaskInfo.taskDesc = processTaskInfoEle.attribute("taskDesc").getValue(); processTaskInfo.pltreatment = Integer.parseInt(processTaskInfoEle.attribute("pltreatment").getValue()); processTaskInfo.popUserDialog = processTaskInfoEle.attribute("popUserDialog").getValue(); } //获取任务属性信息 // List propertyInfoEle = importObjectXmlDoc.selectNodes("/root/"+taskPanel.toString()+"/PropertyInfo" ); List propertyInfoEle = importObjectXmlDoc.selectNodes("/root/ProcessTaskInfo/PropertyInfo" ); PropertyInfo[] taskTypeProperties = null ; if(propertyInfoEle!=null){ taskTypeProperties = new PropertyInfo[propertyInfoEle.size()]; Iterator iter = propertyInfoEle.iterator(); int i=0; if(iter.hasNext()){ PropertyInfo p = new PropertyInfo(); Element next = iter.next(); p.property = next.attribute("property").getValue() == null?"":next.attribute("property").getValue(); p.value = next.attribute("value").getValue() ==null?"":next.attribute("value").getValue(); taskTypeProperties[i] = p; i++; } } processTaskInfo.taskTypeProperties = taskTypeProperties==null?new PropertyInfo[0]:taskTypeProperties; //获取任务属性信息 // List customInfoEle = importObjectXmlDoc.selectNodes("/root/"+taskPanel.toString()+"/CustomInfo" ); List customInfoEle = importObjectXmlDoc.selectNodes("/root/ProcessTaskInfo/CustomInfo" ); CustomInfo[] customUserInfos = null; if(customInfoEle!=null){ customUserInfos = new CustomInfo[customInfoEle.size()]; Iterator iter = customInfoEle.iterator(); int i=0; if(iter.hasNext()){ CustomInfo p = new CustomInfo(); Element next = iter.next(); p.className = next.attribute("className").getValue()==null?"":next.attribute("className").getValue(); p.value = next.attribute("value").getValue()==null?"":next.attribute("value").getValue(); customUserInfos[i] = p; i++; } } processTaskInfo.customUserInfos = customUserInfos==null?new CustomInfo[0]:customUserInfos; taskPanel.setProcessTaskInfo(processTaskInfo); } } } catch (VCIError e) { e.printStackTrace(); } //如果是自定义用户接口,则通过assignHandler的field获取用户字符串 String userDialogControl = CommonProperties.getStringProperty("workflow.UserDialog"); if(userDialogControl!=null&&!"".equals(userDialogControl)){ Element eventElement = element.element(FlowConstants.ASSIFNMENT_HANDLER); if(eventElement!=null){ for (Iterator b = eventElement.elementIterator(); b.hasNext();) { Element fieldElement = (Element)b.next();//多个field element if(fieldElement.getName().equals(FlowConstants.EVENT_FIELD)){ for (Iterator c = fieldElement.elementIterator(); c.hasNext();) { Element stringElement = (Element)c.next(); if(stringElement.getName().equals(FlowConstants.EVENT_STRING)){ List users = new ArrayList(); String userName = stringElement.attributeValue(FlowConstants.EVENT_VALUE); users.add(userName); taskPanel.setTaskOwners(users); } } } } } }else{ Attribute attribute = element.attribute(FlowConstants.XMLUSER); if(attribute != null) { String userName = attribute.getValue(); if(!userName.equals(FlowConstants.PROCESS_APPLICANT)){ List users = new ArrayList(); users.add(userName); taskPanel.setTaskOwners(users); // taskPanel.setTaskCustOwners(userName); } }else{ Attribute usersAttribute = element.attribute(FlowConstants.XMLUSERS); if(usersAttribute != null) { String userName = usersAttribute.getValue(); // String[] splits = userName.split(","); // taskPanel.setTaskOwners(Arrays.asList(splits)); String[] splits = userName.split(";"); if(splits.length == 1){ taskPanel.setTaskOwners(Arrays.asList(splits[0])); } else if(splits.length == 2){ taskPanel.setTaskOwners(Arrays.asList(splits[0])); taskPanel.setTaskRoleOwners(Arrays.asList(splits[1])); } else if(splits.length == 3){ taskPanel.setTaskOwners(Arrays.asList(splits[0])); taskPanel.setTaskRoleOwners(Arrays.asList(splits[1])); taskPanel.setTaskDeptOwners(Arrays.asList(splits[2])); } } } } Attribute constituentAttr = element.attribute(FlowConstants.XMLCONSTITUENT); System.out.println("constituentAttr =="+constituentAttr); if(constituentAttr != null) { String userName = constituentAttr.getValue(); System.out.println("constituentAttr::userName=="+userName); String[] splits = userName.split(","); // taskPanel.setTaskOwners(Arrays.asList(splits)); // String[] splits = userName.split(";"); // if(splits.length == 1){ // taskPanel.setTaskOwners(Arrays.asList(splits[0])); // } else if(splits.length == 2){ // taskPanel.setTaskOwners(Arrays.asList(splits[0])); // taskPanel.setTaskRoleOwners(Arrays.asList(splits[1])); // } else if(splits.length == 3){ // taskPanel.setTaskOwners(Arrays.asList(splits[0])); // taskPanel.setTaskRoleOwners(Arrays.asList(splits[1])); // taskPanel.setTaskDeptOwners(Arrays.asList(splits[2])); // } taskPanel.setconstituents(Arrays.asList(splits)); } //设置抄送人的值 // List taskCCClientObject; // try { // if(jbpmDeploymentId!=null&&!"".equals(jbpmDeploymentId)){ // taskCCClientObject = new TaskCCClientDelegate().getTaskCCInfos(jbpmDeploymentId); // if(taskCCClientObject!=null){ // List list = new ArrayList(); // for(int i =0;i taskDescCObjectEle = importObjectXmlDoc.selectNodes("/root/"+taskPanel.toString()+"/TaskDescCObject" ); List taskDescCObjectEle = importObjectXmlDoc.selectNodes("/root/ProcessTaskInfo/TaskDescCObject" ); if(taskDescCObjectEle!=null){ CustomInfo[] custominfos = new CustomInfo[taskDescCObjectEle.size()]; Iterator iter = taskDescCObjectEle.iterator(); int i=0; if(iter.hasNext()){ CustomInfo info = new CustomInfo(); Element next = iter.next(); desc = next.attribute("pltaskdesc").getValue()==null?"":next.attribute("pltaskdesc").getValue(); flag = Integer.parseInt(next.attribute("pltreatment").getValue()); popuserdialogflag = next.attribute("popUserDialog").getValue()==null?"":next.attribute("popUserDialog").getValue(); info.className = next.attribute("plcustomclassname").getValue()==null?"":next.attribute("plcustomclassname").getValue(); info.value = next.attribute("plcustomparam").getValue()==null?"":next.attribute("plcustomparam").getValue(); custominfos[i] = info; i++; } //设置自定义类的值 taskPanel.setCustomInfo(custominfos); taskPanel.setTaskTreatmentPanel(flag); taskPanel.setPopUserDialog(popuserdialogflag); taskPanel.setTaskDescPanel(desc,urlText); } } //获取撤销策略 if(jbpmDeploymentId!=null&&!"".equals(jbpmDeploymentId)){ TaskRevokeCObject[] taskRevokeCObject = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).getTaskRevokeList(jbpmDeploymentId, taskPanel.toString()); TaskRevokeInfo[] revokeInfos = new TaskRevokeInfo[taskRevokeCObject.length]; String revokeFlag = ""; PropertyInfo[] propertyInfos = new PropertyInfo[taskRevokeCObject.length]; for(int i=0;i a = element.elementIterator(); a.hasNext();) { Element next = (Element)a.next(); if(next.getName().equalsIgnoreCase(FlowConstants.EVENT_ON)) { // //设置自定义候选人 // setCustomuserClass(taskPanel, next); setTaskEvent(taskPanel, next); } // else if(next.getName().equalsIgnoreCase(FlowConstants.CUSTOMUSERCLASS)) { // //设置自定义候选人 // setCustomuserClass(taskPanel, next); // } } }else if(cellType.equalsIgnoreCase(FlowConstants.XMLDECISION)) { JComponent component = ProcessComponentFactory.getComponent(graph, cell); cell.setValue(component); DecisionPanel decisionPanel = (DecisionPanel)component; for (Iterator a = element.elementIterator(); a.hasNext();) { Element next = (Element)a.next(); if(next.getName().equalsIgnoreCase(FlowConstants.HANDLER)) { String handlerClass = next.attributeValue(FlowConstants.EVENT_CLASS); decisionPanel.setHandlerClass(handlerClass); } } Attribute attribute = element.attribute(FlowConstants.EXPRESSION); if(attribute!=null){ if(attribute.getValue()!=null&&!"".equals(attribute.getValue())){ decisionPanel.setValue(attribute.getValue()); } } }else if(cellType.equalsIgnoreCase(FlowConstants.MAIL)){ JComponent component = ProcessComponentFactory.getComponent(graph, cell); cell.setValue(component); MailPanel mailPanel = (MailPanel)component; for (Iterator a = element.elementIterator(); a.hasNext();) { Element next = (Element)a.next(); if(next.getName().equalsIgnoreCase(FlowConstants.XMLTARGET)) { String address = next.attributeValue(FlowConstants.MAIL_ADDRESSES); mailPanel.getAccepterTextArea().setText(address); } else if(next.getName().equalsIgnoreCase(FlowConstants.MAIL_CC)){ String address = next.attributeValue(FlowConstants.MAIL_ADDRESSES); mailPanel.getCcTextArea().setText(address); } else if(next.getName().equalsIgnoreCase(FlowConstants.MAIL_BCC)){ String address = next.attributeValue(FlowConstants.MAIL_ADDRESSES); mailPanel.getBccTextArea().setText(address); } else if(next.getName().equalsIgnoreCase(FlowConstants.MAIL_SUBJECT)){ String subject = next.getTextTrim(); mailPanel.getSubjectTextField().setText(subject); } else if(next.getName().equalsIgnoreCase(FlowConstants.MAIL_TEXT)){ String content = next.getTextTrim(); mailPanel.getContentTextArea().setText(content); } } }else if(cellType.equalsIgnoreCase(FlowConstants.SUBPROCESS)){ JComponent component = ProcessComponentFactory.getComponent(graph, cell); cell.setValue(component); SubProcesslPanel subProcesslPanel = (SubProcesslPanel)component; Attribute attribute = element.attribute(FlowConstants.SUBPROCESSKEY); subProcesslPanel.getSubProcessTextField().setText(attribute.getText().toString()); subProcesslPanel.getOutComeTextField().setText("#{result}"); } } private void setProcessEvent(FlowInfoPanel flowInfoPanel, Element taskElement) { List customClassInfos = new ArrayList(); String eventType = taskElement.attributeValue(FlowConstants.EVENT);//start or end String eventClass = ""; String taskType = eventClass; ProcessTaskInfo processTaskInfo = new ProcessTaskInfo(); processTaskInfo.taskType = taskType; for (Iterator a = taskElement.elementIterator(); a.hasNext();) { Element next = (Element)a.next(); eventClass = next.attributeValue(FlowConstants.EVENT_CLASS); PropertyInfo customClassInfo = new PropertyInfo(); customClassInfo.property = eventClass; customClassInfos.add(customClassInfo); } //设置自定义类的值 flowInfoPanel.setCustomClassInfo(eventType,customClassInfos.toArray(new PropertyInfo[0])); } private void setTaskEvent(TaskPanel taskPanel, Element taskElement) { List customClassInfos = new ArrayList(); String eventType = taskElement.attributeValue(FlowConstants.EVENT);//start or end String eventClass = ""; Map> taskeventMap = new HashMap>(); Map>> resultMap = new HashMap>>(); ArrayList taskeventPropertylist = new ArrayList(); for (Iterator a = taskElement.elementIterator(); a.hasNext();) { taskeventPropertylist = new ArrayList(); Element next = (Element)a.next(); eventClass = next.attributeValue(FlowConstants.EVENT_CLASS); PropertyInfo taskEventClassInfo = new PropertyInfo(); taskEventClassInfo.property = eventClass; customClassInfos.add(taskEventClassInfo); for (Iterator b = next.elementIterator(); b.hasNext();) { PropertyInfo propertyInfo = new PropertyInfo(); Element fieldElement = (Element)b.next();//多个field element if(fieldElement.getName().equals(FlowConstants.EVENT_FIELD)){ propertyInfo.property = fieldElement.attributeValue(FlowConstants.XMLNAME); for (Iterator c = fieldElement.elementIterator(); c.hasNext();) { Element stringElement = (Element)c.next(); if(stringElement.getName().equals(FlowConstants.EVENT_STRING)){ propertyInfo.value = stringElement.attributeValue(FlowConstants.EVENT_VALUE); } taskeventPropertylist.add(propertyInfo); taskeventMap.put(eventClass, taskeventPropertylist); } } } resultMap.put(eventType, taskeventMap); taskPanel.setResultMap(eventType,resultMap); } // ProcessTaskInfo processTaskInfo = new ProcessTaskInfo(); // String taskType = eventClass; // List taskTypeProperties = new ArrayList(); // //设置自定义类的值 taskPanel.setCustomClassInfo(eventType,customClassInfos.toArray(new PropertyInfo[0])); // processTaskInfo.taskTypeProperties = taskTypeProperties.toArray(new PropertyInfo[0]); // // String eventType = taskElement.attributeValue(FlowConstants.EVENT);//start or end // Element eventElement = taskElement.element(FlowConstants.EVENT_LISTENER); // String eventClass = eventElement.attributeValue(FlowConstants.EVENT_CLASS); // ProcessTaskInfo processTaskInfo = new ProcessTaskInfo(); // String taskType = eventClass; // processTaskInfo.taskType = taskType; // List taskTypeProperties = new ArrayList(); // for (Iterator a = eventElement.elementIterator(); a.hasNext();) { // Element fieldElement = (Element)a.next();//多个field element // if(fieldElement.getName().equals(FlowConstants.EVENT_FIELD)){ // PropertyInfo propertyInfo = new PropertyInfo(); // propertyInfo.property = fieldElement.attributeValue(FlowConstants.XMLNAME); // for (Iterator b = fieldElement.elementIterator(); b.hasNext();) { // Element stringElement = (Element)b.next(); // if(stringElement.getName().equals(FlowConstants.EVENT_STRING)){ // propertyInfo.value = stringElement.attributeValue(FlowConstants.EVENT_VALUE); // } // } // taskTypeProperties.add(propertyInfo); // } // } // processTaskInfo.taskTypeProperties = taskTypeProperties.toArray(new PropertyInfo[0]); // taskPanel.setEventInfo(processTaskInfo, eventType); } private void setCustomuserClass(TaskPanel taskPanel, Element taskElement) { List customUserInfos = new ArrayList(); List rescustomUserInfos = new ArrayList(); String eventType = taskElement.attributeValue(FlowConstants.EVENT);//start or end String eventClass = ""; String flag = ""; if("start".equals(eventType)){ for (Iterator a = taskElement.elementIterator(); a.hasNext();) { CustomInfo customClassInfo = new CustomInfo(); Element next = (Element)a.next(); eventClass = next.attributeValue(FlowConstants.EVENT_CLASS); flag = next.attributeValue(FlowConstants.CUSTOMUSERCLASS_flag); if(FlowConstants.CUSTOMUSERCLASS.equals(flag)){ customClassInfo.className = eventClass; customUserInfos.add(customClassInfo); } } if(flag!=null&&!"".equals(flag)){ Element eventElement = taskElement.element(FlowConstants.EVENT_LISTENER); for (Iterator a = eventElement.elementIterator(); a.hasNext();) { CustomInfo customClassInfo = new CustomInfo(); Element fieldElement = (Element)a.next();//多个field element if(fieldElement.getName().equals(FlowConstants.EVENT_FIELD)){ // customClassInfo.property = fieldElement.attributeValue(FlowConstants.XMLNAME); for (Iterator b = fieldElement.elementIterator(); b.hasNext();) { Element stringElement = (Element)b.next(); if(stringElement.getName().equals(FlowConstants.EVENT_STRING)){ customClassInfo.value = stringElement.attributeValue(FlowConstants.EVENT_VALUE); } customUserInfos.add(customClassInfo); } } } for(int i=0;i taskTypeProperties = new ArrayList(); // for (Iterator a = eventElement.elementIterator(); a.hasNext();) { // Element fieldElement = (Element)a.next();//多个field element // if(fieldElement.getName().equals(FlowConstants.EVENT_FIELD)){ // PropertyInfo propertyInfo = new PropertyInfo(); // propertyInfo.property = fieldElement.attributeValue(FlowConstants.XMLNAME); // for (Iterator b = fieldElement.elementIterator(); b.hasNext();) { // Element stringElement = (Element)b.next(); // if(stringElement.getName().equals(FlowConstants.EVENT_STRING)){ // propertyInfo.value = stringElement.attributeValue(FlowConstants.EVENT_VALUE); // } // } // taskTypeProperties.add(propertyInfo); // } // } // List customClassInfos = new ArrayList(); // // String[] customClasses = null; // for(int i=0;i transitionElements) throws VCIError { List customClassInfos = new ArrayList(); String eventType = "trainsition"; String eventClass = ""; Map> taskeventMap = new HashMap>(); Map>> resultMap = new HashMap>>(); ArrayList taskeventPropertylist = new ArrayList(); for(int i =0;i(); eventClass = transitionElements.get(i).attributeValue(FlowConstants.EVENT_CLASS); PropertyInfo customClassInfo = new PropertyInfo(); customClassInfo.property = eventClass; customClassInfos.add(customClassInfo); for (Iterator b = transitionElements.get(i).elementIterator(); b.hasNext();) { PropertyInfo propertyInfo = new PropertyInfo(); Element fieldElement = (Element)b.next();//多个field element if(fieldElement.getName().equals(FlowConstants.EVENT_FIELD)){ propertyInfo.property = fieldElement.attributeValue(FlowConstants.XMLNAME); for (Iterator c = fieldElement.elementIterator(); c.hasNext();) { Element stringElement = (Element)c.next(); if(stringElement.getName().equals(FlowConstants.EVENT_STRING)){ propertyInfo.value = stringElement.attributeValue(FlowConstants.EVENT_VALUE); } taskeventPropertylist.add(propertyInfo); taskeventMap.put(eventClass, taskeventPropertylist); } } } resultMap.put(eventType, taskeventMap); transitionPanel.setResultMap(eventType,resultMap); } //设置自定义类的值 transitionPanel.setCustomClassInfo(eventType,customClassInfos.toArray(new PropertyInfo[0])); } // public PhaseObject[] getPhaseObjects() { // return phaseObjects; // } /* private PhaseObject[] getPhaseByTemplatePuid(String templatePuid) { PhaseClientDelegate phaseServer = new PhaseClientDelegate(LogonApplication.frame.getUserEntityObject()); try { if (!"".equals(templatePuid)) { return phaseServer.getPhasesByTemplateId(templatePuid); } } catch (VCIError e) { e.printStackTrace(); } return null; }*/ private String getI18nForEvent(String key) { return LocaleDisplay.getI18nString(key, "RMIPWorkflow", getLocale()); } }