Author: rebody
Date: 2010-08-14 22:44:16 -0400 (Sat, 14 Aug 2010)
New Revision: 6591
Added:
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/cal/
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/cal/BusinessCalendarTest.java
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cal/BusinessCalendarImpl.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/TimerTest.java
Log:
JBPM-2813 if duration is pass of now, don't throw an exception
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cal/BusinessCalendarImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cal/BusinessCalendarImpl.java 2010-08-13
23:21:22 UTC (rev 6590)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cal/BusinessCalendarImpl.java 2010-08-15
02:44:16 UTC (rev 6591)
@@ -28,44 +28,46 @@
import java.util.TimeZone;
import org.jbpm.api.JbpmException;
+import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.util.Clock;
/**
* a calendar that knows about business hours.
*/
public class BusinessCalendarImpl implements Serializable, BusinessCalendar {
-
+
private static final long serialVersionUID = 1L;
+ private static Log log = Log.getLog(BusinessCalendarImpl.class.getName());
private static BusinessCalendarImpl instance = null;
-
+
protected long oid = -1;
protected int version = 0;
protected TimeZone timeZone = TimeZone.getDefault();
/** array that contains the weekdays in the index as specified by {@link
Calendar#SUNDAY} (=1),
- * {@link Calendar#MONDAY} (=2),... {@link Calendar#SATURDAY} (=7).
- */
+ * {@link Calendar#MONDAY} (=2),... {@link Calendar#SATURDAY} (=7).
+ */
protected Day[] days = null;
protected Holiday[] holidays = null;
-
- protected long secondInMillis = 1000;
- protected long minuteInMillis = 60000;
- protected long hourInMillis = 3600000;
- protected long dayInMillis = 24*hourInMillis;
- protected long weekInMillis = 7*dayInMillis;
- protected long monthInMillis = 30*dayInMillis;
- protected long yearInMillis = 365*dayInMillis;
- protected long businessDayInMillis = 8*hourInMillis;
- protected long businessWeekInMillis = 40*hourInMillis;
- protected long businessMonthInMillis = 21*dayInMillis;
- protected long businessYearInMillis = 220*dayInMillis;
-
+ protected long secondInMillis = 1000;
+ protected long minuteInMillis = 60000;
+ protected long hourInMillis = 3600000;
+ protected long dayInMillis = 24*hourInMillis;
+ protected long weekInMillis = 7*dayInMillis;
+ protected long monthInMillis = 30*dayInMillis;
+ protected long yearInMillis = 365*dayInMillis;
+
+ protected long businessDayInMillis = 8*hourInMillis;
+ protected long businessWeekInMillis = 40*hourInMillis;
+ protected long businessMonthInMillis = 21*dayInMillis;
+ protected long businessYearInMillis = 220*dayInMillis;
+
/** constructor for persistence and creating an empty business calendar */
public BusinessCalendarImpl() {
}
public static synchronized BusinessCalendarImpl getInstance() {
- if (instance==null) {
+ if (instance == null) {
instance = new BusinessCalendarImpl();
}
return instance;
@@ -74,20 +76,23 @@
public Date add(Date date, String duration) {
return add(date, new Duration(duration));
}
-
+
public Date subtract(Date date, String duration) {
- if (duration.contains("business")) {
- throw new JbpmException("Duedate subtraction not supported for business
durations");
- }
+ if (duration.contains("business")) {
+ throw new JbpmException("Duedate subtraction not supported for business
durations");
+ }
return subtract(date, new Duration(duration));
}
public Date subtract(Date date, Duration duration) {
- Date end = null;
+ Date end = null;
long millis = convertToMillis(duration);
- end = new Date(date.getTime()-millis);
+ end = new Date(date.getTime() - millis);
if (end.before(Clock.getTime())) {
- throw new JbpmException("Duedate "+ end+ " in the past");
+ if (log.isWarnEnabled()) {
+ log.warn("Duedate : [" + end + "] in the past of start : ["
+ date + "]");
+ }
+ return Clock.getTime();
}
return end;
}
@@ -132,9 +137,9 @@
return millis;
}
- public boolean isInBusinessHours(Date date) {
- return (findDayPart(date)!=null);
- }
+ public boolean isInBusinessHours(Date date) {
+ return (findDayPart(date)!=null);
+ }
public boolean isHoliday(Date date) {
if (holidays!=null) {
@@ -192,25 +197,25 @@
return dayPart;
}
- protected 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];
- }
- }
- return nextDayPart;
+ protected 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];
+ }
+ }
+ return nextDayPart;
}
-
+
// getters and setters //////////////////////////////////////////////////////
-
+
public long getBusinessDayInMillis() {
return businessDayInMillis;
}
@@ -294,5 +299,5 @@
}
public void setYearInMillis(long yearInMillis) {
this.yearInMillis = yearInMillis;
- }
+ }
}
Added:
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/cal/BusinessCalendarTest.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/cal/BusinessCalendarTest.java
(rev 0)
+++
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/cal/BusinessCalendarTest.java 2010-08-15
02:44:16 UTC (rev 6591)
@@ -0,0 +1,17 @@
+
+package org.jbpm.pvm.internal.cal;
+
+import java.util.*;
+import junit.framework.*;
+import org.jbpm.pvm.internal.model.*;
+
+public class BusinessCalendarTest extends TestCase {
+ public void testSubstract() {
+ BusinessCalendarImpl businessCalendar = new BusinessCalendarImpl();
+
+ Date start = new Date();
+ Date end = businessCalendar.subtract(start, new Duration("1 year"));
+
+ assertEquals(end.getYear(), start.getYear());
+ }
+}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/TimerTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/TimerTest.java 2010-08-13
23:21:22 UTC (rev 6590)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/TimerTest.java 2010-08-15
02:44:16 UTC (rev 6591)
@@ -417,10 +417,7 @@
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, 2);
proc_vars.put("proc_var", cal);
- try {
- executionService.startProcessInstanceByKey("ICL", proc_vars,
"82436");
- fail("Should not happen, exception expected");
- } catch (Exception e) {}
+ executionService.startProcessInstanceByKey("ICL", proc_vars,
"82436");
}
public void testTimerTimeoutCustom() {
Show replies by date