Author: swiderski.maciej
Date: 2010-08-30 12:34:53 -0400 (Mon, 30 Aug 2010)
New Revision: 6635
Added:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryDetailUpdate.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Execution.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryProcessInstance.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryTask.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/AddTaskCommentCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskAssign.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/HistoryProcessInstanceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceMigrationImpl.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/HistoryTaskImpl.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/model/ExecutionImpl.java
jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
jbpm4/trunk/modules/pvm/src/main/resources/jbpm.history.hbm.xml
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryDetailQueryTest.java
Log:
JBPM-2398: improved history coverage, contains few other issues that are linked to
JBPM-2398 in jira
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Execution.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Execution.java 2010-08-29 08:47:23
UTC (rev 6634)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Execution.java 2010-08-30 16:34:53
UTC (rev 6635)
@@ -229,4 +229,7 @@
/** id of the process definition used for this execution */
String getProcessDefinitionId();
+
+ /** returns user id/name who started the process, can be null */
+ String getInitiator();
}
Added:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryDetailUpdate.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryDetailUpdate.java
(rev 0)
+++
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryDetailUpdate.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -0,0 +1,19 @@
+package org.jbpm.api.history;
+
+/**
+ * Additional interface for HistoryDetails to allow retrieving both old and new values.
+ *
+ * @author Tom Baeyens
+ */
+public interface HistoryDetailUpdate<T> {
+
+ /**
+ * Returns previous value of the item.
+ */
+ T getOldValue();
+
+ /**
+ * Returns new value of the item.
+ */
+ T getNewValue();
+}
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryProcessInstance.java
===================================================================
---
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryProcessInstance.java 2010-08-29
08:47:23 UTC (rev 6634)
+++
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryProcessInstance.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -46,6 +46,9 @@
/** the process instance id (== the root execution id) */
String getProcessInstanceId();
+
+ /** the supper process instance id */
+ String getSuperProcessInstanceId();
/** reference to the process definition */
String getProcessDefinitionId();
@@ -73,4 +76,7 @@
/** Returns the name of the end state that was reached when the process was ended.
*/
String getEndActivityName();
+
+ /** returns user id/name who started this process instance */
+ String getInitiator();
}
\ No newline at end of file
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryTask.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryTask.java 2010-08-29
08:47:23 UTC (rev 6634)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryTask.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -60,4 +60,10 @@
/** the outcome of this task */
String getOutcome();
+
+ /** name of this task */
+ String getName();
+
+ /** date and time when this task was completed. This might be null. */
+ Date getDuedate();
}
\ No newline at end of file
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/AddTaskCommentCmd.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/AddTaskCommentCmd.java 2010-08-29
08:47:23 UTC (rev 6634)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/AddTaskCommentCmd.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -24,8 +24,11 @@
import org.jbpm.api.JbpmException;
import org.jbpm.api.cmd.Environment;
import org.jbpm.api.history.HistoryComment;
+import org.jbpm.pvm.internal.client.ClientExecution;
import org.jbpm.pvm.internal.history.model.HistoryCommentImpl;
+import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl;
import org.jbpm.pvm.internal.history.model.HistoryTaskImpl;
+import org.jbpm.pvm.internal.model.ScopeInstanceImpl;
import org.jbpm.pvm.internal.session.DbSession;
@@ -51,7 +54,15 @@
throw new JbpmException("task "+taskDbid+" doesn't
exist");
}
HistoryCommentImpl comment = new HistoryCommentImpl(message);
- historyTask.addDetail(comment);
+
+ ClientExecution execution =
dbSession.findExecutionById(historyTask.getExecutionId());
+ if (execution != null) {
+ HistoryProcessInstanceImpl historyProcessInstance =
dbSession.get(HistoryProcessInstanceImpl.class,
((ScopeInstanceImpl)execution.getProcessInstance()).getDbid());
+
+ historyTask.addDetail(comment, historyProcessInstance);
+ } else {
+ historyTask.addDetail(comment);
+ }
dbSession.save(comment);
return comment;
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskAssign.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskAssign.java 2010-08-29
08:47:23 UTC (rev 6634)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/TaskAssign.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -45,6 +45,8 @@
public void process() {
DbSession dbSession = EnvironmentImpl.getFromCurrent(DbSession.class);
HistoryTaskImpl historyTaskInstance = dbSession.get(HistoryTaskImpl.class,
task.getDbid());
+
+ historyTaskInstance.updated(task);
historyTaskInstance.setAssignee(assignee);
}
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 2010-08-29
08:47:23 UTC (rev 6634)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryPriorityUpdateImpl.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -21,11 +21,13 @@
*/
package org.jbpm.pvm.internal.history.model;
+import org.jbpm.api.history.HistoryDetailUpdate;
+
/**
* @author Tom Baeyens
*/
-public class HistoryPriorityUpdateImpl extends HistoryDetailImpl {
+public class HistoryPriorityUpdateImpl extends HistoryDetailImpl implements
HistoryDetailUpdate<Integer> {
private static final long serialVersionUID = 1L;
@@ -46,4 +48,12 @@
public String toString() {
return (userId!=null ? userId+" updated priority" : "priority
updated")+" from "+oldPriority+" to "+newPriority;
}
+
+ public Integer getNewValue() {
+ return this.newPriority;
+ }
+
+ public Integer getOldValue() {
+ return this.oldPriority;
+ }
}
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 2010-08-29
08:47:23 UTC (rev 6634)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceImpl.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -52,6 +52,8 @@
protected Date startTime;
protected Date endTime;
protected Long duration;
+ protected String superProcessInstanceId;
+ protected String initiator;
protected int nextDetailIndex = 1;
/** only here to get hibernate cascade */
@@ -80,6 +82,10 @@
this.key = processInstance.getKey();
this.state = "active";
this.startTime = Clock.getTime();
+ this.initiator = processInstance.getInitiator();
+ if (processInstance.getSuperProcessExecution() != null) {
+ this.superProcessInstanceId = processInstance.getSuperProcessExecution().getId();
+ }
}
public void setEndTime(Date endTime) {
@@ -118,6 +124,9 @@
public String getKey() {
return key;
}
+ public void setKey(String key) {
+ this.key = key;
+ }
public String getState() {
return state;
}
@@ -139,4 +148,13 @@
public Set<HistoryVariableImpl> getHistoryVariables() {
return historyVariables;
}
+ public String getSuperProcessInstanceId() {
+ return superProcessInstanceId;
+ }
+ public void setSuperProcessInstanceId(String superProcessInstanceId) {
+ this.superProcessInstanceId = superProcessInstanceId;
+ }
+ public String getInitiator() {
+ return this.initiator;
+ }
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceMigrationImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceMigrationImpl.java 2010-08-29
08:47:23 UTC (rev 6634)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceMigrationImpl.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -21,11 +21,13 @@
*/
package org.jbpm.pvm.internal.history.model;
+import org.jbpm.api.history.HistoryDetailUpdate;
+
/**
* @author Koen Aers
*/
-public class HistoryProcessInstanceMigrationImpl extends HistoryDetailImpl {
+public class HistoryProcessInstanceMigrationImpl extends HistoryDetailImpl implements
HistoryDetailUpdate<String> {
private static final long serialVersionUID = 1L;
@@ -46,4 +48,12 @@
public String toString() {
return "migrated process instance " +
this.historyProcessInstance.getProcessInstanceId() + " from " +
oldProcessDefinitionId + " to " + newProcessDefinitionId;
}
+
+ public String getNewValue() {
+ return this.newProcessDefinitionId;
+ }
+
+ public String getOldValue() {
+ return this.oldProcessDefinitionId;
+ }
}
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 2010-08-29
08:47:23 UTC (rev 6634)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskAssignmentImpl.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -21,11 +21,13 @@
*/
package org.jbpm.pvm.internal.history.model;
+import org.jbpm.api.history.HistoryDetailUpdate;
+
/**
* @author Tom Baeyens
*/
-public class HistoryTaskAssignmentImpl extends HistoryDetailImpl {
+public class HistoryTaskAssignmentImpl extends HistoryDetailImpl implements
HistoryDetailUpdate<String> {
private static final long serialVersionUID = 1L;
@@ -46,4 +48,12 @@
public String toString() {
return (userId!=null ? userId+" assigned task" : "task
assigned")+" from "+oldAssignee+" to "+newAssignee;
}
+
+ public String getNewValue() {
+ return this.newAssignee;
+ }
+
+ public String getOldValue() {
+ return this.oldAssignee;
+ }
}
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 2010-08-29
08:47:23 UTC (rev 6634)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskDuedateUpdateImpl.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -23,11 +23,13 @@
import java.util.Date;
+import org.jbpm.api.history.HistoryDetailUpdate;
+
/**
* @author Tom Baeyens
*/
-public class HistoryTaskDuedateUpdateImpl extends HistoryDetailImpl {
+public class HistoryTaskDuedateUpdateImpl extends HistoryDetailImpl implements
HistoryDetailUpdate<Date> {
private static final long serialVersionUID = 1L;
@@ -48,4 +50,12 @@
public String toString() {
return (userId!=null ? userId+" updated task duedate" : "task duedate
updated")+" from "+oldDuedate+" to "+newDuedate;
}
+
+ public Date getNewValue() {
+ return this.newDuedate;
+ }
+
+ public Date getOldValue() {
+ return this.oldDuedate;
+ }
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskImpl.java 2010-08-29
08:47:23 UTC (rev 6634)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryTaskImpl.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -41,6 +41,7 @@
protected long dbid;
protected int dbversion;
+ protected String name;
protected String executionId;
protected String assignee;
protected String state;
@@ -60,11 +61,14 @@
/** only here to get hibernate cascade */
protected Set<HistoryDetailImpl> details = new
HashSet<HistoryDetailImpl>();
+
+
public HistoryTaskImpl() {
}
public HistoryTaskImpl(TaskImpl task) {
this.dbid = task.getDbid();
+ this.name = task.getName();
this.assignee = task.getAssignee();
this.priority = task.getPriority();
this.duedate = task.getDuedate();
@@ -97,6 +101,13 @@
this.details.add(detail);
nextDetailIndex++;
}
+
+ public void addDetail(HistoryDetailImpl detail, HistoryProcessInstanceImpl
historyProcessInstance) {
+ detail.setHistoryTask(this, nextDetailIndex);
+ detail.setHistoryProcessInstance(historyProcessInstance, nextDetailIndex);
+ this.details.add(detail);
+ nextDetailIndex++;
+ }
// subtasks /////////////////////////////////////////////////////////////////
@@ -159,5 +170,11 @@
}
public void setExecutionId(String executionId) {
this.executionId = executionId;
+ }
+ public String getName() {
+ return this.name;
}
+ public Date getDuedate() {
+ return this.duedate;
+ }
}
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 2010-08-29
08:47:23 UTC (rev 6634)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableImpl.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -75,13 +75,16 @@
if ( (value==null && newValue!=null)
|| (value!=null && (!value.equals(newValue)))
) {
+ addDetail(new HistoryVariableUpdateImpl(value, newValue));
this.value = newValue;
- addDetail(new HistoryVariableUpdateImpl(value, newValue));
}
}
public void addDetail(HistoryDetailImpl detail) {
detail.setHistoryVariable(this, nextDetailIndex);
+ detail.setHistoryProcessInstance(this.historyProcessInstance, nextDetailIndex);
+ detail.setHistoryTask(this.historyTask, nextDetailIndex);
+ details.add(detail);
nextDetailIndex++;
}
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 2010-08-29
08:47:23 UTC (rev 6634)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryVariableUpdateImpl.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -21,11 +21,13 @@
*/
package org.jbpm.pvm.internal.history.model;
+import org.jbpm.api.history.HistoryDetailUpdate;
+
/**
* @author Tom Baeyens
*/
-public class HistoryVariableUpdateImpl extends HistoryDetailImpl {
+public class HistoryVariableUpdateImpl extends HistoryDetailImpl implements
HistoryDetailUpdate<String> {
private static final long serialVersionUID = 1L;
@@ -46,4 +48,14 @@
public String toString() {
return (userId!=null ? userId+" " : "")+"updated variable
"+this.historyVariable.getVariableName()+" from "+oldValue+" to
"+newValue;
}
+
+ public String getNewValue() {
+ return this.newValue;
+ }
+
+ public String getOldValue() {
+ return this.oldValue;
+ }
+
+
}
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 2010-08-29
08:47:23 UTC (rev 6634)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -101,6 +101,9 @@
/** a unique id for this execution. */
protected String id;
+
+ /** user id/name who started the process instance, can be null */
+ protected String initiator;
/** are concurrent executions that related to this execution. */
protected Collection<ExecutionImpl> executions = new
ArrayList<ExecutionImpl>();
@@ -182,7 +185,9 @@
this.processInstance = this;
this.state = STATE_CREATED;
this.key = key;
-
+ if (EnvironmentImpl.getCurrent() != null) {
+ this.initiator = EnvironmentImpl.getCurrent().getAuthenticatedUserId();
+ }
save();
HistoryEvent.fire(new ProcessInstanceCreate(), this);
@@ -1041,6 +1046,7 @@
}
subProcessInstance = (ExecutionImpl) processDefinition.createProcessInstance(key);
subProcessInstance.setSuperProcessExecution(this);
+
return subProcessInstance;
}
@@ -1347,4 +1353,10 @@
public void setEventCompletedOperation(AtomicOperation eventCompletedOperation) {
this.eventCompletedOperation = eventCompletedOperation;
}
+ public String getInitiator() {
+ return initiator;
+ }
+ public void setInitiator(String initiator) {
+ this.initiator = initiator;
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2010-08-29 08:47:23
UTC (rev 6634)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2010-08-30 16:34:53
UTC (rev 6635)
@@ -58,6 +58,7 @@
<property name="priority" column="PRIORITY_" />
<property name="historyActivityInstanceDbid"
column="HISACTINST_" />
+ <property name="initiator" column="INITIATOR_" />
<list name="executions"
cascade="all-delete-orphan"
Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.history.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.history.hbm.xml 2010-08-29 08:47:23
UTC (rev 6634)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.history.hbm.xml 2010-08-30 16:34:53
UTC (rev 6635)
@@ -18,6 +18,8 @@
<property name="duration" column="DURATION_" />
<property name="state" column="STATE_" />
<property name="endActivityName" column="ENDACTIVITY_" />
+ <property name="superProcessInstanceId" column="SUPERPROCID_"
/>
+ <property name="initiator" column="INITIATOR_" />
<property name="nextDetailIndex" column="NEXTIDX_" />
@@ -99,7 +101,8 @@
<generator class="assigned" />
</id>
<version name="dbversion" column="DBVERSION_" />
-
+
+ <property name="name" column="NAME_" />
<property name="executionId" column="EXECUTION_" />
<property name="outcome" column="OUTCOME_" />
<property name="assignee" column="ASSIGNEE_" />
@@ -108,6 +111,7 @@
<property name="createTime" column="CREATE_"
type="timestamp" />
<property name="endTime" column="END_"
type="timestamp" />
<property name="duration" column="DURATION_" />
+ <property name="duedate" column="DUEDATE_"
type="timestamp" />
<property name="nextDetailIndex" column="NEXTIDX_" />
<set name="details"
@@ -207,7 +211,7 @@
class="HistoryVariableImpl"
column="HVAR_"
foreign-key="FK_HDETAIL_HVAR"
- index="IDX_HDET_HVAR" />
+ index="IDX_HDET_HVAR" lazy="false"/>
<property name="historyVariableIndex" column="HVARIDX_" />
<subclass name="HistoryCommentImpl"
discriminator-value="comment">
Modified:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryDetailQueryTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryDetailQueryTest.java 2010-08-29
08:47:23 UTC (rev 6634)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryDetailQueryTest.java 2010-08-30
16:34:53 UTC (rev 6635)
@@ -21,13 +21,17 @@
*/
package org.jbpm.test.query;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.List;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.history.HistoryComment;
import org.jbpm.api.history.HistoryDetail;
import org.jbpm.api.history.HistoryDetailQuery;
+import org.jbpm.api.history.HistoryDetailUpdate;
import org.jbpm.api.task.Task;
+import org.jbpm.pvm.internal.util.Clock;
import org.jbpm.test.JbpmTestCase;
import org.jbpm.test.assertion.QueryAssertions;
@@ -148,4 +152,159 @@
taskService.deleteTaskCascade(task.getId());
}
+ @SuppressWarnings("unchecked")
+ public void testHistoryVariable() {
+
+ deployJpdlXmlString("<process name='HistoryTaskDetail'>" +
+ " <variable name='variable-to-update' type='string'
init-expr='alex' history='true'/> " +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <task name='review' " +
+ " assignee='johndoe'>" +
+ " <transition to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>");
+ ProcessInstance pi =
executionService.startProcessInstanceByKey("HistoryTaskDetail");
+
+ assertEquals("alex", executionService.getVariable(pi.getId(),
"variable-to-update"));
+
+ executionService.setVariable(pi.getId(), "variable-to-update",
"peter");
+
+ List<Task> tasks = taskService.findPersonalTasks("johndoe");
+ assertEquals(1, tasks.size());
+
+ assertEquals("peter", executionService.getVariable(pi.getId(),
"variable-to-update"));
+
+ executionService.setVariable(pi.getId(), "variable-to-update",
"jack");
+ assertEquals("jack", historyService.getVariable(pi.getId(),
"variable-to-update"));
+
+ List<HistoryDetail> history =
historyService.createHistoryDetailQuery().processInstanceId(pi.getId()).list();
+ assertNotNull(history);
+ assertEquals(2, history.size());
+ assertEquals("updated variable variable-to-update from alex to peter",
history.get(0).toString());
+ assertEquals("updated variable variable-to-update from peter to jack",
history.get(1).toString());
+
+ assertEquals("alex", ((HistoryDetailUpdate)history.get(0)).getOldValue());
+ assertEquals("peter",
((HistoryDetailUpdate)history.get(0)).getNewValue());
+
+ assertEquals("peter",
((HistoryDetailUpdate)history.get(1)).getOldValue());
+ assertEquals("jack", ((HistoryDetailUpdate)history.get(1)).getNewValue());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testTaskReassignment() {
+ deployJpdlXmlString(
+ "<process name='TaskCommentReassignment'>" +
+ " <start>" +
+ " <transition to='t' />" +
+ " </start>" +
+ " <task name='t' assignee='johndoe'/>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("TaskCommentReassignment");
+
+ String taskId = taskService.createTaskQuery().uniqueResult().getId();
+
+ processEngine.setAuthenticatedUserId("johndoe");
+ taskService.assignTask(taskId, "alex");
+
+
+ List<HistoryDetail> historyDetails =
historyService.createHistoryDetailQuery().list();
+ assertEquals(1, historyDetails.size());
+ assertEquals("johndoe", historyDetails.get(0).getUserId());
+ assertEquals("johndoe",
((HistoryDetailUpdate)historyDetails.get(0)).getOldValue());
+ assertEquals("alex",
((HistoryDetailUpdate)historyDetails.get(0)).getNewValue());
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testTaskChangePriority() {
+ deployJpdlXmlString(
+ "<process name='TaskCommentReassignment'>" +
+ " <start>" +
+ " <transition to='t' />" +
+ " </start>" +
+ " <task name='t' assignee='johndoe'/>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("TaskCommentReassignment");
+
+ String taskId = taskService.createTaskQuery().uniqueResult().getId();
+ Task task = taskService.getTask(taskId);
+ task.setPriority(10);
+ processEngine.setAuthenticatedUserId("johndoe");
+ taskService.saveTask(task);
+
+
+ List<HistoryDetail> historyDetails =
historyService.createHistoryDetailQuery().list();
+ assertEquals(1, historyDetails.size());
+ assertEquals("johndoe", historyDetails.get(0).getUserId());
+ assertEquals(0, ((HistoryDetailUpdate)historyDetails.get(0)).getOldValue());
+ assertEquals(10, ((HistoryDetailUpdate)historyDetails.get(0)).getNewValue());
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testTaskChangeDuedate() {
+ deployJpdlXmlString(
+ "<process name='TaskCommentReassignment'>" +
+ " <start>" +
+ " <transition to='t' />" +
+ " </start>" +
+ " <task name='t' assignee='johndoe'/>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("TaskCommentReassignment");
+
+ String taskId = taskService.createTaskQuery().uniqueResult().getId();
+ Task task = taskService.getTask(taskId);
+ try {
+ task.setDuedate(new
SimpleDateFormat("yyyy-MM-dd").parse("2010-09-30"));
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ processEngine.setAuthenticatedUserId("johndoe");
+ taskService.saveTask(task);
+
+
+ List<HistoryDetail> historyDetails =
historyService.createHistoryDetailQuery().list();
+ assertEquals(1, historyDetails.size());
+ assertEquals("johndoe", historyDetails.get(0).getUserId());
+ assertNull(((HistoryDetailUpdate)historyDetails.get(0)).getOldValue());
+ assertNotNull(((HistoryDetailUpdate)historyDetails.get(0)).getNewValue());
+
+ }
+
+ public void testHistoryTaskComment() {
+
+ deployJpdlXmlString("<process name='HistoryTaskDetail'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <task name='review' " +
+ " assignee='johndoe'>" +
+ " <transition to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>");
+
+ ProcessInstance processInstance =
executionService.startProcessInstanceByKey("HistoryTaskDetail");
+ String processInstanceId = processInstance.getId();
+
+ List<Task> tasks = taskService.findPersonalTasks("johndoe");
+ assertEquals(1, tasks.size());
+ String taskId = tasks.get(0).getId();
+ taskService.addTaskComment(taskId, "Hello world.");
+
+ assertEquals(1, historyService.createHistoryDetailQuery().list().size());
+
+ assertEquals(1,
historyService.createHistoryDetailQuery().processInstanceId(processInstanceId).comments().list().size());
+ }
+
+
}