1 package org.jbpm.jpdl.par; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.util.zip.ZipInputStream ; 6 7 import org.apache.commons.logging.Log; 8 import org.apache.commons.logging.LogFactory; 9 import org.jbpm.db.JbpmSession; 10 import org.jbpm.db.JbpmSessionFactory; 11 import org.jbpm.graph.def.ProcessDefinition; 12 13 16 public class ProcessArchiveDeployer { 17 18 JbpmSessionFactory jbpmSessionFactory = null; 19 20 22 public ProcessArchiveDeployer() { 23 jbpmSessionFactory = JbpmSessionFactory.buildJbpmSessionFactory(); 24 } 25 26 public ProcessArchiveDeployer(JbpmSessionFactory jbpmSessionFactory) { 27 this.jbpmSessionFactory = jbpmSessionFactory; 28 } 29 30 32 public static void deployResource(String parResource) { 33 deployResource(parResource, JbpmSessionFactory.getInstance()); 34 } 35 36 public static void deployResource(String parResource, JbpmSessionFactory jbpmSessionFactory) { 37 ProcessDefinition processDefinition = ProcessDefinition.parseParResource(parResource); 38 deployProcessDefinition(processDefinition, jbpmSessionFactory); 39 } 40 41 public static void deployZipInputStream(ZipInputStream zipInputStream) { 42 deployZipInputStream(zipInputStream, JbpmSessionFactory.getInstance()); 43 } 44 45 public static void deployZipInputStream(ZipInputStream zipInputStream, JbpmSessionFactory jbpmSessionFactory) { 46 ProcessDefinition processDefinition = ProcessDefinition.parseParZipInputStream(zipInputStream); 47 deployProcessDefinition(processDefinition, jbpmSessionFactory); 48 } 49 50 public static void deployProcessDefinition(ProcessDefinition processDefinition) { 51 deployProcessDefinition(processDefinition, JbpmSessionFactory.getInstance()); 52 } 53 54 public static void deployProcessDefinition(ProcessDefinition processDefinition, JbpmSessionFactory jbpmSessionFactory) { 55 JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession(); 56 try { 57 log.debug("starting transaction to deploy process "+processDefinition); 58 jbpmSession.beginTransaction(); 59 60 String processDefinitionName = processDefinition.getName(); 62 if (processDefinitionName!=null) { 64 ProcessDefinition previousLatestVersion = jbpmSession.getGraphSession().findLatestProcessDefinition(processDefinitionName); 66 if (previousLatestVersion!=null) { 68 processDefinition.setVersion( previousLatestVersion.getVersion()+1 ); 70 } else { 71 processDefinition.setVersion(1); 73 } 74 } 75 76 jbpmSession.getGraphSession().saveProcessDefinition(processDefinition); 78 79 log.debug("flushing..."); 80 jbpmSession.getSession().flush(); 81 82 log.debug("committing transaction to deploy process "+processDefinition); 83 jbpmSession.commitTransaction(); 84 } finally { 85 jbpmSession.close(); 86 } 87 } 88 89 public static void main(String [] args) { 90 if ( (args!=null) 91 && (args.length>0) ) { 92 for (int i=0; i<args.length; i++) { 93 try { 94 deployZipInputStream(new ZipInputStream (new FileInputStream (new File (args[i])))); 95 } catch (Exception e) { 96 e.printStackTrace(); 97 } 98 } 99 } 100 } 101 102 private static final Log log = LogFactory.getLog(ProcessArchiveDeployer.class); 103 } 104 | Popular Tags |