[jbpm-commits] JBoss JBPM SVN: r5197 - jbpm4/trunk/modules/integration/graphView-plugin/src/main/java/org/jbpm/integration/console/graphView.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jul 2 17:52:18 EDT 2009


Author: heiko.braun at jboss.com
Date: 2009-07-02 17:52:17 -0400 (Thu, 02 Jul 2009)
New Revision: 5197

Modified:
   jbpm4/trunk/modules/integration/graphView-plugin/src/main/java/org/jbpm/integration/console/graphView/GraphViewerPluginImpl.java
Log:
Process diagram is optional

Modified: jbpm4/trunk/modules/integration/graphView-plugin/src/main/java/org/jbpm/integration/console/graphView/GraphViewerPluginImpl.java
===================================================================
--- jbpm4/trunk/modules/integration/graphView-plugin/src/main/java/org/jbpm/integration/console/graphView/GraphViewerPluginImpl.java	2009-07-02 21:12:56 UTC (rev 5196)
+++ jbpm4/trunk/modules/integration/graphView-plugin/src/main/java/org/jbpm/integration/console/graphView/GraphViewerPluginImpl.java	2009-07-02 21:52:17 UTC (rev 5197)
@@ -26,6 +26,8 @@
 import java.io.InputStream;
 import java.util.List;
 import java.util.ArrayList;
+import java.net.URL;
+import java.net.MalformedURLException;
 
 import javax.naming.InitialContext;
 
@@ -42,6 +44,8 @@
 import org.jbpm.pvm.internal.env.Environment;
 import org.jbpm.pvm.internal.env.EnvironmentFactory;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.integration.spi.mgmt.ServerConfig;
+import org.jbpm.integration.spi.mgmt.ServerConfigFactory;
 
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
@@ -49,13 +53,36 @@
 public class GraphViewerPluginImpl implements GraphViewerPlugin
 {
 
-  private ProcessEngine processEngine = null;
+  protected final static String WEB_CONTEXT = "/gwt-console-server/rs";
 
+  protected ProcessEngine processEngine;
+  protected ServerConfig serverConfig = null;  // lazy
+
+
   public GraphViewerPluginImpl()
   {
     initializeProcessEngine();
   }
 
+  protected ServerConfig getServerConfig()
+  {
+    if(null==serverConfig)
+    {
+      serverConfig = ServerConfigFactory.getServerConfig();
+    }
+    return serverConfig;
+  }
+
+  protected StringBuilder getBaseUrl()
+  {
+    StringBuilder spec = new StringBuilder();
+    spec.append("http://");
+    spec.append(getServerConfig().getWebServiceHost());
+    spec.append(":").append(getServerConfig().getWebServicePort());
+    spec.append(WEB_CONTEXT);
+    return spec;
+  }
+
   public byte[] getProcessImage(String processId)
   {
 
@@ -74,7 +101,7 @@
       );
 
       if(null==in)
-        return null; //throw new RuntimeException("Failed to retrieve image resource: " +imgRes);
+        throw new RuntimeException("Failed to retrieve image resource: " +imgRes);
 
       ByteArrayOutputStream out = new ByteArrayOutputStream();
       final int BUF_SIZE = 1 << 8; //1KiB buffer
@@ -163,4 +190,64 @@
     }
   }
 
+  public URL getDiagramURL(String id)
+  {
+    URL result = null;
+
+    // check resource availability
+    Environment env = ((EnvironmentFactory)processEngine).openEnvironment();
+    boolean hasImageResource = false;
+
+    try
+    {
+      RepositoryService repositoryService = this.processEngine.getRepositoryService();
+      ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
+          .processDefinitionId(id)
+          .uniqueResult();
+
+      InputStream inputStream = null;
+      if(processDefinition!=null)//TODO: JBPM-2383 Suspended definitions don't show up here
+      {
+        String imgRes = processDefinition.getImageResourceName();
+        inputStream = repositoryService.getResourceAsStream(
+            processDefinition.getDeploymentId(), imgRes
+        );
+      }
+
+      if(inputStream!=null)
+      {
+        hasImageResource = true;
+        try
+        {
+          inputStream.close();
+        }
+        catch (IOException e)
+        {
+          throw new RuntimeException("Failed to close stream", e);
+        }
+      }
+
+    }
+    finally{
+      env.close();
+    }
+
+    if(hasImageResource)
+    {
+      StringBuilder sb = getBaseUrl().append("/process/definition/");
+      sb.append(id);
+      sb.append("/image");
+
+      try
+      {
+        result = new URL(sb.toString());
+      }
+      catch (MalformedURLException e)
+      {
+        throw new RuntimeException("Failed to create url", e);
+      }
+    }
+    
+    return result;
+  }
 }




More information about the jbpm-commits mailing list