[jbpm-commits] JBoss JBPM SVN: r4338 - in jbpm4/branches/tbaeyens/modules: api/src/main/java/org/jbpm/session and 11 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Mar 26 16:53:33 EDT 2009


Author: tom.baeyens at jboss.com
Date: 2009-03-26 16:53:33 -0400 (Thu, 26 Mar 2009)
New Revision: 4338

Added:
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetResourceAsStream.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/DeploymentResourcesTest.java
Removed:
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetAttachment.java
   jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessAttachmentsTest.java
Modified:
   jbpm4/branches/tbaeyens/modules/api/src/main/java/org/jbpm/ProcessService.java
   jbpm4/branches/tbaeyens/modules/api/src/main/java/org/jbpm/RepositoryService.java
   jbpm4/branches/tbaeyens/modules/api/src/main/java/org/jbpm/session/RepositorySession.java
   jbpm4/branches/tbaeyens/modules/examples/src/test/java/org/jbpm/examples/hql/HqlTest.java
   jbpm4/branches/tbaeyens/modules/examples/src/test/java/org/jbpm/examples/sql/SqlTest.java
   jbpm4/branches/tbaeyens/modules/examples/src/test/resources/org/jbpm/examples/hql/process.jpdl.xml
   jbpm4/branches/tbaeyens/modules/examples/src/test/resources/org/jbpm/examples/sql/process.jpdl.xml
   jbpm4/branches/tbaeyens/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/model/JpdlProcessDefinition.java
   jbpm4/branches/tbaeyens/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
   jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessServiceImpl.java
Log:
revisiting deployment

Modified: jbpm4/branches/tbaeyens/modules/api/src/main/java/org/jbpm/ProcessService.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/api/src/main/java/org/jbpm/ProcessService.java	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/api/src/main/java/org/jbpm/ProcessService.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -58,10 +58,6 @@
   /** deletes process definition, the existing executions and the history. */
   void deleteProcessDefinitionCascade(String processDefinitionId);
   
-  /** retrieves an attachment of a process definition */
-  byte[] getAttachment(String processDefinitionId, String name);
-
-  
   /** provide a userId that will be used in the next method invocation 
    * on this service by this thread. */
   void setUserId(String userId);

Modified: jbpm4/branches/tbaeyens/modules/api/src/main/java/org/jbpm/RepositoryService.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/api/src/main/java/org/jbpm/RepositoryService.java	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/api/src/main/java/org/jbpm/RepositoryService.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -21,6 +21,7 @@
  */
 package org.jbpm;
 
+import java.io.InputStream;
 
 
 /**
@@ -32,6 +33,6 @@
 
   void deleteDeployment(long deploymentDbid);
 
-  byte[] getResource(long deploymentDbid, String resourceName);
+  InputStream getResourceAsStream(long deploymentDbid, String resourceName);
 
 }
\ No newline at end of file

Modified: jbpm4/branches/tbaeyens/modules/api/src/main/java/org/jbpm/session/RepositorySession.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/api/src/main/java/org/jbpm/session/RepositorySession.java	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/api/src/main/java/org/jbpm/session/RepositorySession.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -21,6 +21,7 @@
  */
 package org.jbpm.session;
 
+import java.io.InputStream;
 import java.util.List;
 
 import org.jbpm.Deployment;
@@ -31,11 +32,13 @@
  */
 public interface RepositorySession {
 
+  long deploy(Deployment deployment);
+
   Object getObject(long deploymentDbid, String objectName);
 
-  long deploy(Deployment deployment);
-
   List<String> findObjectNames(String propertyKey, String propertyValue);
   List<String> findObjectPropertyValues(String objectName, String propertyKey);
   Object findObjectByPropertyValue(String propertyKey, String propertyValue);
+
+  InputStream getResourceAsStream(long deploymentDbid, String resourceName);
 }

Modified: jbpm4/branches/tbaeyens/modules/examples/src/test/java/org/jbpm/examples/hql/HqlTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/examples/src/test/java/org/jbpm/examples/hql/HqlTest.java	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/examples/src/test/java/org/jbpm/examples/hql/HqlTest.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -22,12 +22,10 @@
 package org.jbpm.examples.hql;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 
 import org.jbpm.Execution;
+import org.jbpm.task.Task;
 import org.jbpm.test.JbpmTestCase;
 
 
@@ -37,22 +35,33 @@
 public class HqlTest extends JbpmTestCase {
 
   public void testHql() {
+    // add task laundry
+    Task task = taskService.newTask();
+    task.setName("laundry");
+    taskService.saveTask(task);
+    
+    // add task dishes
+    task = taskService.newTask();
+    task.setName("dishes");
+    taskService.saveTask(task);
+    
+    // add task iron
+    task = taskService.newTask();
+    task.setName("iron");
+    taskService.saveTask(task);
+    
     deployJpdlResource("org/jbpm/examples/hql/process.jpdl.xml");
     
     Execution execution = executionService.startProcessInstanceByKey("Hql");
     String executionId = execution.getId();
     
-    Set<String> variableNames = executionService.getVariableNames(executionId);
-    Map<String, Object> variables = executionService.getVariables(executionId, variableNames);
-
-    Map<String, Object> expectedVariables = new HashMap<String, Object>();
-    List<String> activityNames = new ArrayList<String>();
-    activityNames.add("get process names");
-    activityNames.add("count activities");
-    expectedVariables.put("activities with o", activityNames);
-
-    expectedVariables.put("activities", new Long(4));
-
-    assertEquals(expectedVariables, variables);
+    List<String> expectedTaskNames = new ArrayList<String>();
+    expectedTaskNames.add("dishes");
+    expectedTaskNames.add("iron");
+    Object taskNames = executionService.getVariable(executionId, "tasknames with i");
+    assertEquals(expectedTaskNames, taskNames);
+    
+    Object activities = executionService.getVariable(executionId, "tasks");
+    assertEquals("3", activities.toString());
   }
 }

Modified: jbpm4/branches/tbaeyens/modules/examples/src/test/java/org/jbpm/examples/sql/SqlTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/examples/src/test/java/org/jbpm/examples/sql/SqlTest.java	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/examples/src/test/java/org/jbpm/examples/sql/SqlTest.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -25,6 +25,7 @@
 import java.util.List;
 
 import org.jbpm.Execution;
+import org.jbpm.task.Task;
 import org.jbpm.test.JbpmTestCase;
 
 
@@ -34,19 +35,33 @@
 public class SqlTest extends JbpmTestCase {
 
   public void testSql() {
+    // add task laundry
+    Task task = taskService.newTask();
+    task.setName("laundry");
+    taskService.saveTask(task);
+    
+    // add task dishes
+    task = taskService.newTask();
+    task.setName("dishes");
+    taskService.saveTask(task);
+    
+    // add task iron
+    task = taskService.newTask();
+    task.setName("iron");
+    taskService.saveTask(task);
+
     deployJpdlResource("org/jbpm/examples/sql/process.jpdl.xml");
     
     Execution execution = executionService.startProcessInstanceByKey("Sql");
     String executionId = execution.getId();
     
-    List<String> expectedActivityNames = new ArrayList<String>();
-    expectedActivityNames.add("get process names");
-    expectedActivityNames.add("count activities");
-    Object activityNames = executionService.getVariable(executionId, "activities with o");
-    assertEquals(expectedActivityNames, activityNames);
+    List<String> expectedTaskNames = new ArrayList<String>();
+    expectedTaskNames.add("dishes");
+    expectedTaskNames.add("iron");
+    Object taskNames = executionService.getVariable(executionId, "tasknames with i");
+    assertEquals(expectedTaskNames, taskNames);
     
-    Object activities = executionService.getVariable(executionId, "activities");
-    assertEquals("4", activities.toString());
+    Object activities = executionService.getVariable(executionId, "tasks");
+    assertEquals("3", activities.toString());
   }
-
 }

Modified: jbpm4/branches/tbaeyens/modules/examples/src/test/resources/org/jbpm/examples/hql/process.jpdl.xml
===================================================================
--- jbpm4/branches/tbaeyens/modules/examples/src/test/resources/org/jbpm/examples/hql/process.jpdl.xml	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/examples/src/test/resources/org/jbpm/examples/hql/process.jpdl.xml	2009-03-26 20:53:33 UTC (rev 4338)
@@ -3,30 +3,30 @@
 <process name="Hql" xmlns="http://jbpm.org/4/jpdl">
 
   <start g="17,20,48,48">
-    <transition to="get process names" />
+    <transition to="get task names" />
   </start>
 
-  <hql name="get process names"
-       var="activities with o"
+  <hql name="get task names"
+       var="tasknames with i"
        g="96,16,115,52">
     <query>
-      select activity.name
-      from org.jbpm.pvm.internal.model.ActivityImpl as activity
-      where activity.name like :activityName
+      select task.name
+      from org.jbpm.pvm.internal.task.TaskImpl as task
+      where task.name like :taskName
     </query>
     <parameters>
-      <string name="activityName" value="%o%" />
+      <string name="taskName" value="%i%" />
     </parameters>
-    <transition to="count activities" />
+    <transition to="count tasks" />
   </hql>
   
-  <hql name="count activities"
-       var="activities"
+  <hql name="count tasks"
+       var="tasks"
        unique="true"
        g="243,16,95,52">
     <query>
       select count(*)
-      from org.jbpm.pvm.internal.model.ActivityImpl
+      from org.jbpm.pvm.internal.task.TaskImpl
     </query>
     <transition to="wait" />
   </hql>

Modified: jbpm4/branches/tbaeyens/modules/examples/src/test/resources/org/jbpm/examples/sql/process.jpdl.xml
===================================================================
--- jbpm4/branches/tbaeyens/modules/examples/src/test/resources/org/jbpm/examples/sql/process.jpdl.xml	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/examples/src/test/resources/org/jbpm/examples/sql/process.jpdl.xml	2009-03-26 20:53:33 UTC (rev 4338)
@@ -3,30 +3,30 @@
 <process name="Sql" xmlns="http://jbpm.org/4/jpdl">
 
   <start g="16,20,48,48">
-    <transition to="get process names" />
+    <transition to="get task names" />
   </start>
 
-  <sql name="get process names"
-       var="activities with o"
+  <sql name="get task names"
+       var="tasknames with i"
        g="96,16,126,52">
     <query>
       select NAME_
-      from JBPM_ACTIVITY 
-      where NAME_ like :activityName
+      from JBPM_TASK
+      where NAME_ like :name
     </query>
     <parameters>
-      <string name="activityName" value="%o%" />
+      <string name="name" value="%i%" />
     </parameters>
-    <transition to="count activities" />
+    <transition to="count tasks" />
   </sql>
   
-  <sql name="count activities"
-       var="activities"
+  <sql name="count tasks"
+       var="tasks"
        unique="true"
        g="254,16,92,52">
     <query>
       select count(*)
-      from JBPM_ACTIVITY
+      from JBPM_TASK
     </query>
     <transition to="wait" />
   </sql>

Modified: jbpm4/branches/tbaeyens/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/model/JpdlProcessDefinition.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/model/JpdlProcessDefinition.java	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/model/JpdlProcessDefinition.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -45,6 +45,7 @@
 
   public SwimlaneDefinitionImpl createSwimlaneDefinition(String name) {
     SwimlaneDefinitionImpl swimlaneDefinition = new SwimlaneDefinitionImpl();
+    swimlaneDefinition.setName(name);
     swimlaneDefinitions.put(name, swimlaneDefinition);
     return swimlaneDefinition;
   }

Modified: jbpm4/branches/tbaeyens/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -47,37 +47,34 @@
   public void deploy(DeploymentImpl deployment) {
     
     for (String resourceName: deployment.getResourceNames()) {
-      InputStream inputStream = deployment.getResourceAsStream(resourceName);
       
-      Parse parse = jpdlParser.createParse();
-      parse.setProblems(deployment.getProblems());
-      parse.setInputStream(inputStream);
-      parse.execute();
-      
-      JpdlProcessDefinition processDefinition = 
-          (JpdlProcessDefinition) parse.getDocumentObject();
+      if (resourceName.endsWith(".jpdl.xml")) {
+        InputStream inputStream = deployment.getResourceAsStream(resourceName);
+        Parse parse = jpdlParser.createParse();
+        parse.setProblems(deployment.getProblems());
+        parse.setInputStream(inputStream);
+        parse.execute();
+        JpdlProcessDefinition processDefinition = (JpdlProcessDefinition) parse.getDocumentObject();
+        if ((processDefinition != null) && (processDefinition.getName() != null)) {
+          String processDefinitionName = processDefinition.getName();
 
-      if ( (processDefinition!=null)
-           && (processDefinition.getName()!=null)
-         ) {
-        String processDefinitionName = processDefinition.getName();
+          processDefinition.setDeploymentDbid(deployment.getDbid());
 
-        processDefinition.setDeploymentDbid(deployment.getDbid());
-        
-        String key = deployment.getObjectProperty(processDefinitionName, "jpdl.key");
-        if (key!=null) {
-          String id = deployment.getObjectProperty(processDefinitionName, "jpdl.id");
-          processDefinition.setId(id);
-          processDefinition.setKey(key);
-          deployment.addObject(processDefinitionName, processDefinition);
-          
-        } else {
-          checkKey(processDefinition, deployment);
-          checkId(processDefinition, deployment);
+          String key = deployment.getObjectProperty(processDefinitionName, "jpdl.key");
+          if (key != null) {
+            String id = deployment.getObjectProperty(processDefinitionName, "jpdl.id");
+            processDefinition.setId(id);
+            processDefinition.setKey(key);
+            deployment.addObject(processDefinitionName, processDefinition);
 
-          deployment.addObject(processDefinitionName, processDefinition);
-          deployment.addObjectProperty(processDefinitionName, "jpdl.key", processDefinition.getKey());
-          deployment.addObjectProperty(processDefinitionName, "jpdl.id", processDefinition.getId());
+          } else {
+            checkKey(processDefinition, deployment);
+            checkId(processDefinition, deployment);
+
+            deployment.addObject(processDefinitionName, processDefinition);
+            deployment.addObjectProperty(processDefinitionName, "jpdl.key", processDefinition.getKey());
+            deployment.addObjectProperty(processDefinitionName, "jpdl.id", processDefinition.getId());
+          }
         }
       }
     }

Deleted: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetAttachment.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetAttachment.java	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetAttachment.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -1,51 +0,0 @@
-/*
- * 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 org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.cmd.Command;
-import org.jbpm.env.Environment;
-import org.jbpm.session.PvmDbSession;
-
-
-/**
- * @author Tom Baeyens
- */
-public class GetAttachment extends AbstractCommand<byte[]> {
-
-  private static final long serialVersionUID = 1L;
-  
-  protected String processDefinitionId;
-  protected String name;
-  
-  public GetAttachment(String processDefinitionId, String name) {
-    this.processDefinitionId = processDefinitionId;
-    this.name = name;
-  }
-
-  public byte[] execute(Environment environment) throws Exception {
-    PvmDbSession pvmDbSession = environment.get(PvmDbSession.class);
-    ClientProcessDefinition processDefinition = pvmDbSession.findProcessDefinitionById(processDefinitionId);
-    return processDefinition.getAttachment(name);
-  }
-
-}

Added: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetResourceAsStream.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetResourceAsStream.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetResourceAsStream.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -0,0 +1,50 @@
+/*
+ * 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.env.Environment;
+import org.jbpm.session.RepositorySession;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class GetResourceAsStream extends AbstractCommand<InputStream> {
+
+  private static final long serialVersionUID = 1L;
+  
+  protected long deploymentDbid;
+  protected String resourceName;
+
+  public GetResourceAsStream(long deploymentDbid, String resourceName) {
+    this.deploymentDbid = deploymentDbid;
+    this.resourceName = resourceName;
+  }
+
+  public InputStream execute(Environment environment) {
+    RepositorySession repositorySession = environment.get(RepositorySession.class);
+    InputStream resourceStream = repositorySession.getResourceAsStream(deploymentDbid, resourceName);
+    return resourceStream;
+  }
+}


Property changes on: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetResourceAsStream.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -1016,10 +1016,7 @@
   }
 
   public String getActivityName() {
-    if (getActivity()!=null) {
-      return getActivity().getName();
-    }
-    return null;
+    return activityName;
   }
 
   public ProcessDefinitionImpl getProcessDefinition() {

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositoryServiceImpl.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -21,9 +21,12 @@
  */
 package org.jbpm.pvm.internal.repository;
 
+import java.io.InputStream;
+
 import org.jbpm.Deployment;
 import org.jbpm.RepositoryService;
 import org.jbpm.cmd.CommandService;
+import org.jbpm.pvm.internal.cmd.GetResourceAsStream;
 
 /**
  * @author Tom Baeyens
@@ -39,7 +42,7 @@
   public void deleteDeployment(long deploymentDbid) {
   }
   
-  public byte[] getResource(long deploymentDbid, String resource) {
-    return null;
+  public InputStream getResourceAsStream(long deploymentDbid, String resource) {
+    return commandService.execute(new GetResourceAsStream(deploymentDbid, resource));
   }
 }

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -21,6 +21,7 @@
  */
 package org.jbpm.pvm.internal.repository;
 
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -65,6 +66,10 @@
 
     return deploymentImpl.getDbid();
   }
+  
+  public DeploymentImpl getDeployment(long deploymentDbid) {
+    return (DeploymentImpl) session.get(DeploymentImpl.class, deploymentDbid);
+  }
 
   public Object getObject(long deploymentDbid, String objectName) {
     Object object = repositoryCache.get(deploymentDbid, objectName);
@@ -121,4 +126,12 @@
       "  and deploymentProperty.key = '"+key+"' "
     ).list();
   }
+
+  public InputStream getResourceAsStream(long deploymentDbid, String resourceName) {
+    DeploymentImpl deployment = getDeployment(deploymentDbid);
+    if (deployment==null) {
+      throw new JbpmException("deployment "+deploymentDbid+" doesn't exist");
+    }
+    return deployment.getResourceAsStream(resourceName);
+  }
 }

Modified: jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessServiceImpl.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessServiceImpl.java	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ProcessServiceImpl.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -34,7 +34,7 @@
 import org.jbpm.pvm.internal.cmd.FindProcessDefinitionByIdCmd;
 import org.jbpm.pvm.internal.cmd.FindProcessDefinitionKeysCmd;
 import org.jbpm.pvm.internal.cmd.FindProcessDefinitionsByKeyCmd;
-import org.jbpm.pvm.internal.cmd.GetAttachment;
+import org.jbpm.pvm.internal.cmd.GetResourceAsStream;
 import org.jbpm.pvm.internal.query.ProcessDefinitionQueryImpl;
 import org.jbpm.pvm.internal.repository.DeploymentImpl;
 
@@ -73,10 +73,6 @@
     commandService.execute(new DeleteProcessDefinitionCmd(processDefinitionId, true, true));
   }
 
-  public byte[] getAttachment(String processDefinitionId, String name) {
-    return commandService.execute(new GetAttachment(processDefinitionId, name));
-  }
-
   public ProcessDefinitionQuery createProcessDefinitionQuery() {
     return new ProcessDefinitionQueryImpl(commandService);
   }

Added: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/DeploymentResourcesTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/DeploymentResourcesTest.java	                        (rev 0)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/DeploymentResourcesTest.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -0,0 +1,106 @@
+/*
+ * 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.process;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+
+import org.jbpm.JbpmException;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class DeploymentResourcesTest extends JbpmTestCase {
+
+  public void testProcessWithNameOnly() {
+    byte[] lotOfBytes = generateString("a lot of bytes ", 5000).getBytes();
+    byte[] otherBytes = generateString("other bytes ", 5000).getBytes();
+    
+    long deploymentDbid = 
+    processService.createDeployment()
+      .addResourceFromString("xmlstring.jpdl.xml", 
+                 "<process name='Insurance claim'>" +
+                 "  <start />" +
+                 "</process>")
+      .addResourceFromInputStream("a lot of attachment", new ByteArrayInputStream(lotOfBytes))
+      .addResourceFromInputStream("other attachment", new ByteArrayInputStream(otherBytes))
+      .deploy();
+    
+    registerDeployment(deploymentDbid);
+
+    InputStream stream = repositoryService.getResourceAsStream(deploymentDbid, "a lot of attachment");
+    byte[] retrievedLotOfBytes = readBytes(stream);
+    assertNotNull(retrievedLotOfBytes);
+    assertTrue(Arrays.equals(lotOfBytes, retrievedLotOfBytes));
+    
+    stream = repositoryService.getResourceAsStream(deploymentDbid, "other attachment");
+    byte[] retrievedOtherBytes = readBytes(stream);
+    assertNotNull(retrievedOtherBytes);
+    assertTrue(Arrays.equals(otherBytes, retrievedOtherBytes));
+  }
+
+  protected String generateString(String base, int multiplier) {
+    StringBuffer buffer = new StringBuffer();
+    for (int i=0; i<multiplier; i++) {
+      buffer.append(base);
+    }
+    String string = buffer.toString();
+    return string;
+  }
+
+  public static byte[] readBytes(InputStream inputStream) {
+    byte[] bytes = null;
+    if (inputStream==null) {
+      throw new JbpmException("inputStream is null");
+    }
+    try {
+      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+      transfer(inputStream, outputStream);
+      bytes = outputStream.toByteArray();
+      outputStream.close();
+      return bytes;
+    } catch (IOException e) {
+      throw new JbpmException("couldn't read bytes from inputStream", e);
+    }
+  }
+  public static int transfer(InputStream in, OutputStream out) {
+    int total = 0;
+    byte[] buffer = new byte[4096];
+    try {
+      int bytesRead = in.read( buffer );
+      while ( bytesRead != -1 ) {
+        out.write( buffer, 0, bytesRead );
+        total += bytesRead;
+        bytesRead = in.read( buffer );
+      }
+      return total;
+    } catch (IOException e) {
+      throw new JbpmException("couldn't write bytes to output stream", e);
+    }
+  }
+}


Property changes on: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/DeploymentResourcesTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Deleted: jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessAttachmentsTest.java
===================================================================
--- jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessAttachmentsTest.java	2009-03-26 19:23:55 UTC (rev 4337)
+++ jbpm4/branches/tbaeyens/modules/test-db/src/test/java/org/jbpm/test/process/ProcessAttachmentsTest.java	2009-03-26 20:53:33 UTC (rev 4338)
@@ -1,68 +0,0 @@
-/*
- * 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.process;
-
-import java.io.ByteArrayInputStream;
-import java.util.Arrays;
-import java.util.List;
-
-import org.jbpm.ProcessDefinition;
-import org.jbpm.test.JbpmTestCase;
-
-
-/**
- * @author Tom Baeyens
- */
-public class ProcessAttachmentsTest extends JbpmTestCase {
-
-  public void testProcessWithNameOnly() {
-    byte[] lotOfBytes = generateString("a lot of bytes ", 5000).getBytes();
-    byte[] otherBytes = generateString("other bytes ", 5000).getBytes();
-    
-    long deploymentDbid = 
-    processService.createDeployment()
-      .addResourceFromString("xmlstring.jpdl.xml", 
-                 "<process name='Insurance claim'>" +
-                 "  <start />" +
-                 "</process>")
-      .addResourceFromInputStream("a lot of attachment", new ByteArrayInputStream(lotOfBytes))
-      .addResourceFromInputStream("other attachment", new ByteArrayInputStream(otherBytes))
-      .deploy();
-    
-    registerDeployment(deploymentDbid);
-
-    byte[] retrievedLotOfBytes = repositoryService.getResource(deploymentDbid, "a lot of attachment");
-    assertTrue(Arrays.equals(lotOfBytes, retrievedLotOfBytes));
-    
-    byte[] retrievedOtherBytes = repositoryService.getResource(deploymentDbid, "other attachment");
-    assertTrue(Arrays.equals(otherBytes, retrievedOtherBytes));
-  }
-
-  protected String generateString(String base, int multiplier) {
-    StringBuffer buffer = new StringBuffer();
-    for (int i=0; i<multiplier; i++) {
-      buffer.append(base);
-    }
-    String string = buffer.toString();
-    return string;
-  }
-}




More information about the jbpm-commits mailing list