[jbpm-commits] JBoss JBPM SVN: r3871 - in jbpm4/trunk/modules: api/src/main/java/org/jbpm/activity and 15 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Feb 13 09:40:26 EST 2009


Author: tom.baeyens at jboss.com
Date: 2009-02-13 09:40:26 -0500 (Fri, 13 Feb 2009)
New Revision: 3871

Added:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/HistoryService.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryActivityInstance.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryActivityInstanceQuery.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryProcessInstanceQuery.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AvgDurationPerActivityQueryCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ChoiceDistributionQueryCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/HistoryServiceBinding.java
   jbpm4/trunk/modules/test-db/.settings/
   jbpm4/trunk/modules/test-db/.settings/org.eclipse.jdt.core.prefs
   jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/AvgDurationTest.java
   jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/ChoiceDistributionTest.java
Removed:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/HistoryProcessInstanceQuery.java
Modified:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessEngine.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/activity/ActivityExecution.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryProcessInstance.java
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/StateActivity.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/JbpmConfiguration.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ActivityEnd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskEnd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryActivityInstanceImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryExclusiveInstanceImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskInstanceImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
   jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.history.hbm.xml
   jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.wire.bindings.xml
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java
   jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java
   jbpm4/trunk/modules/test-db/src/main/resources/jbpm.cfg.xml
Log:
further work out of first history infrastructure

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -25,7 +25,10 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.jbpm.history.HistoryActivityInstanceQuery;
+import org.jbpm.history.HistoryProcessInstanceQuery;
 
+
 /** manages runtime process executions.
  *
  * @author Tom Baeyens
@@ -120,9 +123,6 @@
   /** search for process instances with criteria */
   ExecutionQuery createProcessInstanceQuery();
 
-  /** search for process instances in the history */
-  HistoryProcessInstanceQuery createHistoryProcessInstanceQuery();
-
   /** creates or overwrites a variable value on the referenced execution */
   Execution setVariable(String executionId, String name, Object value);
 
@@ -140,5 +140,4 @@
 
   /** delete a process instance */
   void deleteProcessInstance(String processInstanceId);
-
 }

Deleted: jbpm4/trunk/modules/api/src/main/java/org/jbpm/HistoryProcessInstanceQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/HistoryProcessInstanceQuery.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/HistoryProcessInstanceQuery.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -1,46 +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;
-
-import java.util.List;
-
-import org.jbpm.history.HistoryProcessInstance;
-
-
-/**
- * @author Tom Baeyens
- */
-public interface HistoryProcessInstanceQuery {
-  
-  String PROPERTY_STARTTIME = "startTime";
-  String PROPERTY_ENDTIME = "endTime";
-  String PROPERTY_ID = "id";
-
-  HistoryProcessInstanceQuery processDefinitionId(String processDefinitionId);
-
-  HistoryProcessInstanceQuery orderAsc(String property);
-  HistoryProcessInstanceQuery orderDesc(String property);
-
-  HistoryProcessInstanceQuery page(int firstResult, int maxResults);
-
-  List<HistoryProcessInstance> execute();
-}

Added: jbpm4/trunk/modules/api/src/main/java/org/jbpm/HistoryService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/HistoryService.java	                        (rev 0)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/HistoryService.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+import java.util.Map;
+
+import org.jbpm.history.HistoryActivityInstanceQuery;
+import org.jbpm.history.HistoryProcessInstanceQuery;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public interface HistoryService {
+
+  /** search for process instances in the history */
+  HistoryProcessInstanceQuery createHistoryProcessInstanceQuery();
+
+  /** search in history activity instance information for a given processDefinition */ 
+  HistoryActivityInstanceQuery createHistoryActivityInstanceQuery(String processDefinitionId);
+
+  /** returns the average duration in milliseconds for each activity in the given process definition */
+  Map<String, Long> avgDurationPerActivity(String processDefinitionId);
+  
+  /** returns for each transitionName, the number of times that transition was taken */
+  Map<String, Integer> choiceDistribution(String processDefinitionId, String activityName);
+}


Property changes on: jbpm4/trunk/modules/api/src/main/java/org/jbpm/HistoryService.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessEngine.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessEngine.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/ProcessEngine.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -48,6 +48,15 @@
    * be associated to the returned execution service.  */ 
   ExecutionService getExecutionService(Map<String, Object> txResources);
 
+  /** the {@link HistoryService history service} that provides access
+   * to the history executions repository. */ 
+  HistoryService getHistoryService();
+
+  /** the {@link HistoryService history service} that provides access
+   * to the history executions repository. The given transactional resources will only 
+   * be associated to the returned history service.  */ 
+  HistoryService getHistoryService(Map<String, Object> txResources);
+
   /** the {@link TaskService task service} that exposes the 
    * runtime human task lists. */ 
   TaskService getTaskService();

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/activity/ActivityExecution.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/activity/ActivityExecution.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/activity/ActivityExecution.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -283,6 +283,9 @@
   /** marks the end of an activity for history purposes. */
   void historyActivityEnd();
 
+  /** marks the end of an activity with a specific transitionName for history purposes. */
+  void historyActivityEnd(String transitionName);
+
   /** marks the start of a user task for history purposes. */
   void historyTaskStart(String assignee);
 

Added: jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryActivityInstance.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryActivityInstance.java	                        (rev 0)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryActivityInstance.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -0,0 +1,41 @@
+/*
+ * 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.history;
+
+import java.util.Date;
+
+/**
+ * @author Tom Baeyens
+ */
+public interface HistoryActivityInstance {
+
+  String getActivityName();
+
+  Date getStartTime();
+
+  Date getEndTime();
+
+  long getDuration();
+
+  String getExecutionId();
+
+}
\ No newline at end of file


Property changes on: jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryActivityInstance.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryActivityInstanceQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryActivityInstanceQuery.java	                        (rev 0)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryActivityInstanceQuery.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -0,0 +1,56 @@
+/*
+ * 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.history;
+
+import java.util.Date;
+import java.util.List;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public interface HistoryActivityInstanceQuery {
+  
+  String PROPERTY_STARTTIME = "startTime";
+  String PROPERTY_ENDTIME = "endTime";
+  String PROPERTY_EXECUTIONID = "executionId";
+  String PROPERTY_ACTIVITYNAME = "activityName";
+  String PROPERTY_DURATION = "duration";
+
+  HistoryActivityInstanceQuery processDefinitionId(String processDefinitionId);
+  HistoryActivityInstanceQuery executionId(String executionId);
+
+  HistoryActivityInstanceQuery startedAfter(Date time);
+  HistoryActivityInstanceQuery startedBefore(Date time);
+
+  HistoryActivityInstanceQuery activityName(String activityName);
+
+  HistoryActivityInstanceQuery tookLongerThen(long durationInMillis);
+  HistoryActivityInstanceQuery tookLessThen(long durationInMillis);
+
+  HistoryActivityInstanceQuery orderAsc(String property);
+  HistoryActivityInstanceQuery orderDesc(String property);
+
+  HistoryActivityInstanceQuery page(int firstResult, int maxResults);
+
+  List<HistoryActivityInstance> execute(); 
+}


Property changes on: jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryActivityInstanceQuery.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryProcessInstance.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryProcessInstance.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryProcessInstance.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -27,9 +27,14 @@
  * @author Tom Baeyens
  */
 public interface HistoryProcessInstance {
+  
+  String STATE_ENDED = "ended";
+  String STATE_ACTIVE = "active";
 
-  String getId();
+  String getProcessInstanceId();
 
+  String getProcessDefinitionId();
+
   String getKey();
 
   String getState();

Copied: jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryProcessInstanceQuery.java (from rev 3853, jbpm4/trunk/modules/api/src/main/java/org/jbpm/HistoryProcessInstanceQuery.java)
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryProcessInstanceQuery.java	                        (rev 0)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryProcessInstanceQuery.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -0,0 +1,48 @@
+/*
+ * 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.history;
+
+import java.util.List;
+
+
+
+/**
+ * @author Tom Baeyens
+ */
+public interface HistoryProcessInstanceQuery {
+  
+  String PROPERTY_STARTTIME = "startTime";
+  String PROPERTY_ENDTIME = "endTime";
+  String PROPERTY_ID = "id";
+  String PROPERTY_STATE = "state";
+  String PROPERTY_DURATION = "duration";
+
+  HistoryProcessInstanceQuery processDefinitionId(String processDefinitionId);
+  HistoryProcessInstanceQuery state(String state);
+
+  HistoryProcessInstanceQuery orderAsc(String property);
+  HistoryProcessInstanceQuery orderDesc(String property);
+
+  HistoryProcessInstanceQuery page(int firstResult, int maxResults);
+
+  List<HistoryProcessInstance> execute();
+}


Property changes on: jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryProcessInstanceQuery.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/StateActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/StateActivity.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/StateActivity.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -51,7 +51,7 @@
     
     Transition transition = activity.findOutgoingTransition(signalName);
     if (transition!=null) {
-      execution.historyActivityEnd();
+      execution.historyActivityEnd(signalName);
       execution.take(transition);
     } else {
       execution.waitForSignal();

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/JbpmConfiguration.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/JbpmConfiguration.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/JbpmConfiguration.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -29,6 +29,7 @@
 
 import org.jbpm.Configuration;
 import org.jbpm.ExecutionService;
+import org.jbpm.HistoryService;
 import org.jbpm.ManagementService;
 import org.jbpm.ProcessEngine;
 import org.jbpm.ProcessService;
@@ -137,39 +138,36 @@
   public ExecutionService getExecutionService() {
     return environmentFactoryCtxWireContext.get(ExecutionService.class);
   }
-  
-  public ExecutionService getExecutionService(Map<String, Object> txResources) {
-    // TODO Auto-generated method stub
-    return null;
+  public HistoryService getHistoryService() {
+    return environmentFactoryCtxWireContext.get(HistoryService.class);
   }
-
   public ManagementService getManagementService() {
     return environmentFactoryCtxWireContext.get(ManagementService.class);
   }
-
-  public ManagementService getManagementService(Map<String, Object> txResources) {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
   public ProcessService getProcessService() {
     return environmentFactoryCtxWireContext.get(ProcessService.class);
   }
-
-  public ProcessService getProcessService(Map<String, Object> txResources) {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
   public TaskService getTaskService() {
     return environmentFactoryCtxWireContext.get(TaskService.class);
   }
 
   public TaskService getTaskService(Map<String, Object> txResources) {
-    // TODO Auto-generated method stub
-    return null;
+    throw new UnsupportedOperationException("please implement me");
   }
+  public HistoryService getHistoryService(Map<String, Object> txResources) {
+    throw new UnsupportedOperationException("please implement me");
+  }
+  public ExecutionService getExecutionService(Map<String, Object> txResources) {
+    throw new UnsupportedOperationException("please implement me");
+  }
+  public ProcessService getProcessService(Map<String, Object> txResources) {
+    throw new UnsupportedOperationException("please implement me");
+  }
+  public ManagementService getManagementService(Map<String, Object> txResources) {
+    throw new UnsupportedOperationException("please implement me");
+  }
 
+  
   public static EnvironmentFactory parseXmlString(String xmlString) {
     JbpmConfiguration jbpmConfiguration = new JbpmConfiguration();
     jbpmConfiguration.setXmlString(xmlString);

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ActivityEnd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ActivityEnd.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ActivityEnd.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -23,6 +23,7 @@
 
 import org.hibernate.Session;
 import org.jbpm.env.Environment;
+import org.jbpm.history.HistoryActivityInstance;
 import org.jbpm.pvm.internal.history.HistoryEvent;
 import org.jbpm.pvm.internal.history.model.HistoryActivityInstanceImpl;
 import org.jbpm.pvm.internal.util.Clock;
@@ -35,20 +36,30 @@
 
   private static final long serialVersionUID = 1L;
 
+  protected String transitionName;
+  
+  public ActivityEnd() {
+  }
+
+  public ActivityEnd(String transitionName) {
+    this.transitionName = transitionName;
+  }
+
   public void process() {
     Session session = Environment.getFromCurrent(Session.class);
     Long historyActivityInstanceDbId = execution.getHistoryActivityInstanceDbid();
-    HistoryActivityInstanceImpl historyActivityInstanceImpl = (HistoryActivityInstanceImpl) 
+    HistoryActivityInstanceImpl historyActivityInstance = (HistoryActivityInstanceImpl) 
         session.load(getHistoryActivityInstanceClass(), historyActivityInstanceDbId); 
-    historyActivityInstanceImpl.setEndTime(Clock.getCurrentTime());
-    updateActivitySpecificProperties(historyActivityInstanceImpl);
-    session.update(historyActivityInstanceImpl);
+    historyActivityInstance.setEndTime(Clock.getCurrentTime());
+    historyActivityInstance.setTransitionName(transitionName);
+    updateActivitySpecificProperties(historyActivityInstance);
+    session.update(historyActivityInstance);
   }
 
   protected Class<? extends HistoryActivityInstanceImpl> getHistoryActivityInstanceClass() {
     return HistoryActivityInstanceImpl.class;
   }
 
-  protected void updateActivitySpecificProperties(HistoryActivityInstanceImpl historyActivityInstanceImpl) {
+  protected void updateActivitySpecificProperties(HistoryActivityInstance historyActivityInstanceImpl) {
   }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskEnd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskEnd.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskEnd.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -21,6 +21,7 @@
  */
 package org.jbpm.pvm.internal.history.events;
 
+import org.jbpm.history.HistoryActivityInstance;
 import org.jbpm.pvm.internal.history.model.HistoryActivityInstanceImpl;
 import org.jbpm.pvm.internal.history.model.HistoryTaskInstanceImpl;
 
@@ -42,8 +43,8 @@
     return HistoryTaskInstanceImpl.class;
   }
 
-  protected void updateActivitySpecificProperties(HistoryActivityInstanceImpl historyActivityInstanceImpl) {
+  protected void updateActivitySpecificProperties(HistoryActivityInstance historyActivityInstanceImpl) {
     HistoryTaskInstanceImpl historyTaskInstanceImpl = (HistoryTaskInstanceImpl) historyActivityInstanceImpl;
-    historyTaskInstanceImpl.setOutcome(outcome);
+    historyTaskInstanceImpl.setTransitionName(outcome);
   }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryActivityInstanceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryActivityInstanceImpl.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryActivityInstanceImpl.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -23,6 +23,7 @@
 
 import java.util.Date;
 
+import org.jbpm.history.HistoryActivityInstance;
 import org.jbpm.history.HistoryProcessInstance;
 import org.jbpm.pvm.internal.model.ActivityImpl;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
@@ -31,7 +32,7 @@
  *  
  * @author Tom Baeyens
  */
-public class HistoryActivityInstanceImpl {
+public class HistoryActivityInstanceImpl implements HistoryActivityInstance {
 
   protected long dbid;
   protected int dbversion;
@@ -45,6 +46,8 @@
   protected Date endTime;
   protected long duration;
   
+  protected String transitionName;
+  
   public HistoryActivityInstanceImpl() {
   }
 
@@ -88,4 +91,10 @@
   public void setExecutionId(String executionId) {
     this.executionId = executionId;
   }
+  public String getTransitionName() {
+    return transitionName;
+  }
+  public void setTransitionName(String transitionName) {
+    this.transitionName = transitionName;
+  }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryExclusiveInstanceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryExclusiveInstanceImpl.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryExclusiveInstanceImpl.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -30,8 +30,6 @@
  */
 public class HistoryExclusiveInstanceImpl extends HistoryAutomaticInstanceImpl {
 
-  protected String transitionName;
-  
   public HistoryExclusiveInstanceImpl() {
   }
 
@@ -40,7 +38,4 @@
     this.transitionName = transitionName;
   }
 
-  public String getTransitionName() {
-    return transitionName;
-  }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceImpl.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceImpl.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -39,7 +39,8 @@
   protected int dbversion;
   
   protected ProcessDefinitionImpl processDefinition;
-  protected String id;
+  protected String processDefinitionId;
+  protected String processInstanceId;
   protected String key;
   protected String state;
   protected Date startTime;
@@ -54,8 +55,9 @@
 
   public HistoryProcessInstanceImpl(ExecutionImpl processInstance) {
     this.processDefinition = processInstance.getProcessDefinition();
+    this.processDefinitionId = processDefinition.getId();
     this.dbid = processInstance.getDbid();
-    this.id = processInstance.getId();
+    this.processInstanceId = processInstance.getId();
     this.key = processInstance.getKey();
     this.state = "active";
     this.startTime = Clock.getCurrentTime();
@@ -82,8 +84,8 @@
   public long getDuration() {
     return duration;
   }
-  public String getId() {
-    return id;
+  public String getProcessInstanceId() {
+    return processInstanceId;
   }
   public String getKey() {
     return key;
@@ -91,4 +93,7 @@
   public String getState() {
     return state;
   }
+  public String getProcessDefinitionId() {
+    return processDefinitionId;
+  }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskInstanceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskInstanceImpl.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskInstanceImpl.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -31,8 +31,6 @@
 public class HistoryTaskInstanceImpl extends HistoryActivityInstanceImpl {
 
   protected String assignee;
-  protected String outcome;
-
   public HistoryTaskInstanceImpl() {
   }
 
@@ -40,8 +38,4 @@
     super(historyProcessInstanceImpl, execution);
     this.assignee = assignee;
   }
-
-  public void setOutcome(String outcome) {
-    this.outcome = outcome;
-  }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -974,6 +974,10 @@
     fireHistoryEvent(new ActivityEnd());
   }
 
+  public void historyActivityEnd(String transitionName) {
+    fireHistoryEvent(new ActivityEnd(transitionName));
+  }
+
   public void historyTaskStart(String assignee) {
     fireHistoryEvent(new TaskStart(assignee));
   }

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AvgDurationPerActivityQueryCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AvgDurationPerActivityQueryCmd.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AvgDurationPerActivityQueryCmd.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -0,0 +1,76 @@
+/*
+ * 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.query;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.jbpm.cmd.Command;
+import org.jbpm.env.Environment;
+import org.jbpm.pvm.internal.history.model.HistoryActivityInstanceImpl;
+
+/**
+ * @author Tom Baeyens
+ */
+public class AvgDurationPerActivityQueryCmd implements Command<Object> {
+
+  private static final long serialVersionUID = 1L;
+  
+  protected String processDefinitionId;
+
+  public AvgDurationPerActivityQueryCmd(String processDefinitionId) {
+    this.processDefinitionId = processDefinitionId;
+  }
+
+  public Object execute(Environment environment) throws Exception {
+    Session session = environment.get(Session.class);
+    
+    Query query = session.createQuery(
+      "select distinct hai.activityName " +
+      "from "+HistoryActivityInstanceImpl.class.getName()+" as hai " +
+      "where hai.historyProcessInstance.processDefinitionId = :processDefinitionId"
+    );
+    query.setString("processDefinitionId", processDefinitionId);
+    
+    Map<String, Long> avgDuration = new HashMap<String, Long>();
+    
+    List<String> activityNames = query.list();
+    for (String activityName: activityNames) {
+      query = session.createQuery(
+        "select avg(hai.duration) " +
+        "from "+HistoryActivityInstanceImpl.class.getName()+" as hai " +
+        "where hai.historyProcessInstance.processDefinitionId = :processDefinitionId " +
+        "  and hai.activityName = :activityName"
+      );
+      query.setString("processDefinitionId", processDefinitionId);
+      query.setString("activityName", activityName);
+      
+      Number number = (Number) query.uniqueResult();
+      avgDuration.put(activityName, new Long(number.longValue()));
+    }
+    
+    return avgDuration;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AvgDurationPerActivityQueryCmd.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ChoiceDistributionQueryCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ChoiceDistributionQueryCmd.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ChoiceDistributionQueryCmd.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -0,0 +1,76 @@
+/*
+ * 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.query;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.jbpm.cmd.Command;
+import org.jbpm.env.Environment;
+import org.jbpm.pvm.internal.history.model.HistoryActivityInstanceImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ChoiceDistributionQueryCmd implements Command<Object> {
+
+  private static final long serialVersionUID = 1L;
+  
+  protected String processDefinitionId;
+  protected String activityName;
+  
+  public ChoiceDistributionQueryCmd(String processDefinitionId, String activityName) {
+    this.processDefinitionId = processDefinitionId;
+    this.activityName = activityName;
+  }
+
+  public Object execute(Environment environment) {
+    Session session = environment.get(Session.class);
+    
+    Query query = session.createQuery(
+      "select hai.transitionName, count(hai) " +
+      "from "+HistoryActivityInstanceImpl.class.getName()+" as hai " +
+      "where hai.historyProcessInstance.processDefinitionId = :processDefinitionId " +
+      "  and hai.activityName = :activityName " +
+      "group by hai.transitionName "
+    );
+    query.setString("processDefinitionId", processDefinitionId);
+    query.setString("activityName", activityName);
+
+    List<Object[]> transitionCounts = query.list();
+
+    Map<String, Integer> choiceDistributionCounts = new HashMap<String, Integer>();
+    
+    for (Object[] pair: transitionCounts) {
+      String transitionName = (String) pair[0];
+      Number number = (Number) pair[1];
+      
+      choiceDistributionCounts.put(transitionName, new Integer(number.intValue()));
+    }
+    
+    return choiceDistributionCounts;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ChoiceDistributionQueryCmd.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -0,0 +1,167 @@
+/*
+ * 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.query;
+
+import java.util.Date;
+import java.util.List;
+
+import org.hibernate.Query;
+import org.jbpm.JbpmException;
+import org.jbpm.cmd.CommandService;
+import org.jbpm.history.HistoryActivityInstance;
+import org.jbpm.history.HistoryActivityInstanceQuery;
+import org.jbpm.pvm.internal.history.model.HistoryActivityInstanceImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class HistoryActivityInstanceQueryImpl extends AbstractQuery implements HistoryActivityInstanceQuery {
+
+  private static final long serialVersionUID = 1L;
+  
+  protected String processDefinitionId;
+  protected Long tookLessThen;
+  protected Long tookLongerThen;
+  protected Date startedBefore;
+  protected Date startedAfter;
+  protected String executionId;
+  protected String activityName;
+
+  public HistoryActivityInstanceQueryImpl(CommandService commandService, String processInstanceId) {
+    super(commandService);
+    if (processInstanceId==null) {
+      throw new JbpmException("processInstanceId is null");
+    }
+    this.processDefinitionId = processInstanceId;
+  }
+
+  public String hql() {
+    StringBuffer hql = new StringBuffer();
+    hql.append("select hai ");
+    hql.append("from ");
+    hql.append(HistoryActivityInstanceImpl.class.getName());
+    hql.append(" as hai ");
+    
+    if (processDefinitionId!=null) {
+      appendWhereClause(" hai.historyActivityInstance.processDefinitionId = '"+processDefinitionId+"' ", hql);
+    }
+
+    if (tookLessThen!=null) {
+      appendWhereClause(" hai.duration < :tookLessThen ", hql);
+    }
+    
+    if (tookLongerThen!=null) {
+      appendWhereClause(" hai.duration > :tookLongerThen ", hql);
+    }
+    
+    if (startedBefore!=null) {
+      appendWhereClause(" hai.startTime < :startedBefore ", hql);
+    }
+    
+    if (startedAfter!=null) {
+      appendWhereClause(" hai.startTime > :startedAfter ", hql);
+    }
+    
+    if (executionId!=null) {
+      appendWhereClause(" hai.executionId = '"+executionId+"'", hql);
+    }
+    
+    if (activityName!=null) {
+      appendWhereClause(" hai.activityName = '"+activityName+"'", hql);
+    }
+
+    return hql().toString();
+  }
+
+  protected void applyParameters(Query query) {
+    if (tookLessThen!=null) {
+      query.setLong("tookLessThen", tookLessThen);
+    }
+    
+    if (tookLongerThen!=null) {
+      query.setLong("tookLongerThen", tookLongerThen);
+    }
+    
+    if (startedBefore!=null) {
+      query.setTime("startedBefore", startedBefore);
+    }
+    
+    if (startedAfter!=null) {
+      query.setTime("startedAfter", startedAfter);
+    }
+  }
+
+  public List<HistoryActivityInstance> execute() {
+    return (List) commandService.execute(this);
+  }
+
+  public HistoryActivityInstanceQuery activityName(String activityName) {
+    this.activityName = activityName;
+    return this;
+  }
+
+  public HistoryActivityInstanceQuery executionId(String executionId) {
+    this.executionId = executionId;
+    return this;
+  }
+
+  public HistoryActivityInstanceQuery orderAsc(String property) {
+    addOrderByClause("hai."+property+" asc");
+    return this;
+  }
+
+  public HistoryActivityInstanceQuery orderDesc(String property) {
+    addOrderByClause("hai."+property+" desc");
+    return this;
+  }
+
+  public HistoryActivityInstanceQuery page(int firstResult, int maxResults) {
+    this.page = new Page(firstResult, maxResults);
+    return this;
+  }
+
+  public HistoryActivityInstanceQuery processDefinitionId(String processDefinitionId) {
+    this.processDefinitionId = processDefinitionId;
+    return this;
+  }
+
+  public HistoryActivityInstanceQuery startedAfter(Date time) {
+    this.startedAfter = time;
+    return this;
+  }
+
+  public HistoryActivityInstanceQuery startedBefore(Date time) {
+    this.startedBefore = time;
+    return this;
+  }
+
+  public HistoryActivityInstanceQuery tookLessThen(long durationInMillis) {
+    this.tookLessThen = durationInMillis;
+    return this;
+  }
+
+  public HistoryActivityInstanceQuery tookLongerThen(long durationInMillis) {
+    this.tookLongerThen = durationInMillis;
+    return this;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -24,8 +24,8 @@
 import java.util.List;
 
 import org.hibernate.Query;
-import org.jbpm.HistoryProcessInstanceQuery;
 import org.jbpm.cmd.CommandService;
+import org.jbpm.history.HistoryProcessInstanceQuery;
 import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl;
 
 
@@ -37,6 +37,7 @@
   private static final long serialVersionUID = 1L;
   
   protected String processDefinitionId;
+  protected String state;
 
   public HistoryProcessInstanceQueryImpl(CommandService commandService) {
     super(commandService);
@@ -50,9 +51,13 @@
     hql.append(" as hpi ");
     
     if (processDefinitionId!=null) {
-      appendWhereClause(" hpi.processDefinition.id = '"+processDefinitionId+"' ", hql);
+      appendWhereClause(" hpi.processDefinitionId = '"+processDefinitionId+"' ", hql);
     }
     
+    if (state!=null) {
+      appendWhereClause(" hpi.state = '"+state+"' ", hql);
+    }
+    
     return hql.toString();
   }
 
@@ -82,4 +87,9 @@
     this.processDefinitionId = processDefinitionId;
     return this;
   }
+
+  public HistoryProcessInstanceQuery state(String state) {
+    this.state = state;
+    return this;
+  }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -29,8 +29,9 @@
 import org.jbpm.Execution;
 import org.jbpm.ExecutionQuery;
 import org.jbpm.ExecutionService;
-import org.jbpm.HistoryProcessInstanceQuery;
 import org.jbpm.cmd.CommandService;
+import org.jbpm.history.HistoryActivityInstanceQuery;
+import org.jbpm.history.HistoryProcessInstanceQuery;
 import org.jbpm.pvm.internal.cmd.DeleteProcessInstance;
 import org.jbpm.pvm.internal.cmd.FindExecutionsCmd;
 import org.jbpm.pvm.internal.cmd.FindExecutionCmd;
@@ -41,6 +42,7 @@
 import org.jbpm.pvm.internal.cmd.StartExecutionCmd;
 import org.jbpm.pvm.internal.cmd.StartExecutionInLatestCmd;
 import org.jbpm.pvm.internal.query.ExecutionQueryImpl;
+import org.jbpm.pvm.internal.query.HistoryActivityInstanceQueryImpl;
 import org.jbpm.pvm.internal.query.HistoryProcessInstanceQueryImpl;
 
 
@@ -172,8 +174,4 @@
     cmd.setVariables(variables);
     return commandService.execute(cmd);
   }
-
-  public HistoryProcessInstanceQuery createHistoryProcessInstanceQuery() {
-    return new HistoryProcessInstanceQueryImpl(commandService);
-  }
 }

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -0,0 +1,58 @@
+/*
+ * 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.svc;
+
+import java.util.Map;
+
+import org.jbpm.HistoryService;
+import org.jbpm.cmd.CommandService;
+import org.jbpm.history.HistoryActivityInstanceQuery;
+import org.jbpm.history.HistoryProcessInstanceQuery;
+import org.jbpm.pvm.internal.query.AvgDurationPerActivityQueryCmd;
+import org.jbpm.pvm.internal.query.ChoiceDistributionQueryCmd;
+import org.jbpm.pvm.internal.query.HistoryActivityInstanceQueryImpl;
+import org.jbpm.pvm.internal.query.HistoryProcessInstanceQueryImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class HistoryServiceImpl implements HistoryService {
+  
+  protected CommandService commandService;
+
+  public Map<String, Long> avgDurationPerActivity(String processDefinitionId) {
+    return (Map) commandService.execute(new AvgDurationPerActivityQueryCmd(processDefinitionId));
+  }
+
+  public Map<String, Integer> choiceDistribution(String processDefinitionId, String activityName) {
+    return (Map) commandService.execute(new ChoiceDistributionQueryCmd(processDefinitionId, activityName));
+  }
+
+  public HistoryProcessInstanceQuery createHistoryProcessInstanceQuery() {
+    return new HistoryProcessInstanceQueryImpl(commandService);
+  }
+
+  public HistoryActivityInstanceQuery createHistoryActivityInstanceQuery(String processDefinitionId) {
+    return new HistoryActivityInstanceQueryImpl(commandService, processDefinitionId);
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/HistoryServiceBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/HistoryServiceBinding.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/HistoryServiceBinding.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -0,0 +1,47 @@
+/*
+ * 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.wire.binding;
+
+import org.jbpm.cmd.CommandService;
+import org.jbpm.pvm.internal.svc.HistoryServiceImpl;
+import org.jbpm.pvm.internal.wire.descriptor.ContextTypeRefDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class HistoryServiceBinding extends WireDescriptorBinding {
+
+  public HistoryServiceBinding() {
+    super("history-service");
+  }
+
+  public Object parse(Element element, Parse parse, Parser parser) {
+    ObjectDescriptor descriptor = new ObjectDescriptor(HistoryServiceImpl.class);
+    descriptor.addInjection("commandService", new ContextTypeRefDescriptor(CommandService.class));
+    return descriptor;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/HistoryServiceBinding.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.history.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.history.hbm.xml	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.history.hbm.xml	2009-02-13 14:40:26 UTC (rev 3871)
@@ -5,19 +5,21 @@
 
   <!-- ### HISTORY PROCESS INSTANCE ####################################### -->
   <class name="HistoryProcessInstanceImpl" table="JBPM_HIST_PROCINST">
-    <id name="id" column="ID_">
+    <id name="processInstanceId" column="ID_">
       <generator class="assigned" />
     </id>
     <version name="dbversion" column="DBVERSION_" />
 
+    <property name="processDefinitionId" column="PROCDEFID_" />
     <property name="key" column="KEY_" />
     <property name="startTime" column="START_" type="timestamp" />
     <property name="endTime" column="END_" type="timestamp" />
     <property name="duration" column="DURATION_" />
+    <property name="state" column="STATE_" />
 
     <many-to-one name="processDefinition" 
                  class="org.jbpm.pvm.internal.model.ProcessDefinitionImpl" 
-                 column="PROCESS_"
+                 column="PROCDEF_"
                  foreign-key="FK_HISTPI_PROCDEF"
                  index="IDX_HISTPI_PROCDEF" />
                  
@@ -56,16 +58,14 @@
     <property name="startTime" column="START_" type="timestamp" />
     <property name="endTime" column="END_" type="timestamp" />
     <property name="duration" column="DURATION_" />
+    <property name="transitionName" column="TRANSITION_" />
 
     <subclass name="HistoryAutomaticInstanceImpl" discriminator-value="AUT">
-      <subclass name="HistoryExclusiveInstanceImpl" discriminator-value="EXCL">
-        <property name="transitionName" column="TRANSITION_" />
-      </subclass>
+      <subclass name="HistoryExclusiveInstanceImpl" discriminator-value="EXCL" />
     </subclass>
     
     <subclass name="HistoryTaskInstanceImpl" discriminator-value="TASK">
       <property name="assignee" column="ASSIGNEE_" />
-      <property name="outcome" column="TRANSITION_" />
     </subclass>
   </class>
 

Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.wire.bindings.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.wire.bindings.xml	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.wire.bindings.xml	2009-02-13 14:40:26 UTC (rev 3871)
@@ -61,6 +61,7 @@
   <binding class="org.jbpm.pvm.internal.wire.binding.ExecutionServiceBinding" />
   <binding class="org.jbpm.pvm.internal.wire.binding.ManagementServiceBinding" />
   <binding class="org.jbpm.pvm.internal.wire.binding.IdentityServiceBinding" />
+  <binding class="org.jbpm.pvm.internal.wire.binding.HistoryServiceBinding" />
   
   <!-- deployers -->
   <binding class="org.jbpm.pvm.internal.wire.binding.DeployerManagerBinding" />

Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -28,6 +28,7 @@
 import org.jbpm.Configuration;
 import org.jbpm.Execution;
 import org.jbpm.ExecutionService;
+import org.jbpm.HistoryService;
 import org.jbpm.ManagementService;
 import org.jbpm.ProcessDefinition;
 import org.jbpm.ProcessEngine;
@@ -48,6 +49,7 @@
   protected static ExecutionService executionService;
   protected static ManagementService managementService;
   protected static TaskService taskService;
+  protected static HistoryService historyService;
 
   protected static CommandService commandService;
 
@@ -78,6 +80,7 @@
 
       processService = processEngine.getProcessService();
       executionService = processEngine.getExecutionService();
+      historyService = processEngine.getHistoryService();
       managementService = processEngine.getManagementService();
       taskService = processEngine.getTaskService();
       commandService = processEngine.get(CommandService.class);

Added: jbpm4/trunk/modules/test-db/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- jbpm4/trunk/modules/test-db/.settings/org.eclipse.jdt.core.prefs	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/.settings/org.eclipse.jdt.core.prefs	2009-02-13 14:40:26 UTC (rev 3871)
@@ -0,0 +1,5 @@
+#Fri Feb 13 11:21:25 CET 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5

Added: jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/AvgDurationTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/AvgDurationTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/AvgDurationTest.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -0,0 +1,85 @@
+/*
+ * 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.history;
+
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.Execution;
+import org.jbpm.history.HistoryProcessInstance;
+import org.jbpm.history.HistoryProcessInstanceQuery;
+import org.jbpm.test.DbTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class AvgDurationTest extends DbTestCase {
+
+  public void testAvgDuration() throws Exception {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <flow to='one' />" +
+      "  </start>" +
+      "  <state name='one'>" +
+      "    <flow to='two' />" +
+      "  </state>" +
+      "  <state name='two'>" +
+      "    <flow to='three' />" +
+      "  </state>" +
+      "  <state name='three'>" +
+      "    <flow to='end' />" +
+      "  </state>" +
+      "  <end name='end' />" +
+      "</process>"
+    );
+
+    executeProcess();
+    executeProcess();
+    executeProcess();
+
+    Map<String, Long> avgDurations = historyService.avgDurationPerActivity("ICL:1");
+    
+    Long avgDurationOne = avgDurations.get("one");
+    assertNotNull(avgDurationOne);
+    assertTrue(avgDurationOne>50);
+    Long avgDurationTwo = avgDurations.get("two");
+    assertNotNull(avgDurationTwo);
+    assertTrue(avgDurationTwo>20);
+    Long avgDurationThree = avgDurations.get("three");
+    assertNotNull(avgDurationThree);
+    assertTrue(avgDurationThree>0);
+
+    assertEquals(3, avgDurations.size());
+  }
+
+  protected void executeProcess() throws InterruptedException {
+    Execution execution = executionService.startExecutionByKey("ICL");
+    Thread.sleep(50);
+    executionService.signalExecutionById(execution.getId());
+    Thread.sleep(20);
+    executionService.signalExecutionById(execution.getId());
+    executionService.signalExecutionById(execution.getId());
+  }
+
+}


Property changes on: jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/AvgDurationTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/ChoiceDistributionTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/ChoiceDistributionTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/ChoiceDistributionTest.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -0,0 +1,75 @@
+/*
+ * 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.history;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.Execution;
+import org.jbpm.test.DbTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ChoiceDistributionTest extends DbTestCase {
+
+  public void testExclusiveExpression() {
+    deployJpdlXmlString(
+      "<process name='Transport Selection' key='TRS'>" +
+      "  <start>" +
+      "    <flow to='How far?' />" +
+      "  </start>" +
+      "  <exclusive name='How far?' expr='#{distance}'>" +
+      "    <flow name='far'           to='Big car' />" +
+      "    <flow name='nearby'        to='Small car' />" +
+      "    <flow name='other country' to='Airoplane' />" +
+      "  </exclusive>" +
+      "  <state name='Big car' />" +
+      "  <state name='Small car' />" +
+      "  <state name='Airoplane' />" +
+      "</process>"
+    );
+
+    Map<String, Object> variables = new HashMap<String, Object>();
+    variables.put("distance", "far");
+    executionService.startExecutionByKey("TRS", variables);
+
+    variables.put("distance", "nearby");
+    executionService.startExecutionByKey("TRS", variables);
+    executionService.startExecutionByKey("TRS", variables);
+    executionService.startExecutionByKey("TRS", variables);
+
+    variables.put("distance", "other country");
+    executionService.startExecutionByKey("TRS", variables);
+    executionService.startExecutionByKey("TRS", variables);
+
+    Map<String, Integer> choiceDistribution = historyService.choiceDistribution("TRS:1", "How far?");
+    
+    assertEquals(1, (int)choiceDistribution.get("far"));
+    assertEquals(3, (int)choiceDistribution.get("nearby"));
+    assertEquals(2, (int)choiceDistribution.get("other country"));
+      
+  }
+
+
+}


Property changes on: jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/ChoiceDistributionTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java	2009-02-13 14:40:26 UTC (rev 3871)
@@ -23,8 +23,8 @@
 
 import java.util.List;
 
-import org.jbpm.HistoryProcessInstanceQuery;
 import org.jbpm.history.HistoryProcessInstance;
+import org.jbpm.history.HistoryProcessInstanceQuery;
 import org.jbpm.test.DbTestCase;
 
 
@@ -33,7 +33,7 @@
  */
 public class ProcessInstanceHistoryTest extends DbTestCase {
 
-  public void testSignalExecutionByKey() {
+  public void testProcessInstanceHistory() {
     deployJpdlXmlString(
       "<process name='Insurance claim' key='ICL'>" +
       "  <start>" +
@@ -47,13 +47,19 @@
     executionService.startExecutionByKey("ICL");
     executionService.startExecutionByKey("ICL");
     
-    List<HistoryProcessInstance> historyProcessInstances = executionService
+    List<HistoryProcessInstance> historyProcessInstances = historyService
       .createHistoryProcessInstanceQuery()
       .processDefinitionId("ICL:1")
       .orderAsc(HistoryProcessInstanceQuery.PROPERTY_STARTTIME)
       .execute();
 
     assertEquals(3, historyProcessInstances.size());
+    
+    for (HistoryProcessInstance historyProcessInstance: historyProcessInstances) {
+      assertTrue(historyProcessInstance.getProcessInstanceId().startsWith("ICL"));
+      assertEquals(HistoryProcessInstance.STATE_ENDED, historyProcessInstance.getState());
+      assertNotNull(historyProcessInstance.getStartTime());
+      assertNotNull(historyProcessInstance.getEndTime());
+    }
   }
-
 }

Modified: jbpm4/trunk/modules/test-db/src/main/resources/jbpm.cfg.xml
===================================================================
--- jbpm4/trunk/modules/test-db/src/main/resources/jbpm.cfg.xml	2009-02-13 14:19:06 UTC (rev 3870)
+++ jbpm4/trunk/modules/test-db/src/main/resources/jbpm.cfg.xml	2009-02-13 14:40:26 UTC (rev 3871)
@@ -16,7 +16,9 @@
     
     <process-service />
     <execution-service />
+    <history-service />
     <management-service />
+    <identity-service />
     <task-service />
   
     <command-service>




More information about the jbpm-commits mailing list