[jbpm-commits] JBoss JBPM SVN: r5732 - in jbpm4/trunk/modules: jpdl and 6 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Oct 12 09:22:58 EDT 2009
Author: tom.baeyens at jboss.com
Date: 2009-10-12 09:22:58 -0400 (Mon, 12 Oct 2009)
New Revision: 5732
Added:
jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/test/update/
jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/test/update/ProcessUpdateTest.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/UpdateDeploymentResourceCmd.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/RepositoryService.java
jbpm4/trunk/modules/jpdl/pom.xml
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/Deployer.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeployerManager.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/ProcessDeployer.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/RepositorySession.java
Log:
JBPM-2578 adding ability to update a deployment resource
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/RepositoryService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/RepositoryService.java 2009-10-12 08:27:44 UTC (rev 5731)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/RepositoryService.java 2009-10-12 13:22:58 UTC (rev 5732)
@@ -91,4 +91,7 @@
/** the coordinates for the activity on
* {@link ProcessDefinition#getImageResourceName() the process image}. */
ActivityCoordinates getActivityCoordinates(String processDefinitionId, String activityName);
+
+ /** update an existing deployment resource */
+ void updateDeploymentResource(String deploymentId, String string, InputStream inputStream);
}
Modified: jbpm4/trunk/modules/jpdl/pom.xml
===================================================================
--- jbpm4/trunk/modules/jpdl/pom.xml 2009-10-12 08:27:44 UTC (rev 5731)
+++ jbpm4/trunk/modules/jpdl/pom.xml 2009-10-12 13:22:58 UTC (rev 5732)
@@ -49,6 +49,19 @@
<artifactId>junit</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>org/jbpm/test/update/ProcessUpdateTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
<!-- Profiles -->
<profiles>
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java 2009-10-12 08:27:44 UTC (rev 5731)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java 2009-10-12 13:22:58 UTC (rev 5732)
@@ -21,14 +21,33 @@
*/
package org.jbpm.jpdl.internal.repository;
+import java.io.ByteArrayInputStream;
+import java.io.StringWriter;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.internal.log.Log;
import org.jbpm.jpdl.internal.xml.JpdlParser;
+import org.jbpm.pvm.internal.repository.DeploymentImpl;
import org.jbpm.pvm.internal.repository.ProcessDeployer;
+import org.jbpm.pvm.internal.util.XmlUtil;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
/**
* @author Tom Baeyens
*/
public class JpdlDeployer extends ProcessDeployer {
+ private static Log log = Log.getLog(JpdlDeployer.class.getName());
+ private static Parser parser = new Parser();
+
static JpdlParser jpdlParser = new JpdlParser();
static final String jpdlExtension = ".jpdl.xml";
@@ -36,4 +55,57 @@
super(jpdlExtension, jpdlParser);
}
+ public void updateResource(DeploymentImpl deployment, String resourceName, byte[] bytes) {
+ if (resourceName.endsWith(".jpdl.xml")) {
+ Document document = parser
+ .createParse()
+ .setInputStream(new ByteArrayInputStream(bytes))
+ .execute()
+ .getDocument();
+ Element documentElement = document.getDocumentElement();
+ String tagName = XmlUtil.getTagLocalName(documentElement);
+
+ if ("process-update".equals(tagName)) {
+ updateJpdlProcessResource(deployment, resourceName, document);
+ return;
+ }
+ }
+
+ super.updateResource(deployment, resourceName, bytes);
+ }
+
+ public void updateJpdlProcessResource(DeploymentImpl deployment, String resourceName, Document updateDocument) {
+ byte[] processBytes = deployment.getBytes(resourceName);
+ Document processDocument = parser
+ .createParse()
+ .setInputStream(new ByteArrayInputStream(processBytes))
+ .execute()
+ .checkErrors("jPDL process update document")
+ .getDocument();
+ Element processElement = processDocument.getDocumentElement();
+
+ Element updateProcessElement = updateDocument.getDocumentElement();
+ Element updateDescriptionElement = XmlUtil.element(updateProcessElement, "description");
+ if (updateDescriptionElement!=null) {
+ Element processDescriptionElement = XmlUtil.element(processElement, "description");
+ if (processDescriptionElement!=null) {
+ processElement.removeChild(processDescriptionElement);
+ }
+ processElement.appendChild(updateDescriptionElement);
+ }
+
+ try {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ //initialize StreamResult with File object to save to file
+ StreamResult result = new StreamResult(new StringWriter());
+ DOMSource source = new DOMSource(processDocument);
+ transformer.transform(source, result);
+
+ byte[] bytes = result.getWriter().toString().getBytes();
+ deployment.addResourceFromInputStream(resourceName, new ByteArrayInputStream(bytes));
+ } catch (Exception e) {
+ throw new JbpmException("couldn't serialize updated process dom model", e);
+ }
+ }
}
Added: jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/test/update/ProcessUpdateTest.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/test/update/ProcessUpdateTest.java (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/test/update/ProcessUpdateTest.java 2009-10-12 13:22:58 UTC (rev 5732)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test.update;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.jbpm.pvm.internal.util.XmlUtil;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.jbpm.test.JbpmTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ProcessUpdateTest extends JbpmTestCase {
+
+ public void testReplaceActivity() {
+ String deploymentId = deployJpdlXmlString(
+ "<process name='DescriptionProcess'>" +
+ " <start>" +
+ " <transition to='s' />" +
+ " </start>" +
+ " <state name='s' />" +
+ "</process>"
+ );
+
+ updateJpdlXmlString(
+ deploymentId,
+ "<update-process>" +
+ " <description>" +
+ " This is a description" +
+ " </description>" +
+ "</update-process>"
+ );
+
+ InputStream inputStream = repositoryService.getResourceAsStream(deploymentId, "xmlstring.jpdl.xml");
+
+ Document document = new Parser()
+ .createParse()
+ .setInputStream(inputStream)
+ .execute()
+ .getDocument();
+
+ Element documentElement = document.getDocumentElement();
+ Element descriptionElement = XmlUtil.element(documentElement, "description");
+ assertNotNull(descriptionElement);
+ String description = XmlUtil.getContentText(descriptionElement);
+ assertTextPresent("This is a description", description);
+
+ Element stateSElement = XmlUtil.element(documentElement, "state");
+ assertNotNull(stateSElement);
+ assertEquals("s", stateSElement.getAttribute("name"));
+ }
+
+ public void updateJpdlXmlString(String deploymentId, String xmlString) {
+ InputStream inputStream = new ByteArrayInputStream(xmlString.getBytes());
+ repositoryService.updateDeploymentResource(deploymentId, "xmlstring.jpdl.xml", inputStream);
+ }
+}
Property changes on: jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/test/update/ProcessUpdateTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/UpdateDeploymentResourceCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/UpdateDeploymentResourceCmd.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/UpdateDeploymentResourceCmd.java 2009-10-12 13:22:58 UTC (rev 5732)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.cmd;
+
+import java.io.InputStream;
+
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.cmd.Environment;
+import org.jbpm.pvm.internal.session.RepositorySession;
+import org.jbpm.pvm.internal.util.IoUtil;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class UpdateDeploymentResourceCmd implements Command<Void> {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String deploymentId;
+ protected String resourceName;
+ protected byte[] bytes;
+
+ public UpdateDeploymentResourceCmd(String deploymentId, String resourceName, InputStream inputStream) {
+ this.deploymentId = deploymentId;
+ this.resourceName = resourceName;
+ this.bytes = IoUtil.readBytes(inputStream);
+ }
+
+ public Void execute(Environment environment) throws Exception {
+ RepositorySession repositorySession = environment.get(RepositorySession.class);
+ repositorySession.updateDeploymentResource(deploymentId, resourceName, bytes);
+ return null;
+ }
+
+}
Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/UpdateDeploymentResourceCmd.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/Deployer.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/Deployer.java 2009-10-12 08:27:44 UTC (rev 5731)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/Deployer.java 2009-10-12 13:22:58 UTC (rev 5732)
@@ -30,4 +30,6 @@
void deploy(DeploymentImpl deployment);
+ void updateResource(DeploymentImpl deployment, String resourceName, byte[] bytes);
+
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeployerManager.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeployerManager.java 2009-10-12 08:27:44 UTC (rev 5731)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeployerManager.java 2009-10-12 13:22:58 UTC (rev 5732)
@@ -55,4 +55,13 @@
RepositoryCache repositoryCache = EnvironmentImpl.getFromCurrent(RepositoryCache.class);
repositoryCache.set(deployment.getId(), deployment.getObjects());
}
+
+ public void updateResource(DeploymentImpl deployment, String resourceName, byte[] bytes) {
+ for (Deployer deployer: deployers) {
+ deployer.updateResource(deployment, resourceName, bytes);
+ }
+
+ RepositoryCache repositoryCache = EnvironmentImpl.getFromCurrent(RepositoryCache.class);
+ repositoryCache.remove(deployment.getId());
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/ProcessDeployer.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/ProcessDeployer.java 2009-10-12 08:27:44 UTC (rev 5731)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/ProcessDeployer.java 2009-10-12 13:22:58 UTC (rev 5732)
@@ -191,4 +191,8 @@
processDefinition.setVersion(version);
}
}
+
+ public void updateResource(DeploymentImpl deployment, String resourceName, byte[] bytes) {
+ deployment.addResourceFromInputStream(resourceName, new ByteArrayInputStream(bytes));
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java 2009-10-12 08:27:44 UTC (rev 5731)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java 2009-10-12 13:22:58 UTC (rev 5732)
@@ -42,6 +42,7 @@
import org.jbpm.pvm.internal.cmd.GetStartFormResourceNameCmd;
import org.jbpm.pvm.internal.cmd.ResumeDeploymentCmd;
import org.jbpm.pvm.internal.cmd.SuspendDeploymentCmd;
+import org.jbpm.pvm.internal.cmd.UpdateDeploymentResourceCmd;
import org.jbpm.pvm.internal.query.DeploymentQueryImpl;
import org.jbpm.pvm.internal.query.ProcessDefinitionQueryImpl;
@@ -107,4 +108,8 @@
public String getStartFormResourceName(String processDefinitionId, String activityName) {
return commandService.execute(new GetStartFormResourceNameCmd(processDefinitionId, activityName));
}
+
+ public void updateDeploymentResource(String deploymentId, String resourceName, InputStream inputStream) {
+ commandService.execute(new UpdateDeploymentResourceCmd(deploymentId, resourceName, inputStream));
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java 2009-10-12 08:27:44 UTC (rev 5731)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java 2009-10-12 13:22:58 UTC (rev 5732)
@@ -61,7 +61,11 @@
return deploymentImpl.getId();
}
-
+ public void updateDeploymentResource(String deploymentId, String resourceName, byte[] bytes) {
+ DeploymentImpl deployment = getDeployment(deploymentId);
+ deployerManager.updateResource(deployment, resourceName, bytes);
+ }
+
public void cascadeDeploymentSuspend(DeploymentImpl deployment) {
// cascade to all executions in this deployment
Set<String> processDefinitionIds = deployment.getProcessDefinitionIds();
@@ -206,5 +210,5 @@
}
}
-
+
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/RepositorySession.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/RepositorySession.java 2009-10-12 08:27:44 UTC (rev 5731)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/RepositorySession.java 2009-10-12 13:22:58 UTC (rev 5732)
@@ -46,4 +46,6 @@
ProcessDefinitionImpl findProcessDefinitionById(String processDefinitionId);
ProcessDefinitionImpl findProcessDefinitionByKey(String processDefinitionKey);
+
+ void updateDeploymentResource(String deploymentId, String resourceName, byte[] bytes);
}
More information about the jbpm-commits
mailing list