/** 流程发布*/ function processDeploy(){ if(selectedTr!=null){ if(confirm("您确定发布该流程吗?")){ var i = selectedTr.childNodes[0].innerText; ///取得行号。。跟据行号进行赋值。 var name = msgs[i].name; $.ajax({ type:"POST", url:"workflow.do?op=processDeploy&deploymentId="+name, dataType:"json", success:function (msg) { if(msg==true){ alert("部署成功!"); doQuery(); }else{ alert("部署失败!"); } }}); } }else{ alert("请选择要发布的数据!"); } }
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request , HttpServletResponse response) throws Exception {
String op = request.getParameter("op");
//流程发布.
if ("processDeploy".equals(op)) {
try {
String deploymentId = request.getParameter("deploymentId");
FlowDefineType flowDefineType = FlowDefineType.valueOf(deploymentId);
WorkflowService.deployment(flowDefineType);
response.getWriter().print("true");
} catch (Exception e) {
response.getWriter().print("false");
}
}
}
/**
* 流程定义.
*/
public enum FlowDefineType {
gjjt("gjjt", "jbpm/bizflow/公交集团审批流程.jpdl.xml", "公交集团审批流程","jbpm/bizflow/公交集团审批流程.png");
private FlowDefineType(String name, String path, String descript, String imageSrc) {
this.name = name;
this.path = path;
this.descript = descript;
this.imageSrc = imageSrc;
}
private String name;
private String path;
private String descript;
private String imageSrc;
public String getName() {
return name;
}
public String getPath() {
return path;
}
public String getDescript() {
return descript;
}
/**
* 返回指定name的FlowDefineType对象,若无匹配则返回null.
*/
public static FlowDefineType valueOfname(String name) {
for (FlowDefineType flowDefineType : values()) {
if (flowDefineType.getName().equals(name))
return flowDefineType;
}
return null;
}
public String getImageSrc() {
return imageSrc;
}
public void setImageSrc(String imageSrc) {
this.imageSrc = imageSrc;
}
}
WorkflowService.java
/**
* 流程发布.
*
* @param flowDefineType
* @return 流程发布ID
*/
static public String deployment(FlowDefineType flowDefineType) {
//logger.info("发布流程...:" + flowDefineType.getName() + " path:" + flowDefineType.getPath() + " descript:"
// + flowDefineType.getDescript());
RepositoryService repositoryService = getRepositoryService();
String deploymentId = repositoryService.createDeployment().addResourceFromClasspath(flowDefineType.getPath())
.deploy();
//logger.info("流程:" + flowDefineType.getName() + "发布成功!流程发布ID:" + deploymentId);
return deploymentId;
}