|
Author: adrianc
Date: Tue Jan 26 08:28:39 2010 New Revision: 903125 URL: http://svn.apache.org/viewvc?rev=903125&view=rev Log: Hand merged the temporal expression bug fixes from the trunk. Modified: ofbiz/branches/release09.04/ (props changed) ofbiz/branches/release09.04/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalRecurConverter.java ofbiz/branches/release09.04/framework/common/config/TemporalExpressionUiLabels.xml ofbiz/branches/release09.04/framework/common/servicedef/services.xml ofbiz/branches/release09.04/framework/common/webcommon/includes/commonMacros.ftl ofbiz/branches/release09.04/framework/service/data/ServiceDemoData.xml ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpression.java ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionVisitor.java ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionWorker.java ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpressions.java ofbiz/branches/release09.04/framework/webtools/webapp/webtools/tempexpr/tempExprMacros.ftl ofbiz/branches/release09.04/framework/webtools/webapp/webtools/tempexpr/tempExprMaint.ftl Propchange: ofbiz/branches/release09.04/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Tue Jan 26 08:28:39 2010 @@ -1 +1 @@ -/ofbiz/trunk:765933,766011,766015,766293,766307,766316,766325,766462,766522,766800,767060,767072,767093,767098-767099,767102,767123,767125,767127,767279,767287,767671,767688,767694,767822,767845,768358,768490,768550,768675,768686,768705,768811,768815,768960,769030,769500,770272,770308,770997,771073,771477,772401,772464-772465,773076,773557,773628,773659,773697,774014,774632,774661,774995,775292,775667,776227,776594,776620,776922,777004,777020,777768,777792,777893,777947,778078,778094,778107,778273,778278,778280,778364,778374,778402,778576,778594,778628,779020,779477,779496,779639,779834,779856,779866,779873,780111,780138,780180,780199,780203,780906,780945,781201,781534,781549,781669,781680,781694,782663,783257,783266,783833,783913,783917,785123,785764,785967,786778,787126,787435-787436,787442,787520,788965,788983,788987,789329,789337,789506,789548,796769,799185,800461,800846,801023,802346,804364,805307,806127,806377,808786-808787,808792,809141,810370,810438,810465,810807,810 809,810814,810832,810836,810878,810917,811020,811280,811297,811419,811528,811708,811714,811716,811793,811838,811860,811865,811870,812159,812182,812192,812456,812540,813126,813131,813283,813672,813702,814168,814205,814251,814349,814531,814576,814681,814731,815158,815165,815350,815687,815977,816255,816863,818030,818049,818150,818494,818500,818716,818976,819275-819276,819282,819337,821263,821270,822659,823877-823878,823883,823888,823892,824511,825181-825182,826253,827730,828971,829085,829376,829412,829416,829527,830091,830112,830366,830528,830677,830874,830880,831238,831801,832361,832698,832776,832908,833324,833686,833703,834825,835161,835357,835585,836015,881194,881713,882072,882326,882918,883933,884023,884529,884546,884758,885122,885702,887916,888111,888559,888587,889666,890050,890107,890245,891378,891620,896649,899188,901628 +/ofbiz/trunk:765933,766011,766015,766293,766307,766316,766325,766462,766522,766800,767060,767072,767093,767098-767099,767102,767123,767125,767127,767279,767287,767671,767688,767694,767822,767845,768358,768490,768550,768675,768686,768705,768811,768815,768960,769030,769500,770272,770308,770997,771073,771477,772401,772464-772465,773076,773557,773628,773659,773697,774014,774632,774661,774995,775292,775667,776227,776594,776620,776922,777004,777020,777768,777792,777893,777947,778078,778094,778107,778273,778278,778280,778364,778374,778402,778576,778594,778628,779020,779477,779496,779639,779834,779856,779866,779873,780111,780138,780180,780199,780203,780906,780945,781201,781534,781549,781669,781680,781694,782663,783257,783266,783833,783913,783917,785123,785764,785967,786778,787126,787435-787436,787442,787520,788965,788983,788987,789329,789337,789506,789548,796769,799185,800461,800846,801023,802346,804364,805307,806127,806377,808786-808787,808792,809141,810370,810438,810465,810807,810 809,810814,810832,810836,810878,810917,811020,811280,811297,811419,811528,811708,811714,811716,811793,811838,811860,811865,811870,812159,812182,812192,812456,812540,813126,813131,813283,813672,813702,814168,814205,814251,814349,814531,814576,814681,814731,815158,815165,815350,815687,815977,816255,816863,818030,818049,818150,818494,818500,818716,818976,819275-819276,819282,819337,821263,821270,822659,823877-823878,823883,823888,823892,824511,825181-825182,826253,827730,828971,829085,829376,829412,829416,829527,830091,830112,830366,830528,830677,830874,830880,831238,831801,832361,832698,832776,832908,833324,833686,833703,834825,835161,835357,835585,836015,881194,881713,882072,882326,882918,883933,884023,884529,884546,884758,885122,885702,887916,888111,888559,888587,889666,890050,890107,890245,891378,891620,896649,899188,899833,900024,900026,900050,900217,900273,901628 Modified: ofbiz/branches/release09.04/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalRecurConverter.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalRecurConverter.java?rev=903125&r1=903124&r2=903125&view=diff ============================================================================== --- ofbiz/branches/release09.04/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalRecurConverter.java (original) +++ ofbiz/branches/release09.04/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalRecurConverter.java Tue Jan 26 08:28:39 2010 @@ -19,6 +19,7 @@ package org.ofbiz.workeffort.workeffort; +import java.util.Calendar; import java.util.List; import java.util.Set; import java.util.Stack; @@ -30,10 +31,11 @@ import net.fortuna.ical4j.model.property.*; import org.ofbiz.service.calendar.TemporalExpression; -import org.ofbiz.service.calendar.TemporalExpressions; import org.ofbiz.service.calendar.TemporalExpressionVisitor; +import org.ofbiz.service.calendar.TemporalExpressions; import org.ofbiz.service.calendar.TemporalExpressions.*; + /** Temporal Expression to iCalendar recurrence converter. The conversion results * (or conversion success) are unpredictable since the OFBiz Temporal Expressions * are more sophisticated than iCalendar recurrences. This class attempts to @@ -42,15 +44,6 @@ */ public class ICalRecurConverter implements TemporalExpressionVisitor { protected static final WeekDay dayOfWeekArray[] = {WeekDay.SU, WeekDay.MO, WeekDay.TU, WeekDay.WE, WeekDay.TH, WeekDay.FR, WeekDay.SA}; - protected DtStart dateStart = null; - protected List<DateListProperty> incDateList = FastList.newInstance(); - protected List<DateListProperty> exDateList = FastList.newInstance(); - protected List<RRule> incRuleList = FastList.newInstance(); - protected List<ExRule> exRuleList = FastList.newInstance(); - protected VisitorState state = new VisitorState(); - protected Stack<VisitorState> stateStack = new Stack<VisitorState>(); - - protected ICalRecurConverter() {} @SuppressWarnings("unchecked") public static void convert(TemporalExpression expr, PropertyList eventProps) { @@ -76,16 +69,85 @@ eventProps.addAll(converter.exRuleList); } - // ----- TemporalExpressionVisitor Implementation ----- // + protected DtStart dateStart = null; + protected List<DateListProperty> incDateList = FastList.newInstance(); + protected List<DateListProperty> exDateList = FastList.newInstance(); + protected List<RRule> incRuleList = FastList.newInstance(); + protected List<ExRule> exRuleList = FastList.newInstance(); + protected VisitorState state = new VisitorState(); + protected Stack<VisitorState> stateStack = new Stack<VisitorState>(); - public void visit(Null expr) {} + protected ICalRecurConverter() {} - public void visit(Union expr) { - for (TemporalExpression childExpr : expr.getExpressionSet()) { - childExpr.accept(this); + @SuppressWarnings("unchecked") + protected Recur consolidateRecurs(List<Recur> recurList) { + // Try to consolidate a list of Recur instances into one instance + Set<Integer> monthList = FastSet.newInstance(); + Set<Integer> monthDayList = FastSet.newInstance(); + Set<WeekDay> weekDayList = FastSet.newInstance(); + Set<Integer> hourList = FastSet.newInstance(); + String freq = null; + int freqCount = 0; + for (Recur recur : recurList) { + monthList.addAll(recur.getMonthList()); + monthDayList.addAll(recur.getMonthDayList()); + weekDayList.addAll(recur.getDayList()); + hourList.addAll(recur.getHourList()); + if (recur.getInterval() != 0 && freq == null) { + freq = recur.getFrequency(); + freqCount = recur.getInterval(); + } + } + if (freq == null && monthList.size() > 0) { + freq = Recur.MONTHLY; + } else if (freq == null && (monthDayList.size() > 0 || weekDayList.size() > 0)) { + freq = Recur.DAILY; + } else if (freq == null && hourList.size() > 0) { + freq = Recur.HOURLY; + } + if (freq == null) { + throw new IllegalStateException("Unable to convert intersection"); + } + Recur newRecur = new Recur(freq, 0); + if (freqCount != 0) { + newRecur.setInterval(freqCount); + } + newRecur.getMonthList().addAll(monthList); + newRecur.getMonthDayList().addAll(monthDayList); + newRecur.getDayList().addAll(weekDayList); + newRecur.getHourList().addAll(hourList); + return newRecur; + } + + // ----- TemporalExpressionVisitor Implementation ----- // + + @Override + public void visit(Difference expr) { + VisitorState newState = new VisitorState(); + newState.isIntersection = this.state.isIntersection; + this.stateStack.push(this.state); + this.state = newState; + expr.getIncluded().accept(this); + newState.isExcluded = true; + expr.getExcluded().accept(this); + this.state = this.stateStack.pop(); + if (this.state.isIntersection) { + this.state.inclRecurList.addAll(newState.inclRecurList); + this.state.exRecurList.addAll(newState.exRecurList); } } + @SuppressWarnings("unchecked") + @Override + public void visit(HourRange expr) { + NumberList hourList = new NumberList(); + hourList.addAll(expr.getHourRangeAsSet()); + Recur recur = new Recur(Recur.HOURLY, 0); + recur.getHourList().addAll(hourList); + this.state.addRecur(recur); + } + + @Override public void visit(Intersection expr) { this.stateStack.push(this.state); VisitorState newState = new VisitorState(); @@ -104,21 +166,20 @@ } } - public void visit(Difference expr) { - VisitorState newState = new VisitorState(); - newState.isIntersection = this.state.isIntersection; - this.stateStack.push(this.state); - this.state = newState; - expr.getIncluded().accept(this); - newState.isExcluded = true; - expr.getExcluded().accept(this); - this.state = this.stateStack.pop(); - if (this.state.isIntersection) { - this.state.inclRecurList.addAll(newState.inclRecurList); - this.state.exRecurList.addAll(newState.exRecurList); - } + @SuppressWarnings("unchecked") + @Override + public void visit(MinuteRange expr) { + NumberList minuteList = new NumberList(); + minuteList.addAll(expr.getMinuteRangeAsSet()); + Recur recur = new Recur(Recur.MINUTELY, 0); + recur.getMinuteList().addAll(minuteList); + this.state.addRecur(recur); } + @Override + public void visit(Null expr) {} + + @Override public void visit(TemporalExpressions.DateRange expr) { if (this.state.isExcluded) { throw new IllegalStateException("iCalendar does not support excluded date ranges"); @@ -129,84 +190,49 @@ this.incDateList.add(new RDate(periodList)); } - @SuppressWarnings("unchecked") - public void visit(TimeOfDayRange expr) { - // TODO: this needs a better conversion - int startHr = expr.getStartHours(); - int endHr = expr.getEndHours(); - NumberList hourList = new NumberList(); - hourList.add(startHr); - while (startHr != endHr) { - startHr++; - if (startHr == 24) { - startHr = 0; - } - hourList.add(startHr); - } - Recur recur = new Recur(Recur.HOURLY, 0); - recur.getHourList().addAll(hourList); + @Override + public void visit(TemporalExpressions.DayInMonth expr) { + Recur recur = new Recur(Recur.MONTHLY, 0); + recur.getDayList().add(new WeekDay(dayOfWeekArray[expr.getDayOfWeek() - 1], expr.getOccurrence())); this.state.addRecur(recur); } @SuppressWarnings("unchecked") - public void visit(TemporalExpressions.DayOfWeekRange expr) { + @Override + public void visit(TemporalExpressions.DayOfMonthRange expr) { int startDay = expr.getStartDay(); int endDay = expr.getEndDay(); - WeekDayList dayList = new WeekDayList(); - dayList.add(dayOfWeekArray[startDay - 1]); + NumberList dayList = new NumberList(); + dayList.add(startDay); while (startDay != endDay) { startDay++; - if (startDay > java.util.Calendar.SATURDAY) { - startDay = java.util.Calendar.SUNDAY; - } - dayList.add(dayOfWeekArray[startDay - 1]); + dayList.add(startDay); } Recur recur = new Recur(Recur.DAILY, 0); - recur.getDayList().addAll(dayList); - this.state.addRecur(recur); - } - - @SuppressWarnings("unchecked") - public void visit(TemporalExpressions.MonthRange expr) { - int startMonth = expr.getStartMonth(); - int endMonth = expr.getEndMonth(); - java.util.Calendar cal = java.util.Calendar.getInstance(); - int maxMonth = cal.getActualMaximum(java.util.Calendar.MONTH); - NumberList monthList = new NumberList(); - monthList.add(startMonth + 1); - while (startMonth != endMonth) { - startMonth++; - if (startMonth > maxMonth) { - startMonth = java.util.Calendar.JANUARY; - } - monthList.add(startMonth + 1); - } - Recur recur = new Recur(Recur.MONTHLY, 0); - recur.getMonthList().addAll(monthList); + recur.getMonthDayList().addAll(dayList); this.state.addRecur(recur); } @SuppressWarnings("unchecked") - public void visit(TemporalExpressions.DayOfMonthRange expr) { + @Override + public void visit(TemporalExpressions.DayOfWeekRange expr) { int startDay = expr.getStartDay(); int endDay = expr.getEndDay(); - NumberList dayList = new NumberList(); - dayList.add(startDay); + WeekDayList dayList = new WeekDayList(); + dayList.add(dayOfWeekArray[startDay - 1]); while (startDay != endDay) { startDay++; - dayList.add(startDay); + if (startDay > Calendar.SATURDAY) { + startDay = Calendar.SUNDAY; + } + dayList.add(dayOfWeekArray[startDay - 1]); } Recur recur = new Recur(Recur.DAILY, 0); - recur.getMonthDayList().addAll(dayList); - this.state.addRecur(recur); - } - - public void visit(TemporalExpressions.DayInMonth expr) { - Recur recur = new Recur(Recur.MONTHLY, 0); - recur.getDayList().add(new WeekDay(dayOfWeekArray[expr.getDayOfWeek() - 1], expr.getOccurrence())); + recur.getDayList().addAll(dayList); this.state.addRecur(recur); } + @Override public void visit(TemporalExpressions.Frequency expr) { if (this.dateStart == null) { this.dateStart = new DtStart(new net.fortuna.ical4j.model.Date(expr.getStartDate())); @@ -214,59 +240,66 @@ int freqCount = expr.getFreqCount(); int freqType = expr.getFreqType(); switch (freqType) { - case java.util.Calendar.SECOND: + case Calendar.SECOND: this.state.addRecur((new Recur(Recur.SECONDLY, freqCount))); - case java.util.Calendar.MINUTE: + case Calendar.MINUTE: this.state.addRecur((new Recur(Recur.MINUTELY, freqCount))); - case java.util.Calendar.HOUR: + case Calendar.HOUR: this.state.addRecur((new Recur(Recur.HOURLY, freqCount))); - case java.util.Calendar.DAY_OF_MONTH: + case Calendar.DAY_OF_MONTH: this.state.addRecur((new Recur(Recur.DAILY, freqCount))); - case java.util.Calendar.MONTH: + case Calendar.MONTH: this.state.addRecur((new Recur(Recur.MONTHLY, freqCount))); - case java.util.Calendar.YEAR: + case Calendar.YEAR: this.state.addRecur((new Recur(Recur.YEARLY, freqCount))); } } @SuppressWarnings("unchecked") - protected Recur consolidateRecurs(List<Recur> recurList) { - // Try to consolidate a list of Recur instances into one instance - Set<Integer> monthList = FastSet.newInstance(); - Set<Integer> monthDayList = FastSet.newInstance(); - Set<WeekDay> weekDayList = FastSet.newInstance(); - Set<Integer> hourList = FastSet.newInstance(); - String freq = null; - int freqCount = 0; - for (Recur recur : recurList) { - monthList.addAll(recur.getMonthList()); - monthDayList.addAll(recur.getMonthDayList()); - weekDayList.addAll(recur.getDayList()); - hourList.addAll(recur.getHourList()); - if (recur.getInterval() != 0 && freq == null) { - freq = recur.getFrequency(); - freqCount = recur.getInterval(); + @Override + public void visit(TemporalExpressions.MonthRange expr) { + int startMonth = expr.getStartMonth(); + int endMonth = expr.getEndMonth(); + Calendar cal = Calendar.getInstance(); + int maxMonth = cal.getActualMaximum(Calendar.MONTH); + NumberList monthList = new NumberList(); + monthList.add(startMonth + 1); + while (startMonth != endMonth) { + startMonth++; + if (startMonth > maxMonth) { + startMonth = Calendar.JANUARY; } + monthList.add(startMonth + 1); } - if (freq == null && monthList.size() > 0) { - freq = Recur.MONTHLY; - } else if (freq == null && (monthDayList.size() > 0 || weekDayList.size() > 0)) { - freq = Recur.DAILY; - } else if (freq == null && hourList.size() > 0) { - freq = Recur.HOURLY; - } - if (freq == null) { - throw new IllegalStateException("Unable to convert intersection"); + Recur recur = new Recur(Recur.MONTHLY, 0); + recur.getMonthList().addAll(monthList); + this.state.addRecur(recur); + } + + @SuppressWarnings({ "unchecked", "deprecation" }) + @Override + public void visit(TimeOfDayRange expr) { + int startHr = expr.getStartHours(); + int endHr = expr.getEndHours(); + NumberList hourList = new NumberList(); + hourList.add(startHr); + while (startHr != endHr) { + startHr++; + if (startHr == 24) { + startHr = 0; + } + hourList.add(startHr); } - Recur newRecur = new Recur(freq, 0); - if (freqCount != 0) { - newRecur.setInterval(freqCount); + Recur recur = new Recur(Recur.HOURLY, 0); + recur.getHourList().addAll(hourList); + this.state.addRecur(recur); + } + + @Override + public void visit(Union expr) { + for (TemporalExpression childExpr : expr.getExpressionSet()) { + childExpr.accept(this); } - newRecur.getMonthList().addAll(monthList); - newRecur.getMonthDayList().addAll(monthDayList); - newRecur.getDayList().addAll(weekDayList); - newRecur.getHourList().addAll(hourList); - return newRecur; } protected class VisitorState { Modified: ofbiz/branches/release09.04/framework/common/config/TemporalExpressionUiLabels.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/framework/common/config/TemporalExpressionUiLabels.xml?rev=903125&r1=903124&r2=903125&view=diff ============================================================================== --- ofbiz/branches/release09.04/framework/common/config/TemporalExpressionUiLabels.xml (original) +++ ofbiz/branches/release09.04/framework/common/config/TemporalExpressionUiLabels.xml Tue Jan 26 08:28:39 2010 @@ -109,18 +109,24 @@ <value xml:lang="fr">Fréquence</value> <value xml:lang="it">Frequenza</value> </property> + <property key="TemporalExpression_HOUR_RANGE"> + <value xml:lang="en">Hour Range</value> + </property> <property key="TemporalExpression_INTERSECTION"> <value xml:lang="en">Intersection</value> <value xml:lang="fr">Intersection</value> <value xml:lang="it">Intersezione</value> </property> + <property key="TemporalExpression_MINUTE_RANGE"> + <value xml:lang="en">Minute Range</value> + </property> <property key="TemporalExpression_MONTH_RANGE"> <value xml:lang="en">Month Range</value> <value xml:lang="fr">Intervalle entre 2 mois</value> <value xml:lang="it">Intervallo di mese</value> </property> <property key="TemporalExpression_TIME_OF_DAY_RANGE"> - <value xml:lang="en">Time Of Day Range</value> + <value xml:lang="en">Time Of Day Range (deprecated)</value> <value xml:lang="fr">Intervalle entre 2 heures d'un jour</value> <value xml:lang="it">Ora nel giorno dell'intervallo</value> </property> Modified: ofbiz/branches/release09.04/framework/common/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/framework/common/servicedef/services.xml?rev=903125&r1=903124&r2=903125&view=diff ============================================================================== --- ofbiz/branches/release09.04/framework/common/servicedef/services.xml (original) +++ ofbiz/branches/release09.04/framework/common/servicedef/services.xml Tue Jan 26 08:28:39 2010 @@ -527,7 +527,7 @@ <service name="createTemporalExpression" default-entity-name="TemporalExpression" engine="entity-auto" invoke="create" auth="true"> <description>Create a Temporal Expression</description> <permission-service service-name="tempExprPermissionCheck" main-action="CREATE"/> - <auto-attributes include="pk" mode="OUT" optional="false"/> + <auto-attributes include="pk" mode="INOUT" optional="true"/> <auto-attributes include="nonpk" mode="IN" optional="true"/> </service> <service name="updateTemporalExpression" default-entity-name="TemporalExpression" engine="entity-auto" invoke="update" auth="true"> Modified: ofbiz/branches/release09.04/framework/common/webcommon/includes/commonMacros.ftl URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/framework/common/webcommon/includes/commonMacros.ftl?rev=903125&r1=903124&r2=903125&view=diff ============================================================================== --- ofbiz/branches/release09.04/framework/common/webcommon/includes/commonMacros.ftl (original) +++ ofbiz/branches/release09.04/framework/common/webcommon/includes/commonMacros.ftl Tue Jan 26 08:28:39 2010 @@ -53,6 +53,28 @@ </#if> </#macro> +<#macro HourOfDayField fieldName="" fieldValue=-1 fieldClass=""> + <select name="${fieldName}"<#if fieldClass?has_content> class="${fieldClass}"</#if>> + <#list 0..23 as i> + <option value="${i}"<#if i == fieldValue> selected="selected"</#if>>${i}</option> + </#list> + </select> + <#if fieldClass == "required"> + <span class="tooltip">${uiLabelMap.CommonRequired}</span> + </#if> +</#macro> + +<#macro MinuteField fieldName="" fieldValue=-1 fieldClass=""> + <select name="${fieldName}"<#if fieldClass?has_content> class="${fieldClass}"</#if>> + <#list 0..59 as i> + <option value="${i}"<#if i == fieldValue> selected="selected"</#if>>${i}</option> + </#list> + </select> + <#if fieldClass == "required"> + <span class="tooltip">${uiLabelMap.CommonRequired}</span> + </#if> +</#macro> + <#macro DayOfWeekField fieldName="" fieldValue=-1 fieldClass=""> <select name="${fieldName}"<#if fieldClass?has_content> class="${fieldClass}"</#if>> <#list dayValueList as dayValue> Modified: ofbiz/branches/release09.04/framework/service/data/ServiceDemoData.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/framework/service/data/ServiceDemoData.xml?rev=903125&r1=903124&r2=903125&view=diff ============================================================================== --- ofbiz/branches/release09.04/framework/service/data/ServiceDemoData.xml (original) +++ ofbiz/branches/release09.04/framework/service/data/ServiceDemoData.xml Tue Jan 26 08:28:39 2010 @@ -21,6 +21,94 @@ <entity-engine-xml> <!-- Temporal Expression demo data --> + <!-- Pre-define all 60 minutes --> + <TemporalExpression tempExprId="MINUTE_00" tempExprTypeId="MINUTE_RANGE" integer1="0" integer2="0"/> + <TemporalExpression tempExprId="MINUTE_01" tempExprTypeId="MINUTE_RANGE" integer1="1" integer2="1"/> + <TemporalExpression tempExprId="MINUTE_02" tempExprTypeId="MINUTE_RANGE" integer1="2" integer2="2"/> + <TemporalExpression tempExprId="MINUTE_03" tempExprTypeId="MINUTE_RANGE" integer1="3" integer2="3"/> + <TemporalExpression tempExprId="MINUTE_04" tempExprTypeId="MINUTE_RANGE" integer1="4" integer2="4"/> + <TemporalExpression tempExprId="MINUTE_05" tempExprTypeId="MINUTE_RANGE" integer1="5" integer2="5"/> + <TemporalExpression tempExprId="MINUTE_06" tempExprTypeId="MINUTE_RANGE" integer1="6" integer2="6"/> + <TemporalExpression tempExprId="MINUTE_07" tempExprTypeId="MINUTE_RANGE" integer1="7" integer2="7"/> + <TemporalExpression tempExprId="MINUTE_08" tempExprTypeId="MINUTE_RANGE" integer1="8" integer2="8"/> + <TemporalExpression tempExprId="MINUTE_09" tempExprTypeId="MINUTE_RANGE" integer1="9" integer2="9"/> + <TemporalExpression tempExprId="MINUTE_10" tempExprTypeId="MINUTE_RANGE" integer1="10" integer2="10"/> + <TemporalExpression tempExprId="MINUTE_11" tempExprTypeId="MINUTE_RANGE" integer1="11" integer2="11"/> + <TemporalExpression tempExprId="MINUTE_12" tempExprTypeId="MINUTE_RANGE" integer1="12" integer2="12"/> + <TemporalExpression tempExprId="MINUTE_13" tempExprTypeId="MINUTE_RANGE" integer1="13" integer2="13"/> + <TemporalExpression tempExprId="MINUTE_14" tempExprTypeId="MINUTE_RANGE" integer1="14" integer2="14"/> + <TemporalExpression tempExprId="MINUTE_15" tempExprTypeId="MINUTE_RANGE" integer1="15" integer2="15"/> + <TemporalExpression tempExprId="MINUTE_16" tempExprTypeId="MINUTE_RANGE" integer1="16" integer2="16"/> + <TemporalExpression tempExprId="MINUTE_17" tempExprTypeId="MINUTE_RANGE" integer1="17" integer2="17"/> + <TemporalExpression tempExprId="MINUTE_18" tempExprTypeId="MINUTE_RANGE" integer1="18" integer2="18"/> + <TemporalExpression tempExprId="MINUTE_19" tempExprTypeId="MINUTE_RANGE" integer1="19" integer2="19"/> + <TemporalExpression tempExprId="MINUTE_20" tempExprTypeId="MINUTE_RANGE" integer1="20" integer2="20"/> + <TemporalExpression tempExprId="MINUTE_21" tempExprTypeId="MINUTE_RANGE" integer1="21" integer2="21"/> + <TemporalExpression tempExprId="MINUTE_22" tempExprTypeId="MINUTE_RANGE" integer1="22" integer2="22"/> + <TemporalExpression tempExprId="MINUTE_23" tempExprTypeId="MINUTE_RANGE" integer1="23" integer2="23"/> + <TemporalExpression tempExprId="MINUTE_24" tempExprTypeId="MINUTE_RANGE" integer1="24" integer2="24"/> + <TemporalExpression tempExprId="MINUTE_25" tempExprTypeId="MINUTE_RANGE" integer1="25" integer2="25"/> + <TemporalExpression tempExprId="MINUTE_26" tempExprTypeId="MINUTE_RANGE" integer1="26" integer2="26"/> + <TemporalExpression tempExprId="MINUTE_27" tempExprTypeId="MINUTE_RANGE" integer1="27" integer2="27"/> + <TemporalExpression tempExprId="MINUTE_28" tempExprTypeId="MINUTE_RANGE" integer1="28" integer2="28"/> + <TemporalExpression tempExprId="MINUTE_29" tempExprTypeId="MINUTE_RANGE" integer1="29" integer2="29"/> + <TemporalExpression tempExprId="MINUTE_30" tempExprTypeId="MINUTE_RANGE" integer1="30" integer2="30"/> + <TemporalExpression tempExprId="MINUTE_31" tempExprTypeId="MINUTE_RANGE" integer1="31" integer2="31"/> + <TemporalExpression tempExprId="MINUTE_32" tempExprTypeId="MINUTE_RANGE" integer1="32" integer2="32"/> + <TemporalExpression tempExprId="MINUTE_33" tempExprTypeId="MINUTE_RANGE" integer1="33" integer2="33"/> + <TemporalExpression tempExprId="MINUTE_34" tempExprTypeId="MINUTE_RANGE" integer1="34" integer2="34"/> + <TemporalExpression tempExprId="MINUTE_35" tempExprTypeId="MINUTE_RANGE" integer1="35" integer2="35"/> + <TemporalExpression tempExprId="MINUTE_36" tempExprTypeId="MINUTE_RANGE" integer1="36" integer2="36"/> + <TemporalExpression tempExprId="MINUTE_37" tempExprTypeId="MINUTE_RANGE" integer1="37" integer2="37"/> + <TemporalExpression tempExprId="MINUTE_38" tempExprTypeId="MINUTE_RANGE" integer1="38" integer2="38"/> + <TemporalExpression tempExprId="MINUTE_39" tempExprTypeId="MINUTE_RANGE" integer1="39" integer2="39"/> + <TemporalExpression tempExprId="MINUTE_40" tempExprTypeId="MINUTE_RANGE" integer1="40" integer2="40"/> + <TemporalExpression tempExprId="MINUTE_41" tempExprTypeId="MINUTE_RANGE" integer1="41" integer2="41"/> + <TemporalExpression tempExprId="MINUTE_42" tempExprTypeId="MINUTE_RANGE" integer1="42" integer2="42"/> + <TemporalExpression tempExprId="MINUTE_43" tempExprTypeId="MINUTE_RANGE" integer1="43" integer2="43"/> + <TemporalExpression tempExprId="MINUTE_44" tempExprTypeId="MINUTE_RANGE" integer1="44" integer2="44"/> + <TemporalExpression tempExprId="MINUTE_45" tempExprTypeId="MINUTE_RANGE" integer1="45" integer2="45"/> + <TemporalExpression tempExprId="MINUTE_46" tempExprTypeId="MINUTE_RANGE" integer1="46" integer2="46"/> + <TemporalExpression tempExprId="MINUTE_47" tempExprTypeId="MINUTE_RANGE" integer1="47" integer2="47"/> + <TemporalExpression tempExprId="MINUTE_48" tempExprTypeId="MINUTE_RANGE" integer1="48" integer2="48"/> + <TemporalExpression tempExprId="MINUTE_49" tempExprTypeId="MINUTE_RANGE" integer1="49" integer2="49"/> + <TemporalExpression tempExprId="MINUTE_50" tempExprTypeId="MINUTE_RANGE" integer1="50" integer2="50"/> + <TemporalExpression tempExprId="MINUTE_51" tempExprTypeId="MINUTE_RANGE" integer1="51" integer2="51"/> + <TemporalExpression tempExprId="MINUTE_52" tempExprTypeId="MINUTE_RANGE" integer1="52" integer2="52"/> + <TemporalExpression tempExprId="MINUTE_53" tempExprTypeId="MINUTE_RANGE" integer1="53" integer2="53"/> + <TemporalExpression tempExprId="MINUTE_54" tempExprTypeId="MINUTE_RANGE" integer1="54" integer2="54"/> + <TemporalExpression tempExprId="MINUTE_55" tempExprTypeId="MINUTE_RANGE" integer1="55" integer2="55"/> + <TemporalExpression tempExprId="MINUTE_56" tempExprTypeId="MINUTE_RANGE" integer1="56" integer2="56"/> + <TemporalExpression tempExprId="MINUTE_57" tempExprTypeId="MINUTE_RANGE" integer1="57" integer2="57"/> + <TemporalExpression tempExprId="MINUTE_58" tempExprTypeId="MINUTE_RANGE" integer1="58" integer2="58"/> + <TemporalExpression tempExprId="MINUTE_59" tempExprTypeId="MINUTE_RANGE" integer1="59" integer2="59"/> + + <!-- Pre-define all 24 hours of the day --> + <TemporalExpression tempExprId="HOUR_00" tempExprTypeId="HOUR_RANGE" integer1="0" integer2="0"/> + <TemporalExpression tempExprId="HOUR_01" tempExprTypeId="HOUR_RANGE" integer1="1" integer2="1"/> + <TemporalExpression tempExprId="HOUR_02" tempExprTypeId="HOUR_RANGE" integer1="2" integer2="2"/> + <TemporalExpression tempExprId="HOUR_03" tempExprTypeId="HOUR_RANGE" integer1="3" integer2="3"/> + <TemporalExpression tempExprId="HOUR_04" tempExprTypeId="HOUR_RANGE" integer1="4" integer2="4"/> + <TemporalExpression tempExprId="HOUR_05" tempExprTypeId="HOUR_RANGE" integer1="5" integer2="5"/> + <TemporalExpression tempExprId="HOUR_06" tempExprTypeId="HOUR_RANGE" integer1="6" integer2="6"/> + <TemporalExpression tempExprId="HOUR_07" tempExprTypeId="HOUR_RANGE" integer1="7" integer2="7"/> + <TemporalExpression tempExprId="HOUR_08" tempExprTypeId="HOUR_RANGE" integer1="8" integer2="8"/> + <TemporalExpression tempExprId="HOUR_09" tempExprTypeId="HOUR_RANGE" integer1="9" integer2="9"/> + <TemporalExpression tempExprId="HOUR_10" tempExprTypeId="HOUR_RANGE" integer1="10" integer2="10"/> + <TemporalExpression tempExprId="HOUR_11" tempExprTypeId="HOUR_RANGE" integer1="11" integer2="11"/> + <TemporalExpression tempExprId="HOUR_12" tempExprTypeId="HOUR_RANGE" integer1="12" integer2="12"/> + <TemporalExpression tempExprId="HOUR_13" tempExprTypeId="HOUR_RANGE" integer1="13" integer2="13"/> + <TemporalExpression tempExprId="HOUR_14" tempExprTypeId="HOUR_RANGE" integer1="14" integer2="14"/> + <TemporalExpression tempExprId="HOUR_15" tempExprTypeId="HOUR_RANGE" integer1="15" integer2="15"/> + <TemporalExpression tempExprId="HOUR_16" tempExprTypeId="HOUR_RANGE" integer1="16" integer2="16"/> + <TemporalExpression tempExprId="HOUR_17" tempExprTypeId="HOUR_RANGE" integer1="17" integer2="17"/> + <TemporalExpression tempExprId="HOUR_18" tempExprTypeId="HOUR_RANGE" integer1="18" integer2="18"/> + <TemporalExpression tempExprId="HOUR_19" tempExprTypeId="HOUR_RANGE" integer1="19" integer2="19"/> + <TemporalExpression tempExprId="HOUR_20" tempExprTypeId="HOUR_RANGE" integer1="20" integer2="20"/> + <TemporalExpression tempExprId="HOUR_21" tempExprTypeId="HOUR_RANGE" integer1="21" integer2="21"/> + <TemporalExpression tempExprId="HOUR_22" tempExprTypeId="HOUR_RANGE" integer1="22" integer2="22"/> + <TemporalExpression tempExprId="HOUR_23" tempExprTypeId="HOUR_RANGE" integer1="23" integer2="23"/> + <!-- Pre-define all days of the week (Sunday -> Saturday) --> <TemporalExpression tempExprId="DAYOFWEEK_01" tempExprTypeId="DAY_OF_WEEK_RANGE" integer1="1" integer2="1"/> <TemporalExpression tempExprId="DAYOFWEEK_02" tempExprTypeId="DAY_OF_WEEK_RANGE" integer1="2" integer2="2"/> @@ -155,8 +243,7 @@ <!-- An 8am Mon-Fri expression that excludes US federal holidays --> <TemporalExpression tempExprId="DAILY_GRIND" tempExprTypeId="INTERSECTION"/> - <TemporalExpression tempExprId="8AM" tempExprTypeId="TIME_OF_DAY_RANGE" string1="08:00" string2="08:00"/> - <TemporalExpressionAssoc fromTempExprId="DAILY_GRIND" toTempExprId="8AM"/> + <TemporalExpressionAssoc fromTempExprId="DAILY_GRIND" toTempExprId="HOUR_08"/> <TemporalExpressionAssoc fromTempExprId="DAILY_GRIND" toTempExprId="GOVT_WORK_SCHED"/> <!-- An every-other-Monday at 5pm expression --> @@ -168,15 +255,17 @@ values are typically obtained from the java.util.Calendar field constants. For more information, see the org.ofbiz.service.calendar.TemporalExpressions.java file. - tempExprTypeId integer1 integer2 date1 date2 string1 string2 - ==================== ============== =============== ====== ====== ========== ======== - DATE_RANGE start end - TIME_OF_DAY_RANGE interval [9] count [7] start [1] end [1] - DAY_OF_WEEK_RANGE start [2] end [2] - MONTH_RANGE start [3] end [3] - DAY_OF_MONTH_RANGE start [4] end [4] - DAY_IN_MONTH day [2] occurrence [5] - FREQUENCY freq type [6] freq count [7] start[8] + tempExprTypeId integer1 integer2 date1 date2 string1 string2 + ==================== ============== =============== ====== ====== ========== ======== + HOUR_RANGE start[11] end[11] + DATE_RANGE start end + TIME_OF_DAY_RANGE[10] interval [9] count [7] start [1] end [1] + DAY_OF_WEEK_RANGE start [2] end [2] + MINUTE_RANGE start [12] end [12] + MONTH_RANGE start [3] end [3] + DAY_OF_MONTH_RANGE start [4] end [4] + DAY_IN_MONTH day [2] occurrence [5] + FREQUENCY freq type [6] freq count [7] start[8] [1] hh:mm:ss [2] Day of week: 1 = Sunday, 7 = Saturday @@ -187,6 +276,9 @@ [7] Positive integer, zero excluded [8] If null, defaults to system date when the expression was retrieved from storage. [9] Second = 13, Minute = 12, Hour = 11 (default) + [10] Deprecated - do not use + [11] Integer: 0 to 23, midnight = 0 + [12] Integer: 0 to 59 --> </entity-engine-xml> Modified: ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java?rev=903125&r1=903124&r2=903125&view=diff ============================================================================== --- ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java (original) +++ ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java Tue Jan 26 08:28:39 2010 @@ -350,6 +350,7 @@ public RecurrenceWrapper(RecurrenceInfo info) { this.info = info; } + @Override public Calendar first(Calendar cal) { long result = this.info.first(); if (result == 0) { @@ -359,10 +360,12 @@ first.setTimeInMillis(result); return first; } + @Override public boolean includesDate(Calendar cal) { return this.info.isValidCurrent(cal.getTimeInMillis()); } - public Calendar next(Calendar cal) { + @Override + public Calendar next(Calendar cal, ExpressionContext context) { long result = this.info.next(cal.getTimeInMillis()); if (result == 0) { return null; @@ -371,6 +374,7 @@ next.setTimeInMillis(result); return next; } + @Override public void accept(TemporalExpressionVisitor visitor) {} } } Modified: ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpression.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpression.java?rev=903125&r1=903124&r2=903125&view=diff ============================================================================== --- ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpression.java (original) +++ ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpression.java Tue Jan 26 08:28:39 2010 @@ -25,29 +25,34 @@ import java.util.TreeSet; /** Temporal expression abstract class. */ +@SuppressWarnings("serial") public abstract class TemporalExpression implements Serializable, Comparable<TemporalExpression> { - protected TemporalExpression() {} - /** Field used to sort expressions. Expression evaluation depends * on correct ordering. Expressions are evaluated from lowest value * to highest value. */ protected int sequence = Integer.MAX_VALUE; - /** Field used to sort expressions. Expression evaluation depends - * on correct ordering. Expressions are evaluated from lowest value - * to highest value. */ - protected int subSequence = Integer.MAX_VALUE; - /** A unique ID for this expression. This field is intended to be used by * persistence classes. */ protected String id = null; - /** Returns true if this expression includes the specified date. - * @param cal A date to evaluate - * @return true if this expression includes the date represented by - * <code>cal</code> + protected TemporalExpression() {} + + /** Handles a <code>TemporalExpressionVisitor</code> visit. + * @param visitor */ - public abstract boolean includesDate(Calendar cal); + public abstract void accept(TemporalExpressionVisitor visitor); + + public int compareTo(TemporalExpression obj) { + if (this.equals(obj) || obj.sequence == this.sequence) { + return 0; + } + return obj.sequence < this.sequence ? 1 : -1; + } + + protected boolean containsExpression(TemporalExpression expression) { + return false; + } /** Returns a date representing the first occurrence of this expression * on or after a specified date. Returns <code>null</code> if there @@ -58,30 +63,11 @@ */ public abstract Calendar first(Calendar cal); - /** Returns a date representing the next occurrence of this expression - * after a specified date. Returns <code>null</code> if there - * is no matching date. - * @param cal A date to evaluate - * @return A Calendar instance representing the first matching date, - * or <code>null</code> if no matching date is found - */ - public abstract Calendar next(Calendar cal); - - /** Handles a <code>TemporalExpressionVisitor</code> visit. - * @param visitor + /** Returns this expression's ID. + * @return Expression ID String */ - public abstract void accept(TemporalExpressionVisitor visitor); - - public int compareTo(TemporalExpression obj) { - if (this.equals(obj)) { - return 0; - } - if (obj.sequence < this.sequence) { - return 1; - } else if (obj.sequence > this.sequence) { - return -1; - } - return obj.subSequence < this.subSequence ? 1 : -1; + public String getId() { + return this.id; } /** Returns a range of dates matching this expression. Returns an @@ -105,13 +91,26 @@ return set; } - /** Returns this expression's ID. - * @return Expression ID String + /** Returns true if this expression includes the specified date. + * @param cal A date to evaluate + * @return true if this expression includes the date represented by + * <code>cal</code> */ - public String getId() { - return this.id; + public abstract boolean includesDate(Calendar cal); + + /** Returns a date representing the next occurrence of this expression + * after a specified date. Returns <code>null</code> if there + * is no matching date. + * @param cal A date to evaluate + * @return A Calendar instance representing the first matching date, + * or <code>null</code> if no matching date is found + */ + public Calendar next(Calendar cal) { + return next(cal, new ExpressionContext()); } + protected abstract Calendar next(Calendar cal, ExpressionContext context); + /** Sets this expression's ID. * @param id Expression ID String */ @@ -119,15 +118,14 @@ this.id = id; } - protected boolean containsExpression(TemporalExpression expression) { - return false; + @Override + public String toString() { + return this.getClass().getSimpleName() + " [" + this.id + "]"; } - protected Calendar setStartOfDay(Calendar cal) { - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - cal.set(Calendar.MILLISECOND, 0); - return cal; + protected class ExpressionContext { + public boolean hourBumped = false; + public boolean dayBumped = false; + public boolean monthBumped = false; } } Modified: ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionVisitor.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionVisitor.java?rev=903125&r1=903124&r2=903125&view=diff ============================================================================== --- ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionVisitor.java (original) +++ ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionVisitor.java Tue Jan 26 08:28:39 2010 @@ -20,15 +20,18 @@ /** Temporal expression visitor interface. */ public interface TemporalExpressionVisitor { - void visit(TemporalExpressions.Null expr); - void visit(TemporalExpressions.Union expr); - void visit(TemporalExpressions.Intersection expr); - void visit(TemporalExpressions.Difference expr); void visit(TemporalExpressions.DateRange expr); - void visit(TemporalExpressions.TimeOfDayRange expr); - void visit(TemporalExpressions.DayOfWeekRange expr); - void visit(TemporalExpressions.MonthRange expr); - void visit(TemporalExpressions.DayOfMonthRange expr); void visit(TemporalExpressions.DayInMonth expr); + void visit(TemporalExpressions.DayOfMonthRange expr); + void visit(TemporalExpressions.DayOfWeekRange expr); + void visit(TemporalExpressions.Difference expr); void visit(TemporalExpressions.Frequency expr); + void visit(TemporalExpressions.HourRange expr); + void visit(TemporalExpressions.Intersection expr); + void visit(TemporalExpressions.MinuteRange expr); + void visit(TemporalExpressions.MonthRange expr); + void visit(TemporalExpressions.Null expr); + @SuppressWarnings("deprecation") + void visit(TemporalExpressions.TimeOfDayRange expr); + void visit(TemporalExpressions.Union expr); } Modified: ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionWorker.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionWorker.java?rev=903125&r1=903124&r2=903125&view=diff ============================================================================== --- ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionWorker.java (original) +++ ofbiz/branches/release09.04/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionWorker.java Tue Jan 26 08:28:39 2010 @@ -23,17 +23,19 @@ import java.util.Set; import java.util.TreeSet; +import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; -import org.ofbiz.entity.util.EntityUtil; /** TemporalExpression persistence worker. */ public class TemporalExpressionWorker { + public final static String module = TemporalExpressionWorker.class.getName(); + // Temporal expression constants public final static String DateRange = "DATE_RANGE"; public final static String DayInMonth = "DAY_IN_MONTH"; @@ -41,12 +43,15 @@ public final static String DayOfWeekRange = "DAY_OF_WEEK_RANGE"; public final static String Difference = "DIFFERENCE"; public final static String Frequency = "FREQUENCY"; + public final static String HourRange = "HOUR_RANGE"; public final static String Intersection = "INTERSECTION"; + public final static String MinuteRange = "MINUTE_RANGE"; public final static String MonthRange = "MONTH_RANGE"; + public final static String Substitution = "SUBSTITUTION"; public final static String TimeOfDayRange = "TIME_OF_DAY_RANGE"; public final static String Union = "UNION"; public final static String ExpressionTypeList[] = {DateRange, DayInMonth, DayOfMonthRange, DayOfWeekRange, - Difference, Frequency, Intersection, MonthRange, TimeOfDayRange, Union}; + Difference, Frequency, HourRange, Intersection, MinuteRange, MonthRange, TimeOfDayRange, Substitution, Union}; /** Get a <code>TemporalExpression</code> from persistent storage. * @param delegator @@ -62,7 +67,8 @@ if (UtilValidate.isEmpty(exprValue)) { throw new IllegalArgumentException("tempExprId argument invalid - expression not found"); } - return makeTemporalExpression(delegator, exprValue); + TemporalExpression result = makeTemporalExpression(delegator, exprValue); + return result; } /** Create a <code>TemporalExpression</code> instance from a TemporalExpression @@ -73,30 +79,44 @@ * @return A <code>TemporalExpression</code> instance based on <code>exprValue</code> * @throws GenericEntityException */ + @SuppressWarnings("deprecation") public static TemporalExpression makeTemporalExpression(GenericDelegator delegator, GenericValue exprValue) throws GenericEntityException { String tempExprId = exprValue.getString("tempExprId"); String tempExprTypeId = exprValue.getString("tempExprTypeId"); if (DateRange.equals(tempExprTypeId)) { - return new TemporalExpressions.DateRange(exprValue.getTimestamp("date1"), exprValue.getTimestamp("date2")); + return setExpressionId(exprValue, new TemporalExpressions.DateRange(exprValue.getTimestamp("date1"), exprValue.getTimestamp("date2"))); } else if (DayInMonth.equals(tempExprTypeId)) { - return new TemporalExpressions.DayInMonth(exprValue.getLong("integer1").intValue(), exprValue.getLong("integer2").intValue()); + return setExpressionId(exprValue, new TemporalExpressions.DayInMonth(exprValue.getLong("integer1").intValue(), exprValue.getLong("integer2").intValue())); } else if (DayOfMonthRange.equals(tempExprTypeId)) { - return new TemporalExpressions.DayOfMonthRange(exprValue.getLong("integer1").intValue(), exprValue.getLong("integer2").intValue()); + return setExpressionId(exprValue, new TemporalExpressions.DayOfMonthRange(exprValue.getLong("integer1").intValue(), exprValue.getLong("integer2").intValue())); } else if (DayOfWeekRange.equals(tempExprTypeId)) { - return new TemporalExpressions.DayOfWeekRange(exprValue.getLong("integer1").intValue(), exprValue.getLong("integer2").intValue()); + return setExpressionId(exprValue, new TemporalExpressions.DayOfWeekRange(exprValue.getLong("integer1").intValue(), exprValue.getLong("integer2").intValue())); } else if (Difference.equals(tempExprTypeId)) { - GenericValue inclAssoc = EntityUtil.getFirst(delegator.findList("TemporalExpressionAssoc", EntityCondition.makeCondition(EntityCondition.makeCondition("fromTempExprId", tempExprId), EntityCondition.makeCondition("exprAssocType", "INCLUDE")), null, null, null, true)); - GenericValue exclAssoc = EntityUtil.getFirst(delegator.findList("TemporalExpressionAssoc", EntityCondition.makeCondition(EntityCondition.makeCondition("fromTempExprId", tempExprId), EntityCondition.makeCondition("exprAssocType", "EXCLUDE")), null, null, null, true)); + List<GenericValue> childExpressions = delegator.findList("TemporalExpressionAssoc", EntityCondition.makeCondition("fromTempExprId", tempExprId), null, null, null, true); + GenericValue inclAssoc = null; + GenericValue exclAssoc = null; + for (GenericValue childExpression : childExpressions) { + if ("INCLUDE".equals(childExpression.get("exprAssocType"))) { + inclAssoc = childExpression; + } else if ("EXCLUDE".equals(childExpression.get("exprAssocType"))) { + exclAssoc = childExpression; + } + } if (inclAssoc != null && exclAssoc != null) { - return new TemporalExpressions.Difference(getTemporalExpression(delegator, inclAssoc.getString("toTempExprId")), getTemporalExpression(delegator, exclAssoc.getString("toTempExprId"))); + return setExpressionId(exprValue, new TemporalExpressions.Difference(getTemporalExpression(delegator, inclAssoc.getString("toTempExprId")), getTemporalExpression(delegator, exclAssoc.getString("toTempExprId")))); } } else if (Frequency.equals(tempExprTypeId)) { - return new TemporalExpressions.Frequency(exprValue.getTimestamp("date1"), exprValue.getLong("integer1").intValue(), exprValue.getLong("integer2").intValue()); + return setExpressionId(exprValue, new TemporalExpressions.Frequency(exprValue.getTimestamp("date1"), exprValue.getLong("integer1").intValue(), exprValue.getLong("integer2").intValue())); + } else if (HourRange.equals(tempExprTypeId)) { + return setExpressionId(exprValue, new TemporalExpressions.HourRange(exprValue.getLong("integer1").intValue(), exprValue.getLong("integer2").intValue())); } else if (Intersection.equals(tempExprTypeId)) { - return new TemporalExpressions.Intersection(getChildExpressions(delegator, tempExprId)); + return setExpressionId(exprValue, new TemporalExpressions.Intersection(getChildExpressions(delegator, tempExprId))); + } else if (MinuteRange.equals(tempExprTypeId)) { + return setExpressionId(exprValue, new TemporalExpressions.MinuteRange(exprValue.getLong("integer1").intValue(), exprValue.getLong("integer2").intValue())); } else if (MonthRange.equals(tempExprTypeId)) { - return new TemporalExpressions.MonthRange(exprValue.getLong("integer1").intValue(), exprValue.getLong("integer2").intValue()); + return setExpressionId(exprValue, new TemporalExpressions.MonthRange(exprValue.getLong("integer1").intValue(), exprValue.getLong("integer2").intValue())); } else if (TimeOfDayRange.equals(tempExprTypeId)) { + Debug.logWarning(TimeOfDayRange + " has been deprecated. Use " + HourRange + " and/or " + MinuteRange, module); int interval = Calendar.HOUR_OF_DAY; int count = 1; Long longObj = exprValue.getLong("integer1"); @@ -107,9 +127,9 @@ if (longObj != null) { count = longObj.intValue(); } - return new TemporalExpressions.TimeOfDayRange(exprValue.getString("string1"), exprValue.getString("string2"), interval, count); + return setExpressionId(exprValue, new TemporalExpressions.TimeOfDayRange(exprValue.getString("string1"), exprValue.getString("string2"), interval, count)); } else if (Union.equals(tempExprTypeId)) { - return new TemporalExpressions.Union(getChildExpressions(delegator, tempExprId)); + return setExpressionId(exprValue, new TemporalExpressions.Union(getChildExpressions(delegator, tempExprId))); } return TemporalExpressions.NullExpression; } @@ -125,4 +145,9 @@ } return exprList; } + + protected static TemporalExpression setExpressionId(GenericValue value, TemporalExpression expression) { + expression.setId(value.getString("tempExprId")); + return expression; + } } |
| Free forum by Nabble | Edit this page |
