[jbpm-commits] JBoss JBPM SVN: r2542 - in jbpm3/trunk/modules/gwt-console: rpc/src/main/java/org/jboss/bpm/console/client/model/util and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Oct 15 03:59:29 EDT 2008


Author: heiko.braun at jboss.com
Date: 2008-10-15 03:59:29 -0400 (Wed, 15 Oct 2008)
New Revision: 2542

Added:
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3CommandDelegate.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/gson/
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/gson/GsonFactory.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/gson/SQLDateTypeAdapter.java
Modified:
   jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/ProcessInstance.java
   jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/util/DateLocale.java
   jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/util/SimpleDateFormat.java
   jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/util/SimpleDateParser.java
   jbpm3/trunk/modules/gwt-console/server/pom.xml
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/BufferedResponseWrapper.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/JBPM3Management.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/ProcessManagement.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/DiagramDAO.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3DiagramDAO.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3ProcessDAO.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/MockDiagramDAO.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/MockProcessDAO.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/Transform.java
Log:
JBPM3 DAO implementations based on the CommandServiceBean, first cut

Modified: jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/ProcessInstance.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/ProcessInstance.java	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/ProcessInstance.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -22,8 +22,6 @@
 package org.jboss.bpm.console.client.model;
 
 
-import org.jboss.bpm.console.client.model.util.SimpleDateFormat;
-
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import java.util.Date;
@@ -34,7 +32,7 @@
 @XmlRootElement(name="processInstance")
 public class ProcessInstance
 {
-   private long Id;
+   private long instanceId;
    private long parentId;
 
    private String key;
@@ -48,7 +46,7 @@
 
    public ProcessInstance(long id, long parentId, String status, Date startDate, Date endDate)
    {
-      this.Id = id;
+      this.instanceId = id;
       this.parentId = parentId;
       this.status = status;
       this.startDate = startDate;
@@ -56,14 +54,14 @@
    }
 
    @XmlElement(name = "instanceId")
-   public long getId()
+   public long getInstanceId()
    {
-      return Id;
+      return instanceId;
    }
 
-   public void setId(long id)
+   public void setInstanceId(long instanceId)
    {
-      Id = id;
+      this.instanceId = instanceId;
    }
 
    @XmlElement(name = "parentId")
@@ -100,10 +98,9 @@
    }
 
    @XmlElement(name = "start")
-   public String getStartDate()
+   public Date getStartDate()
    {
-      SimpleDateFormat df = new SimpleDateFormat("y-M-d H:mm:ss");
-      return df.format(startDate);
+      return startDate;
    }
 
    public void setStartDate(Date startDate)
@@ -112,15 +109,9 @@
    }
 
    @XmlElement(name = "end")
-   public String getEndDate()
+   public Date getEndDate()
    {
-      String s = "";
-      if(endDate!=null)
-      {
-         SimpleDateFormat df = new SimpleDateFormat("y-M-d H:m:s");
-         s = df.format(endDate);
-      }
-      return s;
+      return endDate;
    }
 
    public void setEndDate(Date endDate)

Modified: jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/util/DateLocale.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/util/DateLocale.java	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/util/DateLocale.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -1,23 +1,17 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
+ * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
  *
- * 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.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * 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.
+ *    http://www.apache.org/licenses/LICENSE-2.0
  *
- * 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.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 package org.jboss.bpm.console.client.model.util;
 

Modified: jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/util/SimpleDateFormat.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/util/SimpleDateFormat.java	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/util/SimpleDateFormat.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -1,31 +1,22 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
+ * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
  *
- * 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.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * 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.
+ *    http://www.apache.org/licenses/LICENSE-2.0
  *
- * 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.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 package org.jboss.bpm.console.client.model.util;
 
 import java.util.Date;
 
-/**
- * @author Heiko.Braun <heiko.braun at jboss.com>
- */
 @SuppressWarnings("deprecation")
 public class SimpleDateFormat {
    private String format;

Modified: jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/util/SimpleDateParser.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/util/SimpleDateParser.java	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/rpc/src/main/java/org/jboss/bpm/console/client/model/util/SimpleDateParser.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -1,23 +1,17 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
+ * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
  *
- * 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.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * 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.
+ *    http://www.apache.org/licenses/LICENSE-2.0
  *
- * 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.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 package org.jboss.bpm.console.client.model.util;
 

Modified: jbpm3/trunk/modules/gwt-console/server/pom.xml
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/pom.xml	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/server/pom.xml	2008-10-15 07:59:29 UTC (rev 2542)
@@ -57,6 +57,12 @@
          <artifactId>resteasy-jaxrs</artifactId>
          <version>1.0-beta-8</version>
       </dependency>
+      <dependency>
+         <groupId>com.google.code.gson</groupId>
+         <artifactId>gson</artifactId>
+         <version>1.2.1</version>
+         <scope>compile</scope>
+      </dependency>
    </dependencies>
 
    <build>
@@ -82,4 +88,17 @@
       </plugins>
       <finalName>gwt-console-server</finalName>
    </build>
+
+   <repositories>
+      <repository>
+         <id>gson</id>
+         <url>http://google-gson.googlecode.com/svn/mavenrepo</url>
+         <snapshots>
+            <enabled>true</enabled>
+         </snapshots>
+         <releases>
+            <enabled>true</enabled>
+         </releases>
+      </repository>
+   </repositories>
 </project>

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/BufferedResponseWrapper.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/BufferedResponseWrapper.java	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/BufferedResponseWrapper.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -31,6 +31,7 @@
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
  */
+ at SuppressWarnings("deprecation")
 public class BufferedResponseWrapper extends HttpServletResponseWrapper
 {
    private ByteArrayOutputStream output;

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/JBPM3Management.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/JBPM3Management.java	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/JBPM3Management.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -108,7 +108,7 @@
      HttpServletRequest request
    )
    {
-      return getDiagramDAO(request).getActivNodeInfo(getProcessDAO(request), id);
+      return getDiagramDAO(request).getActivNodeInfo(id);
    }
 
 }

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/ProcessManagement.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/ProcessManagement.java	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/ProcessManagement.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -21,15 +21,18 @@
  */
 package org.jboss.bpm.console.server;
 
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
 import org.jboss.bpm.console.client.model.ProcessDefinitionWrapper;
 import org.jboss.bpm.console.client.model.ProcessInstanceWrapper;
 import org.jboss.bpm.console.server.dao.DAOFactory;
 import org.jboss.bpm.console.server.dao.ProcessDAO;
+import org.jboss.bpm.console.server.gson.GsonFactory;
 
-import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.*;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
 
 /**
  * REST server module for accessing process related data.
@@ -58,48 +61,64 @@
    @GET
    @Path("definitions")
    @Produces("application/json")
-   public ProcessDefinitionWrapper getDefinitionsJSON(
+   public Response getDefinitionsJSON(
      @Context
      HttpServletRequest request
    )
-   {     
-      return new ProcessDefinitionWrapper( getProcessDAO(request).getAllDefinitions() );
+   {
+      ProcessDefinitionWrapper wrapper =
+        new ProcessDefinitionWrapper(getProcessDAO(request).getAllDefinitions());
+      return createJsonResponse(wrapper);
    }
 
    @POST
    @Path("definitions/{id}/remove")
    @Produces("application/json")
-   public ProcessDefinitionWrapper removeDefinitionsJSON(
+   public Response removeDefinitionsJSON(
      @PathParam("id")
      long processId,
      @Context
      HttpServletRequest request
    )
    {
-      return new ProcessDefinitionWrapper( getProcessDAO(request).removeDefinition(processId) );
+      ProcessDefinitionWrapper wrapper =
+        new ProcessDefinitionWrapper( getProcessDAO(request).removeDefinition(processId));
+      return createJsonResponse(wrapper);
    }
 
    @GET
    @Path("definitions/{id}/instances")
    @Produces("application/json")
-   public ProcessInstanceWrapper getInstancesJSON(
+   public Response getInstancesJSON(
      @PathParam("id")
      long processId,
      @Context
      HttpServletRequest request)
    {
-      return new ProcessInstanceWrapper( getProcessDAO(request).getInstancesByProcessId(processId) );
+
+      ProcessInstanceWrapper wrapper =
+        new ProcessInstanceWrapper(getProcessDAO(request).getInstancesByProcessId(processId));
+      return createJsonResponse(wrapper);
    }
 
    @POST
    @Path("instances/{id}/remove")
    @Produces("application/json")
-   public ProcessInstanceWrapper removeInstancesJSON(
+   public Response removeInstancesJSON(
      @PathParam("id")
      long instanceId,
      @Context
      HttpServletRequest request)
    {
-      return new ProcessInstanceWrapper( getProcessDAO(request).removeInstance(instanceId) );
+      ProcessInstanceWrapper wrapper =
+        new ProcessInstanceWrapper(getProcessDAO(request).removeInstance(instanceId));
+      return createJsonResponse(wrapper);
    }
+
+   private Response createJsonResponse(Object wrapper)
+   {
+      Gson gson = GsonFactory.createInstance();
+      String json = gson.toJson(wrapper);
+      return Response.ok(json).type("application/json").build();
+   }
 }

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/DiagramDAO.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/DiagramDAO.java	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/DiagramDAO.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -34,5 +34,5 @@
 
    DiagramInfo getDiagramInfo(long processId);
 
-   ActiveNodeInfo getActivNodeInfo(ProcessDAO processDAO, long instanceId);
+   ActiveNodeInfo getActivNodeInfo(long instanceId);
 }

Added: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3CommandDelegate.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3CommandDelegate.java	                        (rev 0)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3CommandDelegate.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jboss.bpm.console.server.dao.internal;
+
+import org.jbpm.command.GetProcessDefinitionsCommand;
+import org.jbpm.command.GetProcessInstanceCommand;
+import org.jbpm.command.GetProcessInstancesCommand;
+import org.jbpm.ejb.LocalCommandService;
+import org.jbpm.ejb.LocalCommandServiceHome;
+import org.jbpm.graph.def.ProcessDefinition;
+
+import javax.ejb.CreateException;
+import java.util.List;
+
+/**
+ * Adopts a business interface to the command facade.<br>
+ * Depends on the CommandServiceBean (<code>java:ejb/CommandServiceBean</code>).
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+class JBPM3CommandDelegate
+{
+
+   private LocalCommandService facade;
+   private static final String DEFAULT_JNDI_NAME = "java:ejb/CommandServiceBean";
+
+   /**
+    * Lookup with particluar JNDI name.
+    * @param jndiName
+    */
+   public JBPM3CommandDelegate(String jndiName)
+   {
+      ejbLookup(jndiName);
+   }
+
+   /**
+    * Lookup using default JNDI name.
+    *
+    * @see #DEFAULT_JNDI_NAME
+    */
+
+   public JBPM3CommandDelegate()
+   {
+      ejbLookup(DEFAULT_JNDI_NAME);
+   }
+
+   private void ejbLookup(String jndiName)
+   {
+      try
+      {
+         LocalCommandServiceHome home = (LocalCommandServiceHome)
+           ServiceLocator.getEjbLocalHome(jndiName);
+         this.facade = home.create();
+      }
+      catch (CreateException e)
+      {
+         throw new RuntimeException("Failed to create LocalCommandService", e);
+      }
+   }
+
+   public List<ProcessDefinition> getActualDefinitions()
+   {
+      List<org.jbpm.graph.def.ProcessDefinition> defs = (List<org.jbpm.graph.def.ProcessDefinition>)
+        facade.execute( new GetProcessDefinitionsCommand() );
+      return defs;
+   }
+
+   public org.jbpm.graph.def.ProcessDefinition getActualDefinition(long processId)
+   {
+      List<org.jbpm.graph.def.ProcessDefinition> defs = getActualDefinitions();
+
+      org.jbpm.graph.def.ProcessDefinition match = null;
+      for(org.jbpm.graph.def.ProcessDefinition p0 : defs)
+      {
+         if(processId == p0.getId())
+         {
+            match = p0;
+            break;
+         }
+      }
+
+      if(null==match)
+         throw new IllegalArgumentException("No process definition with ID " + processId);
+
+      return match;
+   }
+
+   public org.jbpm.graph.exe.ProcessInstance getActualInstance(long instanceId)
+   {
+      org.jbpm.graph.exe.ProcessInstance instance = (org.jbpm.graph.exe.ProcessInstance)
+        facade.execute( new GetProcessInstanceCommand(instanceId));
+      return instance;
+   }
+
+   public List<org.jbpm.graph.exe.ProcessInstance> getActualInstances(long processId)
+   {
+      org.jbpm.graph.def.ProcessDefinition p0 = getActualDefinition(processId);
+      GetProcessInstancesCommand command = new GetProcessInstancesCommand();
+      command.setProcessName(p0.getName());
+
+      List<org.jbpm.graph.exe.ProcessInstance> instances =
+        (List<org.jbpm.graph.exe.ProcessInstance>) facade.execute(command);
+
+      return instances;
+   }
+}


Property changes on: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3CommandDelegate.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3DiagramDAO.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3DiagramDAO.java	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3DiagramDAO.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -21,29 +21,43 @@
  */
 package org.jboss.bpm.console.server.dao.internal;
 
+import org.jboss.bpm.console.client.model.jbpm3.ActiveNodeInfo;
+import org.jboss.bpm.console.client.model.jbpm3.DiagramInfo;
 import org.jboss.bpm.console.server.dao.DiagramDAO;
-import org.jboss.bpm.console.server.dao.ProcessDAO;
-import org.jboss.bpm.console.client.model.jbpm3.DiagramInfo;
-import org.jboss.bpm.console.client.model.jbpm3.ActiveNodeInfo;
 
+import java.io.InputStream;
+
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
  */
 public class JBPM3DiagramDAO implements DiagramDAO
 {
+   private JBPM3CommandDelegate delegate;
+   
+   private static final String PROCESSIMAGE_FILENAME = "processimage.jpg";
+   private static final String GPD_XML_FILENAME = "gpd.xml";
 
+   public JBPM3DiagramDAO()
+   {
+      this.delegate = new JBPM3CommandDelegate();
+   }
+
    public byte[] getProcessImage(long processId)
    {
-      return new byte[0];
+      org.jbpm.graph.def.ProcessDefinition p0 = delegate.getActualDefinition(processId);
+      return p0.getFileDefinition().getBytes(PROCESSIMAGE_FILENAME);
    }
 
    public DiagramInfo getDiagramInfo(long processId)
    {
-      return null;
+      org.jbpm.graph.def.ProcessDefinition p0 = delegate.getActualDefinition(processId);
+      InputStream in = p0.getFileDefinition().getInputStream(GPD_XML_FILENAME);
+      return DiagramInfoParser.parse(in);
    }
 
-   public ActiveNodeInfo getActivNodeInfo(ProcessDAO processDAO, long instanceId)
+   public ActiveNodeInfo getActivNodeInfo(long instanceId)
    {
-      return null;  
+      
+      throw new RuntimeException("Not implemented");
    }
 }

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3ProcessDAO.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3ProcessDAO.java	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3ProcessDAO.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -24,42 +24,25 @@
 import org.jboss.bpm.console.client.model.ProcessDefinition;
 import org.jboss.bpm.console.client.model.ProcessInstance;
 import org.jboss.bpm.console.server.dao.ProcessDAO;
-import org.jbpm.ejb.LocalCommandService;
-import org.jbpm.ejb.LocalCommandServiceHome;
-import org.jbpm.command.GetProcessDefinitionsCommand;
-import org.jbpm.command.GetProcessDefinitionCommand;
-import org.jbpm.command.GetProcessInstanceCommand;
-import org.jbpm.command.GetProcessInstancesCommand;
 
-import javax.ejb.CreateException;
-import java.util.List;
 import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
  */
 public class JBPM3ProcessDAO implements ProcessDAO
 {
-   private LocalCommandService facade;
+   private JBPM3CommandDelegate delegate;
 
    public JBPM3ProcessDAO()
    {
-      try
-      {
-         LocalCommandServiceHome home = (LocalCommandServiceHome)
-           ServiceLocator.getEjbLocalHome("java:ejb/CommandServiceBean");
-         this.facade = home.create();
-      }
-      catch (CreateException e)
-      {
-         throw new RuntimeException("Failed to create LocalCommandService", e);
-      }
+      this.delegate = new JBPM3CommandDelegate();
    }
 
    public List<ProcessDefinition> getAllDefinitions()
    {
-      List<org.jbpm.graph.def.ProcessDefinition> defs = (List<org.jbpm.graph.def.ProcessDefinition>)
-        facade.execute( new GetProcessDefinitionsCommand() );
+      List<org.jbpm.graph.def.ProcessDefinition> defs = delegate.getActualDefinitions();
 
       List<ProcessDefinition> results = new ArrayList<ProcessDefinition>(defs.size());
       for(org.jbpm.graph.def.ProcessDefinition p0 : defs)
@@ -71,25 +54,7 @@
 
    public ProcessDefinition getDefinitionById(long processId)
    {
-      List<ProcessDefinition> defs = getAllDefinitions();
-      ProcessDefinition parent = null;
-      for(ProcessDefinition p : defs)
-      {
-         if(processId == p.getProcessId())
-         {
-            parent = p;
-            break;
-         }
-      }
-
-      if(null==parent)
-         throw new IllegalArgumentException("No process definition with ID " + processId);
-
-      GetProcessDefinitionCommand command = new GetProcessDefinitionCommand();
-      command.setName(parent.getName());
-
-      org.jbpm.graph.def.ProcessDefinition p0 = (org.jbpm.graph.def.ProcessDefinition)
-        facade.execute(command);
+      org.jbpm.graph.def.ProcessDefinition p0 = delegate.getActualDefinition(processId);
       return Transform.processDefinition(p0);
    }
 
@@ -100,13 +65,7 @@
 
    public List<ProcessInstance> getInstancesByProcessId(long processId)
    {
-      ProcessDefinition parent = getDefinitionById(processId);
-      GetProcessInstancesCommand command = new GetProcessInstancesCommand();
-      command.setProcessName(parent.getName());
-      
-      List<org.jbpm.graph.exe.ProcessInstance> instances =
-        (List<org.jbpm.graph.exe.ProcessInstance>) facade.execute(command);
-
+      List<org.jbpm.graph.exe.ProcessInstance> instances = delegate.getActualInstances(processId);
       List<ProcessInstance> results = new ArrayList<ProcessInstance>(instances.size());
       for(org.jbpm.graph.exe.ProcessInstance i0 : instances)
       {
@@ -117,9 +76,7 @@
 
    public ProcessInstance getInstanceById(long instanceId)
    {
-      org.jbpm.graph.exe.ProcessInstance instance = (org.jbpm.graph.exe.ProcessInstance)
-        facade.execute( new GetProcessInstanceCommand(instanceId));
-
+      org.jbpm.graph.exe.ProcessInstance instance = delegate.getActualInstance(instanceId);
       return Transform.processInstance(instance);
    }
 

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/MockDiagramDAO.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/MockDiagramDAO.java	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/MockDiagramDAO.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -35,9 +35,14 @@
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
  */
-public class MockDiagramDAO implements DiagramDAO
+public class MockDiagramDAO extends MockProcessDAO implements DiagramDAO
 {
 
+   public MockDiagramDAO()
+   {
+      super();
+   }
+
    public byte[] getProcessImage(long processId)
    {
       byte[] imageBytes = null;
@@ -67,10 +72,10 @@
       return DiagramInfoParser.parse(in);
    }
 
-   public ActiveNodeInfo getActivNodeInfo(ProcessDAO processDAO, long instanceId)
+   public ActiveNodeInfo getActivNodeInfo(long instanceId)
    {
 
-      ProcessInstance pi = processDAO.getInstanceById(instanceId);
+      ProcessInstance pi = super.getInstanceById(instanceId);
       DiagramInfo diagram = getDiagramInfo(pi.getParentId());
       List<DiagramNodeInfo> nodes = diagram.getNodeList();
 

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/MockProcessDAO.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/MockProcessDAO.java	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/MockProcessDAO.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -111,7 +111,7 @@
       ProcessInstance toBeRemoved = null;
       for(ProcessInstance instance : instances)
       {
-         if(instanceId == instance.getId())
+         if(instanceId == instance.getInstanceId())
             toBeRemoved = instance;
       }
 
@@ -129,7 +129,7 @@
       ProcessInstance match = null;
       for(ProcessInstance instance : instances)
       {
-         if(instanceId == instance.getId())
+         if(instanceId == instance.getInstanceId())
             match = instance;
       }
 

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/Transform.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/Transform.java	2008-10-15 07:58:33 UTC (rev 2541)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/Transform.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -24,6 +24,8 @@
 import org.jboss.bpm.console.client.model.ProcessDefinition;
 import org.jboss.bpm.console.client.model.ProcessInstance;
 
+import java.util.Date;
+
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
  */
@@ -37,6 +39,8 @@
    public static ProcessInstance processInstance(org.jbpm.graph.exe.ProcessInstance i0)
    {
       // TODO: status?
-      return new ProcessInstance(i0.getId(), i0.getProcessDefinition().getId(), "Unknown", i0.getStart(), i0.getEnd());
+      Date start = i0.getStart();      
+      Date end = i0.getEnd();
+      return new ProcessInstance(i0.getId(), i0.getProcessDefinition().getId(), "Unknown", start, end);
    }
 }

Added: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/gson/GsonFactory.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/gson/GsonFactory.java	                        (rev 0)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/gson/GsonFactory.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jboss.bpm.console.server.gson;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class GsonFactory
+{
+   public static Gson createInstance()
+   {
+      Gson gson = new GsonBuilder()
+        .setDateFormat("y-M-d H:m:s")
+        .registerTypeAdapter(java.sql.Timestamp.class, new SQLDateTypeAdapter()) 
+        .create();
+      return gson;
+   }
+}


Property changes on: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/gson/GsonFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/gson/SQLDateTypeAdapter.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/gson/SQLDateTypeAdapter.java	                        (rev 0)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/gson/SQLDateTypeAdapter.java	2008-10-15 07:59:29 UTC (rev 2542)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jboss.bpm.console.server.gson;
+
+import com.google.gson.*;
+
+import java.util.Date;
+import java.text.*;
+import java.lang.reflect.Type;
+
+
+/**
+ * A default type adapter for a {@link java.util.Date} object.<br>
+ * Create a GSON instance that can serialize/deserialize "java.util.Date" objects:
+ * <pre>
+ * Gson gson = new GsonBuilder()
+ * .registerTypeAdapter(new DateTypeAdapter())
+ * .create();
+ * </pre>
+ *
+ * @author Joel Leitch
+ */
+public class SQLDateTypeAdapter implements JsonSerializer<java.sql.Timestamp>, JsonDeserializer<Date>
+{
+   private final DateFormat format = new SimpleDateFormat("y-M-d H:m:s");
+
+   public JsonElement serialize(java.sql.Timestamp src, Type typeOfSrc, JsonSerializationContext context)
+   {
+      String dateFormatAsString = format.format(src);
+      return new JsonPrimitive(dateFormatAsString);
+   }
+
+   public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
+     throws JsonParseException
+   {
+      if (!(json instanceof JsonPrimitive)) {
+         throw new JsonParseException("The date should be a string value");
+      }
+
+      try
+      {
+         return format.parse(json.getAsString());
+      }
+      catch (ParseException e)
+      {
+         throw new JsonParseException(e);
+      }
+
+   }
+}


Property changes on: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/gson/SQLDateTypeAdapter.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jbpm-commits mailing list