JBoss JBPM SVN: r6637 - in jbpm4/trunk/modules: api/src/main/java/org/jbpm/api/history and 3 other directories.
by do-not-reply@jboss.org
Author: swiderski.maciej
Date: 2010-08-31 13:35:24 -0400 (Tue, 31 Aug 2010)
New Revision: 6637
Added:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/QueryOperand.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/DeploymentQuery.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/JobQuery.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessDefinitionQuery.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessInstanceQuery.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/TaskQuery.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryActivityInstanceQuery.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryDetailQuery.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryProcessInstanceQuery.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryTaskQuery.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.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/query/HistoryDetailQueryImpl.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/query/HistoryTaskQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/JobQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessEndTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryTaskQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/JobQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessDefinitionQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessInstanceQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java
Log:
JBPM-2873 and JBPM-2868: support for using various query operands (like, in, not in, equals) with query parameters
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/DeploymentQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/DeploymentQuery.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/DeploymentQuery.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -35,6 +35,9 @@
/** only include a specific deployment by id */
DeploymentQuery deploymentId(String id);
+ /** only include a specific deployment by id allows to specify query operand*/
+ DeploymentQuery deploymentId(String id, QueryOperand operand);
+
/** only select suspended deployments */
DeploymentQuery suspended();
@@ -60,4 +63,5 @@
/** execute a count(*) query and returns number of results */
long count();
+
}
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/JobQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/JobQuery.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/JobQuery.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -49,6 +49,9 @@
/** only select jobs related to the given process instance */
JobQuery processInstanceId(String processInstanceId);
+
+ /** only select jobs related to the given process instance, allows to specify query operand*/
+ JobQuery processInstanceId(String processInstanceId, QueryOperand operand);
/** only select jobs that were rolled back due to an exception */
JobQuery exception(boolean hasException);
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessDefinitionQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessDefinitionQuery.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessDefinitionQuery.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -55,7 +55,19 @@
/** select only process definitions within the given deployment */
ProcessDefinitionQuery deploymentId(String deploymentId);
+
+ /** select only the process definition with the given id, allows to specify query operand */
+ ProcessDefinitionQuery processDefinitionId(String processDefinitionId, QueryOperand operand);
+ /** select only process definitions with the given key, allows to specify query operand */
+ ProcessDefinitionQuery processDefinitionKey(String key, QueryOperand operand);
+
+ /** select only process definitions with an exact match for the given name, allows to specify query operand */
+ ProcessDefinitionQuery processDefinitionName(String name, QueryOperand operand);
+
+ /** select only process definitions within the given deployment, allows to specify query operand */
+ ProcessDefinitionQuery deploymentId(String deploymentId, QueryOperand operand);
+
/** select only suspended process definitions */
ProcessDefinitionQuery suspended();
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessInstanceQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessInstanceQuery.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ProcessInstanceQuery.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -45,7 +45,22 @@
/** select only specific process instances using a business key */
ProcessInstanceQuery processInstanceKey(String processInstanceKey);
+
+ /** select only process instances that were started be given user */
+ ProcessInstanceQuery initiator(String user);
+
+ /** select only process instances for the given process definition, allows to specify query operand */
+ ProcessInstanceQuery processDefinitionId(String processDefinitionId, QueryOperand operand);
+ /** select only a specific process instances using the process instance id, allows to specify query operand */
+ ProcessInstanceQuery processInstanceId(String processInstanceId, QueryOperand operand);
+
+ /** select only specific process instances using a business key, allows to specify query operand */
+ ProcessInstanceQuery processInstanceKey(String processInstanceKey, QueryOperand operand);
+
+ /** select only process instances that were started be given user, allows to specify query operand */
+ ProcessInstanceQuery initiator(String user, QueryOperand operand);
+
/** select only suspended process definitions */
ProcessInstanceQuery suspended();
@@ -69,4 +84,5 @@
/** execute a count(*) query and returns number of results */
long count();
+
}
Added: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/QueryOperand.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/QueryOperand.java (rev 0)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/QueryOperand.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -0,0 +1,26 @@
+package org.jbpm.api;
+
+
+public enum QueryOperand {
+
+ EQUALS(0, "="),
+ LIKE(1, "like"),
+ IN(2, "in"),
+ NOT_IN(3, "not in");
+
+ @SuppressWarnings("unused")
+ private int id;
+ private String value;
+
+ QueryOperand(int id, String value) {
+ this.id = id;
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return this.value;
+ }
+
+
+}
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/TaskQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/TaskQuery.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/TaskQuery.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -70,7 +70,26 @@
/** only select tasks that are associated to the given activity name. This
* can be used in combination with the {@link #processDefinitionId(String)} */
TaskQuery activityName(String activityName);
+
+ /** only query for tasks for which the given user is a candidate, allows to specify query operand.
+ * The user could be associated directly as a candidate participant
+ * to the task or the user could be a member of a group that is
+ * associated as a candidate group to the task. */
+ TaskQuery assignee(String userId, QueryOperand operand);
+
+ /** only select tasks that are associated to the given execution, allows to specify query operand */
+ TaskQuery executionId(String executionId, QueryOperand operand);
+ /** only select tasks that are associated to the given process instance, allows to specify query operand */
+ TaskQuery processInstanceId(String processInstanceId, QueryOperand operand);
+
+ /** only select tasks that are associated to the given process definition, allows to specify query operand */
+ TaskQuery processDefinitionId(String processDefinitionId, QueryOperand operand);
+
+ /** only select tasks that are associated to the given activity name, allows to specify query operand. This
+ * can be used in combination with the {@link #processDefinitionId(String)} */
+ TaskQuery activityName(String activityName, QueryOperand operand);
+
/** only select suspended tasks */
TaskQuery suspended();
@@ -94,4 +113,5 @@
/** execute the query and obtain the unique {@link Task} */
Task uniqueResult();
+
}
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryActivityInstanceQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryActivityInstanceQuery.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryActivityInstanceQuery.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -24,10 +24,13 @@
import java.util.Date;
import java.util.List;
+import org.jbpm.api.QueryOperand;
+
/** query for {@link HistoryActivityInstance activity occurrences}.
*
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public interface HistoryActivityInstanceQuery {
@@ -50,7 +53,16 @@
/** only select activity instances for the given process instance id */
HistoryActivityInstanceQuery processInstanceId(String processInstanceId);
+
+ /** only select activity instances for the given process definition, allows to specify query operand */
+ HistoryActivityInstanceQuery processDefinitionId(String processDefinitionId, QueryOperand operand);
+ /** only select activity instances for the given execution, allows to specify query operand */
+ HistoryActivityInstanceQuery executionId(String executionId, QueryOperand operand);
+
+ /** only select activity instances for the given process instance id, allows to specify query operand */
+ HistoryActivityInstanceQuery processInstanceId(String processInstanceId, QueryOperand operand);
+
/** only select activity instances started after the given time */
HistoryActivityInstanceQuery startedAfter(Date time);
@@ -60,6 +72,13 @@
/** only select activity instances for the given activity
* (this usually used in combination with {@link #processDefinitionId(String)}) */
HistoryActivityInstanceQuery activityName(String activityName);
+
+ /** only select activity instances that are not active any more */
+ HistoryActivityInstanceQuery completedOnly();
+
+ /** only select activity instances for the given activity, allows to specify query operand
+ * (this usually used in combination with {@link #processDefinitionId(String)}) */
+ HistoryActivityInstanceQuery activityName(String activityName, QueryOperand operand);
/** only select activity instances that took longer then the given duration in milliseconds */
HistoryActivityInstanceQuery tookLongerThen(long durationInMillis);
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 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryDetailQuery.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -24,10 +24,13 @@
import java.util.Date;
import java.util.List;
+import org.jbpm.api.QueryOperand;
+
/** query for task comments, task assignments and so on.
*
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public interface HistoryDetailQuery {
@@ -44,7 +47,16 @@
/** only select details for the given taskId */
HistoryDetailQuery taskId(String taskId);
+
+ /** only select details for the given processInstanceId, allows to specify query operand */
+ HistoryDetailQuery processInstanceId(String processInstanceId, QueryOperand operand);
+ /** only select details for the given activityInstanceId, allows to specify query operand */
+ HistoryDetailQuery activityInstanceId(String activityInstanceId, QueryOperand operand);
+
+ /** only select details for the given taskId, allows to specify query operand */
+ HistoryDetailQuery taskId(String taskId, QueryOperand operand);
+
/** only select details after the given time */
HistoryDetailQuery timeAfter(Date time);
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryProcessInstanceQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryProcessInstanceQuery.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryProcessInstanceQuery.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -24,11 +24,14 @@
import java.util.Date;
import java.util.List;
+import org.jbpm.api.QueryOperand;
+
/** query for ongoing and finished
* {@linkplain HistoryProcessInstance process instances}.
*
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public interface HistoryProcessInstanceQuery {
@@ -56,7 +59,33 @@
/** select only process instances in the given state */
HistoryProcessInstanceQuery state(String state);
+
+ /** select only process instances that were started be given user */
+ HistoryProcessInstanceQuery initiator(String user);
+
+ /** select only the process instances with the super process instance as given id,
+ * in other words sub process instances */
+ HistoryProcessInstanceQuery superProcessInstanceId(String processInstanceId);
+
+ /** select only the process instances with the given id, allows to specify query operand */
+ HistoryProcessInstanceQuery processInstanceId(String processInstanceId, QueryOperand operand);
+ /** select only process instances with the given process definition, allows to specify query operand */
+ HistoryProcessInstanceQuery processDefinitionId(String processDefinitionId, QueryOperand operand);
+
+ /** select only process instances with the given business key, allows to specify query operand */
+ HistoryProcessInstanceQuery processInstanceKey(String processInstanceKey, QueryOperand operand);
+
+ /** select only process instances in the given state, allows to specify query operand */
+ HistoryProcessInstanceQuery state(String state, QueryOperand operand);
+
+ /** select only process instances that were started be given user, allows to specify query operand */
+ HistoryProcessInstanceQuery initiator(String user, QueryOperand operand);
+
+ /** select only the process instances with the super process instance as given id,
+ * in other words sub process instances, allows to specify query operand */
+ HistoryProcessInstanceQuery superProcessInstanceId(String processInstanceId, QueryOperand operand);
+
/** order selected process instances ascending for certain {@link #PROPERTY_STARTTIME properties} */
HistoryProcessInstanceQuery orderAsc(String property);
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryTaskQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryTaskQuery.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/history/HistoryTaskQuery.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -24,10 +24,13 @@
import java.util.Date;
import java.util.List;
+import org.jbpm.api.QueryOperand;
+
/** query for history tasks.
*
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public interface HistoryTaskQuery {
@@ -51,6 +54,9 @@
/** only select the history task for the given id */
HistoryTaskQuery taskId(String taskId);
+ /** only select history tasks within the given processInstanceId */
+ HistoryTaskQuery processInstanceId(String processInstanceId);
+
/** only select history tasks within the given execution */
HistoryTaskQuery executionId(String executionId);
@@ -59,9 +65,27 @@
/** only select history tasks in the given state */
HistoryTaskQuery state(String state);
+
+ /** only select the history task for the given id, allows to specify query operand */
+ HistoryTaskQuery taskId(String taskId, QueryOperand operand);
+
+ /** only select history tasks within the given processInstanceId, allows to specify query operand */
+ HistoryTaskQuery processInstanceId(String processInstanceId, QueryOperand operand);
+
+ /** only select history tasks within the given execution, allows to specify query operand */
+ HistoryTaskQuery executionId(String executionId, QueryOperand operand);
+
+ /** only select history tasks for the given assignee, allows to specify query operand */
+ HistoryTaskQuery assignee(String assignee, QueryOperand operand);
+ /** only select history tasks in the given state, allows to specify query operand */
+ HistoryTaskQuery state(String state, QueryOperand operand);
+
/** only select history tasks that have the given outcome */
HistoryTaskQuery outcome(String outcome);
+
+ /** only select history tasks that have the given outcome, allows to specify query operand */
+ HistoryTaskQuery outcome(String outcome, QueryOperand operand);
/** order selected history tasks ascending for certain {@link #PROPERTY_ID properties} */
HistoryTaskQuery orderAsc(String property);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -22,12 +22,15 @@
package org.jbpm.pvm.internal.query;
import java.io.ObjectStreamException;
+import java.lang.reflect.Array;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.hibernate.Query;
import org.hibernate.Session;
-
import org.jbpm.api.JbpmException;
+import org.jbpm.api.QueryOperand;
import org.jbpm.api.cmd.Command;
import org.jbpm.api.cmd.Environment;
import org.jbpm.pvm.internal.cmd.CommandService;
@@ -35,6 +38,7 @@
/**
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public abstract class AbstractQuery implements Command<Object> {
@@ -47,6 +51,8 @@
protected boolean count;
protected boolean uniqueResult;
+ protected Map<String, QueryOperand> parameterOperands = new HashMap<String, QueryOperand>();
+
protected abstract void applyParameters(Query query);
public abstract String hql();
@@ -155,7 +161,66 @@
this.commandService = null;
return this;
}
+
+ protected QueryOperand getOperand(String param) {
+ if (parameterOperands.containsKey(param)) {
+ return parameterOperands.get(param);
+ }
+ return QueryOperand.EQUALS;
+ }
+
+ protected boolean isListOperand(String param) {
+ QueryOperand operand = getOperand(param);
+
+ if (operand == QueryOperand.IN || operand == QueryOperand.NOT_IN) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Transforms given string (<code>parameter</code>) to an array of given type (<code>clazz</code>).
+ * <code>parameter</code> will be split using separator ',' (comma).
+ * Array will be populated based on split string by creating new instance of class <code>clazz</code>
+ * using its constructor that accepts String argument.
+ * All exceptions will be silently skipped.
+ */
+ @SuppressWarnings("unchecked")
+ protected <T> T[] transformToArray(String parameter, T clazz) {
+ String[] idsStr = parameter.split(",");
+ if (clazz instanceof String) {
+ return (T[]) idsStr;
+ }
+ T[] ids = (T[]) Array.newInstance( (Class)clazz, idsStr.length);
+
+ for (int i = 0; i < idsStr.length; i++) {
+ try {
+ ids[i] = (T) ((Class)clazz).getConstructor(String.class).newInstance(idsStr[i]);
+ } catch (Exception e) {
+ }
+ }
+ return ids;
+ }
+
+ protected void appendWhereClauseWithOperand(String where, String namedParam, StringBuilder hql) {
+ QueryOperand operand = getOperand(namedParam);
+ if (isListOperand(namedParam)) {
+ appendWhereClause(where + " " + operand + " (:" + namedParam + ") ", hql);
+ } else {
+ appendWhereClause(where + " " + operand + " :" + namedParam + " ", hql);
+ }
+ }
+
+ protected void applyParameterWithOperand(String parameter, String namedParam, Class<?> clazz, Query query) {
+ if (isListOperand(namedParam)) {
+ query.setParameterList(namedParam, transformToArray(parameter, clazz));
+ } else {
+ query.setString(namedParam, parameter);
+ }
+ }
+
public void setCommandService(CommandService commandService) {
this.commandService = commandService;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -26,12 +26,14 @@
import org.hibernate.Query;
import org.jbpm.api.Deployment;
import org.jbpm.api.DeploymentQuery;
+import org.jbpm.api.QueryOperand;
import org.jbpm.pvm.internal.repository.DeploymentImpl;
import org.jbpm.pvm.internal.util.CollectionUtil;
/**
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public class DeploymentQueryImpl extends AbstractQuery implements DeploymentQuery {
@@ -53,7 +55,7 @@
hql.append(" as d ");
if (deploymentId!=null) {
- appendWhereClause("d.dbid = "+deploymentId+" ", hql);
+ appendWhereClauseWithOperand("d.dbid", "deploymentId", hql);
}
if (suspended!=null) {
@@ -70,6 +72,10 @@
}
protected void applyParameters(Query query) {
+
+ if (deploymentId != null) {
+ applyParameterWithOperand(deploymentId, "deploymentId", Long.class, query);
+ }
}
public DeploymentQuery deploymentId(String deploymentId) {
@@ -109,4 +115,10 @@
public Deployment uniqueResult() {
return (Deployment) untypedUniqueResult();
}
+
+ public DeploymentQuery deploymentId(String id, QueryOperand operand) {
+ this.deploymentId = id;
+ parameterOperands.put("deploymentId", operand);
+ return this;
+ }
}
Modified: 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 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -26,6 +26,7 @@
import org.hibernate.Query;
import org.jbpm.api.JbpmException;
+import org.jbpm.api.QueryOperand;
import org.jbpm.api.history.HistoryActivityInstance;
import org.jbpm.api.history.HistoryActivityInstanceQuery;
import org.jbpm.pvm.internal.history.model.HistoryActivityInstanceImpl;
@@ -34,6 +35,7 @@
/**
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public class HistoryActivityInstanceQueryImpl extends AbstractQuery implements HistoryActivityInstanceQuery {
@@ -47,6 +49,7 @@
protected String executionId;
protected String processInstanceId;
protected String activityName;
+ protected boolean completedOnly;
public String hql() {
StringBuilder hql = new StringBuilder();
@@ -63,7 +66,7 @@
hql.append(" as hai ");
if (processDefinitionId!=null) {
- appendWhereClause(" hai.historyProcessInstance.processDefinitionId = '"+processDefinitionId+"' ", hql);
+ appendWhereClauseWithOperand("hai.historyProcessInstance.processDefinitionId", "processDefinitionId", hql);
}
if (tookLessThen!=null) {
@@ -83,17 +86,21 @@
}
if (processInstanceId!=null) {
- appendWhereClause(" hai.historyProcessInstance.processInstanceId = '"+processInstanceId+"'", hql);
+ appendWhereClauseWithOperand("hai.historyProcessInstance.processInstanceId", "processInstanceId", hql);
}
if (executionId!=null) {
- appendWhereClause(" hai.executionId = '"+executionId+"'", hql);
+ appendWhereClauseWithOperand("hai.executionId", "executionId", hql);
}
if (activityName!=null) {
- appendWhereClause(" hai.activityName = '"+activityName+"'", hql);
+ appendWhereClauseWithOperand("hai.activityName", "activityName", hql);
}
+ if (completedOnly) {
+ appendWhereClause(" hai.endTime is not null ", hql);
+ }
+
appendOrderByClause(hql);
return hql.toString();
@@ -115,6 +122,22 @@
if (startedAfter!=null) {
query.setTimestamp("startedAfter", startedAfter);
}
+
+ if (processDefinitionId!=null) {
+ applyParameterWithOperand(processDefinitionId, "processDefinitionId", String.class, query);
+ }
+
+ if (processInstanceId!=null) {
+ applyParameterWithOperand(processInstanceId, "processInstanceId", String.class, query);
+ }
+
+ if (executionId!=null) {
+ applyParameterWithOperand(executionId, "executionId", String.class, query);
+ }
+
+ if (activityName!=null) {
+ applyParameterWithOperand(activityName, "activityName", String.class, query);
+ }
}
public List<HistoryActivityInstance> list() {
@@ -182,4 +205,37 @@
this.tookLongerThen = durationInMillis;
return this;
}
+
+ public HistoryActivityInstanceQuery completedOnly() {
+ this.completedOnly = true;
+ return this;
+ }
+
+ public HistoryActivityInstanceQuery activityName(String activityName, QueryOperand operand) {
+ this.activityName = activityName;
+ parameterOperands.put("activityName", operand);
+
+ return this;
+ }
+
+ public HistoryActivityInstanceQuery executionId(String executionId, QueryOperand operand) {
+ this.executionId = executionId;
+ parameterOperands.put("executionId", operand);
+
+ return this;
+ }
+
+ public HistoryActivityInstanceQuery processDefinitionId(String processDefinitionId, QueryOperand operand) {
+ this.processDefinitionId = processDefinitionId;
+ parameterOperands.put("processDefinitionId", operand);
+
+ return this;
+ }
+
+ public HistoryActivityInstanceQuery processInstanceId(String processInstanceId, QueryOperand operand) {
+ this.processInstanceId = processInstanceId;
+ parameterOperands.put("processInstanceId", operand);
+
+ return this;
+ }
}
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 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryDetailQueryImpl.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -25,6 +25,7 @@
import java.util.List;
import org.hibernate.Query;
+import org.jbpm.api.QueryOperand;
import org.jbpm.api.history.HistoryDetail;
import org.jbpm.api.history.HistoryDetailQuery;
import org.jbpm.pvm.internal.history.model.HistoryCommentImpl;
@@ -34,6 +35,7 @@
/**
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public class HistoryDetailQueryImpl extends AbstractQuery implements HistoryDetailQuery {
@@ -48,21 +50,26 @@
public String hql() {
StringBuilder hql = new StringBuilder();
- hql.append("select hd ");
+ hql.append("select ");
+ if (count) {
+ hql.append("count(hd) ");
+ } else {
+ hql.append("hd ");
+ }
hql.append("from ");
hql.append(type.getName());
hql.append(" as hd ");
if (taskId!=null) {
- appendWhereClause(" hd.historyTask.dbid = "+taskId+" ", hql);
+ appendWhereClauseWithOperand("hd.historyTask.dbid", "taskId", hql);
}
if (processInstanceId!=null) {
- appendWhereClause(" hd.historyProcessInstance.processInstanceId = '"+processInstanceId+"' ", hql);
+ appendWhereClauseWithOperand("hd.historyProcessInstance.processInstanceId", "processInstanceId", hql);
}
if (activityInstanceId!=null) {
- appendWhereClause(" hd.historyActivityInstance.dbid = "+activityInstanceId+" ", hql);
+ appendWhereClauseWithOperand("hd.historyActivityInstance.dbid", "activityInstanceId", hql);
}
if (timeBefore!=null) {
@@ -86,6 +93,18 @@
if (timeBefore!=null) {
query.setTime("timeBefore", timeBefore);
}
+
+ if (taskId!=null) {
+ applyParameterWithOperand(taskId, "taskId", Long.class, query);
+ }
+
+ if (processInstanceId!=null) {
+ applyParameterWithOperand(processInstanceId, "processInstanceId", String.class, query);
+ }
+
+ if (activityInstanceId!=null) {
+ applyParameterWithOperand(activityInstanceId, "activityInstanceId", Long.class, query);
+ }
}
public List<HistoryDetail> list() {
@@ -140,4 +159,25 @@
this.timeBefore = timeBefore;
return this;
}
+
+ public HistoryDetailQuery activityInstanceId(String activityInstanceId, QueryOperand operand) {
+ this.activityInstanceId = activityInstanceId;
+ parameterOperands.put("activityInstanceId", operand);
+
+ return this;
+ }
+
+ public HistoryDetailQuery processInstanceId(String processInstanceId, QueryOperand operand) {
+ this.processInstanceId = processInstanceId;
+ parameterOperands.put("processInstanceId", operand);
+
+ return this;
+ }
+
+ public HistoryDetailQuery taskId(String taskId, QueryOperand operand) {
+ this.taskId = taskId;
+ parameterOperands.put("taskId", operand);
+
+ return this;
+ }
}
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 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -25,6 +25,7 @@
import java.util.List;
import org.hibernate.Query;
+import org.jbpm.api.QueryOperand;
import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.history.HistoryProcessInstanceQuery;
import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl;
@@ -33,6 +34,7 @@
/**
* @author Tom Baeyens
* @author Alejandro Guizar
+ * @author Maciej Swiderski
*/
public class HistoryProcessInstanceQueryImpl extends AbstractQuery implements HistoryProcessInstanceQuery {
@@ -42,10 +44,13 @@
protected String state;
protected String processInstanceId;
protected String processInstanceKey;
+ protected String initiator;
+ protected String superProcessInstanceId;
protected boolean ended;
protected Date endedBefore;
protected Date endedAfter;
+
public String hql() {
StringBuilder hql = new StringBuilder();
@@ -62,21 +67,29 @@
hql.append(" as hpi ");
if (processInstanceId!=null) {
- appendWhereClause(" hpi.processInstanceId = '"+processInstanceId+"' ", hql);
+ appendWhereClauseWithOperand("hpi.processInstanceId", "processInstanceId", hql);
}
if (processDefinitionId!=null) {
- appendWhereClause(" hpi.processDefinitionId = '"+processDefinitionId+"' ", hql);
+ appendWhereClauseWithOperand("hpi.processDefinitionId", "processDefinitionId", hql);
}
if (state!=null) {
- appendWhereClause(" hpi.state = '"+state+"' ", hql);
+ appendWhereClauseWithOperand("hpi.state", "state", hql);
}
if (processInstanceKey!=null) {
- appendWhereClause(" hpi.key = '" + processInstanceKey + "'", hql);
+ appendWhereClauseWithOperand("hpi.key", "processInstanceKey", hql);
}
+ if (initiator!=null) {
+ appendWhereClauseWithOperand("hpi.initiator", "initiator", hql);
+ }
+
+ if (superProcessInstanceId!=null) {
+ appendWhereClauseWithOperand("hpi.superProcessInstanceId", "superProcessInstanceId", hql);
+ }
+
if (ended) {
appendWhereClause(" hpi.endTime is not null", hql);
}
@@ -99,6 +112,30 @@
if (endedAfter != null) {
query.setTimestamp("after", endedAfter);
}
+
+ if (processInstanceId!=null) {
+ applyParameterWithOperand(processInstanceId, "processInstanceId", String.class, query);
+ }
+
+ if (processDefinitionId!=null) {
+ applyParameterWithOperand(processDefinitionId, "processDefinitionId", String.class, query);
+ }
+
+ if (state!=null) {
+ applyParameterWithOperand(state, "state", String.class, query);
+ }
+
+ if (processInstanceKey!=null) {
+ applyParameterWithOperand(processInstanceKey, "processInstanceKey", String.class, query);
+ }
+
+ if (initiator!=null) {
+ applyParameterWithOperand(initiator, "initiator", String.class, query);
+ }
+
+ if (superProcessInstanceId!=null) {
+ applyParameterWithOperand(superProcessInstanceId, "superProcessInstanceId", String.class, query);
+ }
}
public List<HistoryProcessInstance> list() {
@@ -143,6 +180,11 @@
this.state = state;
return this;
}
+
+ public HistoryProcessInstanceQuery initiator(String user) {
+ this.initiator = user;
+ return this;
+ }
public HistoryProcessInstanceQuery ended() {
ended = true;
@@ -167,4 +209,52 @@
ended = false;
return this;
}
+
+ public HistoryProcessInstanceQuery processDefinitionId(String processDefinitionId, QueryOperand operand) {
+ this.processDefinitionId = processDefinitionId;
+ parameterOperands.put("processDefinitionId", operand);
+
+ return this;
+ }
+
+ public HistoryProcessInstanceQuery processInstanceId(String processInstanceId, QueryOperand operand) {
+ this.processInstanceId = processInstanceId;
+ parameterOperands.put("processInstanceId", operand);
+
+ return this;
+ }
+
+ public HistoryProcessInstanceQuery processInstanceKey(String processInstanceKey, QueryOperand operand) {
+ this.processInstanceKey = processInstanceKey;
+ parameterOperands.put("processInstanceKey", operand);
+
+ return this;
+ }
+
+ public HistoryProcessInstanceQuery state(String state, QueryOperand operand) {
+ this.state = state;
+ parameterOperands.put("state", operand);
+
+ return this;
+ }
+
+ public HistoryProcessInstanceQuery initiator(String user, QueryOperand operand) {
+ this.initiator = user;
+ parameterOperands.put("initiator", operand);
+
+ return this;
+ }
+
+ public HistoryProcessInstanceQuery superProcessInstanceId(String processInstanceId) {
+ this.superProcessInstanceId = processInstanceId;
+
+ return this;
+ }
+
+ public HistoryProcessInstanceQuery superProcessInstanceId(String processInstanceId, QueryOperand operand) {
+ this.superProcessInstanceId = processInstanceId;
+ parameterOperands.put("superProcessInstanceId", operand);
+
+ return this;
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryTaskQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryTaskQueryImpl.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryTaskQueryImpl.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -26,18 +26,22 @@
import org.hibernate.Query;
+import org.jbpm.api.QueryOperand;
import org.jbpm.api.history.HistoryTask;
import org.jbpm.api.history.HistoryTaskQuery;
import org.jbpm.pvm.internal.history.model.HistoryTaskImpl;
+import org.jbpm.pvm.internal.history.model.HistoryTaskInstanceImpl;
import org.jbpm.pvm.internal.util.CollectionUtil;
/**
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public class HistoryTaskQueryImpl extends AbstractQuery implements HistoryTaskQuery {
protected String taskId;
protected String executionId;
+ protected String processInstanceId;
protected String assignee;
protected String state;
protected String outcome;
@@ -60,24 +64,32 @@
hql.append(HistoryTaskImpl.class.getName());
hql.append(" as ht ");
+ if (processInstanceId != null) {
+ hql.append(", ");
+ hql.append(HistoryTaskInstanceImpl.class.getName());
+ hql.append(" as hti ");
+ appendWhereClause("ht = hti.historyTask", hql);
+ appendWhereClauseWithOperand("hti.historyProcessInstance.processInstanceId", "processInstanceId", hql);
+ }
+
if (taskId!=null) {
- appendWhereClause(" ht.dbid = "+taskId+" ", hql);
+ appendWhereClauseWithOperand("ht.dbid", "taskId", hql);
}
if (executionId!=null) {
- appendWhereClause(" ht.executionId = '"+executionId+"' ", hql);
+ appendWhereClauseWithOperand("ht.executionId", "executionId", hql);
}
if (assignee!=null) {
- appendWhereClause(" ht.assignee = '"+assignee+"' ", hql);
+ appendWhereClauseWithOperand("ht.assignee", "assignee", hql);
}
if (state!=null) {
- appendWhereClause(" ht.state = '"+state+"' ", hql);
+ appendWhereClauseWithOperand("ht.state", "state", hql);
}
if (outcome!=null) {
- appendWhereClause(" ht.outcome = '"+outcome+"' ", hql);
+ appendWhereClauseWithOperand("ht.outcome", "outcome", hql);
}
if (tookLessThen!=null) {
@@ -117,6 +129,30 @@
if (startedAfter!=null) {
query.setTimestamp("startedAfter", startedAfter);
}
+
+ if (processInstanceId!=null) {
+ applyParameterWithOperand(processInstanceId, "processInstanceId", String.class, query);
+ }
+
+ if (taskId!=null) {
+ applyParameterWithOperand(taskId, "taskId", Long.class, query);
+ }
+
+ if (executionId!=null) {
+ applyParameterWithOperand(executionId, "executionId", String.class, query);
+ }
+
+ if (assignee!=null) {
+ applyParameterWithOperand(assignee, "assignee", String.class, query);
+ }
+
+ if (state!=null) {
+ applyParameterWithOperand(state, "state", String.class, query);
+ }
+
+ if (outcome!=null) {
+ applyParameterWithOperand(outcome, "outcome", String.class, query);
+ }
}
public List<HistoryTask> list() {
@@ -132,6 +168,11 @@
return this;
}
+ public HistoryTaskQuery processInstanceId(String processInstanceId) {
+ this.processInstanceId = processInstanceId;
+ return this;
+ }
+
public HistoryTaskQuery executionId(String executionId) {
this.executionId = executionId;
return this;
@@ -186,4 +227,46 @@
this.tookLongerThen = durationInMillis;
return this;
}
+
+ public HistoryTaskQuery assignee(String assignee, QueryOperand operand) {
+ this.assignee = assignee;
+ parameterOperands.put("assignee", operand);
+
+ return this;
+ }
+
+ public HistoryTaskQuery processInstanceId(String processInstanceId, QueryOperand operand) {
+ this.processInstanceId = processInstanceId;
+ parameterOperands.put("processInstanceId", operand);
+
+ return this;
+ }
+
+ public HistoryTaskQuery executionId(String executionId, QueryOperand operand) {
+ this.executionId = executionId;
+ parameterOperands.put("executionId", operand);
+
+ return this;
+ }
+
+ public HistoryTaskQuery state(String state, QueryOperand operand) {
+ this.state = state;
+ parameterOperands.put("state", operand);
+
+ return this;
+ }
+
+ public HistoryTaskQuery taskId(String taskId, QueryOperand operand) {
+ this.taskId = taskId;
+ parameterOperands.put("taskId", operand);
+
+ return this;
+ }
+
+ public HistoryTaskQuery outcome(String outcome, QueryOperand operand) {
+ this.outcome = outcome;
+ parameterOperands.put("outcome", operand);
+
+ return this;
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/JobQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/JobQueryImpl.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/JobQueryImpl.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -25,6 +25,7 @@
import org.hibernate.Query;
import org.jbpm.api.JobQuery;
+import org.jbpm.api.QueryOperand;
import org.jbpm.api.job.Job;
import org.jbpm.pvm.internal.job.JobImpl;
import org.jbpm.pvm.internal.job.MessageImpl;
@@ -34,6 +35,7 @@
/**
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public class JobQueryImpl extends AbstractQuery implements JobQuery {
@@ -43,6 +45,8 @@
protected boolean timersOnly = false;
protected String processInstanceId = null;
protected Boolean exception;
+
+
public String hql() {
StringBuilder hql = new StringBuilder();
@@ -65,8 +69,9 @@
hql.append(" j ");
if (processInstanceId!=null) {
- appendWhereClause("j.processInstance.id = '"+processInstanceId+"' ", hql);
- }
+ appendWhereClauseWithOperand("j.processInstance.id", "processInstanceId", hql);
+ }
+
if (exception!=null) {
if (exception) {
@@ -82,6 +87,9 @@
}
protected void applyParameters(Query query) {
+ if (processInstanceId != null) {
+ applyParameterWithOperand(processInstanceId, "processInstanceId", String.class, query);
+ }
}
public List<Job> list() {
@@ -126,4 +134,11 @@
this.processInstanceId = processInstanceId;
return this;
}
+
+ public JobQuery processInstanceId(String processInstanceId, QueryOperand operand) {
+ this.processInstanceId = processInstanceId;
+ parameterOperands.put("processInstanceId", operand);
+
+ return this;
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -31,6 +31,7 @@
import org.jbpm.api.Deployment;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessDefinitionQuery;
+import org.jbpm.api.QueryOperand;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
import org.jbpm.pvm.internal.repository.DeploymentImpl;
@@ -51,6 +52,7 @@
* to get the properly initialized ProcessDefinitionImpl.
*
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public class ProcessDefinitionQueryImpl extends AbstractQuery implements ProcessDefinitionQuery {
@@ -126,24 +128,25 @@
appendWhereClause("versionProperty.deployment = deployment ", hql);
if (id!=null) {
- appendWhereClause("idProperty.stringValue = '"+id+"'", hql);
+ appendWhereClauseWithOperand("idProperty.stringValue", "id", hql);
}
- if (nameLike!=null) {
- appendWhereClause("idProperty.objectName like '"+nameLike+"' ", hql);
- }
-
if (name!=null) {
- appendWhereClause("idProperty.objectName = '"+name+"' ", hql);
+ appendWhereClauseWithOperand("idProperty.objectName", "name", hql);
}
if (key!=null) {
- appendWhereClause("keyProperty.stringValue = '"+key+"' ", hql);
+ appendWhereClauseWithOperand("keyProperty.stringValue", "key", hql);
}
if (deploymentId!=null) {
- appendWhereClause("idProperty.deployment.dbid = "+deploymentId+" ", hql);
+ appendWhereClauseWithOperand("idProperty.deployment.dbid", "deploymentId", hql);
}
+
+ // @deprecated, should be used with operand
+ if (nameLike!=null) {
+ appendWhereClause("idProperty.objectName like '"+nameLike+"' ", hql);
+ }
appendOrderByClause(hql);
@@ -151,6 +154,22 @@
}
protected void applyParameters(Query query) {
+ if (id != null) {
+ applyParameterWithOperand(id, "id", String.class, query);
+ }
+
+ if (name != null) {
+ applyParameterWithOperand(name, "name", String.class, query);
+ }
+
+ if (key != null) {
+ applyParameterWithOperand(key, "key", String.class, query);
+ }
+
+ if (deploymentId != null) {
+ applyParameterWithOperand(deploymentId, "deploymentId", Long.class, query);
+ }
+
}
public List<ProcessDefinition> list() {
@@ -215,4 +234,32 @@
this.page = new Page(firstResult, maxResults);
return this;
}
+
+ public ProcessDefinitionQuery deploymentId(String deploymentId, QueryOperand operand) {
+ this.deploymentId = deploymentId;
+ parameterOperands.put("deploymentId", operand);
+
+ return this;
+ }
+
+ public ProcessDefinitionQuery processDefinitionId(String processDefinitionId, QueryOperand operand) {
+ this.id = processDefinitionId;
+ parameterOperands.put("processDefinitionId", operand);
+
+ return this;
+ }
+
+ public ProcessDefinitionQuery processDefinitionKey(String key, QueryOperand operand) {
+ this.key = key;
+ parameterOperands.put("key", operand);
+
+ return this;
+ }
+
+ public ProcessDefinitionQuery processDefinitionName(String name, QueryOperand operand) {
+ this.name = name;
+ parameterOperands.put("name", operand);
+
+ return this;
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -26,11 +26,13 @@
import org.hibernate.Query;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.ProcessInstanceQuery;
+import org.jbpm.api.QueryOperand;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.util.CollectionUtil;
/**
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public class ProcessInstanceQueryImpl extends AbstractQuery implements ProcessInstanceQuery {
@@ -40,6 +42,7 @@
protected String processInstanceId;
protected String processInstanceKey;
protected Boolean suspended;
+ protected String initiator;
public ProcessInstance uniqueResult() {
return (ProcessInstance)untypedUniqueResult();
@@ -74,16 +77,20 @@
}
if (processInstanceId != null) {
- appendWhereClause("processInstance.processInstance.id = '" + processInstanceId+"' ", hql);
+ appendWhereClauseWithOperand("processInstance.processInstance.id", "processInstanceId", hql);
}
if (processDefinitionId != null) {
- appendWhereClause("processInstance.processDefinitionId = '" + processDefinitionId+"' ", hql);
+ appendWhereClauseWithOperand("processInstance.processDefinitionId", "processDefinitionId", hql);
}
if (processInstanceKey != null) {
- appendWhereClause("processInstance.key = '" + processInstanceKey + "'", hql);
+ appendWhereClauseWithOperand("processInstance.key", "processInstanceKey", hql);
}
+
+ if (initiator!=null) {
+ appendWhereClauseWithOperand("processInstance.initiator", "initiator", hql);
+ }
appendOrderByClause(hql);
@@ -91,6 +98,21 @@
}
protected void applyParameters(Query query) {
+ if (processInstanceId != null) {
+ applyParameterWithOperand(processInstanceId, "processInstanceId", String.class, query);
+ }
+
+ if (processDefinitionId != null) {
+ applyParameterWithOperand(processDefinitionId, "processDefinitionId", String.class, query);
+ }
+
+ if (processInstanceKey != null) {
+ applyParameterWithOperand(processInstanceKey, "processInstanceKey", String.class, query);
+ }
+
+ if (initiator!=null) {
+ applyParameterWithOperand(initiator, "initiator", String.class, query);
+ }
}
public ProcessInstanceQuery orderAsc(String property) {
@@ -127,10 +149,44 @@
this.processInstanceKey = processInstanceKey;
return this;
}
+
+ public ProcessInstanceQuery initiator(String user) {
+ this.initiator = user;
+ return this;
+ }
public ProcessInstanceQuery notSuspended() {
this.suspended = false;
return this;
}
+ public String operand(String parameter, QueryOperand operand) {
+ parameterOperands.put(parameter, operand);
+
+ return parameter;
+ }
+
+ public ProcessInstanceQuery processDefinitionId(String processDefinitionId, QueryOperand operand) {
+ this.processDefinitionId = processDefinitionId;
+ parameterOperands.put("processDefinitionId", operand);
+ return this;
+ }
+
+ public ProcessInstanceQuery processInstanceId(String processInstanceId, QueryOperand operand) {
+ this.processInstanceId = processInstanceId;
+ parameterOperands.put("processInstanceId", operand);
+ return this;
+ }
+
+ public ProcessInstanceQuery processInstanceKey(String processInstanceKey, QueryOperand operand) {
+ this.processInstanceKey = processInstanceKey;
+ parameterOperands.put("processInstanceKey", operand);
+ return this;
+ }
+ public ProcessInstanceQuery initiator(String user, QueryOperand operand) {
+ this.initiator = user;
+ parameterOperands.put("initiator", operand);
+
+ return this;
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -30,6 +30,7 @@
import org.hibernate.Session;
import org.jbpm.api.JbpmException;
+import org.jbpm.api.QueryOperand;
import org.jbpm.api.TaskQuery;
import org.jbpm.api.identity.Group;
import org.jbpm.api.task.Task;
@@ -45,6 +46,7 @@
* @author Tom Baeyens
* @author Heiko Braun <heiko.braun(a)jboss.com>
* @author Huisheng Xu
+ * @author Maciej Swiderski
*/
public class TaskQueryImpl extends AbstractQuery implements TaskQuery {
@@ -133,7 +135,7 @@
if (log.isDebugEnabled()) {
log.debug("setting parameter assignee: " + assignee);
}
- query.setString("assignee", assignee);
+ applyParameterWithOperand(assignee, "assignee", String.class, query);
}
// canidate parameter
@@ -156,28 +158,28 @@
if (log.isDebugEnabled()) {
log.debug("setting parameter executionId: " + executionId);
}
- query.setString("executionId", executionId);
+ applyParameterWithOperand(executionId, "executionId", String.class, query);
}
if (processInstanceId != null) {
if (log.isDebugEnabled()) {
log.debug("setting parameter processInstanceId: " + processInstanceId);
}
- query.setString("processInstanceId", processInstanceId);
+ applyParameterWithOperand(processInstanceId, "processInstanceId", String.class, query);
}
if (activityName != null) {
if (log.isDebugEnabled()) {
log.debug("setting parameter activityName: " + activityName);
}
- query.setString("activityName", activityName );
+ applyParameterWithOperand(activityName, "activityName", String.class, query);
}
if (processDefinitionId != null) {
if (log.isDebugEnabled()) {
log.debug("setting parameter processDefinitionId: " + processDefinitionId);
}
- query.setString("processDefinitionId", processDefinitionId);
+ applyParameterWithOperand(processDefinitionId, "processDefinitionId", String.class, query);
}
}
@@ -234,23 +236,23 @@
}
if (executionId != null) {
- appendWhereClause("task.execution.id = :executionId ", hql);
+ appendWhereClauseWithOperand("task.execution.id", "executionId", hql);
}
if (processInstanceId != null) {
- appendWhereClause("task.processInstance.id = :processInstanceId ", hql);
+ appendWhereClauseWithOperand("task.processInstance.id", "processInstanceId", hql);
}
if (activityName != null) {
- appendWhereClause("task.execution.activityName = :activityName ", hql);
+ appendWhereClauseWithOperand("task.execution.activityName", "activityName", hql);
}
if (processDefinitionId != null) {
- appendWhereClause("task.processInstance.processDefinitionId = :processDefinitionId ", hql);
+ appendWhereClauseWithOperand("task.processInstance.processDefinitionId", "processDefinitionId", hql);
}
if (assignee != null) {
- appendWhereClause("task.assignee = :assignee ", hql);
+ appendWhereClauseWithOperand("task.assignee", "assignee", hql);
} else if (unassigned) {
appendWhereClause("task.assignee is null ", hql);
}
@@ -295,4 +297,39 @@
public Task uniqueResult() {
return (Task) untypedUniqueResult();
}
+
+ public TaskQuery activityName(String activityName, QueryOperand operand) {
+ this.activityName = activityName;
+ parameterOperands.put("activityName", operand);
+
+ return this;
+ }
+
+ public TaskQuery assignee(String userId, QueryOperand operand) {
+ this.assignee = userId;
+ parameterOperands.put("assignee", operand);
+
+ return this;
+ }
+
+ public TaskQuery executionId(String executionId, QueryOperand operand) {
+ this.executionId = executionId;
+ parameterOperands.put("executionId", operand);
+
+ return this;
+ }
+
+ public TaskQuery processDefinitionId(String processDefinitionId, QueryOperand operand) {
+ this.processDefinitionId = processDefinitionId;
+ parameterOperands.put("processDefinitionId", operand);
+
+ return this;
+ }
+
+ public TaskQuery processInstanceId(String processInstanceId, QueryOperand operand) {
+ this.processInstanceId = processInstanceId;
+ parameterOperands.put("processInstanceId", operand);
+
+ return this;
+ }
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessEndTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessEndTest.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessEndTest.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -28,7 +28,10 @@
import java.util.List;
import java.util.Map;
+import org.jbpm.api.Execution;
import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.QueryOperand;
+import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.task.Task;
import org.jbpm.test.JbpmTestCase;
@@ -54,14 +57,28 @@
super.tearDown();
}
+ @SuppressWarnings("unchecked")
public void testSubProcessJoinEnd() {
ProcessInstance processInstance = executionService.startProcessInstanceByKey("mp");
+ String execIdSp1 = ((List<Execution>)processInstance.getExecutions()).get(0).getId();
+ String execIdSp2 = ((List<Execution>)processInstance.getExecutions()).get(1).getId();
+
List<Task> taskList = taskService.findPersonalTasks("v");
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("result", "reject");
taskService.setVariables(taskList.get(0).getId(), variables);
taskService.completeTask(taskList.get(0).getId());
- this.assertTrue(true);
+
+
+ List<HistoryProcessInstance> history = historyService.createHistoryProcessInstanceQuery().processInstanceId("sp2%", QueryOperand.LIKE).list();
+ assertNotNull(history);
+ assertNotNull(history.get(0).getSuperProcessInstanceId());
+ assertEquals(execIdSp2, history.get(0).getSuperProcessInstanceId());
+
+ history = historyService.createHistoryProcessInstanceQuery().processInstanceId("sp1%", QueryOperand.LIKE).list();
+ assertNotNull(history);
+ assertNotNull(history.get(0).getSuperProcessInstanceId());
+ assertEquals(execIdSp1, history.get(0).getSuperProcessInstanceId());
}
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessTest.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessTest.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -24,12 +24,11 @@
*/
package org.jbpm.test.activity.subprocess;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.List;
-import org.eclipse.jdt.internal.compiler.ast.AssertStatement;
-import org.jbpm.api.JbpmException;
import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.QueryOperand;
+import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.task.Task;
import org.jbpm.test.JbpmTestCase;
@@ -136,5 +135,34 @@
assertEquals(0, executionService.createProcessInstanceQuery().list().size());
}
+
+ public void testSubProcessHistoryIds() {
+ deployJpdlXmlString(SUB_PROCESS);
+ deployJpdlXmlString(MAIN_PROCESS);
+ processEngine.setAuthenticatedUserId("mike");
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess");
+ assertEquals(2, executionService.createProcessInstanceQuery().list().size());
+
+ Task task = taskService.findPersonalTasks("johndoe").get(0);
+ taskService.completeTask(task.getId(), "nok");
+ assertActivityActive(processInstance.getId(), "update");
+
+ processInstance = executionService.signalExecutionById(processInstance.getId());
+
+ assertProcessInstanceEnded(processInstance);
+ assertEquals(0, executionService.createProcessInstanceQuery().list().size());
+
+
+ List<HistoryProcessInstance> history = historyService.createHistoryProcessInstanceQuery().processInstanceId("SubProcessReview%", QueryOperand.LIKE).list();
+ assertNotNull(history);
+ assertNotNull(history.get(0).getSuperProcessInstanceId());
+ assertEquals(processInstance.getId(), history.get(0).getSuperProcessInstanceId());
+
+ history = historyService.createHistoryProcessInstanceQuery().superProcessInstanceId(processInstance.getId()).list();
+ assertNotNull(history);
+ assertNotNull(history.get(0).getSuperProcessInstanceId());
+ assertEquals(processInstance.getId(), history.get(0).getSuperProcessInstanceId());
+ }
+
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -28,6 +28,7 @@
import org.jbpm.api.Deployment;
import org.jbpm.api.DeploymentQuery;
+import org.jbpm.api.QueryOperand;
import org.jbpm.test.JbpmTestCase;
import org.jbpm.test.assertion.QueryAssertions;
@@ -113,6 +114,42 @@
deleteCascade(deploymentIds);
}
+ public void testEquals() {
+ List<String> deploymentIds = deployTestProcesses();
+
+ assertEquals(1, repositoryService.createDeploymentQuery().deploymentId(deploymentIds.get(0), QueryOperand.EQUALS).count());
+
+
+ deleteCascade(deploymentIds);
+ }
+
+ public void testLike() {
+ List<String> deploymentIds = deployTestProcesses();
+
+ assertEquals(1, repositoryService.createDeploymentQuery().deploymentId(deploymentIds.get(0), QueryOperand.LIKE).count());
+
+
+ deleteCascade(deploymentIds);
+ }
+
+ public void testIn() {
+ List<String> deploymentIds = deployTestProcesses();
+
+ assertEquals(2, repositoryService.createDeploymentQuery().deploymentId(deploymentIds.get(0) + ","+deploymentIds.get(1), QueryOperand.IN).count());
+
+
+ deleteCascade(deploymentIds);
+ }
+
+ public void testNotIn() {
+ List<String> deploymentIds = deployTestProcesses();
+
+ assertEquals(2, repositoryService.createDeploymentQuery().deploymentId(deploymentIds.get(0), QueryOperand.NOT_IN).count());
+
+
+ deleteCascade(deploymentIds);
+ }
+
/* --------------
* HELPER METHODS
* -------------- */
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -30,6 +30,7 @@
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.QueryOperand;
import org.jbpm.api.history.HistoryActivityInstance;
import org.jbpm.api.history.HistoryActivityInstanceQuery;
import org.jbpm.pvm.internal.util.Clock;
@@ -104,6 +105,79 @@
assertEquals(1, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(3)).list().size());
}
+ public void testQueryByExecutionIdLike() {
+ deployStartAndSignalTestProcesses();
+
+ assertEquals(9, historyService.createHistoryActivityInstanceQuery().executionId("abc%", QueryOperand.LIKE).list().size());
+
+ }
+
+ public void testQueryByExecutionIdIn() {
+ List<String> ids = deployStartAndSignalTestProcesses();
+
+ assertEquals(6, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(0) + "," + ids.get(1), QueryOperand.IN).list().size());
+
+ }
+
+ public void testQueryByExecutionIdNotIn() {
+ List<String> ids = deployStartAndSignalTestProcesses();
+
+ assertEquals(3, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(0) + "," + ids.get(1), QueryOperand.NOT_IN).list().size());
+
+ }
+
+ public void testQueryByProcessInstanceIdLike() {
+ deployStartAndSignalTestProcesses();
+
+ assertEquals(9, historyService.createHistoryActivityInstanceQuery().processInstanceId("abc%", QueryOperand.LIKE).list().size());
+
+ }
+
+ public void testQueryByProcessInstanceIdIn() {
+ List<String> ids = deployStartAndSignalTestProcesses();
+
+ assertEquals(6, historyService.createHistoryActivityInstanceQuery().processInstanceId(ids.get(0) + "," + ids.get(1), QueryOperand.IN).list().size());
+
+ }
+
+ public void testQueryByProcessInstanceIdNotIn() {
+ List<String> ids = deployStartAndSignalTestProcesses();
+
+ assertEquals(3, historyService.createHistoryActivityInstanceQuery().processInstanceId(ids.get(0) + "," + ids.get(1), QueryOperand.NOT_IN).list().size());
+
+ }
+
+ public void testQueryByProcessDefinitionIdLike() {
+ deployStartAndSignalTestProcesses();
+ deployTestProcessWithTask();
+ generateHistoryForTestProcessWithTask();
+ deployTestProcessWithTask();
+
+ assertEquals(12, historyService.createHistoryActivityInstanceQuery().processInstanceId("abc%", QueryOperand.LIKE).list().size());
+
+ }
+
+ public void testQueryByProcessDefinitionIdIn() {
+ deployStartAndSignalTestProcesses();
+ deployTestProcessWithTask();
+ List<String> idsTask = generateHistoryForTestProcessWithTask();
+ List<String> ids = deployStartAndSignalTestProcesses();
+
+
+ assertEquals(6, historyService.createHistoryActivityInstanceQuery().processInstanceId(ids.get(0) + "," + idsTask.get(0), QueryOperand.IN).list().size());
+
+ }
+
+ public void testQueryByProcessDefinitionIdNotIn() {
+ deployStartAndSignalTestProcesses();
+ deployTestProcessWithTask();
+ List<String> idsTask = generateHistoryForTestProcessWithTask();
+ List<String> ids = deployStartAndSignalTestProcesses();
+
+ assertEquals(15, historyService.createHistoryActivityInstanceQuery().processInstanceId(ids.get(0) + "," + idsTask.get(0), QueryOperand.NOT_IN).list().size());
+
+ }
+
// Currently only verifies the size of the result set
public void testQueryByStartedAfter() {
deployTestProcess();
@@ -146,6 +220,24 @@
assertEquals(2, historyService.createHistoryActivityInstanceQuery().activityName("c").list().size());
}
+ public void testQueryByActivityNameLike() {
+ deployStartAndSignalTestProcesses();
+ assertEquals(9, historyService.createHistoryActivityInstanceQuery().activityName("%", QueryOperand.LIKE).list().size());
+
+ }
+
+ public void testQueryByActivityNameIn() {
+ deployStartAndSignalTestProcesses();
+ assertEquals(6, historyService.createHistoryActivityInstanceQuery().activityName("a,c", QueryOperand.IN).list().size());
+
+ }
+
+ public void testQueryByActivityNameNotIn() {
+ deployStartAndSignalTestProcesses();
+ assertEquals(2, historyService.createHistoryActivityInstanceQuery().activityName("a,b", QueryOperand.NOT_IN).list().size());
+
+ }
+
//Currently only verifies the size of the result set
public void testQueryByTookLessThen() {
deployStartAndSignalTestProcesses();
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -30,6 +30,7 @@
import java.util.List;
import org.jbpm.api.ProcessDefinition;
+import org.jbpm.api.QueryOperand;
import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.history.HistoryProcessInstanceQuery;
import org.jbpm.pvm.internal.util.Clock;
@@ -86,7 +87,115 @@
.count());
}
}
+
+ public void testQueryByProcessInstanceIdLike() {
+ createTestHistoryProcessInstances(7);
+ assertEquals(7, historyService.createHistoryProcessInstanceQuery()
+ .processInstanceId("theProcess%", QueryOperand.LIKE)
+ .count());
+
+ }
+
+ public void testQueryByProcessInstanceIdIn() {
+ List<String> procInstIds = createTestHistoryProcessInstances(7);
+
+ assertEquals(2, historyService.createHistoryProcessInstanceQuery()
+ .processInstanceId(procInstIds.get(0) + "," + procInstIds.get(1), QueryOperand.IN)
+ .count());
+
+ }
+
+ public void testQueryByProcessInstanceIdNotIn() {
+ List<String> procInstIds = createTestHistoryProcessInstances(7);
+
+ assertEquals(5, historyService.createHistoryProcessInstanceQuery()
+ .processInstanceId(procInstIds.get(0) + "," + procInstIds.get(1), QueryOperand.NOT_IN)
+ .count());
+
+ }
+
+ public void testQueryByProcessInstanceKeyLike() {
+ createTestHistoryProcessInstances(7);
+
+ assertEquals(7, historyService.createHistoryProcessInstanceQuery()
+ .processInstanceKey("theProcess-%", QueryOperand.LIKE)
+ .count());
+
+ }
+
+ public void testQueryByProcessInstanceKeyIn() {
+ createTestHistoryProcessInstances(7);
+
+ assertEquals(2, historyService.createHistoryProcessInstanceQuery()
+ .processInstanceKey("theProcess-1,theProcess-5", QueryOperand.IN)
+ .count());
+
+ }
+
+ public void testQueryByProcessInstanceKeyNotIn() {
+ createTestHistoryProcessInstances(7);
+
+ assertEquals(4, historyService.createHistoryProcessInstanceQuery()
+ .processInstanceKey("theProcess-1,theProcess-5,theProcess-6", QueryOperand.NOT_IN)
+ .count());
+
+ }
+
+ public void testQueryByInitiator() {
+
+ deployJpdlXmlString("<process name='theProcess'>"
+ + " <start>"
+ + " <transition to='wait' />"
+ + " </start>"
+ + " <state name='wait'>"
+ + " <transition to='end' />"
+ + " </state>"
+ + " <end name='end' />"
+ + "</process>");
+
+ processEngine.setAuthenticatedUserId("mike");
+ executionService.startProcessInstanceByKey("theProcess");
+ processEngine.setAuthenticatedUserId("alex");
+ executionService.startProcessInstanceByKey("theProcess");
+ processEngine.setAuthenticatedUserId("erik");
+ executionService.startProcessInstanceByKey("theProcess");
+ processEngine.setAuthenticatedUserId("peter");
+ executionService.startProcessInstanceByKey("theProcess");
+
+ assertEquals(1, historyService.createHistoryProcessInstanceQuery().initiator("peter").count());
+ assertEquals(1, historyService.createHistoryProcessInstanceQuery().initiator("erik").count());
+ assertEquals(1, historyService.createHistoryProcessInstanceQuery().initiator("mike").count());
+ assertEquals(1, historyService.createHistoryProcessInstanceQuery().initiator("alex").count());
+
+ }
+
+ public void testQueryByInitiatorLike() {
+
+ deployJpdlXmlString("<process name='theProcess'>"
+ + " <start>"
+ + " <transition to='wait' />"
+ + " </start>"
+ + " <state name='wait'>"
+ + " <transition to='end' />"
+ + " </state>"
+ + " <end name='end' />"
+ + "</process>");
+
+ processEngine.setAuthenticatedUserId("mike");
+ executionService.startProcessInstanceByKey("theProcess");
+ processEngine.setAuthenticatedUserId("alex");
+ executionService.startProcessInstanceByKey("theProcess");
+ processEngine.setAuthenticatedUserId("erik");
+ executionService.startProcessInstanceByKey("theProcess");
+ processEngine.setAuthenticatedUserId("peter");
+ executionService.startProcessInstanceByKey("theProcess");
+
+ assertEquals(4, historyService.createHistoryProcessInstanceQuery().initiator("%e%", QueryOperand.LIKE).count());
+
+
+ }
+
public void testOrderByStartTime() {
testOrderByNaturalOrdening(HistoryProcessInstanceQuery.PROPERTY_STARTTIME, 4);
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryTaskQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryTaskQueryTest.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryTaskQueryTest.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -32,6 +32,8 @@
import java.util.Date;
import java.util.List;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.QueryOperand;
import org.jbpm.api.history.HistoryTask;
import org.jbpm.api.history.HistoryTaskQuery;
import org.jbpm.pvm.internal.util.Clock;
@@ -104,6 +106,75 @@
.taskId("-1").count());
}
+ public void testAssigneeLike() {
+ createTestHistoryTasks();
+
+ assertEquals(2, historyService.createHistoryTaskQuery().assignee("%o%", QueryOperand.LIKE).count());
+
+ }
+
+ public void testAssigneeIn() {
+ createTestHistoryTasks();
+
+ assertEquals(2, historyService.createHistoryTaskQuery().assignee("Tom,Alex", QueryOperand.IN).count());
+
+ }
+
+ public void testAssigneeNotIn() {
+ createTestHistoryTasks();
+
+ assertEquals(1, historyService.createHistoryTaskQuery().assignee("Tom,Alex", QueryOperand.NOT_IN).count());
+
+ }
+
+ public void testTaskIdLike() {
+ createTestHistoryTasks();
+
+ assertEquals(3, historyService.createHistoryTaskQuery().taskId("%", QueryOperand.LIKE).count());
+
+ }
+
+ public void testTaskIdIn() {
+ List<String> taskIds = createTestHistoryTasks();
+
+ assertEquals(2, historyService.createHistoryTaskQuery().taskId(taskIds.get(0) + "," + taskIds.get(1), QueryOperand.IN).count());
+
+ }
+
+ public void testTaskIdNotIn() {
+ List<String> taskIds = createTestHistoryTasks();
+
+ assertEquals(1, historyService.createHistoryTaskQuery().taskId(taskIds.get(0) + "," + taskIds.get(1), QueryOperand.NOT_IN).count());
+
+ }
+
+ public void testExecutionIdLike() {
+ createTestHistoryTasks();
+
+ assertEquals(3, historyService.createHistoryTaskQuery().executionId("theProcess%", QueryOperand.LIKE).count());
+
+ }
+ public void testStateLike() {
+ createTestHistoryTasks();
+
+ assertEquals(3, historyService.createHistoryTaskQuery().state("%", QueryOperand.LIKE).count());
+
+ }
+
+ public void testStateIn() {
+ createTestHistoryTasks();
+
+ assertEquals(3, historyService.createHistoryTaskQuery().state(HistoryTask.STATE_COMPLETED + "," + HistoryTask.STATE_OBSOLETE, QueryOperand.IN).count());
+
+ }
+
+ public void testStateNotIn() {
+ createTestHistoryTasks();
+
+ assertEquals(0, historyService.createHistoryTaskQuery().state(HistoryTask.STATE_COMPLETED + "," + HistoryTask.STATE_OBSOLETE, QueryOperand.NOT_IN).count());
+
+ }
+
@SuppressWarnings("unchecked")
private void testOrderBy(String property, List expectedValues,
Integer expectedNrOfResults, boolean naturalOrderCheck) {
@@ -163,6 +234,126 @@
return taskIds;
}
+ public void testHistoryTaskQuerySingleTaskByProcessId() {
+ deployJpdlXmlString(
+ "<process name='TaskAssignee'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <task name='review' " +
+ " assignee='johndoe'>" +
+ " <transition to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>"
+ );
+
+ ProcessInstance pi = executionService.startProcessInstanceByKey("TaskAssignee");
+
+ taskService.completeTask(taskService.findPersonalTasks("johndoe").get(0).getId());
+
+ HistoryTask task = historyService.createHistoryTaskQuery().processInstanceId(pi.getId()).uniqueResult();
+ assertNotNull(task.getName());
+ assertEquals("review", task.getName());
+ assertEquals("completed", task.getState());
+
+ }
+
+ public void testHistoryTaskQueryTaskByProcessId() {
+ deployJpdlXmlString(
+ "<process name='TaskAssignee'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <task name='review' " +
+ " assignee='johndoe'>" +
+ " <transition to='review-mgmt' />" +
+ " </task>" +
+ " <task name='review-mgmt' " +
+ " assignee='mike'>" +
+ " <transition to='review-top-mgmt' />" +
+ " </task>" +
+ " <task name='review-top-mgmt' " +
+ " assignee='peter'>" +
+ " <transition to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>"
+ );
+
+ ProcessInstance pi = executionService.startProcessInstanceByKey("TaskAssignee");
+
+ taskService.completeTask(taskService.findPersonalTasks("johndoe").get(0).getId());
+
+ taskService.completeTask(taskService.findPersonalTasks("mike").get(0).getId());
+
+ taskService.completeTask(taskService.findPersonalTasks("peter").get(0).getId());
+
+ List<HistoryTask> tasks = historyService.createHistoryTaskQuery().processInstanceId(pi.getId()).list();
+ assertNotNull(tasks);
+ assertEquals(3, tasks.size());
+
+ String[] expectedTasks = new String[] {"review", "review-mgmt", "review-top-mgmt"};
+ String[] expectedAssignees = new String[] {"johndoe", "mike", "peter"};
+ int i = 0;
+ for (HistoryTask task : tasks) {
+ assertEquals(expectedTasks[i], task.getName());
+ assertEquals(expectedAssignees[i], task.getAssignee());
+ assertEquals("completed", task.getState());
+ i++;
+ }
+
+ }
+
+ public void testHistoryTaskQueryTaskByProcessIdWithTimer() {
+ deployJpdlXmlString(
+ "<process name='TaskAssignee'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <task name='review' " +
+ " assignee='johndoe'>" +
+ " <transition to='review-mgmt' />" +
+ " <transition name='lunch' to='wait'>" +
+ " <timer duedate='10 seconds' />" +
+ " </transition>" +
+ " </task>" +
+ " <task name='review-mgmt' " +
+ " assignee='mike'>" +
+ " <transition to='review-top-mgmt' />" +
+ " </task>" +
+ " <task name='review-top-mgmt' " +
+ " assignee='peter'>" +
+ " <transition to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>"
+ );
+
+ ProcessInstance pi = executionService.startProcessInstanceByKey("TaskAssignee");
+
+ taskService.completeTask(taskService.findPersonalTasks("johndoe").get(0).getId());
+
+ taskService.completeTask(taskService.findPersonalTasks("mike").get(0).getId());
+
+ taskService.completeTask(taskService.findPersonalTasks("peter").get(0).getId());
+
+ List<HistoryTask> tasks = historyService.createHistoryTaskQuery().processInstanceId(pi.getId()).list();
+ assertNotNull(tasks);
+ assertEquals(3, tasks.size());
+
+ String[] expectedTasks = new String[] {"review", "review-mgmt", "review-top-mgmt"};
+ String[] expectedAssignees = new String[] {"johndoe", "mike", "peter"};
+ int i = 0;
+ for (HistoryTask task : tasks) {
+ assertEquals(expectedTasks[i], task.getName());
+ assertEquals(expectedAssignees[i], task.getAssignee());
+ assertEquals("completed", task.getState());
+ i++;
+ }
+
+ }
+
private Date stringToDate(String dateString) {
DateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy");
try {
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/JobQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/JobQueryTest.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/JobQueryTest.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -26,6 +26,7 @@
import java.util.List;
import org.jbpm.api.JobQuery;
+import org.jbpm.api.QueryOperand;
import org.jbpm.api.job.Job;
import org.jbpm.test.JbpmTestCase;
import org.jbpm.test.assertion.QueryAssertions;
@@ -143,6 +144,38 @@
}
+ public void testProcessIdLike() {
+ startTestProcessInstances(6);
+
+ JobQuery query = managementService.createJobQuery();
+ assertEquals(6, query.processInstanceId("TimerQueryTest%", QueryOperand.LIKE).count());
+
+ }
+
+ public void testProcessIdEquals() {
+ List<String> procInstIds = startTestProcessInstances(6);
+
+ JobQuery query = managementService.createJobQuery();
+ assertEquals(1, query.processInstanceId(procInstIds.get(0), QueryOperand.EQUALS).count());
+
+ }
+
+ public void testProcessIdIn() {
+ List<String> procInstIds = startTestProcessInstances(6);
+
+ JobQuery query = managementService.createJobQuery();
+ assertEquals(2, query.processInstanceId(""+procInstIds.get(0)+","+procInstIds.get(1)+"", QueryOperand.IN).count());
+
+ }
+
+ public void testProcessIdNotIn() {
+ List<String> procInstIds = startTestProcessInstances(6);
+
+ JobQuery query = managementService.createJobQuery();
+ assertEquals(4, query.processInstanceId(""+procInstIds.get(0)+","+procInstIds.get(1)+"", QueryOperand.NOT_IN).count());
+
+ }
+
private List<String> startTestProcessInstances(int nrOfInstances) {
deployJpdlXmlString(
"<process name='TimerQueryTest' >" +
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessDefinitionQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessDefinitionQueryTest.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessDefinitionQueryTest.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -25,6 +25,7 @@
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessDefinitionQuery;
+import org.jbpm.api.QueryOperand;
import org.jbpm.test.JbpmTestCase;
@@ -135,4 +136,127 @@
assertEquals("make_friends-3", processDefinitions.get(2).getId());
assertEquals("make_print-1", processDefinitions.get(3).getId());
}
+
+ public void testQueryProcessDefinitionsLike() {
+ deployJpdlXmlString(
+ "<process name='make print'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='use phone'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='make friends'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='clean whiteboard'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='fix coffeemaker'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ List<ProcessDefinition> processDefinitions =
+ repositoryService.createProcessDefinitionQuery().processDefinitionName("%make%", QueryOperand.LIKE)
+ .orderAsc(ProcessDefinitionQuery.PROPERTY_NAME)
+ .list();
+
+ assertEquals("fix coffeemaker", processDefinitions.get(0).getName());
+ assertEquals("make friends", processDefinitions.get(1).getName());
+ assertEquals("make print", processDefinitions.get(2).getName());
+ }
+
+ public void testQueryProcessDefinitionsIn() {
+ String dbId1 = deployJpdlXmlString(
+ "<process name='make print'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ String dbId2 = deployJpdlXmlString(
+ "<process name='use phone'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='make friends'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='clean whiteboard'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='fix coffeemaker'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();
+ List<ProcessDefinition> processDefinitions =
+ query.deploymentId(dbId1+","+dbId2, QueryOperand.IN)
+ .orderAsc(ProcessDefinitionQuery.PROPERTY_NAME)
+ .list();
+
+ assertEquals(2, processDefinitions.size());
+
+ }
+
+ public void testQueryProcessDefinitionsNotIn() {
+ String dbId1 = deployJpdlXmlString(
+ "<process name='make print'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ String dbId2 = deployJpdlXmlString(
+ "<process name='use phone'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='make friends'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='clean whiteboard'>" +
+ " <start />" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='fix coffeemaker'>" +
+ " <start />" +
+ "</process>"
+ );
+
+
+ List<ProcessDefinition> processDefinitions =
+ repositoryService.createProcessDefinitionQuery().deploymentId(dbId1+","+dbId2, QueryOperand.NOT_IN)
+ .orderAsc(ProcessDefinitionQuery.PROPERTY_NAME)
+ .list();
+
+ assertEquals(3, processDefinitions.size());
+
+ }
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessInstanceQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessInstanceQueryTest.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessInstanceQueryTest.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -31,6 +31,8 @@
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.ProcessInstanceQuery;
+import org.jbpm.api.QueryOperand;
+import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.test.JbpmTestCase;
@@ -217,6 +219,126 @@
}
+ public void testProcessInstanceLike() {
+ startTestProcesses(4, 6);
+
+ assertEquals(10, executionService.createProcessInstanceQuery().count());
+
+ assertEquals(4, executionService.createProcessInstanceQuery().processInstanceId("testProcess1.%", QueryOperand.LIKE).count());
+
+ assertEquals(6, executionService.createProcessInstanceQuery().processInstanceId("testProcess2.%", QueryOperand.LIKE).count());
+ }
+
+ public void testProcessDefinitionLike() {
+ startTestProcesses(4, 6);
+
+ assertEquals(10, executionService.createProcessInstanceQuery().count());
+
+ assertEquals(10, executionService.createProcessInstanceQuery().processDefinitionId("testProcess%", QueryOperand.LIKE).count());
+
+ }
+
+ public void testProcessInstanceKeyLike() {
+ startTestProcesses(4, 6);
+
+ assertEquals(10, executionService.createProcessInstanceQuery().count());
+
+ assertEquals(4, executionService.createProcessInstanceQuery().processInstanceKey("testProcess1-%", QueryOperand.LIKE).count());
+
+ }
+
+ public void testProcessInstanceIn() {
+ Map<String, ArrayList<String>> processInstanceIds = startTestProcesses(4, 6);
+ List<String> idsForTestProcess1 = processInstanceIds.get(TEST_PROCESS_1_KEY);
+ List<String> idsForTestProcess2 = processInstanceIds.get(TEST_PROCESS_2_KEY);
+
+ assertEquals(10, executionService.createProcessInstanceQuery().count());
+
+ assertEquals(2, executionService.createProcessInstanceQuery().processInstanceId(idsForTestProcess1.get(0) + "," + idsForTestProcess1.get(1), QueryOperand.IN).count());
+
+ assertEquals(2, executionService.createProcessInstanceQuery().processInstanceId(idsForTestProcess2.get(0) + "," + idsForTestProcess2.get(1), QueryOperand.IN).count());
+ }
+
+ public void testProcessDefinitionIn() {
+ startTestProcesses(4, 6);
+
+ assertEquals(10, executionService.createProcessInstanceQuery().count());
+
+ assertEquals(4, executionService.createProcessInstanceQuery().processDefinitionId("testProcess1-1,testProcess2", QueryOperand.IN).count());
+
+ }
+
+ public void testProcessInstanceKeyIn() {
+ startTestProcesses(4, 6);
+
+ assertEquals(10, executionService.createProcessInstanceQuery().count());
+
+ assertEquals(2, executionService.createProcessInstanceQuery().processInstanceKey("testProcess1-0,testProcess1-1", QueryOperand.IN).count());
+
+ }
+
+ public void testProcessInstanceNotIn() {
+ Map<String, ArrayList<String>> processInstanceIds = startTestProcesses(4, 6);
+ List<String> idsForTestProcess1 = processInstanceIds.get(TEST_PROCESS_1_KEY);
+ List<String> idsForTestProcess2 = processInstanceIds.get(TEST_PROCESS_2_KEY);
+
+ assertEquals(10, executionService.createProcessInstanceQuery().count());
+
+ assertEquals(8, executionService.createProcessInstanceQuery().processInstanceId(idsForTestProcess1.get(0) + "," + idsForTestProcess1.get(1), QueryOperand.NOT_IN).count());
+
+ assertEquals(8, executionService.createProcessInstanceQuery().processInstanceId(idsForTestProcess2.get(0) + "," + idsForTestProcess2.get(1), QueryOperand.NOT_IN).count());
+ }
+
+ public void testProcessDefinitionNotIn() {
+ startTestProcesses(4, 6);
+
+ assertEquals(10, executionService.createProcessInstanceQuery().count());
+
+ assertEquals(6, executionService.createProcessInstanceQuery().processDefinitionId("testProcess1-1,testProcess2", QueryOperand.NOT_IN).count());
+
+ }
+
+ public void testProcessInstanceKeyNotIn() {
+ startTestProcesses(4, 6);
+
+ assertEquals(10, executionService.createProcessInstanceQuery().count());
+
+ assertEquals(8, executionService.createProcessInstanceQuery().processInstanceKey("testProcess1-0,testProcess1-1", QueryOperand.NOT_IN).count());
+
+ }
+
+ public void testQueryByProcessInstanceIdWithInitiator() {
+ deployJpdlXmlString(TEST_PROCESS_1);
+ deployJpdlXmlString(TEST_PROCESS_2);
+
+ processEngine.setAuthenticatedUserId("mike");
+ ProcessInstance pi = executionService.startProcessInstanceByKey(TEST_PROCESS_1_KEY);
+
+ processEngine.setAuthenticatedUserId("alex");
+ ProcessInstance pi2 = executionService.startProcessInstanceByKey(TEST_PROCESS_2_KEY);
+
+ assertEquals(2, executionService.createProcessInstanceQuery().initiator("%e%", QueryOperand.LIKE).count());
+
+ assertNotNull(pi.getInitiator());
+ assertEquals("mike", pi.getInitiator());
+
+ assertNotNull(pi2.getInitiator());
+ assertEquals("alex", pi2.getInitiator());
+
+ HistoryProcessInstance historypi = historyService.createHistoryProcessInstanceQuery().processInstanceId(pi.getId()).uniqueResult();
+ assertNotNull(historypi.getInitiator());
+ assertEquals("mike", historypi.getInitiator());
+
+ historypi = historyService.createHistoryProcessInstanceQuery().processInstanceId(pi2.getId()).uniqueResult();
+ assertNotNull(historypi.getInitiator());
+ assertEquals("alex", historypi.getInitiator());
+
+ historypi = historyService.createHistoryProcessInstanceQuery().initiator("mike").uniqueResult();
+ assertNotNull(historypi);
+
+ assertEquals(2, historyService.createHistoryProcessInstanceQuery().initiator("%e%", QueryOperand.LIKE).count());
+ }
+
/**
* Returns a map containing a processKey - processInstanceId mapping.
* eg. TEST_PROCESS_1 - {"1", "5", "7", "8"}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java 2010-08-31 05:05:48 UTC (rev 6636)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java 2010-08-31 17:35:24 UTC (rev 6637)
@@ -29,6 +29,7 @@
import java.util.Date;
import java.util.List;
+import org.jbpm.api.QueryOperand;
import org.jbpm.api.TaskQuery;
import org.jbpm.api.task.Task;
import org.jbpm.test.JbpmTestCase;
@@ -132,7 +133,31 @@
deleteTasks(tasks);
}
+ public void testTaskQueryAssigneeLike() {
+ List<Task> tasks = createTestTasks();
+
+ assertEquals(2, taskService.createTaskQuery().assignee("%o%m", QueryOperand.LIKE).count());
+
+ deleteTasks(tasks);
+ }
+ public void testTaskQueryAssigneeIn() {
+ List<Task> tasks = createTestTasks();
+
+ assertEquals(2, taskService.createTaskQuery().assignee("Koen,Tom", QueryOperand.IN).count());
+
+ deleteTasks(tasks);
+ }
+
+ public void testTaskQueryAssigneeNotIn() {
+ List<Task> tasks = createTestTasks();
+
+ assertEquals(1, taskService.createTaskQuery().assignee("Koen,Tom,Alex", QueryOperand.NOT_IN).count());
+
+ deleteTasks(tasks);
+ }
+
+
/* -------------------------------------------------------------------
* HELPER METHODS
* ------------------------------------------------------------------- */
14 years, 2 months
JBoss JBPM SVN: r6636 - in jbpm3/branches/jbpm-3.2-soa/modules: core/src/main/java/org/jbpm/persistence/db and 4 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-08-31 01:05:48 -0400 (Tue, 31 Aug 2010)
New Revision: 6636
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/GraphElement.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1775/JBPM1775Test.java
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java
Log:
JBPM-2918 do not consider a jta transaction marked for rollback as active;
query transaction manager to determine whether a jta transaction is present
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/GraphElement.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/GraphElement.java 2010-08-30 16:34:53 UTC (rev 6635)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/GraphElement.java 2010-08-31 05:05:48 UTC (rev 6636)
@@ -373,29 +373,29 @@
* Tells whether the given context can handle exception by checking for:
* <ul>
* <li>the absence of a previous exception</li>
- * <li>an active transaction, or no transaction at all</li>
+ * <li>an active transaction, or no transaction present</li>
* </ul>
*/
private static boolean isAbleToHandleExceptions(ExecutionContext executionContext) {
// if executionContext has an exception set, it is already handling an exception
// in this case, do not offer exception to handlers; throw at client
- // see https://jira.jboss.org/jira/browse/JBPM-1887
+ // see https://jira.jboss.org/browse/JBPM-1887
if (executionContext.getException() != null) return false;
// check whether transaction is still active before scanning exception handlers
// this way, the exception handlers can be loaded lazily
- // see https://jira.jboss.org/jira/browse/JBPM-1775
+ // see https://jira.jboss.org/browse/JBPM-1775
JbpmContext jbpmContext = executionContext.getJbpmContext();
if (jbpmContext != null) {
Service service = jbpmContext.getServices().getPersistenceService();
if (service instanceof DbPersistenceService) {
DbPersistenceService persistenceService = (DbPersistenceService) service;
return persistenceService.isTransactionActive()
- || persistenceService.getTransaction() == null;
+ || !persistenceService.isTransactionPresent();
}
}
- // no transaction detected, probably running in memory only
+ // no transaction present; likely running in memory
return true;
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java 2010-08-30 16:34:53 UTC (rev 6635)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java 2010-08-31 05:05:48 UTC (rev 6636)
@@ -96,25 +96,20 @@
}
public Session getSession() {
- if (session == null && getSessionFactory() != null) {
- Connection connection = getConnection(false);
+ if (session == null) {
+ SessionFactory sessionFactory = persistenceServiceFactory.getSessionFactory();
+
if (isCurrentSessionEnabled) {
- session = getSessionFactory().getCurrentSession();
+ session = sessionFactory.getCurrentSession();
mustSessionBeFlushed = false;
mustSessionBeClosed = false;
- mustConnectionBeClosed = false;
}
- else if (connection != null) {
- session = getSessionFactory().openSession(connection);
- mustSessionBeFlushed = true;
- mustSessionBeClosed = true;
- mustConnectionBeClosed = false;
- }
else {
- session = getSessionFactory().openSession();
+ Connection connection = getConnection(false);
+ session = connection != null ? sessionFactory.openSession(connection)
+ : sessionFactory.openSession();
mustSessionBeFlushed = true;
mustSessionBeClosed = true;
- mustConnectionBeClosed = false;
}
if (isTransactionEnabled) beginTransaction();
@@ -138,7 +133,7 @@
throw new JbpmPersistenceException("transaction commit failed", commitException);
}
}
- else { // isRollbackOnly==true
+ else {
Exception rollbackException = rollback();
if (rollbackException != null) {
closeSession();
@@ -167,7 +162,7 @@
}
}
else {
- if (resolveSession) {
+ if (session == null && resolveSession) {
// initializes the session member
getSession();
}
@@ -198,6 +193,10 @@
return transaction != null && transaction.isActive();
}
+ public boolean isTransactionPresent() {
+ return transaction != null;
+ }
+
protected boolean isTransactionManagedExternally() {
return !isTransactionEnabled;
}
@@ -240,7 +239,6 @@
transaction.commit();
}
catch (HibernateException e) {
- // avoid log and throw antipattern
return e;
}
}
@@ -257,7 +255,6 @@
transaction.rollback();
}
catch (HibernateException e) {
- // avoid log and throw antipattern
return e;
}
}
@@ -271,7 +268,6 @@
session.flush();
}
catch (HibernateException e) {
- // avoid log and throw antipattern
return e;
}
}
@@ -289,7 +285,6 @@
session.close();
}
catch (HibernateException e) {
- // avoid log and throw antipattern
return e;
}
}
@@ -307,7 +302,6 @@
connection.close();
}
catch (SQLException e) {
- // avoid log and throw antipattern
return e;
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java 2010-08-30 16:34:53 UTC (rev 6635)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java 2010-08-31 05:05:48 UTC (rev 6636)
@@ -32,8 +32,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hibernate.Session;
import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.util.JTAHelper;
import org.jbpm.JbpmException;
import org.jbpm.persistence.JbpmPersistenceException;
@@ -41,35 +41,38 @@
public class JtaDbPersistenceService extends DbPersistenceService {
- private UserTransaction transaction;
+ private UserTransaction userTransaction;
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(JtaDbPersistenceService.class);
public JtaDbPersistenceService(JtaDbPersistenceServiceFactory persistenceServiceFactory) {
super(persistenceServiceFactory);
- if (!isTransactionActive()) beginTransaction();
}
public boolean isTransactionActive() {
- SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) getSessionFactory();
- return JTAHelper.isTransactionInProgress(sessionFactory);
+ return getTransactionStatus() == Status.STATUS_ACTIVE;
}
+ public boolean isTransactionPresent() {
+ int status = getTransactionStatus();
+ return status != Status.STATUS_NO_TRANSACTION && status != Status.STATUS_UNKNOWN;
+ }
+
protected boolean isTransactionManagedExternally() {
- return transaction == null;
+ return userTransaction == null;
}
protected boolean isTransactionRollbackOnly() {
return super.isTransactionRollbackOnly()
- || JTAHelper.isMarkedForRollback(getTransactionStatus());
+ || getTransactionStatus() == Status.STATUS_MARKED_ROLLBACK;
}
public void beginTransaction() {
try {
JtaDbPersistenceServiceFactory jtaFactory = (JtaDbPersistenceServiceFactory) persistenceServiceFactory;
- transaction = jtaFactory.getUserTransaction();
- transaction.begin();
+ userTransaction = jtaFactory.getUserTransaction();
+ userTransaction.begin();
}
catch (NotSupportedException e) {
throw new JbpmException("transaction is already in course", e);
@@ -79,27 +82,37 @@
}
}
+ public Session getSession() {
+ if (!isTransactionPresent()) beginTransaction();
+ return super.getSession();
+ }
+
private int getTransactionStatus() {
try {
- if (transaction != null) {
- return transaction.getStatus();
+ if (userTransaction != null) {
+ return userTransaction.getStatus();
}
else {
- SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) getSessionFactory();
- TransactionManager transactionManager = sessionFactory.getTransactionManager();
- if (transactionManager != null) return transactionManager.getStatus();
+ TransactionManager transactionManager = getTransactionManager();
+ return transactionManager != null ? transactionManager.getStatus()
+ : Status.STATUS_NO_TRANSACTION;
}
}
catch (SystemException e) {
log.error("could not get transaction status", e);
+ return Status.STATUS_UNKNOWN;
}
- return Status.STATUS_UNKNOWN;
}
+ private TransactionManager getTransactionManager() {
+ SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) getSessionFactory();
+ return sessionFactory.getTransactionManager();
+ }
+
protected Exception commit() {
- if (transaction != null) {
+ if (userTransaction != null) {
try {
- transaction.commit();
+ userTransaction.commit();
}
catch (RollbackException e) {
return e;
@@ -118,22 +131,21 @@
}
protected Exception rollback() {
- if (transaction != null) {
+ if (userTransaction != null) {
try {
- transaction.rollback();
+ userTransaction.rollback();
}
catch (SystemException e) {
return e;
}
}
else {
- SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) getSessionFactory();
- TransactionManager transactionManager = sessionFactory.getTransactionManager();
+ TransactionManager transactionManager = getTransactionManager();
if (transactionManager == null) {
- throw new JbpmPersistenceException("cannot honor rollback request under external transaction manager");
+ throw new JbpmPersistenceException("cannot honor rollback request in transaction manager absence");
}
try {
- transactionManager.getTransaction().setRollbackOnly();
+ transactionManager.setRollbackOnly();
}
catch (SystemException e) {
return e;
@@ -142,6 +154,7 @@
return null;
}
+ /** @deprecated use !{@link #isTransactionManagedExternally()} instead */
public boolean isJtaTxCreated() {
return !isTransactionManagedExternally();
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java 2010-08-30 16:34:53 UTC (rev 6635)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java 2010-08-31 05:05:48 UTC (rev 6636)
@@ -68,7 +68,7 @@
/*
* EJB 2.1 section 20.9 The container must make the UserTransaction interface available
* to the enterprise beans that are allowed to use this interface (only session and
- * message- driven beans with bean-managed transaction demarcation are allowed to use
+ * message-driven beans with bean-managed transaction demarcation are allowed to use
* this interface) in JNDI under the name java:comp/UserTransaction.
*/
/*
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1775/JBPM1775Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1775/JBPM1775Test.java 2010-08-30 16:34:53 UTC (rev 6635)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1775/JBPM1775Test.java 2010-08-31 05:05:48 UTC (rev 6636)
@@ -21,6 +21,8 @@
*/
package org.jbpm.jbpm1775;
+import org.hibernate.TransactionException;
+
import org.jbpm.db.AbstractDbTestCase;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.def.DelegationException;
@@ -40,17 +42,13 @@
public void testExceptionInAction() {
ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<?xml version='1.0'?>"
- + "<process-definition name='"
- + getName()
- + "'>"
- + " <exception-handler exception-class='java.lang.IllegalStateException'>"
+ + "<process-definition name='jbpm1775'>"
+ + " <exception-handler exception-class='" + TransactionException.class.getName() + "'>"
+ " <action class='org.example.NoSuchAction' />"
+ " </exception-handler>"
+ " <start-state name='start'>"
+ " <transition to='end'>"
- + " <action class='"
- + ExceptionAction.class.getName()
- + "' />"
+ + " <action class='" + RollbackAction.class.getName() + "' />"
+ " </transition>"
+ " </start-state>"
+ " <end-state name='end' />"
@@ -63,7 +61,7 @@
}
catch (DelegationException e) {
jbpmContext.setRollbackOnly();
- assertSame(IllegalStateException.class, e.getCause().getClass());
+ assert e.getCause() instanceof TransactionException : e.getCause();
try {
closeJbpmContext();
@@ -75,7 +73,7 @@
}
}
- public static class ExceptionAction implements ActionHandler {
+ public static class RollbackAction implements ActionHandler {
private static final long serialVersionUID = 1L;
public void execute(ExecutionContext executionContext) throws Exception {
@@ -86,7 +84,7 @@
.getPersistenceService();
persistenceService.getTransaction().rollback();
// throw exception
- throw new IllegalStateException("transaction was forcefully rolled back");
+ throw new TransactionException("transaction rolled back");
}
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java 2010-08-30 16:34:53 UTC (rev 6635)
+++ jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java 2010-08-31 05:05:48 UTC (rev 6636)
@@ -83,22 +83,19 @@
protected CommandService createCommandService() throws Exception {
if (commandServiceHome == null) {
- commandServiceHome = (LocalCommandServiceHome) getEnvironment().lookup(
- "ejb/CommandServiceBean");
+ commandServiceHome = (LocalCommandServiceHome) getEnvironment().lookup("ejb/CommandServiceBean");
}
return new RetryCommandService(commandServiceHome.create());
}
protected ProcessDefinition deployProcessDefinition(String xml) {
- ProcessDefinition processDefinition = (ProcessDefinition) commandService
- .execute(new DeployProcessCommand(xml));
+ ProcessDefinition processDefinition = (ProcessDefinition) commandService.execute(new DeployProcessCommand(xml));
processDefinitions.add(processDefinition);
return processDefinition;
}
protected ProcessDefinition deployProcessDefinition(byte[] processArchive) {
- ProcessDefinition processDefinition = (ProcessDefinition) commandService
- .execute(new DeployProcessCommand(processArchive));
+ ProcessDefinition processDefinition = (ProcessDefinition) commandService.execute(new DeployProcessCommand(processArchive));
processDefinitions.add(processDefinition);
return processDefinition;
}
@@ -115,8 +112,7 @@
}
protected boolean hasProcessInstanceEnded(final long processInstanceId) {
- ProcessInstance processInstance = (ProcessInstance) commandService
- .execute(new GetProcessInstanceCommand(processInstanceId));
+ ProcessInstance processInstance = (ProcessInstance) commandService.execute(new GetProcessInstanceCommand(processInstanceId));
return processInstance.hasEnded();
}
@@ -136,8 +132,7 @@
private static final long serialVersionUID = 1L;
public Object execute(JbpmContext jbpmContext) throws Exception {
- DbPersistenceServiceFactory factory = (DbPersistenceServiceFactory) jbpmContext
- .getServiceFactory(Services.SERVICENAME_PERSISTENCE);
+ DbPersistenceServiceFactory factory = (DbPersistenceServiceFactory) jbpmContext.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
return factory.getConfiguration().getProperty(Environment.DIALECT);
}
});
@@ -160,7 +155,7 @@
return environment;
}
- static final class RetryCommandService implements CommandService {
+ private static final class RetryCommandService implements CommandService {
private final CommandService delegate;
@@ -178,8 +173,8 @@
catch (RuntimeException e) {
if (!DbPersistenceService.isLockingException(e)) throw e;
// if this is a locking exception, keep it quiet
- StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(
- "failed to execute " + command);
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error("failed to execute "
+ + command);
lockingException = e;
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java 2010-08-30 16:34:53 UTC (rev 6635)
+++ jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java 2010-08-31 05:05:48 UTC (rev 6636)
@@ -23,9 +23,8 @@
import junit.framework.Test;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
+import org.hibernate.TransactionException;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
@@ -37,64 +36,106 @@
public class JtaDbPersistenceTest extends AbstractEnterpriseTestCase {
- private static final Log log = LogFactory.getLog(JtaDbPersistenceTest.class);
-
- public static Test suite() throws Exception {
+ public static Test suite() {
return new IntegrationTestSetup(JtaDbPersistenceTest.class, "enterprise-test.war");
}
protected CommandService createCommandService() throws Exception {
- return getName().indexOf("Container") != -1 ? super.createCommandService() : new CommandServiceImpl(
- JbpmConfiguration.getInstance());
+ return getName().indexOf("Container") != -1 ? super.createCommandService()
+ : new CommandServiceImpl(JbpmConfiguration.getInstance());
}
- public void testContainerTxSuccess() throws Exception {
- playTransaction(false);
+ public void testContainerTxSuccess() {
+ executeProcess();
}
- public void testContainerTxFailure() throws Exception {
- playTransaction(true);
+ public void testContainerTxFailure() {
+ executeProcess();
}
- public void testUserTxSuccess() throws Exception {
- playTransaction(false);
+ public void testContainerTxRollback() {
+ executeProcess();
}
- public void testUserTxFailure() throws Exception {
- playTransaction(true);
+ public void testContainerTxExceptionHandler() {
+ executeExceptionProcess();
}
- private void playTransaction(boolean fail) throws Exception {
+ public void testUserTxSuccess() {
+ executeProcess();
+ }
+
+ public void testUserTxFailure() {
+ executeProcess();
+ }
+
+ public void testUserTxRollback() {
+ executeProcess();
+ }
+
+ public void testUserTxExceptionHandler() {
+ executeExceptionProcess();
+ }
+
+ private void executeProcess() {
deployProcessDefinition("<process-definition name='jta'>"
- + " <start-state name='start'>"
- + " <transition to='midway' />"
- + " </start-state>"
- + " <state name='midway'>"
- + " <transition to='end' />"
- + " </state>"
- + " <end-state name='end' />"
- + "</process-definition>");
- long processInstanceId = startProcessInstance("jta").getId();
+ + " <start-state name='start'>"
+ + " <transition to='midway' />"
+ + " </start-state>"
+ + " <state name='midway'>"
+ + " <transition to='end' />"
+ + " </state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ final long processInstanceId = startProcessInstance("jta").getId();
+ final String testName = getName();
try {
- signal(processInstanceId, fail);
+ commandService.execute(new Command() {
+ private static final long serialVersionUID = 1L;
+
+ public Object execute(JbpmContext jbpmContext) {
+ jbpmContext.loadProcessInstance(processInstanceId).signal();
+ if (testName.endsWith("Failure")) throw new HibernateException("simulated failure");
+ if (testName.endsWith("Rollback")) jbpmContext.setRollbackOnly();
+ return null;
+ }
+ });
}
catch (RuntimeException e) {
- log.debug("signal failed on process instance #" + processInstanceId, e);
+ assertSame(HibernateException.class, getUltimateCause(e).getClass());
}
- assertEquals(!fail, hasProcessInstanceEnded(processInstanceId));
+ assertEquals(testName.endsWith("Success"), hasProcessInstanceEnded(processInstanceId));
}
- private void signal(final long processInstanceId, final boolean fail) throws Exception {
- commandService.execute(new Command() {
+ private void executeExceptionProcess() {
+ deployProcessDefinition("<process-definition name='jbpm2918'>"
+ + " <exception-handler exception-class='" + TransactionException.class.getName() + "'>"
+ + " <action class='org.example.NoSuchAction' />"
+ + " </exception-handler>"
+ + " <start-state name='start'>"
+ + " <transition to='end'>"
+ + " <script>"
+ + " executionContext.getJbpmContext().getSessionFactory().getTransactionManager().setRollbackOnly();"
+ + " throw new org.hibernate.TransactionException(\"transaction marked for rollback\");"
+ + " </script>"
+ + " </transition>"
+ + " </start-state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ try {
+ startProcessInstance("jbpm2918");
+ fail("expected exception");
+ }
+ catch (RuntimeException e) {
+ assertSame(TransactionException.class, getUltimateCause(e).getClass());
+ }
+ }
- private static final long serialVersionUID = 1L;
-
- public Object execute(JbpmContext jbpmContext) throws Exception {
- jbpmContext.loadProcessInstance(processInstanceId).signal();
- if (fail) throw new HibernateException("simulated failure");
- return null;
- }
- });
+ private static Throwable getUltimateCause(Throwable exception) {
+ Throwable cause = exception;
+ while (cause.getCause() != null) {
+ cause = cause.getCause();
+ }
+ return cause;
}
-
}
14 years, 2 months
JBoss JBPM SVN: r6635 - in jbpm4/trunk/modules: api/src/main/java/org/jbpm/api/history and 6 other directories.
by do-not-reply@jboss.org
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());
+ }
+
+
}
14 years, 2 months
JBoss JBPM SVN: r6634 - in jbpm4/trunk/modules: jpdl/src/main/java/org/jbpm/jpdl/internal/activity and 1 other directories.
by do-not-reply@jboss.org
Author: swiderski.maciej
Date: 2010-08-29 04:47:23 -0400 (Sun, 29 Aug 2010)
New Revision: 6634
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskWithEventTest.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/Event.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/TaskActivity.java
Log:
JBPM-2924: introduced new event type TASK_CREATED that is fired when task is fully created and initialized so it can be found and accessed from within event listener
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/Event.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/Event.java 2010-08-29 08:38:15 UTC (rev 6633)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/Event.java 2010-08-29 08:47:23 UTC (rev 6634)
@@ -38,6 +38,8 @@
String ASSIGN = "assign";
/** fired when an assignee is reminded of a task */
String REMIND = "remind";
+ /** fired when a task is created */
+ String TASK_CREATED = "task-created";
/** get the name of event. */
String getName();
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/TaskActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/TaskActivity.java 2010-08-29 08:38:15 UTC (rev 6633)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/TaskActivity.java 2010-08-29 08:47:23 UTC (rev 6634)
@@ -26,6 +26,7 @@
import org.jbpm.api.JbpmException;
import org.jbpm.api.activity.ActivityExecution;
+import org.jbpm.api.model.Event;
import org.jbpm.api.model.Transition;
import org.jbpm.pvm.internal.cal.Duration;
import org.jbpm.pvm.internal.el.Expression;
@@ -106,6 +107,8 @@
execution.initializeAssignments(taskDefinition, task);
+ execution.fire(Event.TASK_CREATED, execution.getActivity());
+
HistoryEvent.fire(new TaskActivityStart(task), execution);
execution.waitForSignal();
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskWithEventTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskWithEventTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskWithEventTest.java 2010-08-29 08:47:23 UTC (rev 6634)
@@ -0,0 +1,64 @@
+package org.jbpm.test.task;
+
+import java.util.List;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.listener.EventListener;
+import org.jbpm.api.listener.EventListenerExecution;
+import org.jbpm.api.model.Event;
+import org.jbpm.api.task.Task;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.session.DbSession;
+import org.jbpm.test.JbpmTestCase;
+
+
+public class TaskWithEventTest extends JbpmTestCase {
+
+ public void testTaskWithEvent() {
+ deployJpdlXmlString(""
+ + "<process name='process' xmlns='http://jbpm.org/4.0/jpdl' key='process' version='1'> "
+ + " <start name='start1' g='74,95,48,48'> "
+ + " <transition name='to task1' to='task1' g='1,-23'/> "
+ + " </start> "
+ + " <end name='end1' g='73,270,48,48'/> "
+ + " <task name='task1' g='215,141,92,52' assignee='alex'> "
+ + " <on event='task-created'> "
+ + " <event-listener class='" + TaskEventListener.class.getName() + "' /> "
+ + " </on> "
+ + " <transition name='to task2' to='task2' g='-50,-21'/> "
+ + " </task> "
+ + " <task name='task2' g='214,270,92,52' assignee='mike'> "
+ + " <transition name='to end1' to='end1' g='-48,-21'/> "
+ + " </task> "
+ + " </process>"
+ );
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("process");
+ List<Task> tasks = taskService.findPersonalTasks("alex");
+ taskService.completeTask(tasks.get(0).getId());
+
+ String eventName = (String) executionService.getVariable(processInstance.getId(), "event-type");
+ assertEquals(Event.TASK_CREATED, eventName);
+
+ String assigneeName = (String) executionService.getVariable(processInstance.getId(), "assignee");
+ assertEquals("alex", assigneeName);
+
+ tasks = taskService.findPersonalTasks("mike");
+ taskService.completeTask(tasks.get(0).getId());
+
+ }
+
+
+ public static class TaskEventListener implements EventListener {
+
+ private static final long serialVersionUID = 1L;
+
+ public void notify(EventListenerExecution execution) {
+
+ DbSession session = EnvironmentImpl.getFromCurrent(DbSession.class);
+ execution.setVariable("assignee", session.findTaskByExecution(execution.getProcessInstance()).getAssignee());
+ execution.setVariable("event-type", ((ExecutionImpl)execution).getEvent().getName());
+ }
+ }
+}
14 years, 2 months
JBoss JBPM SVN: r6633 - in jbpm4/trunk/modules: test-db/src/test/java/org/jbpm/test/activity/forkjoin and 1 other directory.
by do-not-reply@jboss.org
Author: swiderski.maciej
Date: 2010-08-29 04:38:15 -0400 (Sun, 29 Aug 2010)
New Revision: 6633
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkWithConditionTest.java
Modified:
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkBinding.java
Log:
JBPM-2920: enables possibility to use conditional transitions on fork activity
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkBinding.java 2010-08-28 03:20:20 UTC (rev 6632)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkBinding.java 2010-08-29 08:38:15 UTC (rev 6633)
@@ -21,13 +21,20 @@
*/
package org.jbpm.jpdl.internal.activity;
+import java.util.List;
+
import org.jbpm.jpdl.internal.xml.JpdlParser;
+import org.jbpm.pvm.internal.model.ActivityImpl;
+import org.jbpm.pvm.internal.model.ExpressionCondition;
+import org.jbpm.pvm.internal.model.TransitionImpl;
+import org.jbpm.pvm.internal.util.XmlUtil;
import org.jbpm.pvm.internal.xml.Parse;
import org.w3c.dom.Element;
/**
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public class ForkBinding extends JpdlBinding {
@@ -35,7 +42,30 @@
super("fork");
}
+ @SuppressWarnings("unchecked")
public Object parseJpdl(Element element, Parse parse, JpdlParser parser) {
+
+ List<Element> transitionElements = XmlUtil.elements(element, "transition");
+ ActivityImpl activity = parse.contextStackFind(ActivityImpl.class);
+ List<TransitionImpl> transitions = (List<TransitionImpl>) activity.getOutgoingTransitions();
+
+ for (int i=0; i<transitionElements.size(); i++) {
+ TransitionImpl transition = transitions.get(i);
+ Element transitionElement = transitionElements.get(i);
+
+ Element conditionElement = XmlUtil.element(transitionElement, "condition");
+ if (conditionElement!=null) {
+
+ if (conditionElement.hasAttribute("expr")) {
+ ExpressionCondition expressionCondition = new ExpressionCondition();
+ expressionCondition.setExpression(conditionElement.getAttribute("expr"));
+ expressionCondition.setLanguage(XmlUtil.attribute(conditionElement, "lang"));
+ transition.setCondition(expressionCondition);
+
+ }
+ }
+ }
+
return new ForkActivity();
}
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkWithConditionTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkWithConditionTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkWithConditionTest.java 2010-08-29 08:38:15 UTC (rev 6633)
@@ -0,0 +1,114 @@
+package org.jbpm.test.activity.forkjoin;
+
+import java.util.Collections;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstance;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+
+public class ForkWithConditionTest extends JbpmTestCase {
+
+ private static final String PROCESS = ""
+ + "<process name='ForkCondition' xmlns='http://jbpm.org/4.4/jpdl'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to fork1' to='fork1'/>"
+ + " </start>"
+ + " <fork g='185,95,49,50' name='fork1' >"
+ + " <transition name='left' to='task1' g='-44,-18'>"
+ + " <condition expr='#{test > 1}' />"
+ + " </transition>"
+ + " <transition name='right' to='task2' g='-44,-18'>"
+ + " <condition expr='#{test > 2}' />"
+ + " </transition>"
+ + " <transition name='right' to='task3' g='-44,-18'>"
+ + " <condition expr='#{test > 3}' />"
+ + " </transition>"
+ + " </fork>"
+ + " <task name='task1' g='90,177,73,44' assignee='mike'>"
+ + " <transition name='to join1' to='join1' g='-43,-18'/>"
+ + " </task>"
+ + " <task name='task2' g='90,177,73,44' assignee='alex'>"
+ + " <transition name='to join1' to='join1' g='-43,-18'/>"
+ + " </task>"
+ + " <task name='task3' g='90,177,73,44' assignee='peter'>"
+ + " <transition name='to join1' to='join1' g='-43,-18'/>"
+ + " </task>"
+ + " <join name='join1' g='192,511,57,44' multiplicity='2'>"
+ + " <transition name='to Big car' to='Big car' g='-42,-18'/>"
+ + " </join>"
+ + " <state name='Big car' > "
+ + " <transition name='to end1' to='end1' g='-43,-18'/>"
+ + " </state> "
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>";
+
+ public void testForkConditionNotAllTrue() {
+ deployJpdlXmlString(PROCESS);
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForkCondition", Collections.singletonMap("test", 3));
+
+ assertTrue(processInstance.getExecutions().size() == 2);
+
+ Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult();
+ assertNotNull(taskAlex);
+ assertEquals("task2", taskAlex.getActivityName());
+
+ taskService.completeTask(taskAlex.getId());
+
+ Task taskMike = taskService.createTaskQuery().assignee("mike").uniqueResult();
+ assertNotNull(taskMike);
+ assertEquals("task1", taskMike.getActivityName());
+
+ taskService.completeTask(taskMike.getId());
+
+ processInstance = executionService.findProcessInstanceById(processInstance.getId());
+
+
+ executionService.signalExecutionById(processInstance.getId());
+
+
+ HistoryProcessInstance history = historyService
+ .createHistoryProcessInstanceQuery()
+ .processInstanceId(processInstance.getId())
+ .uniqueResult();
+
+ assertNotNull(history);
+ assertEquals(ProcessInstance.STATE_ENDED, history.getState());
+ assertEquals("end1", history.getEndActivityName());
+ }
+
+ public void testForkConditionAllTrue() {
+ deployJpdlXmlString(PROCESS);
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForkCondition", Collections.singletonMap("test", 4));
+
+ assertTrue(processInstance.getExecutions().size() == 3);
+
+ Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult();
+ assertNotNull(taskAlex);
+ assertEquals("task2", taskAlex.getActivityName());
+
+ taskService.completeTask(taskAlex.getId());
+
+ Task taskMike = taskService.createTaskQuery().assignee("mike").uniqueResult();
+ assertNotNull(taskMike);
+ assertEquals("task1", taskMike.getActivityName());
+
+ taskService.completeTask(taskMike.getId());
+
+ processInstance = executionService.findProcessInstanceById(processInstance.getId());
+ executionService.signalExecutionById(processInstance.getId());
+
+ HistoryProcessInstance history = historyService
+ .createHistoryProcessInstanceQuery()
+ .processInstanceId(processInstance.getId())
+ .uniqueResult();
+
+ assertNotNull(history);
+ assertEquals(ProcessInstance.STATE_ENDED, history.getState());
+ assertEquals("end1", history.getEndActivityName());
+ }
+
+}
14 years, 2 months
JBoss JBPM SVN: r6632 - jbpm3/branches/jbpm-3.2-soa.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-08-27 23:20:20 -0400 (Fri, 27 Aug 2010)
New Revision: 6632
Modified:
jbpm3/branches/jbpm-3.2-soa/pom.xml
Log:
replace or exclude artifacts no longer found in maven repositories
Modified: jbpm3/branches/jbpm-3.2-soa/pom.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/pom.xml 2010-08-27 23:10:10 UTC (rev 6631)
+++ jbpm3/branches/jbpm-3.2-soa/pom.xml 2010-08-28 03:20:20 UTC (rev 6632)
@@ -178,6 +178,12 @@
<groupId>org.jboss.cluster</groupId>
<artifactId>hibernate-jbc-cacheprovider</artifactId>
<version>1.0.2-SNAPSHOT</version>
+ <exclusions>
+ <exclusion>
+ <groupId>hibernate</groupId>
+ <artifactId>hibernate3</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.izpack</groupId>
@@ -237,7 +243,7 @@
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
- <version>1.4</version>
+ <version>1.4.2</version>
</dependency>
<dependency>
<groupId>net.sf.retrotranslator</groupId>
14 years, 2 months
JBoss JBPM SVN: r6631 - jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-08-27 19:10:10 -0400 (Fri, 27 Aug 2010)
New Revision: 6631
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmContext.java
Log:
JBPM-2911 address possible performance problem caused by autoSaveProcessInstances
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmContext.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmContext.java 2010-08-27 20:04:45 UTC (rev 6630)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmContext.java 2010-08-27 23:10:10 UTC (rev 6631)
@@ -23,9 +23,10 @@
import java.io.Serializable;
import java.sql.Connection;
-import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
@@ -103,7 +104,7 @@
private final String name;
private final Services services;
private final JbpmConfiguration jbpmConfiguration;
- private List autoSaveProcessInstances;
+ private Set autoSaveProcessInstances;
private boolean isClosed;
/**
@@ -689,7 +690,7 @@
public void addAutoSaveProcessInstance(ProcessInstance processInstance) {
ensureOpen();
- if (autoSaveProcessInstances == null) autoSaveProcessInstances = new ArrayList();
+ if (autoSaveProcessInstances == null) autoSaveProcessInstances = new HashSet();
autoSaveProcessInstances.add(processInstance);
}
14 years, 2 months
JBoss JBPM SVN: r6630 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src: test/java/org/jbpm/calendar and 1 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-08-27 16:04:45 -0400 (Fri, 27 Aug 2010)
New Revision: 6630
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/DayPart.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/BusinessCalendarTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java
Log:
JBPM-1776 rework findPreviousDayPart and findNextDayPart methods
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java 2010-08-27 06:54:23 UTC (rev 6629)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java 2010-08-27 20:04:45 UTC (rev 6630)
@@ -32,7 +32,6 @@
import java.util.Properties;
import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmException;
import org.jbpm.util.ClassLoaderUtil;
/**
@@ -66,13 +65,8 @@
}
public BusinessCalendar(Properties calendarProperties) {
- try {
- weekDays = Day.parseWeekDays(calendarProperties, this);
- holidays = Holiday.parseHolidays(calendarProperties, this);
- }
- catch (Exception e) {
- throw new JbpmException("could not create business calendar", e);
- }
+ weekDays = Day.parseWeekDays(calendarProperties, this);
+ holidays = Holiday.parseHolidays(calendarProperties, this);
}
public Day[] getWeekDays() {
@@ -98,15 +92,12 @@
if (dayPart == null) {
// outside business hours
Day day = findDay(date);
- Object[] result = new Object[2];
if (duration.isNegative()) {
- day.findPreviousDayPartEnd(date, result);
+ dayPart = day.findPreviousDayPart(date);
}
else {
- day.findNextDayPartStart(0, date, result);
+ dayPart = day.findNextDayPart(date);
}
- date = (Date) result[0];
- dayPart = (DayPart) result[1];
}
end = dayPart.add(date, duration);
}
@@ -182,9 +173,7 @@
if (nextDayPart == null) {
date = findStartOfNextDay(date);
Day day = findDay(date);
- Object result[] = new Object[2];
- day.findNextDayPartStart(0, date, result);
- nextDayPart = (DayPart) result[1];
+ nextDayPart = day.findNextDayPart(date);
}
return nextDayPart;
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java 2010-08-27 06:54:23 UTC (rev 6629)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java 2010-08-27 20:04:45 UTC (rev 6630)
@@ -49,7 +49,8 @@
Day[] weekDays = new Day[WEEK_DAY_KEYS.length];
for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
- weekDays[i] = new Day(calendarProperties.getProperty(WEEK_DAY_KEYS[i]), timeFormat,
+ weekDays[i] = new Day(calendarProperties.getProperty(WEEK_DAY_KEYS[i]),
+ timeFormat,
businessCalendar);
}
return weekDays;
@@ -70,6 +71,7 @@
}
}
+ /** @deprecated with no replacement */
public void findNextDayPartStart(int dayPartIndex, Date date, Object[] result) {
// if there is a day part that starts after the given date
if (dayPartIndex < dayParts.length) {
@@ -90,26 +92,64 @@
}
}
- void findPreviousDayPartEnd(Date date, Object[] result) {
- findPreviousDayPartEnd(dayParts.length - 1, date, result);
+ DayPart findNextDayPart(Date date) {
+ return findNextDayPart(date, 0);
}
- void findPreviousDayPartEnd(int dayPartIndex, Date date, Object[] result) {
+ /**
+ * Finds the business day part that starts on or after the given date and determines the time
+ * that day part begins.
+ *
+ * @param date on input, the base date; on output, the day part start date.
+ * <strong>Beware!</strong> The method modifies the date.
+ */
+ DayPart findNextDayPart(Date date, int dayPartIndex) {
+ // if there is a day part that starts after the given date
+ if (dayPartIndex < dayParts.length) {
+ DayPart dayPart = dayParts[dayPartIndex];
+ if (dayPart.isStartAfter(date)) {
+ date.setTime(dayPart.getStartTime(date).getTime());
+ return dayPart;
+ }
+ else {
+ return findNextDayPart(date, dayPartIndex + 1);
+ }
+ }
+ else {
+ // descend recursively
+ date.setTime(businessCalendar.findStartOfNextDay(date).getTime());
+ Day nextDay = businessCalendar.findDay(date);
+ return nextDay.findNextDayPart(date);
+ }
+ }
+
+ DayPart findPreviousDayPart(Date date) {
+ return findPreviousDayPart(date, dayParts.length - 1);
+ }
+
+ /**
+ * Finds the business day part that ends on or before the given date and determines the time
+ * that day part ends.
+ *
+ * @param date on input, the base date; on output, the day part end date.
+ * <strong>Beware!</strong> The method modifies the date.
+ */
+ DayPart findPreviousDayPart(Date date, int dayPartIndex) {
// if there is a day part that ends before the given date
if (dayPartIndex >= 0) {
DayPart dayPart = dayParts[dayPartIndex];
if (dayPart.endsBefore(date)) {
- result[0] = dayPart.getEndTime(date);
- result[1] = dayPart;
+ date.setTime(dayPart.getEndTime(date).getTime());
+ return dayPart;
}
else {
- findPreviousDayPartEnd(dayPartIndex - 1, date, result);
+ return findPreviousDayPart(date, dayPartIndex - 1);
}
}
else {
- date = businessCalendar.findEndOfPreviousDay(date);
+ date.setTime(businessCalendar.findEndOfPreviousDay(date).getTime());
Day previousDay = businessCalendar.findDay(date);
- previousDay.findPreviousDayPartEnd(date, result);
+ return previousDay.findPreviousDayPart(date);
}
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/DayPart.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/DayPart.java 2010-08-27 06:54:23 UTC (rev 6629)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/DayPart.java 2010-08-27 20:04:45 UTC (rev 6630)
@@ -38,8 +38,8 @@
final int endHour;
final int endMinute;
- final Day day;
- final int index;
+ private final Day day;
+ private final int index;
public DayPart(String dayPartText, DateFormat timeFormat, Day day, int index) {
// parse start time
@@ -90,10 +90,8 @@
Duration remainder = new Duration(durationMillis - dayPartMillis);
Date dayPartStartDate = new Date(date.getTime() + dayPartMillis);
- Object[] result = new Object[2];
- day.findPreviousDayPartEnd(index - 1, dayPartStartDate, result);
- Date previousDayPartEnd = (Date) result[0];
- DayPart previousDayPart = (DayPart) result[1];
+ DayPart previousDayPart = day.findPreviousDayPart(dayPartStartDate, index - 1);
+ Date previousDayPartEnd = dayPartStartDate;
return previousDayPart.add(previousDayPartEnd, remainder);
}
@@ -105,10 +103,8 @@
Duration remainder = new Duration(durationMillis - dayPartMillis);
Date dayPartEndDate = new Date(date.getTime() + dayPartMillis);
- Object[] result = new Object[2];
- day.findNextDayPartStart(index + 1, dayPartEndDate, result);
- Date nextDayPartStart = (Date) result[0];
- DayPart nextDayPart = (DayPart) result[1];
+ DayPart nextDayPart = day.findNextDayPart(dayPartEndDate, index + 1);
+ Date nextDayPartStart = dayPartEndDate;
return nextDayPart.add(nextDayPartStart, remainder);
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/BusinessCalendarTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/BusinessCalendarTest.java 2010-08-27 06:54:23 UTC (rev 6629)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/BusinessCalendarTest.java 2010-08-27 20:04:45 UTC (rev 6630)
@@ -30,7 +30,7 @@
static BusinessCalendar businessCalendar = new BusinessCalendar();
- public void testNonBusinessSecondAddition() throws Exception {
+ public void testNonBusinessSecondAddition() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 10, 30, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -43,7 +43,7 @@
assertEquals(expected, actual);
}
- public void testNonBusinessMinuteAddition() throws Exception {
+ public void testNonBusinessMinuteAddition() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -80,7 +80,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("10 days")));
}
- public void testNonBusinessWeekAddition() throws Exception {
+ public void testNonBusinessWeekAddition() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
calendar.set(Calendar.MILLISECOND, 125);
@@ -92,7 +92,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("5 weeks")));
}
- public void testNonBusinessMonthAddition() throws Exception {
+ public void testNonBusinessMonthAddition() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
calendar.set(Calendar.MILLISECOND, 125);
@@ -104,7 +104,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("3 months")));
}
- public void testNonBusinessYearAddition() throws Exception {
+ public void testNonBusinessYearAddition() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
calendar.set(Calendar.MILLISECOND, 125);
@@ -116,7 +116,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("1 year")));
}
- public void testBusinessDurationAdditionOverBusinessTime() throws Exception {
+ public void testBusinessDurationAdditionOverBusinessTime() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -128,7 +128,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("1 business minute")));
}
- public void testBusinessDurationAdditionOverLunchBreak() throws Exception {
+ public void testBusinessDurationAdditionOverLunchBreak() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -142,7 +142,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("10 business minutes")));
}
- public void testBusinessDurationAdditionOverDayBreak() throws Exception {
+ public void testBusinessDurationAdditionOverDayBreak() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 16, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -156,7 +156,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("10 business minutes")));
}
- public void testBusinessDurationAdditionOverHoliday() throws Exception {
+ public void testBusinessDurationAdditionOverHoliday() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2010, Calendar.NOVEMBER, 10, 16, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -172,7 +172,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("10 business minutes")));
}
- public void testBusinessDurationAdditionOverWeekend() throws Exception {
+ public void testBusinessDurationAdditionOverWeekend() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 8, 16, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -188,7 +188,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("10 business minutes")));
}
- public void testTwoBusinessHoursOverLunch() throws Exception {
+ public void testTwoBusinessHoursOverLunch() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 11, 15, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -202,7 +202,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("2 business hours")));
}
- public void testBusinessDurationAdditionOutsideBusinessHours() throws Exception {
+ public void testBusinessDurationAdditionOutsideBusinessHours() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 8, 12, 15, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -216,7 +216,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("30 business minutes")));
}
- public void testBusinessDurationAdditionOutsideBusinessHoursOverWeekend() throws Exception {
+ public void testBusinessDurationAdditionOutsideBusinessHoursOverWeekend() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 8, 12, 15, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -301,40 +301,4 @@
assertEquals(expected, businessCalendar.add(start, new Duration("1 business year")));
}
-
- public void testNextDayStart() {
- Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(2005, Calendar.APRIL, 8, 13, 15);
- Date fridayAfterLunch = calendar.getTime();
-
- calendar.add(Calendar.DAY_OF_MONTH, 1);
- calendar.set(Calendar.HOUR_OF_DAY, 0);
- calendar.set(Calendar.MINUTE, 0);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- Date nextDay = calendar.getTime();
-
- assertEquals(nextDay, businessCalendar.findStartOfNextDay(fridayAfterLunch));
- }
-
- public void testDayOfWeek() {
- Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(2005, Calendar.APRIL, 8, 13, 15);
- Date fridayAfterLunch = calendar.getTime();
-
- Day day = businessCalendar.findDay(fridayAfterLunch);
- assertSame(businessCalendar.getWeekDays()[Calendar.FRIDAY], day);
- }
-
- public void testFindNextDayPart() {
- Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(2005, Calendar.APRIL, 8, 21, 15);
- Date fridayNight = calendar.getTime();
-
- DayPart dayPart = businessCalendar.findNextDayPart(fridayNight);
- assertEquals(9, dayPart.startHour);
- assertEquals(0, dayPart.startMinute);
- assertEquals(businessCalendar.getWeekDays()[Calendar.MONDAY], dayPart.day);
- assertEquals(0, dayPart.index);
- }
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java 2010-08-27 06:54:23 UTC (rev 6629)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java 2010-08-27 20:04:45 UTC (rev 6630)
@@ -38,7 +38,7 @@
static BusinessCalendar businessCalendar = new BusinessCalendar();
- public void testNonBusinessSecondSubtraction() throws Exception {
+ public void testNonBusinessSecondSubtraction() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 10, 30, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -51,7 +51,7 @@
assertEquals(expected, actual);
}
- public void testNonBusinessMinuteSubtraction() throws Exception {
+ public void testNonBusinessMinuteSubtraction() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -88,7 +88,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-10 days")));
}
- public void testNonBusinessWeekSubtraction() throws Exception {
+ public void testNonBusinessWeekSubtraction() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
calendar.set(Calendar.MILLISECOND, 125);
@@ -100,7 +100,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-5 weeks")));
}
- public void testNonBusinessMonthSubtraction() throws Exception {
+ public void testNonBusinessMonthSubtraction() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
calendar.set(Calendar.MILLISECOND, 125);
@@ -112,7 +112,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-3 months")));
}
- public void testNonBusinessYearSubtraction() throws Exception {
+ public void testNonBusinessYearSubtraction() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
calendar.set(Calendar.MILLISECOND, 125);
@@ -124,7 +124,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-1 year")));
}
- public void testBusinessDurationSubtractionOverBusinessTime() throws Exception {
+ public void testBusinessDurationSubtractionOverBusinessTime() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -136,7 +136,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-1 business minute")));
}
- public void testBusinessDurationSubtractionOverLunchBreak() throws Exception {
+ public void testBusinessDurationSubtractionOverLunchBreak() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 12, 35, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -150,7 +150,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
}
- public void testBusinessDurationSubtractionOverDayBreak() throws Exception {
+ public void testBusinessDurationSubtractionOverDayBreak() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 8, 9, 5, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -164,7 +164,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
}
- public void testBusinessDurationSubtractionOverHoliday() throws Exception {
+ public void testBusinessDurationSubtractionOverHoliday() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2010, Calendar.NOVEMBER, 12, 9, 5, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -180,7 +180,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
}
- public void testBusinessDurationSubtractionOverWeekend() throws Exception {
+ public void testBusinessDurationSubtractionOverWeekend() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 11, 9, 5, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -196,7 +196,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
}
- public void testTwoBusinessHoursOverLunch() throws Exception {
+ public void testTwoBusinessHoursOverLunch() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 13, 45, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -210,7 +210,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-2 business hours")));
}
- public void testBusinessDurationSubtractionOutsideBusinessHours() throws Exception {
+ public void testBusinessDurationSubtractionOutsideBusinessHours() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 8, 12, 15, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -224,7 +224,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-30 business minutes")));
}
- public void testBusinessDurationSubtractionOutsideBusinessHoursOverWeekend() throws Exception {
+ public void testBusinessDurationSubtractionOutsideBusinessHoursOverWeekend() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 11, 12, 15, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -241,4 +241,55 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-5 business hours")));
}
+
+ public void testBusinessDaySubtraction() {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2005, Calendar.FEBRUARY, 21, 9, 30, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.set(Calendar.DAY_OF_MONTH, 7);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-10 business days")));
+ }
+
+ public void testBusinessWeekSubtraction() {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2005, Calendar.MARCH, 14, 9, 30, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.set(Calendar.MONTH, Calendar.FEBRUARY);
+ calendar.set(Calendar.DAY_OF_MONTH, 7);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-5 business weeks")));
+ }
+
+ public void testBusinessMonthSubtraction() {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2010, Calendar.MAY, 7, 9, 30, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.set(Calendar.MONTH, Calendar.FEBRUARY);
+ calendar.set(Calendar.DAY_OF_MONTH, 8);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-3 business months")));
+ }
+
+ public void testBusinessYearSubtraction() {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2011, Calendar.FEBRUARY, 9, 9, 30, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.set(Calendar.YEAR, 2010);
+ calendar.set(Calendar.DAY_OF_MONTH, 8);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-1 business year")));
+ }
}
14 years, 2 months
JBoss JBPM SVN: r6629 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm: scheduler/exe and 1 other directory.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-08-27 02:54:23 -0400 (Fri, 27 Aug 2010)
New Revision: 6629
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/scheduler/exe/SchedulerTest.java
Log:
JBPM-1776 correct exception message assumption in scheduler test;
replace "substraction" with "subtraction"
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java 2010-08-27 06:48:53 UTC (rev 6628)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java 2010-08-27 06:54:23 UTC (rev 6629)
@@ -29,7 +29,7 @@
import org.jbpm.calendar.Duration;
/**
- * Business time substraction delivers unexpected results.
+ * Business time subtraction delivers unexpected results.
*
* @see <a href="https://jira.jboss.org/browse/JBPM-1776">JBPM-1776</a>
* @author Alejandro Guizar
@@ -38,7 +38,7 @@
static BusinessCalendar businessCalendar = new BusinessCalendar();
- public void testNonBusinessSecondSubstraction() throws Exception {
+ public void testNonBusinessSecondSubtraction() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 10, 30, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -51,7 +51,7 @@
assertEquals(expected, actual);
}
- public void testNonBusinessMinuteSubstraction() throws Exception {
+ public void testNonBusinessMinuteSubtraction() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -63,7 +63,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-10 minutes")));
}
- public void testNonBusinessFractionalDurationSubstraction() {
+ public void testNonBusinessFractionalDurationSubtraction() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
calendar.set(Calendar.MILLISECOND, 125);
@@ -76,7 +76,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-7.75 hours")));
}
- public void testNonBusinessDaySubstraction() {
+ public void testNonBusinessDaySubtraction() {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.FEBRUARY, 5, 6, 30, 45);
calendar.set(Calendar.MILLISECOND, 125);
@@ -88,7 +88,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-10 days")));
}
- public void testNonBusinessWeekSubstraction() throws Exception {
+ public void testNonBusinessWeekSubtraction() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
calendar.set(Calendar.MILLISECOND, 125);
@@ -100,7 +100,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-5 weeks")));
}
- public void testNonBusinessMonthSubstraction() throws Exception {
+ public void testNonBusinessMonthSubtraction() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
calendar.set(Calendar.MILLISECOND, 125);
@@ -112,7 +112,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-3 months")));
}
- public void testNonBusinessYearSubstraction() throws Exception {
+ public void testNonBusinessYearSubtraction() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
calendar.set(Calendar.MILLISECOND, 125);
@@ -124,7 +124,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-1 year")));
}
- public void testBusinessDurationSubstractionOverBusinessTime() throws Exception {
+ public void testBusinessDurationSubtractionOverBusinessTime() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -136,7 +136,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-1 business minute")));
}
- public void testBusinessDurationSubstractionOverLunchBreak() throws Exception {
+ public void testBusinessDurationSubtractionOverLunchBreak() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 7, 12, 35, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -150,7 +150,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
}
- public void testBusinessDurationSubstractionOverDayBreak() throws Exception {
+ public void testBusinessDurationSubtractionOverDayBreak() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 8, 9, 5, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -164,7 +164,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
}
- public void testBusinessDurationSubstractionOverHoliday() throws Exception {
+ public void testBusinessDurationSubtractionOverHoliday() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2010, Calendar.NOVEMBER, 12, 9, 5, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -180,7 +180,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
}
- public void testBusinessDurationSubstractionOverWeekend() throws Exception {
+ public void testBusinessDurationSubtractionOverWeekend() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 11, 9, 5, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -210,7 +210,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-2 business hours")));
}
- public void testBusinessDurationSubstractionOutsideBusinessHours() throws Exception {
+ public void testBusinessDurationSubtractionOutsideBusinessHours() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 8, 12, 15, 0);
calendar.set(Calendar.MILLISECOND, 0);
@@ -224,7 +224,7 @@
assertEquals(expected, businessCalendar.add(start, new Duration("-30 business minutes")));
}
- public void testBusinessDurationSubstractionOutsideBusinessHoursOverWeekend() throws Exception {
+ public void testBusinessDurationSubtractionOutsideBusinessHoursOverWeekend() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
calendar.set(2005, Calendar.APRIL, 11, 12, 15, 0);
calendar.set(Calendar.MILLISECOND, 0);
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/scheduler/exe/SchedulerTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/scheduler/exe/SchedulerTest.java 2010-08-27 06:48:53 UTC (rev 6628)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/scheduler/exe/SchedulerTest.java 2010-08-27 06:54:23 UTC (rev 6629)
@@ -691,7 +691,7 @@
catch (JbpmException je) {
Throwable cause = je.getCause();
assertSame(IllegalArgumentException.class, cause.getClass());
- assert cause.getMessage().indexOf("1 demo") != -1 : cause;
+ assert cause.getMessage().indexOf("demo") != -1 : cause;
}
finally {
jbpmContext.close();
14 years, 2 months
JBoss JBPM SVN: r6628 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src: main/resources/org/jbpm/calendar and 3 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-08-27 02:48:53 -0400 (Fri, 27 Aug 2010)
New Revision: 6628
Added:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/DayPart.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Duration.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Holiday.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/calendar/jbpm.business.calendar.properties
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/BusinessCalendarTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/DayPartTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/DayTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/HolidayTest.java
Log:
JBPM-1776 deliver expected results from business time substraction;
update business calendar properties to 2010 u.s. holidays
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java 2010-08-25 12:52:13 UTC (rev 6627)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java 2010-08-27 06:48:53 UTC (rev 6628)
@@ -95,10 +95,16 @@
Date end = null;
if (duration.isBusinessTime()) {
DayPart dayPart = findDayPart(date);
- boolean isInbusinessHours = (dayPart != null);
- if (!isInbusinessHours) {
+ if (dayPart == null) {
+ // outside business hours
+ Day day = findDay(date);
Object[] result = new Object[2];
- findDay(date).findNextDayPartStart(0, date, result);
+ if (duration.isNegative()) {
+ day.findPreviousDayPartEnd(date, result);
+ }
+ else {
+ day.findNextDayPartStart(0, date, result);
+ }
date = (Date) result[0];
dayPart = (DayPart) result[1];
}
@@ -118,6 +124,7 @@
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
+
date = calendar.getTime();
while (isHoliday(date)) {
calendar.setTime(date);
@@ -127,6 +134,24 @@
return date;
}
+ Date findEndOfPreviousDay(Date date) {
+ Calendar calendar = getCalendar();
+ calendar.setTime(date);
+ calendar.add(Calendar.DATE, -1);
+ calendar.set(Calendar.HOUR_OF_DAY, 23);
+ calendar.set(Calendar.MINUTE, 0);
+ calendar.set(Calendar.SECOND, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+
+ date = calendar.getTime();
+ while (isHoliday(date)) {
+ calendar.setTime(date);
+ calendar.add(Calendar.DATE, -1);
+ date = calendar.getTime();
+ }
+ return date;
+ }
+
public Day findDay(Date date) {
Calendar calendar = getCalendar();
calendar.setTime(date);
@@ -142,34 +167,30 @@
}
private DayPart findDayPart(Date date) {
- DayPart dayPart = null;
if (!isHoliday(date)) {
Day day = findDay(date);
- for (int i = 0; ((i < day.dayParts.length) && (dayPart == null)); i++) {
- DayPart candidate = day.dayParts[i];
- if (candidate.includes(date)) dayPart = candidate;
+ for (int i = 0; i < day.dayParts.length; i++) {
+ DayPart dayPart = day.dayParts[i];
+ if (dayPart.includes(date)) return dayPart;
}
}
- return dayPart;
+ return null;
}
public DayPart findNextDayPart(Date date) {
- DayPart nextDayPart = null;
- while (nextDayPart == null) {
- nextDayPart = findDayPart(date);
- if (nextDayPart == null) {
- date = findStartOfNextDay(date);
- Object result[] = new Object[2];
- Day day = findDay(date);
- day.findNextDayPartStart(0, date, result);
- nextDayPart = (DayPart) result[1];
- }
+ DayPart nextDayPart = findDayPart(date);
+ if (nextDayPart == null) {
+ date = findStartOfNextDay(date);
+ Day day = findDay(date);
+ Object result[] = new Object[2];
+ day.findNextDayPartStart(0, date, result);
+ nextDayPart = (DayPart) result[1];
}
return nextDayPart;
}
public boolean isInBusinessHours(Date date) {
- return (findDayPart(date) != null);
+ return findDayPart(date) != null;
}
public static Calendar getCalendar() {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java 2010-08-25 12:52:13 UTC (rev 6627)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java 2010-08-27 06:48:53 UTC (rev 6628)
@@ -35,20 +35,21 @@
private static final long serialVersionUID = 1L;
- DayPart[] dayParts;
- BusinessCalendar businessCalendar;
+ final DayPart[] dayParts;
+ private final BusinessCalendar businessCalendar;
+ private static final String[] WEEK_DAY_KEYS = {
+ null, "weekday.sunday", "weekday.monday", "weekday.tuesday", "weekday.wednesday",
+ "weekday.thursday", "weekday.friday", "weekday.saturday"
+ };
+
public static Day[] parseWeekDays(Properties calendarProperties,
BusinessCalendar businessCalendar) {
- DateFormat dateFormat = new SimpleDateFormat(calendarProperties.getProperty("hour.format"));
- String[] weekDayKeys = {
- null, "weekday.sunday", "weekday.monday", "weekday.tuesday", "weekday.wednesday",
- "weekday.thursday", "weekday.friday", "weekday.saturday"
- };
+ DateFormat timeFormat = new SimpleDateFormat(calendarProperties.getProperty("hour.format"));
- Day[] weekDays = new Day[weekDayKeys.length];
+ Day[] weekDays = new Day[WEEK_DAY_KEYS.length];
for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
- weekDays[i] = new Day(calendarProperties.getProperty(weekDayKeys[i]), dateFormat,
+ weekDays[i] = new Day(calendarProperties.getProperty(WEEK_DAY_KEYS[i]), timeFormat,
businessCalendar);
}
return weekDays;
@@ -70,11 +71,12 @@
}
public void findNextDayPartStart(int dayPartIndex, Date date, Object[] result) {
- // if there is a day part in this day that starts after the given date
+ // if there is a day part that starts after the given date
if (dayPartIndex < dayParts.length) {
- if (dayParts[dayPartIndex].isStartAfter(date)) {
- result[0] = dayParts[dayPartIndex].getStartTime(date);
- result[1] = dayParts[dayPartIndex];
+ DayPart dayPart = dayParts[dayPartIndex];
+ if (dayPart.isStartAfter(date)) {
+ result[0] = dayPart.getStartTime(date);
+ result[1] = dayPart;
}
else {
findNextDayPartStart(dayPartIndex + 1, date, result);
@@ -87,4 +89,27 @@
nextDay.findNextDayPartStart(0, date, result);
}
}
+
+ void findPreviousDayPartEnd(Date date, Object[] result) {
+ findPreviousDayPartEnd(dayParts.length - 1, date, result);
+ }
+
+ void findPreviousDayPartEnd(int dayPartIndex, Date date, Object[] result) {
+ // if there is a day part that ends before the given date
+ if (dayPartIndex >= 0) {
+ DayPart dayPart = dayParts[dayPartIndex];
+ if (dayPart.endsBefore(date)) {
+ result[0] = dayPart.getEndTime(date);
+ result[1] = dayPart;
+ }
+ else {
+ findPreviousDayPartEnd(dayPartIndex - 1, date, result);
+ }
+ }
+ else {
+ date = businessCalendar.findEndOfPreviousDay(date);
+ Day previousDay = businessCalendar.findDay(date);
+ previousDay.findPreviousDayPartEnd(date, result);
+ }
+ }
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/DayPart.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/DayPart.java 2010-08-25 12:52:13 UTC (rev 6627)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/DayPart.java 2010-08-27 06:48:53 UTC (rev 6628)
@@ -23,120 +23,137 @@
import java.io.Serializable;
import java.text.*;
-import java.text.DateFormat;
import java.util.*;
/**
- * is part of a day that can for example be used to represent business hours.
- *
+ * is part of a day that can for example be used to represent business hours.
+ *
*/
public class DayPart implements Serializable {
private static final long serialVersionUID = 1L;
-
- int fromHour = -1;
- int fromMinute = -1;
- int toHour = -1;
- int toMinute = -1;
- Day day = null;
- int index = -1;
- public DayPart(String dayPartText, DateFormat dateFormat, Day day, int index) {
- this.day = day;
- this.index = index;
-
- int separatorIndex = dayPartText.indexOf('-');
- if (separatorIndex==-1) throw new IllegalArgumentException("improper format of daypart '"+dayPartText+"'");
- String fromText = dayPartText.substring(0, separatorIndex).trim().toLowerCase();
- String toText = dayPartText.substring(separatorIndex+1).trim().toLowerCase();
-
- try {
- Date from = dateFormat.parse(fromText);
- Date to = dateFormat.parse(toText);
-
- Calendar calendar = BusinessCalendar.getCalendar();
- calendar.setTime(from);
- fromHour = calendar.get(Calendar.HOUR_OF_DAY);
- fromMinute = calendar.get(Calendar.MINUTE);
+ final int startHour;
+ final int startMinute;
+ final int endHour;
+ final int endMinute;
- calendar.setTime(to);
- toHour = calendar.get(Calendar.HOUR_OF_DAY);
- if (toHour==0) {
- toHour=24;
- }
- toMinute = calendar.get(Calendar.MINUTE);
+ final Day day;
+ final int index;
- } catch (ParseException e) {
- throw new IllegalArgumentException("improper format of daypart '" + dayPartText + "'");
+ public DayPart(String dayPartText, DateFormat timeFormat, Day day, int index) {
+ // parse start time
+ ParsePosition parsePosition = new ParsePosition(Duration.indexOfNonWhite(dayPartText, 0));
+ Date startTime = timeFormat.parse(dayPartText, parsePosition);
+ if (startTime == null) {
+ throw new IllegalArgumentException("failed to parse day part start time: " + dayPartText);
}
+
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.setTime(startTime);
+ startHour = calendar.get(Calendar.HOUR_OF_DAY);
+ startMinute = calendar.get(Calendar.MINUTE);
+
+ // check time separator
+ int separatorIndex = Duration.indexOfNonWhite(dayPartText, parsePosition.getIndex());
+ if (dayPartText.charAt(separatorIndex) != '-') {
+ throw new IllegalArgumentException("missing '-' in day part: " + dayPartText);
+ }
+
+ // parse end time
+ parsePosition.setIndex(separatorIndex + 1);
+ Date endTime = timeFormat.parse(dayPartText, parsePosition);
+ if (endTime == null) {
+ throw new IllegalArgumentException("failed to parse day part end time: " + dayPartText);
+ }
+ calendar.setTime(endTime);
+ int hour = calendar.get(Calendar.HOUR_OF_DAY);
+ endHour = hour == 0 ? 24 : hour;
+ endMinute = calendar.get(Calendar.MINUTE);
+
+ this.day = day;
+ this.index = index;
}
public Date add(Date date, Duration duration) {
- Date end = null;
-
Calendar calendar = BusinessCalendar.getCalendar();
calendar.setTime(date);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
+ long durationMillis = duration.getMilliseconds();
- long millisInThisDayPart = (toHour - hour) * Duration.HOUR + (toMinute - minute) * Duration.MINUTE;
- long durationMillis = duration.getMilliseconds();
-
- if (durationMillis <= millisInThisDayPart) {
- end = duration.addTo(date);
- } else {
- Duration remainder = new Duration(durationMillis - millisInThisDayPart);
- Date dayPartEndDate = new Date(date.getTime() + millisInThisDayPart);
-
+ if (duration.isNegative()) {
+ long dayPartMillis = (startHour - hour) * Duration.HOUR + (startMinute - minute)
+ * Duration.MINUTE;
+ if (durationMillis >= dayPartMillis) return duration.addTo(date);
+
+ Duration remainder = new Duration(durationMillis - dayPartMillis);
+ Date dayPartStartDate = new Date(date.getTime() + dayPartMillis);
+
Object[] result = new Object[2];
- day.findNextDayPartStart(index+1, dayPartEndDate, result);
+ day.findPreviousDayPartEnd(index - 1, dayPartStartDate, result);
+ Date previousDayPartEnd = (Date) result[0];
+ DayPart previousDayPart = (DayPart) result[1];
+
+ return previousDayPart.add(previousDayPartEnd, remainder);
+ }
+ else {
+ long dayPartMillis = (endHour - hour) * Duration.HOUR + (endMinute - minute)
+ * Duration.MINUTE;
+ if (durationMillis <= dayPartMillis) return duration.addTo(date);
+
+ Duration remainder = new Duration(durationMillis - dayPartMillis);
+ Date dayPartEndDate = new Date(date.getTime() + dayPartMillis);
+
+ Object[] result = new Object[2];
+ day.findNextDayPartStart(index + 1, dayPartEndDate, result);
Date nextDayPartStart = (Date) result[0];
DayPart nextDayPart = (DayPart) result[1];
-
- end = nextDayPart.add(nextDayPartStart, remainder);
+
+ return nextDayPart.add(nextDayPartStart, remainder);
}
-
- return end;
}
-
- public boolean isStartAfter(Date date) {
+
+ public boolean isStartAfter(Date time) {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.setTime(date);
+ calendar.setTime(time);
+
int hour = calendar.get(Calendar.HOUR_OF_DAY);
- int minute = calendar.get(Calendar.MINUTE);
-
- return ( (hour<fromHour)
- || ( (hour==fromHour)
- && (minute<=fromMinute)
- )
- );
+ return startHour > hour
+ || (startHour == hour && startMinute >= calendar.get(Calendar.MINUTE));
}
+ boolean endsBefore(Date time) {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.setTime(time);
- public boolean includes(Date date) {
+ int hour = calendar.get(Calendar.HOUR_OF_DAY);
+ return endHour < hour || (endHour == hour && endMinute <= calendar.get(Calendar.MINUTE));
+ }
+
+ public boolean includes(Date time) {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.setTime(date);
+ calendar.setTime(time);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
-
- return ( ( (fromHour<hour)
- || ( (fromHour==hour)
- && (fromMinute<=minute)
- )
- ) &&
- ( (hour<toHour)
- || ( (hour==toHour)
- && (minute<=toMinute)
- )
- )
- );
+
+ return (startHour < hour || (startHour == hour && startMinute <= minute))
+ && (hour < endHour || (hour == endHour && minute <= endMinute));
}
- public Date getStartTime(Date date) {
+ public Date getStartTime(Date time) {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.setTime(date);
- calendar.set(Calendar.HOUR_OF_DAY, fromHour);
- calendar.set(Calendar.MINUTE, fromMinute);
+ calendar.setTime(time);
+ calendar.set(Calendar.HOUR_OF_DAY, startHour);
+ calendar.set(Calendar.MINUTE, startMinute);
return calendar.getTime();
}
+
+ Date getEndTime(Date time) {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.setTime(time);
+ calendar.set(Calendar.HOUR_OF_DAY, endHour);
+ calendar.set(Calendar.MINUTE, endMinute);
+ return calendar.getTime();
+ }
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Duration.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Duration.java 2010-08-25 12:52:13 UTC (rev 6627)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Duration.java 2010-08-27 06:48:53 UTC (rev 6628)
@@ -32,8 +32,6 @@
import java.util.Map;
import java.util.Properties;
-import org.jbpm.JbpmException;
-
/**
* interprets textual descriptions of a duration.
* <p>
@@ -41,11 +39,11 @@
* Where
* <ul>
* <li><quantity> is a piece of text that is parsable with
- * <code>NumberFormat.getNumberInstance().parse(quantity)</code>. </li>
+ * <code>NumberFormat.getNumberInstance().parse(quantity)</code>.</li>
* <li><unit> is one of {second, seconds, minute, minutes, hour, hours, day, days, week,
- * weeks, month, months, year, years}. </li>
+ * weeks, month, months, year, years}.</li>
* <li>And adding the optional indication <code>business</code> means that only business hours
- * should be taken into account for this duration. </li>
+ * should be taken into account for this duration.</li>
* </ul>
* </p>
*/
@@ -174,8 +172,8 @@
}
/**
- * creates a duration from a textual description. syntax: {number} space {unit} where number is
- * parsable to a java.lang.Number and unit is one of
+ * creates a duration from a textual description. syntax: {number} space {unit} where number
+ * is parsable to a java.lang.Number and unit is one of
* <ul>
* <li>second</li>
* <li>seconds</li>
@@ -194,28 +192,26 @@
* </ul>
*/
public Duration(String duration) {
- if (duration == null)
- throw new JbpmException("duration is null");
-
int index = indexOfNonWhite(duration, 0);
char lead = duration.charAt(index);
- if (lead == '+' || lead == '-')
- ++index;
+ if (lead == '+' || lead == '-') ++index;
// parse quantity
NumberFormat format = NumberFormat.getNumberInstance(Locale.US);
index = indexOfNonWhite(duration, index);
ParsePosition position = new ParsePosition(index);
Number quantity = format.parse(duration, position);
- if (quantity == null)
- throw new IllegalArgumentException("improper format of duration '" + duration + "'");
+ if (quantity == null) {
+ throw new IllegalArgumentException("failed to parse amount: " + duration);
+ }
String unitText = duration.substring(position.getIndex()).trim();
if (unitText.startsWith("business")) {
// parse unit
Long unit = (Long) businessAmounts.get(unitText);
- if (unit == null)
- throw new IllegalArgumentException("improper format of duration '" + duration + "'");
+ if (unit == null) {
+ throw new IllegalArgumentException("no such time unit: " + unitText);
+ }
field = Calendar.MILLISECOND;
amount = multiply(quantity, unit.longValue());
@@ -224,8 +220,9 @@
else {
// parse unit
Integer unit = (Integer) calendarFields.get(unitText);
- if (unit == null)
- throw new IllegalArgumentException("improper format of duration '" + duration + "'");
+ if (unit == null) {
+ throw new IllegalArgumentException("no such time unit: " + unitText);
+ }
// is quantity exactly representable as int?
if (quantity instanceof Long && isInteger(quantity.longValue())) {
@@ -252,23 +249,25 @@
amount = (long) (quantity.doubleValue() * WEEK);
break;
default:
- throw new IllegalArgumentException("fractional amount not supported for unit '"
- + unitText
- + "'");
+ throw new IllegalArgumentException("fractional amount not supported for time unit: "
+ + unitText);
}
}
}
- if (lead == '-')
- amount = -amount;
+ if (lead == '-') amount = -amount;
}
- private static int indexOfNonWhite(String str, int fromIndex) {
+ boolean isNegative() {
+ return amount < 0;
+ }
+
+ static int indexOfNonWhite(String str, int fromIndex) {
int off = fromIndex;
- int len = str.length();
- while (off < len && str.charAt(off) <= ' ')
- off++;
- return off;
+ for (int len = str.length(); off < len; off++) {
+ if (str.charAt(off) != ' ') return off;
+ }
+ return -1;
}
private static boolean isInteger(long number) {
@@ -276,8 +275,7 @@
}
public Date addTo(Date date) {
- if (field == Calendar.MILLISECOND)
- return new Date(date.getTime() + amount);
+ if (field == Calendar.MILLISECOND) return new Date(date.getTime() + amount);
Calendar calendar = BusinessCalendar.getCalendar();
calendar.setTime(date);
@@ -300,9 +298,8 @@
case Calendar.WEEK_OF_MONTH:
return amount * WEEK;
default:
- throw new IllegalStateException("calendar field '"
- + field
- + "' does not have a fixed duration");
+ throw new IllegalStateException("calendar field '" + field
+ + "' does not have a fixed duration");
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Holiday.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Holiday.java 2010-08-25 12:52:13 UTC (rev 6627)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Holiday.java 2010-08-27 06:48:53 UTC (rev 6628)
@@ -23,7 +23,7 @@
import java.io.Serializable;
import java.text.DateFormat;
-import java.text.ParseException;
+import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@@ -32,28 +32,26 @@
import java.util.List;
import java.util.Properties;
-import org.jbpm.JbpmException;
-
/**
* identifies a continuous set of days.
*/
public class Holiday implements Serializable {
-
+
private static final long serialVersionUID = 1L;
-
- Date fromDay = null;
- Date toDay = null;
- BusinessCalendar businessCalendar = null;
- public static List parseHolidays(Properties calendarProperties, BusinessCalendar businessCalendar) {
+ final Date startDate;
+ final Date endDate;
+
+ public static List parseHolidays(Properties calendarProperties,
+ BusinessCalendar businessCalendar) {
List holidays = new ArrayList();
-
+
DateFormat dateFormat = new SimpleDateFormat(calendarProperties.getProperty("day.format"));
- Iterator iter = calendarProperties.keySet().iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = calendarProperties.keySet().iterator(); iter.hasNext();) {
String key = (String) iter.next();
if (key.startsWith("holiday")) {
- Holiday holiday = new Holiday(calendarProperties.getProperty(key), dateFormat, businessCalendar);
+ Holiday holiday = new Holiday(calendarProperties.getProperty(key), dateFormat,
+ businessCalendar);
holidays.add(holiday);
}
}
@@ -62,33 +60,37 @@
}
public Holiday(String holidayText, DateFormat dateFormat, BusinessCalendar businessCalendar) {
- this.businessCalendar = businessCalendar;
- try {
- int separatorIndex = holidayText.indexOf('-');
- if (separatorIndex==-1) {
- fromDay = dateFormat.parse(holidayText.trim());
- toDay = fromDay;
- } else {
- String fromText = holidayText.substring(0, separatorIndex).trim();
- String toText = holidayText.substring(separatorIndex+1).trim();
- fromDay = dateFormat.parse(fromText);
- toDay = dateFormat.parse(toText);
+ ParsePosition parsePosition = new ParsePosition(Duration.indexOfNonWhite(holidayText, 0));
+ startDate = dateFormat.parse(holidayText, parsePosition);
+ if (startDate == null) {
+ throw new IllegalArgumentException("failed to parse holiday start date: " + holidayText);
+ }
+
+ Date end;
+ int separatorIndex = Duration.indexOfNonWhite(holidayText, parsePosition.getIndex());
+ if (separatorIndex != -1) {
+ if (holidayText.charAt(separatorIndex) != '-') {
+ throw new IllegalArgumentException("expected '-' in holiday date range: " + holidayText);
}
- // now we are going to set the toDay to the end of the day, rather then the beginning.
- // we take the start of the next day as the end of the toDay.
- Calendar calendar = BusinessCalendar.getCalendar();
- calendar.setTime(toDay);
- calendar.add(Calendar.DATE, 1);
- toDay = calendar.getTime();
-
- } catch (ParseException e) {
- throw new JbpmException("couldn't parse holiday '"+holidayText+"'", e);
+
+ parsePosition.setIndex(Duration.indexOfNonWhite(holidayText, separatorIndex + 1));
+ end = dateFormat.parse(holidayText, parsePosition);
+ if (end == null) {
+ throw new IllegalArgumentException("failed to parse holiday end date: " + holidayText);
+ }
}
+ else {
+ end = startDate;
+ }
+ // now set endDate to the end of the day, rather then the beginning
+ // take the start of the next day as the end of the endDate
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.setTime(end);
+ calendar.add(Calendar.DATE, 1);
+ endDate = calendar.getTime();
}
public boolean includes(Date date) {
- return ( (fromDay.getTime()<=date.getTime())
- && (date.getTime()<toDay.getTime())
- );
+ return startDate.getTime() <= date.getTime() && date.getTime() < endDate.getTime();
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/calendar/jbpm.business.calendar.properties
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/calendar/jbpm.business.calendar.properties 2010-08-25 12:52:13 UTC (rev 6627)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/calendar/jbpm.business.calendar.properties 2010-08-27 06:48:53 UTC (rev 6628)
@@ -15,19 +15,29 @@
# holiday ::= <holiday-period>
# holiday-period ::= <start-day> [- <end-day>]
# start-day and end-day must be in the day.format
-# below are the belgian official holidays
-holiday.1= 01/01/2005 # nieuwjaar (saturday)
-holiday.2= 27/03/2005 # pasen (sunday)
-holiday.3= 28/03/2005 # paasmaandag
-holiday.4= 01/05/2005 # feest van de arbeid (sunday)
-holiday.5= 05/05/2005 # hemelvaart
-holiday.6= 15/05/2005 # pinksteren (sunday)
-holiday.7= 16/05/2005 # pinkstermaandag
-holiday.8= 21/07/2005 # my birthday
-holiday.9= 15/08/2005 # moederkesdag
-holiday.10= 01/11/2005 # allerheiligen
-holiday.11= 11/11/2005 # wapenstilstand
-holiday.12= 25/12/2005 # kerstmis (sunday)
+# below are the u.s. official holidays
+# new year's day
+holiday.1= 01/01/2010
+# birthday of martin luther king
+holiday.2= 18/01/2010
+# washington's birthday
+holiday.3= 15/02/2010
+# memorial day
+holiday.4= 31/05/2010
+# independence day
+holiday.5= 05/07/2010
+# labor day
+holiday.6= 06/09/2010
+# columbus day
+holiday.7= 11/10/2010
+# veterans day
+holiday.8= 11/11/2010
+# thanksgiving day
+holiday.9= 25/11/2010
+# day after thanksgiving
+holiday.10= 26/11/2010
+# christmas day
+holiday.11= 24/12/2010
# typical workday excluding breaks
business.day.expressed.in.hours= 7.5
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/BusinessCalendarTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/BusinessCalendarTest.java 2010-08-25 12:52:13 UTC (rev 6627)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/BusinessCalendarTest.java 2010-08-27 06:48:53 UTC (rev 6628)
@@ -30,58 +30,29 @@
static BusinessCalendar businessCalendar = new BusinessCalendar();
- public void testNonBusinessDurationAddition() throws Exception {
+ public void testNonBusinessSecondAddition() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 7);
- calendar.set(Calendar.HOUR_OF_DAY, 10);
- calendar.set(Calendar.MINUTE, 30);
- calendar.set(Calendar.SECOND, 0);
+ calendar.set(2005, Calendar.APRIL, 7, 10, 30, 0);
calendar.set(Calendar.MILLISECOND, 0);
Date start = calendar.getTime();
- Date twentySecondsLater =
- businessCalendar.add(start, new Duration("20 seconds"));
-
- calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 7);
- calendar.set(Calendar.HOUR_OF_DAY, 10);
- calendar.set(Calendar.MINUTE, 30);
- calendar.set(Calendar.SECOND, 20);
- calendar.set(Calendar.MILLISECOND, 0);
+ calendar.add(Calendar.SECOND, 20);
Date expected = calendar.getTime();
- assertEquals(expected, twentySecondsLater);
+ Date actual = businessCalendar.add(start, new Duration("20 seconds"));
+ assertEquals(expected, actual);
}
- public void testNonBusinessDurationAdditionOverNonBusinessTime() throws Exception {
+ public void testNonBusinessMinuteAddition() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 7);
- calendar.set(Calendar.HOUR_OF_DAY, 11);
- calendar.set(Calendar.MINUTE, 55);
- calendar.set(Calendar.SECOND, 0);
+ calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
- Date fiveBeforeTwelve = calendar.getTime();
+ Date start = calendar.getTime();
- Date tenMinutesLaterThenFiveBeforeTwelve =
- businessCalendar.add(fiveBeforeTwelve, new Duration("10 minutes"));
-
- calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 7);
- calendar.set(Calendar.HOUR_OF_DAY, 12);
- calendar.set(Calendar.MINUTE, 5);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- Date fiveAfterTwelve = calendar.getTime();
+ calendar.add(Calendar.MINUTE, 10);
+ Date expected = calendar.getTime();
- assertEquals(fiveAfterTwelve, tenMinutesLaterThenFiveBeforeTwelve);
+ assertEquals(expected, businessCalendar.add(start, new Duration("10 minutes")));
}
public void testNonBusinessFractionalDurationAddition() {
@@ -90,13 +61,11 @@
calendar.set(Calendar.MILLISECOND, 125);
Date start = calendar.getTime();
- Date fiveWeeksLater = businessCalendar.add(start, new Duration("7.75 hours"));
-
- calendar.set(Calendar.HOUR_OF_DAY, 14);
- calendar.set(Calendar.MINUTE, 15);
+ calendar.add(Calendar.HOUR, 7);
+ calendar.add(Calendar.MINUTE, 45);
Date expected = calendar.getTime();
- assertEquals(expected, fiveWeeksLater);
+ assertEquals(expected, businessCalendar.add(start, new Duration("7.75 hours")));
}
public void testNonBusinessDayAddition() {
@@ -105,7 +74,7 @@
calendar.set(Calendar.MILLISECOND, 125);
Date start = calendar.getTime();
- calendar.set(Calendar.DAY_OF_MONTH, 15);
+ calendar.add(Calendar.DAY_OF_MONTH, 10);
Date expected = calendar.getTime();
assertEquals(expected, businessCalendar.add(start, new Duration("10 days")));
@@ -117,8 +86,7 @@
calendar.set(Calendar.MILLISECOND, 125);
Date start = calendar.getTime();
- calendar.set(Calendar.MONTH, Calendar.MARCH);
- calendar.set(Calendar.DAY_OF_MONTH, 11);
+ calendar.add(Calendar.WEEK_OF_YEAR, 5);
Date expected = calendar.getTime();
assertEquals(expected, businessCalendar.add(start, new Duration("5 weeks")));
@@ -130,7 +98,7 @@
calendar.set(Calendar.MILLISECOND, 125);
Date start = calendar.getTime();
- calendar.set(Calendar.MONTH, Calendar.MAY);
+ calendar.add(Calendar.MONTH, 3);
Date expected = calendar.getTime();
assertEquals(expected, businessCalendar.add(start, new Duration("3 months")));
@@ -142,227 +110,128 @@
calendar.set(Calendar.MILLISECOND, 125);
Date start = calendar.getTime();
- calendar.set(Calendar.YEAR, 2009);
+ calendar.add(Calendar.YEAR, 1);
Date expected = calendar.getTime();
assertEquals(expected, businessCalendar.add(start, new Duration("1 year")));
}
- public void testBusinessDurationAdditionInBusinessTime() throws Exception {
+ public void testBusinessDurationAdditionOverBusinessTime() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 7);
- calendar.set(Calendar.HOUR_OF_DAY, 11);
- calendar.set(Calendar.MINUTE, 55);
- calendar.set(Calendar.SECOND, 0);
+ calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
- Date fiveBeforeTwelve = calendar.getTime();
+ Date start = calendar.getTime();
- Date oneMinuteLaterThenFiveBeforeTwelve =
- businessCalendar.add(fiveBeforeTwelve, new Duration("1 business minute"));
-
- calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 7);
- calendar.set(Calendar.HOUR_OF_DAY, 11);
- calendar.set(Calendar.MINUTE, 56);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- Date fourBeforeTwelve = calendar.getTime();
+ calendar.add(Calendar.MINUTE, 1);
+ Date expected = calendar.getTime();
- assertEquals(fourBeforeTwelve, oneMinuteLaterThenFiveBeforeTwelve);
+ assertEquals(expected, businessCalendar.add(start, new Duration("1 business minute")));
}
public void testBusinessDurationAdditionOverLunchBreak() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 7);
- calendar.set(Calendar.HOUR_OF_DAY, 11);
- calendar.set(Calendar.MINUTE, 55);
- calendar.set(Calendar.SECOND, 0);
+ calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
- Date fiveBeforeTwelve = calendar.getTime();
+ Date start = calendar.getTime();
- Date tenBusinessMinutesAfterFiveBeforeTwelve =
- businessCalendar.add(fiveBeforeTwelve, new Duration("10 business minutes"));
-
- calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 7);
- calendar.set(Calendar.HOUR_OF_DAY, 12);
- calendar.set(Calendar.MINUTE, 35);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- Date twelveThirtyfive = calendar.getTime();
+ calendar.add(Calendar.MINUTE, 10);
+ // lunch break spans 30 minutes
+ calendar.add(Calendar.MINUTE, 30);
+ Date expected = calendar.getTime();
- assertEquals(twelveThirtyfive, tenBusinessMinutesAfterFiveBeforeTwelve);
+ assertEquals(expected, businessCalendar.add(start, new Duration("10 business minutes")));
}
public void testBusinessDurationAdditionOverDayBreak() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 7);
- calendar.set(Calendar.HOUR_OF_DAY, 16);
- calendar.set(Calendar.MINUTE, 55);
- calendar.set(Calendar.SECOND, 0);
+ calendar.set(2005, Calendar.APRIL, 7, 16, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
- Date fiveBeforeFive = calendar.getTime();
+ Date start = calendar.getTime();
- Date tenBusinessMinutesAfterFiveBeforeFive =
- businessCalendar.add(fiveBeforeFive, new Duration("10 business minutes"));
-
- calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 8);
- calendar.set(Calendar.HOUR_OF_DAY, 9);
- calendar.set(Calendar.MINUTE, 5);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- Date fiveAfterNineNextDay = calendar.getTime();
+ calendar.add(Calendar.MINUTE, 10);
+ // there are 16 hours between 17:00 and 9:00
+ calendar.add(Calendar.HOUR, 16);
+ Date expected = calendar.getTime();
- assertEquals(fiveAfterNineNextDay, tenBusinessMinutesAfterFiveBeforeFive);
+ assertEquals(expected, businessCalendar.add(start, new Duration("10 business minutes")));
}
- public void testBusinessDurationAdditionOverHolidayBreak() throws Exception {
+ public void testBusinessDurationAdditionOverHoliday() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.MAY);
- calendar.set(Calendar.DAY_OF_MONTH, 4);
- calendar.set(Calendar.HOUR_OF_DAY, 16);
- calendar.set(Calendar.MINUTE, 55);
- calendar.set(Calendar.SECOND, 0);
+ calendar.set(2010, Calendar.NOVEMBER, 10, 16, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
- Date fiveBeforeFive = calendar.getTime();
+ Date start = calendar.getTime();
- Date tenBusinessMinutesAfterFiveBeforeFive =
- businessCalendar.add(fiveBeforeFive, new Duration("10 business minutes"));
-
- calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.MAY);
- calendar.set(Calendar.DAY_OF_MONTH, 6);
- calendar.set(Calendar.HOUR_OF_DAY, 9);
- calendar.set(Calendar.MINUTE, 5);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- Date fiveAfterNineTwoDaysLater = calendar.getTime();
+ calendar.add(Calendar.MINUTE, 10);
+ // there are 16 hours between 17:00 and 9:00
+ calendar.add(Calendar.HOUR, 16);
+ // holiday
+ calendar.add(Calendar.DAY_OF_MONTH, 1);
+ Date expected = calendar.getTime();
- assertEquals(fiveAfterNineTwoDaysLater, tenBusinessMinutesAfterFiveBeforeFive);
+ assertEquals(expected, businessCalendar.add(start, new Duration("10 business minutes")));
}
- public void testBusinessDurationAdditionOverWeekendBreak() throws Exception {
+ public void testBusinessDurationAdditionOverWeekend() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 8);
- calendar.set(Calendar.HOUR_OF_DAY, 16);
- calendar.set(Calendar.MINUTE, 55);
- calendar.set(Calendar.SECOND, 0);
+ calendar.set(2005, Calendar.APRIL, 8, 16, 55, 0);
calendar.set(Calendar.MILLISECOND, 0);
- Date fiveBeforeFive = calendar.getTime();
+ Date start = calendar.getTime();
- Date tenBusinessMinutesAfterFiveBeforeFive =
- businessCalendar.add(fiveBeforeFive, new Duration("10 business minutes"));
-
- calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 11);
- calendar.set(Calendar.HOUR_OF_DAY, 9);
- calendar.set(Calendar.MINUTE, 5);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- Date fiveAfterNineAfterTheWeekend = calendar.getTime();
+ calendar.add(Calendar.MINUTE, 10);
+ // there are 16 hours between 17:00 and 9:00
+ calendar.add(Calendar.HOUR, 16);
+ // weekend
+ calendar.add(Calendar.DAY_OF_MONTH, 2);
+ Date expected = calendar.getTime();
- assertEquals(fiveAfterNineAfterTheWeekend, tenBusinessMinutesAfterFiveBeforeFive);
+ assertEquals(expected, businessCalendar.add(start, new Duration("10 business minutes")));
}
public void testTwoBusinessHoursOverLunch() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 7);
- calendar.set(Calendar.HOUR_OF_DAY, 11);
- calendar.set(Calendar.MINUTE, 15);
- calendar.set(Calendar.SECOND, 0);
+ calendar.set(2005, Calendar.APRIL, 7, 11, 15, 0);
calendar.set(Calendar.MILLISECOND, 0);
- Date quarterPastTwelve = calendar.getTime();
+ Date start = calendar.getTime();
- Date twoBusinessHoursAfterFiveBeforeFive =
- businessCalendar.add(quarterPastTwelve, new Duration("2 business hours"));
-
- calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 7);
- calendar.set(Calendar.HOUR_OF_DAY, 13);
- calendar.set(Calendar.MINUTE, 45);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- Date rightAfterLunch = calendar.getTime();
+ calendar.add(Calendar.HOUR, 2);
+ // lunch break spans 30 minutes
+ calendar.add(Calendar.MINUTE, 30);
+ Date expected = calendar.getTime();
- assertEquals(rightAfterLunch, twoBusinessHoursAfterFiveBeforeFive);
+ assertEquals(expected, businessCalendar.add(start, new Duration("2 business hours")));
}
- public void testBusinessDurationAdditionStartingOutsideBusinessHours() throws Exception {
+ public void testBusinessDurationAdditionOutsideBusinessHours() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 8);
- calendar.set(Calendar.HOUR_OF_DAY, 12);
- calendar.set(Calendar.MINUTE, 15);
- calendar.set(Calendar.SECOND, 0);
+ calendar.set(2005, Calendar.APRIL, 8, 12, 15, 0);
calendar.set(Calendar.MILLISECOND, 0);
- Date quarterPastTwelve = calendar.getTime();
+ Date start = calendar.getTime();
- Date tenBusinessMinutesAfterQuarterPastTwelve =
- businessCalendar.add(quarterPastTwelve, new Duration("30 business minutes"));
-
- calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 8);
- calendar.set(Calendar.HOUR_OF_DAY, 13);
- calendar.set(Calendar.MINUTE, 0);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- Date oneOClock = calendar.getTime();
+ calendar.add(Calendar.MINUTE, 30);
+ // lunch break ends at 12:30
+ calendar.add(Calendar.MINUTE, 15);
+ Date expected = calendar.getTime();
- assertEquals(oneOClock, tenBusinessMinutesAfterQuarterPastTwelve);
+ assertEquals(expected, businessCalendar.add(start, new Duration("30 business minutes")));
}
- public void testBusinessDurationAdditionStartingOutsideBusinessHoursAndOverWeekend()
- throws Exception {
+ public void testBusinessDurationAdditionOutsideBusinessHoursOverWeekend() throws Exception {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 8);
- calendar.set(Calendar.HOUR_OF_DAY, 12);
- calendar.set(Calendar.MINUTE, 15);
- calendar.set(Calendar.SECOND, 0);
+ calendar.set(2005, Calendar.APRIL, 8, 12, 15, 0);
calendar.set(Calendar.MILLISECOND, 0);
- Date quarterPastTwelve = calendar.getTime();
+ Date start = calendar.getTime();
- Date fiveBusinessHoursAfterQuarterPastTwelve =
- businessCalendar.add(quarterPastTwelve, new Duration("5 business hours"));
-
- calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 11);
- calendar.set(Calendar.HOUR_OF_DAY, 9);
- calendar.set(Calendar.MINUTE, 30);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- Date halfPastNineAfterTheWeekend = calendar.getTime();
+ calendar.add(Calendar.HOUR, 5);
+ // lunch break ends at 12:30
+ calendar.add(Calendar.MINUTE, 15);
+ // there are 16 hours between 17:00 and 9:00
+ calendar.add(Calendar.HOUR, 16);
+ // weekend
+ calendar.add(Calendar.DAY_OF_MONTH, 2);
+ Date expected = calendar.getTime();
- assertEquals(halfPastNineAfterTheWeekend, fiveBusinessHoursAfterQuarterPastTwelve);
+ assertEquals(expected, businessCalendar.add(start, new Duration("5 business hours")));
}
public void testBusinessFractionalDurationAddition() {
@@ -371,8 +240,12 @@
calendar.set(Calendar.MILLISECOND, 0);
Date start = calendar.getTime();
- calendar.set(Calendar.DAY_OF_MONTH, 8);
- calendar.set(Calendar.MINUTE, 45);
+ calendar.add(Calendar.HOUR, 7);
+ calendar.add(Calendar.MINUTE, 45);
+ // lunch break spans 30 minutes
+ calendar.add(Calendar.MINUTE, 30);
+ // there are 16 hours between 17:00 and 9:00
+ calendar.add(Calendar.HOUR, 16);
Date expected = calendar.getTime();
assertEquals(expected, businessCalendar.add(start, new Duration("7.75 business hours")));
@@ -405,12 +278,12 @@
public void testBusinessMonthAddition() {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(2005, Calendar.FEBRUARY, 7, 9, 30, 0);
+ calendar.set(2010, Calendar.FEBRUARY, 8, 9, 30, 0);
calendar.set(Calendar.MILLISECOND, 0);
Date start = calendar.getTime();
calendar.set(Calendar.MONTH, Calendar.MAY);
- calendar.set(Calendar.DAY_OF_MONTH, 9);
+ calendar.set(Calendar.DAY_OF_MONTH, 7);
Date expected = calendar.getTime();
assertEquals(expected, businessCalendar.add(start, new Duration("3 business months")));
@@ -418,12 +291,12 @@
public void testBusinessYearAddition() {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(2005, Calendar.FEBRUARY, 7, 9, 30, 0);
+ calendar.set(2010, Calendar.FEBRUARY, 8, 9, 30, 0);
calendar.set(Calendar.MILLISECOND, 0);
Date start = calendar.getTime();
- calendar.set(Calendar.YEAR, 2006);
- calendar.set(Calendar.DAY_OF_MONTH, 6);
+ calendar.set(Calendar.YEAR, 2011);
+ calendar.set(Calendar.DAY_OF_MONTH, 9);
Date expected = calendar.getTime();
assertEquals(expected, businessCalendar.add(start, new Duration("1 business year")));
@@ -431,48 +304,37 @@
public void testNextDayStart() {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 8);
- calendar.set(Calendar.HOUR_OF_DAY, 13);
- calendar.set(Calendar.MINUTE, 15);
- Date justAfterLunchOnAprilEight2005 = calendar.getTime();
- Date startOfNextDay = businessCalendar.findStartOfNextDay(justAfterLunchOnAprilEight2005);
+ calendar.set(2005, Calendar.APRIL, 8, 13, 15);
+ Date fridayAfterLunch = calendar.getTime();
- calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 9);
+ calendar.add(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
- assertEquals(calendar.getTime(), startOfNextDay);
+ Date nextDay = calendar.getTime();
+
+ assertEquals(nextDay, businessCalendar.findStartOfNextDay(fridayAfterLunch));
}
public void testDayOfWeek() {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 8);
- calendar.set(Calendar.HOUR_OF_DAY, 13);
- calendar.set(Calendar.MINUTE, 15);
- Date justAfterLunchOnAprilEight2005 = calendar.getTime();
+ calendar.set(2005, Calendar.APRIL, 8, 13, 15);
+ Date fridayAfterLunch = calendar.getTime();
- Day day = businessCalendar.findDay(justAfterLunchOnAprilEight2005);
+ Day day = businessCalendar.findDay(fridayAfterLunch);
assertSame(businessCalendar.getWeekDays()[Calendar.FRIDAY], day);
}
public void testFindNextDayPart() {
Calendar calendar = BusinessCalendar.getCalendar();
- calendar.set(Calendar.YEAR, 2005);
- calendar.set(Calendar.MONTH, Calendar.APRIL);
- calendar.set(Calendar.DAY_OF_MONTH, 8);
- calendar.set(Calendar.HOUR_OF_DAY, 21);
- calendar.set(Calendar.MINUTE, 15);
- Date outsideBusinessHours = calendar.getTime();
+ calendar.set(2005, Calendar.APRIL, 8, 21, 15);
+ Date fridayNight = calendar.getTime();
- BusinessCalendar bc = new BusinessCalendar();
- bc.findNextDayPart(outsideBusinessHours);
+ DayPart dayPart = businessCalendar.findNextDayPart(fridayNight);
+ assertEquals(9, dayPart.startHour);
+ assertEquals(0, dayPart.startMinute);
+ assertEquals(businessCalendar.getWeekDays()[Calendar.MONDAY], dayPart.day);
+ assertEquals(0, dayPart.index);
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/DayPartTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/DayPartTest.java 2010-08-25 12:52:13 UTC (rev 6627)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/DayPartTest.java 2010-08-27 06:48:53 UTC (rev 6628)
@@ -31,28 +31,28 @@
public void testDayPartParsing() {
DateFormat dateFormat = new SimpleDateFormat("HH:mm");
DayPart dayPart = new DayPart("9:00-12:15", dateFormat, null, 0);
- assertEquals(9, dayPart.fromHour);
- assertEquals(0, dayPart.fromMinute);
- assertEquals(12, dayPart.toHour);
- assertEquals(15, dayPart.toMinute);
+ assertEquals(9, dayPart.startHour);
+ assertEquals(0, dayPart.startMinute);
+ assertEquals(12, dayPart.endHour);
+ assertEquals(15, dayPart.endMinute);
}
public void testDayPartWithSpacesParsing() {
DateFormat dateFormat = new SimpleDateFormat("HH:mm");
DayPart dayPart = new DayPart(" 9:00 - 12:15 ", dateFormat, null, 0);
- assertEquals(9, dayPart.fromHour);
- assertEquals(0, dayPart.fromMinute);
- assertEquals(12, dayPart.toHour);
- assertEquals(15, dayPart.toMinute);
+ assertEquals(9, dayPart.startHour);
+ assertEquals(0, dayPart.startMinute);
+ assertEquals(12, dayPart.endHour);
+ assertEquals(15, dayPart.endMinute);
}
public void testDayPartAmPmParsing() {
DateFormat dateFormat = new SimpleDateFormat("hh'h'mma");
DayPart dayPart = new DayPart("9h00am-12h15pm", dateFormat, null, 0);
- assertEquals(9, dayPart.fromHour);
- assertEquals(0, dayPart.fromMinute);
- assertEquals(12, dayPart.toHour);
- assertEquals(15, dayPart.toMinute);
+ assertEquals(9, dayPart.startHour);
+ assertEquals(0, dayPart.startMinute);
+ assertEquals(12, dayPart.endHour);
+ assertEquals(15, dayPart.endMinute);
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/DayTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/DayTest.java 2010-08-25 12:52:13 UTC (rev 6627)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/DayTest.java 2010-08-27 06:48:53 UTC (rev 6628)
@@ -33,10 +33,10 @@
Day day = new Day("9:00-12:15", dateFormat, null);
assertEquals(1, day.dayParts.length);
DayPart dayPart = day.dayParts[0];
- assertEquals(9, dayPart.fromHour);
- assertEquals(0, dayPart.fromMinute);
- assertEquals(12, dayPart.toHour);
- assertEquals(15, dayPart.toMinute);
+ assertEquals(9, dayPart.startHour);
+ assertEquals(0, dayPart.startMinute);
+ assertEquals(12, dayPart.endHour);
+ assertEquals(15, dayPart.endMinute);
}
public void testDayMultipleDayPartsParsing() {
@@ -44,10 +44,10 @@
Day day = new Day("9:00-12:15 & 13:00-17:00", dateFormat, null);
assertEquals(2, day.dayParts.length);
DayPart dayPart = day.dayParts[1];
- assertEquals(13, dayPart.fromHour);
- assertEquals(0, dayPart.fromMinute);
- assertEquals(17, dayPart.toHour);
- assertEquals(0, dayPart.toMinute);
+ assertEquals(13, dayPart.startHour);
+ assertEquals(0, dayPart.startMinute);
+ assertEquals(17, dayPart.endHour);
+ assertEquals(0, dayPart.endMinute);
}
public void testEmptyDayParsing() {
@@ -61,14 +61,14 @@
Day day = new Day("8:00-12:30 & 13:30-24:00", dateFormat, null);
assertEquals(2, day.dayParts.length);
DayPart dayPart = day.dayParts[0];
- assertEquals(8, dayPart.fromHour);
- assertEquals(0, dayPart.fromMinute);
- assertEquals(12, dayPart.toHour);
- assertEquals(30, dayPart.toMinute);
+ assertEquals(8, dayPart.startHour);
+ assertEquals(0, dayPart.startMinute);
+ assertEquals(12, dayPart.endHour);
+ assertEquals(30, dayPart.endMinute);
dayPart = day.dayParts[1];
- assertEquals(13, dayPart.fromHour);
- assertEquals(30, dayPart.fromMinute);
- assertEquals(24, dayPart.toHour);
- assertEquals(0, dayPart.toMinute);
+ assertEquals(13, dayPart.startHour);
+ assertEquals(30, dayPart.startMinute);
+ assertEquals(24, dayPart.endHour);
+ assertEquals(0, dayPart.endMinute);
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/HolidayTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/HolidayTest.java 2010-08-25 12:52:13 UTC (rev 6627)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/HolidayTest.java 2010-08-27 06:48:53 UTC (rev 6628)
@@ -44,7 +44,7 @@
calendar.set(Calendar.MILLISECOND, 0);
Date expectedFromDay = calendar.getTime();
- assertEquals(expectedFromDay, holiday.fromDay);
+ assertEquals(expectedFromDay, holiday.startDate);
calendar.set(Calendar.YEAR, 2005);
calendar.set(Calendar.MONTH, Calendar.JULY);
@@ -55,7 +55,7 @@
calendar.set(Calendar.MILLISECOND, 0);
Date expectedToDay = calendar.getTime();
- assertEquals(expectedToDay, holiday.toDay);
+ assertEquals(expectedToDay, holiday.endDate);
}
public void testHolidayMulitDayParsing() throws Exception {
@@ -72,7 +72,7 @@
calendar.set(Calendar.MILLISECOND, 0);
Date expectedFromDay = calendar.getTime();
- assertEquals(expectedFromDay, holiday.fromDay);
+ assertEquals(expectedFromDay, holiday.startDate);
calendar.set(Calendar.YEAR, 2005);
calendar.set(Calendar.MONTH, Calendar.SEPTEMBER);
@@ -83,6 +83,6 @@
calendar.set(Calendar.MILLISECOND, 0);
Date expectedToDay = calendar.getTime();
- assertEquals(expectedToDay, holiday.toDay);
+ assertEquals(expectedToDay, holiday.endDate);
}
}
Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java 2010-08-27 06:48:53 UTC (rev 6628)
@@ -0,0 +1,244 @@
+/*
+ * 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.jbpm1776;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import org.jbpm.AbstractJbpmTestCase;
+import org.jbpm.calendar.BusinessCalendar;
+import org.jbpm.calendar.Duration;
+
+/**
+ * Business time substraction delivers unexpected results.
+ *
+ * @see <a href="https://jira.jboss.org/browse/JBPM-1776">JBPM-1776</a>
+ * @author Alejandro Guizar
+ */
+public class JBPM1776Test extends AbstractJbpmTestCase {
+
+ static BusinessCalendar businessCalendar = new BusinessCalendar();
+
+ public void testNonBusinessSecondSubstraction() throws Exception {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2005, Calendar.APRIL, 7, 10, 30, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.SECOND, -20);
+ Date expected = calendar.getTime();
+
+ Date actual = businessCalendar.add(start, new Duration("-20 seconds"));
+ assertEquals(expected, actual);
+ }
+
+ public void testNonBusinessMinuteSubstraction() throws Exception {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.MINUTE, -10);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-10 minutes")));
+ }
+
+ public void testNonBusinessFractionalDurationSubstraction() {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
+ calendar.set(Calendar.MILLISECOND, 125);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.HOUR, -7);
+ calendar.add(Calendar.MINUTE, -45);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-7.75 hours")));
+ }
+
+ public void testNonBusinessDaySubstraction() {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2005, Calendar.FEBRUARY, 5, 6, 30, 45);
+ calendar.set(Calendar.MILLISECOND, 125);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.DAY_OF_MONTH, -10);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-10 days")));
+ }
+
+ public void testNonBusinessWeekSubstraction() throws Exception {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
+ calendar.set(Calendar.MILLISECOND, 125);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.WEEK_OF_YEAR, -5);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-5 weeks")));
+ }
+
+ public void testNonBusinessMonthSubstraction() throws Exception {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
+ calendar.set(Calendar.MILLISECOND, 125);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.MONTH, -3);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-3 months")));
+ }
+
+ public void testNonBusinessYearSubstraction() throws Exception {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
+ calendar.set(Calendar.MILLISECOND, 125);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.YEAR, -1);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-1 year")));
+ }
+
+ public void testBusinessDurationSubstractionOverBusinessTime() throws Exception {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.MINUTE, -1);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-1 business minute")));
+ }
+
+ public void testBusinessDurationSubstractionOverLunchBreak() throws Exception {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2005, Calendar.APRIL, 7, 12, 35, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.MINUTE, -10);
+ // lunch break spans 30 minutes
+ calendar.add(Calendar.MINUTE, -30);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
+ }
+
+ public void testBusinessDurationSubstractionOverDayBreak() throws Exception {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2005, Calendar.APRIL, 8, 9, 5, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.MINUTE, -10);
+ // there are 16 hours between 17:00 and 9:00
+ calendar.add(Calendar.HOUR, -16);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
+ }
+
+ public void testBusinessDurationSubstractionOverHoliday() throws Exception {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2010, Calendar.NOVEMBER, 12, 9, 5, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.MINUTE, -10);
+ // there are 16 hours between 17:00 and 9:00
+ calendar.add(Calendar.HOUR, -16);
+ // holiday
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
+ }
+
+ public void testBusinessDurationSubstractionOverWeekend() throws Exception {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2005, Calendar.APRIL, 11, 9, 5, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.MINUTE, -10);
+ // there are 16 hours between 17:00 and 9:00
+ calendar.add(Calendar.HOUR, -16);
+ // weekend
+ calendar.add(Calendar.DAY_OF_MONTH, -2);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
+ }
+
+ public void testTwoBusinessHoursOverLunch() throws Exception {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2005, Calendar.APRIL, 7, 13, 45, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.HOUR, -2);
+ // lunch break spans 30 minutes
+ calendar.add(Calendar.MINUTE, -30);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-2 business hours")));
+ }
+
+ public void testBusinessDurationSubstractionOutsideBusinessHours() throws Exception {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2005, Calendar.APRIL, 8, 12, 15, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.MINUTE, -30);
+ // lunch break ends at 12:30
+ calendar.add(Calendar.MINUTE, -15);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-30 business minutes")));
+ }
+
+ public void testBusinessDurationSubstractionOutsideBusinessHoursOverWeekend() throws Exception {
+ Calendar calendar = BusinessCalendar.getCalendar();
+ calendar.set(2005, Calendar.APRIL, 11, 12, 15, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+ Date start = calendar.getTime();
+
+ calendar.add(Calendar.HOUR, -5);
+ // lunch break ends at 12:30
+ calendar.add(Calendar.MINUTE, -15);
+ // there are 16 hours between 17:00 and 9:00
+ calendar.add(Calendar.HOUR, -16);
+ // weekend
+ calendar.add(Calendar.DAY_OF_MONTH, -2);
+ Date expected = calendar.getTime();
+
+ assertEquals(expected, businessCalendar.add(start, new Duration("-5 business hours")));
+ }
+}
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 2 months