Here's what I finally did to update files stored in the database for a Process
Definition, such as JSP pages, xml files, class files (handlers) etc:
- I copied ProcessUploadServlet.java from jbpm source, and created my own version in my
webapp source code.
- In web.xml I used my ProcessUploadServlet.java, instead of the one in the jpbm package.
- I copied the method 'GraphSession.deployProcessDefinition(processDefinition)'
into my ProcessUploadServlet.java
- I copied the method 'GraphSession.findLatestProcessDefinition' into my
ProcessUploadServlet.java
- In the handleRequest method in my ProcessUploadServlet.java, where the
deployProcessDefinition method is called, I replaced it to call my own
deployProcessDefinition method, as shown below:
String updateProcessDefinitionFilesStr =
(String)request.getParameter(Constants.UPDATE_PROCESS_DEFINITION_FILES);
| boolean updateProcessDefinition = false;
| if (updateProcessDefinitionFilesStr != null &&
updateProcessDefinitionFilesStr.equalsIgnoreCase("Yes")) {
| updateProcessDefinition = true;
| }
- I then modified my copy of the deployProcessDefinition to look as follows:
/**
| * The code for the original method can be found at:
jbpm-jpdl-3.2.2\src\jpdl\org\jbpm\db\GraphSession.java
| * We are using our customized method instead, so we can update Process Definition
files if we want,
| * instead of creating a new version.
| * Note: if the version of JBPM is updated, we need to re-look at this method to make
sure
| * it will still work according to the new version.
| * @param processDefinition
| * @param jbpmContext
| * @param updateProcessDefinition
| */
| private void deployProcessDefinition(ProcessDefinition processDefinition, JbpmContext
jbpmContext, boolean updateProcessDefinition) {
| Session session = jbpmContext.getSession();
| String processDefinitionName = processDefinition.getName();
| // if the process definition has a name (process versioning only applies to named
process definitions)
| if (processDefinitionName!=null) {
| // find the current latest process definition
| ProcessDefinition previousLatestVersion =
findLatestProcessDefinition(processDefinitionName, jbpmContext);
| // if there is a current latest process definition
| if (previousLatestVersion!=null) {
| if (updateProcessDefinition) {
| log.info("Updating Process Definition
'"+previousLatestVersion.getName()+"' version
'"+previousLatestVersion.getVersion()+"'");
| Map fileBytes = processDefinition.getFileDefinition().getBytesMap();
| FileDefinition previousFileDefinition =
previousLatestVersion.getFileDefinition();
| session.createSQLQuery("delete from jbpm_byteblock where PROCESSFILE_ IN
(select ID_ from jbpm_bytearray where FILEDEFINITION_ =
"+previousFileDefinition.getId()+")").executeUpdate();
| session.createSQLQuery("delete from jbpm_bytearray where FILEDEFINITION_ =
"+previousFileDefinition.getId()).executeUpdate();
| for (Iterator it = fileBytes.keySet().iterator();it.hasNext();) {
| String fileName = (String)it.next();
| previousFileDefinition.addFile(fileName, (byte[])fileBytes.get(fileName));
| }
| //don't change version, but instead update existing process definition
| session.save(previousFileDefinition);
| log.info("Process Definition Updated.");
| return;
| }
| else {
| //new version
| log.info("Creating new version
'"+(previousLatestVersion.getVersion()+1)+"' for Process Definition
'"+processDefinition.getName()+"'");
| processDefinition.setVersion(previousLatestVersion.getVersion()+1);
| }
| }
| else {
| // start from 1
| processDefinition.setVersion(1);
| }
|
| session.save(processDefinition);
|
| }
| else {
| throw new JbpmException("process definition does not have a name");
| }
| }
- In eclipse, when deploying my Process Definition, under the 'Server Deployer'
field, I add on the parameter 'updateProcessDefinitionFiles=Yes'. Eg:
/workflow/upload?updateProcessDefinitionFiles=Yes
This seems to work for me, if all I want to do is update the ProcessDefinition's
FileDefinition object with new files. (ie. updating the files in the database).
Any feedback is welcome, I would like to know if there's a better way to do it, or if
you see any possible problems/pitfalls with this way of doing it.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4140108#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...