Author: tom.baeyens(a)jboss.com
Date: 2009-07-17 09:52:24 -0400 (Fri, 17 Jul 2009)
New Revision: 5325
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/HistoryDetailQueryTest.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryDetailQuery.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryCommentImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryPriorityUpdateImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskAssignmentImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskDuedateUpdateImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableUpdateImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryDetailQueryImpl.java
Log:
JBPM-2398 added history detail query impl and started on the test
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryDetailQuery.java
===================================================================
---
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryDetailQuery.java 2009-07-17
13:50:03 UTC (rev 5324)
+++
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryDetailQuery.java 2009-07-17
13:52:24 UTC (rev 5325)
@@ -39,8 +39,8 @@
/** only select details for the given processInstanceId */
HistoryDetailQuery processInstanceId(String processInstanceId);
- /** only select details for the given historyActivityInstanceId */
- HistoryDetailQuery processActivityInstanceId(String historyActivityInstanceId);
+ /** only select details for the given activityInstanceId */
+ HistoryDetailQuery activityInstanceId(String activityInstanceId);
/** only select details for the given taskId */
HistoryDetailQuery taskId(String taskId);
@@ -51,9 +51,9 @@
/** only select details before the given time */
HistoryDetailQuery timeBefore(Date time);
- /** only select activity instances for the given activity
+ /** only select details of type comment
* (this usually used in combination with {@link #processDefinitionId(String)}) */
- HistoryDetailQuery taskComments();
+ HistoryDetailQuery comments();
/** order selected process definitions descending for certain {@link #PROPERTY_USERID
properties} */
HistoryDetailQuery orderDesc(String property);
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryCommentImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryCommentImpl.java 2009-07-17
13:50:03 UTC (rev 5324)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryCommentImpl.java 2009-07-17
13:52:24 UTC (rev 5325)
@@ -51,6 +51,10 @@
this.message = message;
}
+ public String toString() {
+ return (userId!=null ? userId+" comments: " : "comment:
")+message;
+ }
+
// replies //////////////////////////////////////////////////////////////////
public HistoryCommentImpl createReply(String message) {
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryPriorityUpdateImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryPriorityUpdateImpl.java 2009-07-17
13:50:03 UTC (rev 5324)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryPriorityUpdateImpl.java 2009-07-17
13:52:24 UTC (rev 5325)
@@ -42,4 +42,8 @@
this.oldPriority = oldPriority;
this.newPriority = newPriority;
}
+
+ public String toString() {
+ return (userId!=null ? userId+" updated priority" : "priority
updated")+" from "+oldPriority+" to "+newPriority;
+ }
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskAssignmentImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskAssignmentImpl.java 2009-07-17
13:50:03 UTC (rev 5324)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskAssignmentImpl.java 2009-07-17
13:52:24 UTC (rev 5325)
@@ -42,4 +42,8 @@
this.oldAssignee = oldAssignee;
this.newAssignee = newAssignee;
}
+
+ public String toString() {
+ return (userId!=null ? userId+" assigned task" : "task
assigned")+" from "+oldAssignee+" to "+newAssignee;
+ }
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskDuedateUpdateImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskDuedateUpdateImpl.java 2009-07-17
13:50:03 UTC (rev 5324)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskDuedateUpdateImpl.java 2009-07-17
13:52:24 UTC (rev 5325)
@@ -44,4 +44,8 @@
this.oldDuedate = oldDuedate;
this.newDuedate = newDuedate;
}
+
+ public String toString() {
+ return (userId!=null ? userId+" updated task duedate" : "task duedate
updated")+" from "+oldDuedate+" to "+newDuedate;
+ }
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableImpl.java 2009-07-17
13:50:03 UTC (rev 5324)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableImpl.java 2009-07-17
13:52:24 UTC (rev 5325)
@@ -25,7 +25,6 @@
import java.util.HashSet;
import java.util.Set;
-import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.type.Variable;
@@ -84,4 +83,36 @@
detail.setHistoryVariable(this, nextDetailIndex);
nextDetailIndex++;
}
+
+
+ public long getDbid() {
+ return dbid;
+ }
+ public int getDbversion() {
+ return dbversion;
+ }
+ public HistoryProcessInstanceImpl getHistoryProcessInstance() {
+ return historyProcessInstance;
+ }
+ public HistoryTaskImpl getHistoryTask() {
+ return historyTask;
+ }
+ public String getProcessInstanceId() {
+ return processInstanceId;
+ }
+ public String getExecutionId() {
+ return executionId;
+ }
+ public String getVariableName() {
+ return variableName;
+ }
+ public String getValue() {
+ return value;
+ }
+ public int getNextDetailIndex() {
+ return nextDetailIndex;
+ }
+ public Set<HistoryDetailImpl> getDetails() {
+ return details;
+ }
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableUpdateImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableUpdateImpl.java 2009-07-17
13:50:03 UTC (rev 5324)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableUpdateImpl.java 2009-07-17
13:52:24 UTC (rev 5325)
@@ -42,4 +42,8 @@
this.oldValue = oldValue;
this.newValue = newValue;
}
+
+ public String toString() {
+ return (userId!=null ? userId+" " : "")+"updated variable
"+this.historyVariable.getVariableName()+" from "+oldValue+" to
"+newValue;
+ }
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryDetailQueryImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryDetailQueryImpl.java 2009-07-17
13:50:03 UTC (rev 5324)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryDetailQueryImpl.java 2009-07-17
13:52:24 UTC (rev 5325)
@@ -27,6 +27,8 @@
import org.hibernate.Query;
import org.jbpm.api.history.HistoryDetail;
import org.jbpm.api.history.HistoryDetailQuery;
+import org.jbpm.pvm.internal.history.model.HistoryCommentImpl;
+import org.jbpm.pvm.internal.history.model.HistoryDetailImpl;
/**
@@ -34,53 +36,105 @@
*/
public class HistoryDetailQueryImpl extends AbstractQuery implements HistoryDetailQuery
{
- @Override
- protected void applyParameters(Query query) {
- }
+ protected Class<?> type = HistoryDetailImpl.class;
- @Override
+ protected Date timeBefore;
+ protected Date timeAfter;
+
+ protected String processInstanceId;
+ protected String activityInstanceId;
+ protected String taskId;
+
public String hql() {
- return null;
+ StringBuilder hql = new StringBuilder();
+ hql.append("select hd ");
+ hql.append("from ");
+ hql.append(type.getName());
+ hql.append(" as hd ");
+
+ if (taskId!=null) {
+ appendWhereClause(" hd.historyTask.dbid = "+taskId+" ", hql);
+ }
+
+ if (processInstanceId!=null) {
+ appendWhereClause(" hd.historyProcessInstance.dbid =
"+processInstanceId+" ", hql);
+ }
+
+ if (activityInstanceId!=null) {
+ appendWhereClause(" hd.historyActivityInstance.dbid =
"+activityInstanceId+" ", hql);
+ }
+
+ if (timeBefore!=null) {
+ appendWhereClause(" hd.time < :timeBefore ", hql);
+ }
+
+ if (timeAfter!=null) {
+ appendWhereClause(" hd.time > :timeAfter ", hql);
+ }
+
+ return hql.toString();
}
+ protected void applyParameters(Query query) {
+ if (timeAfter!=null) {
+ query.setTime("timeAfter", timeAfter);
+ }
+
+ if (timeBefore!=null) {
+ query.setTime("timeBefore", timeBefore);
+ }
+ }
+
public List<HistoryDetail> list() {
- return null;
+ return (List) untypedList();
}
+
+ public HistoryDetail uniqueResult() {
+ return (HistoryDetail) untypedUniqueResult();
+ }
- public HistoryDetailQuery orderDesc(String property) {
- return null;
+ public HistoryDetailQuery taskId(String taskId) {
+ this.taskId = taskId;
+ return this;
}
- public HistoryDetailQuery page(int firstResult, int maxResults) {
- return null;
+ public HistoryDetailQuery orderAsc(String property) {
+ addOrderByClause("hd."+property+" asc");
+ return this;
}
- public HistoryDetailQuery processActivityInstanceId(String historyActivityInstanceId)
{
- return null;
+ public HistoryDetailQuery orderDesc(String property) {
+ addOrderByClause("hd."+property+" desc");
+ return this;
}
- public HistoryDetailQuery processInstanceId(String processInstanceId) {
- return null;
+ public HistoryDetailQuery page(int firstResult, int maxResults) {
+ this.page = new Page(firstResult, maxResults);
+ return this;
}
- public HistoryDetailQuery taskComments() {
- return null;
+ public HistoryDetailQuery activityInstanceId(String activityInstanceId) {
+ this.activityInstanceId = activityInstanceId;
+ return this;
}
- public HistoryDetailQuery taskId(String taskId) {
- return null;
+ public HistoryDetailQuery processInstanceId(String processInstanceId) {
+ this.processInstanceId = processInstanceId;
+ return this;
}
- public HistoryDetailQuery timeAfter(Date time) {
- return null;
+ public HistoryDetailQuery comments() {
+ type = HistoryCommentImpl.class;
+ return this;
}
- public HistoryDetailQuery timeBefore(Date time) {
- return null;
+ public HistoryDetailQuery timeAfter(Date timeAfter) {
+ this.timeAfter = timeAfter;
+ return this;
}
- public HistoryDetail uniqueResult() {
- return null;
+ public HistoryDetailQuery timeBefore(Date timeBefore) {
+ this.timeBefore = timeBefore;
+ return this;
}
-
}
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/HistoryDetailQueryTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/HistoryDetailQueryTest.java
(rev 0)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/HistoryDetailQueryTest.java 2009-07-17
13:52:24 UTC (rev 5325)
@@ -0,0 +1,97 @@
+/*
+ * 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 org.jbpm.api.history.HistoryComment;
+import org.jbpm.api.history.HistoryDetail;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class HistoryDetailQueryTest extends JbpmTestCase {
+
+ public void testTaskCommentDetail() {
+ deployJpdlXmlString(
+ "<process name='TaskCommentDetail'>" +
+ " <start>" +
+ " <transition to='t' />" +
+ " </start>" +
+ " <task name='t' assignee='johndoe'/>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("TaskCommentDetail");
+
+ String taskId = taskService.createTaskQuery().uniqueResult().getId();
+
+ taskService.addTaskComment(taskId, "hello");
+
+ List<HistoryDetail> historyDetails =
historyService.createHistoryDetailQuery().list();
+ assertEquals(historyDetails.toString(), 1, historyDetails.size());
+
+ historyDetails = historyService
+ .createHistoryDetailQuery()
+ .comments()
+ .list();
+
+ assertEquals(historyDetails.toString(), 1, historyDetails.size());
+
+ HistoryComment historyComment = (HistoryComment) historyDetails.get(0);
+ assertEquals("hello", historyComment.getMessage());
+ }
+
+ public void testTaskCommentRepliesDetail() {
+ deployJpdlXmlString(
+ "<process name='TaskCommentRepliesDetail'>" +
+ " <start>" +
+ " <transition to='t' />" +
+ " </start>" +
+ " <task name='t' assignee='johndoe'/>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("TaskCommentRepliesDetail");
+
+ String taskId = taskService.createTaskQuery().uniqueResult().getId();
+
+ processEngine.setAuthenticatedUserId("johndoe");
+ String helloCommentId = taskService.addTaskComment(taskId, "hi, how are you
guys?").getId();
+
+ processEngine.setAuthenticatedUserId("joesmoe");
+ taskService.addReplyComment(helloCommentId, "i'm doing fine, thanks");
+
+ processEngine.setAuthenticatedUserId("jackblack");
+ taskService.addReplyComment(helloCommentId, "i got a hangover");
+
+ List<HistoryDetail> historyDetails =
historyService.createHistoryDetailQuery().list();
+ assertEquals(historyDetails.toString(), 3, historyDetails.size());
+
+ historyDetails = historyService
+ .createHistoryDetailQuery()
+ .comments()
+ .list();
+ }
+}
Property changes on:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/HistoryDetailQueryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain