svn commit: r700661 - in /ofbiz/trunk/applications/workeffort: entitydef/entitymodel.xml src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java widget/CommonScreens.xml widget/WorkEffortForms.xml

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r700661 - in /ofbiz/trunk/applications/workeffort: entitydef/entitymodel.xml src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java widget/CommonScreens.xml widget/WorkEffortForms.xml

adrianc
Author: adrianc
Date: Tue Sep 30 19:37:07 2008
New Revision: 700661

URL: http://svn.apache.org/viewvc?rev=700661&view=rev
Log:
Added Temporal Expression support to Work Effort. Recurring work efforts appear in the calendar.

Notes:

1. The work effort estimated start time and estimated end time must span the recurrence.
2. Until we have a way of tracking event duration, the recurring event duration is set to the requested time period.

Modified:
    ofbiz/trunk/applications/workeffort/entitydef/entitymodel.xml
    ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java
    ofbiz/trunk/applications/workeffort/widget/CommonScreens.xml
    ofbiz/trunk/applications/workeffort/widget/WorkEffortForms.xml

Modified: ofbiz/trunk/applications/workeffort/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/entitydef/entitymodel.xml?rev=700661&r1=700660&r2=700661&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/workeffort/entitydef/entitymodel.xml Tue Sep 30 19:37:07 2008
@@ -280,6 +280,7 @@
       <field name="facilityId" type="id"></field>
       <field name="infoUrl" type="long-varchar"></field>
       <field name="recurrenceInfoId" type="id"></field>
+      <field name="tempExprId" type="id"></field>
       <field name="runtimeDataId" type="id"></field>
       <field name="noteId" type="id"></field>
       <field name="serviceLoaderName" type="name"></field>
@@ -327,6 +328,9 @@
       <relation type="one" fk-name="WK_EFFRT_RECINFO" rel-entity-name="RecurrenceInfo">
         <key-map field-name="recurrenceInfoId"/>
       </relation>
+      <relation type="one" fk-name="WK_EFFRT_TEMPEXPR" rel-entity-name="TemporalExpression">
+        <key-map field-name="tempExprId"/>
+      </relation>
       <relation type="one" fk-name="WK_EFFRT_RNTMDTA" rel-entity-name="RuntimeData">
         <key-map field-name="runtimeDataId"/>
       </relation>

Modified: ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java?rev=700661&r1=700660&r2=700661&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java (original)
+++ ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java Tue Sep 30 19:37:07 2008
@@ -20,7 +20,9 @@
 package org.ofbiz.workeffort.workeffort;
 
 import java.sql.Timestamp;
+import java.util.Calendar;
 import java.util.Collection;
+import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
@@ -32,6 +34,7 @@
 import javolution.util.FastMap;
 import javolution.util.FastSet;
 
+import org.ofbiz.base.util.DateRange;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilGenerics;
@@ -43,13 +46,14 @@
 import org.ofbiz.entity.condition.EntityCondition;
 import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.condition.EntityExpr;
-import org.ofbiz.entity.condition.EntityFieldValue;
 import org.ofbiz.entity.condition.EntityJoinOperator;
 import org.ofbiz.entity.condition.EntityOperator;
 import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.security.Security;
 import org.ofbiz.service.DispatchContext;
 import org.ofbiz.service.ServiceUtil;
+import org.ofbiz.service.calendar.TemporalExpression;
+import org.ofbiz.service.calendar.TemporalExpressionWorker;
 
 /**
  * WorkEffortServices - WorkEffort related Services
@@ -518,63 +522,72 @@
         // Split the WorkEffort list into a map with entries for each period, period start is the key
         List<Map<String, Object>> periods = FastList.newInstance();
         if (validWorkEfforts != null) {
-
-            // For each day in the set we check all work efforts to see if they fall within range
+            List<DateRange> periodRanges = FastList.newInstance();
             for (int i = 0; i < numPeriods; i++) {
                 Timestamp curPeriodStart = UtilDateTime.adjustTimestamp(startStamp, periodType, i, timeZone, locale);
                 Timestamp curPeriodEnd = UtilDateTime.adjustTimestamp(curPeriodStart, periodType, 1, timeZone, locale);
+                curPeriodEnd = new Timestamp(curPeriodEnd.getTime() - 1);
+                periodRanges.add(new DateRange(curPeriodStart, curPeriodEnd));
+            }
+            try {
+                // Process recurring work efforts
+                Set<GenericValue> exclusions = FastSet.newInstance();
+                Set<GenericValue> inclusions = FastSet.newInstance();
+                DateRange range = new DateRange(startStamp, endStamp);
+                Calendar cal = UtilDateTime.toCalendar(startStamp, timeZone, locale);
+                for (GenericValue workEffort : validWorkEfforts) {
+                    if (UtilValidate.isNotEmpty(workEffort.getString("tempExprId"))) {
+                        TemporalExpression tempExpr = TemporalExpressionWorker.getTemporalExpression(delegator, workEffort.getString("tempExprId"));
+                        Set<Date> occurrences = tempExpr.getRange(range, cal);
+                        for (Date occurrence : occurrences) {
+                            for (DateRange periodRange : periodRanges) {
+                                if (periodRange.includesDate(occurrence)) {
+                                    GenericValue cloneWorkEffort = (GenericValue) workEffort.clone();
+                                    cloneWorkEffort.set("estimatedStartDate", periodRange.startStamp());
+                                    cloneWorkEffort.set("estimatedCompletionDate", periodRange.endStamp());
+                                    inclusions.add(cloneWorkEffort);
+                                }
+                            }
+                        }
+                        exclusions.add(workEffort);
+                    }
+                }
+                validWorkEfforts.removeAll(exclusions);
+                validWorkEfforts.addAll(inclusions);
+            } catch (GenericEntityException e) {
+                Debug.logWarning(e, module);
+            }
+
+            // For each period in the set we check all work efforts to see if they fall within range
+            boolean firstEntry = true;
+            for (DateRange periodRange : periodRanges) {
                 List<Map<String, Object>> curWorkEfforts = FastList.newInstance();
                 Map<String, Object> entry = FastMap.newInstance();
-
-                for (int j = 0; j < validWorkEfforts.size(); j++) {
-
-                    GenericValue workEffort = validWorkEfforts.get(j);
-                    // Debug.log("Got workEffort: " + workEffort.toString(), module);
-
-                    Timestamp estimatedStartDate = workEffort.getTimestamp("estimatedStartDate");
-                    Timestamp estimatedCompletionDate = workEffort.getTimestamp("estimatedCompletionDate");
-
-                    if (estimatedStartDate == null || estimatedCompletionDate == null)
-                        continue;
-
-                    if (estimatedStartDate.compareTo(curPeriodEnd) < 0 && estimatedCompletionDate.compareTo(curPeriodStart) > 0) {
-                        // Debug.logInfo("Task start: "+estimatedStartDate+" Task end: "+estimatedCompletionDate+" Period start: "+curPeriodStart+" Period end: "+curPeriodEnd, module);
-
+                for (GenericValue workEffort : validWorkEfforts) {
+                    DateRange weRange = new DateRange(workEffort.getTimestamp("estimatedStartDate"), workEffort.getTimestamp("estimatedCompletionDate"));
+                    if (periodRange.intersectsRange(weRange)) {
                         Map<String, Object> calEntry = FastMap.newInstance();
                         calEntry.put("workEffort", workEffort);
-
-                        long length = ((estimatedCompletionDate.after(endStamp) ? endStamp.getTime() : estimatedCompletionDate.getTime()) - (estimatedStartDate.before(startStamp) ? startStamp.getTime() : estimatedStartDate.getTime()));
+                        long length = ((weRange.end().after(endStamp) ? endStamp.getTime() : weRange.end().getTime()) - (weRange.start().before(startStamp) ? startStamp.getTime() : weRange.start().getTime()));
                         int periodSpan = (int) Math.ceil((double) length / periodLen);
                         calEntry.put("periodSpan", Integer.valueOf(periodSpan));
-
-                        if (i == 0) {
+                        if (firstEntry) {
                             // If this is the first period any valid entry is starting here
                             calEntry.put("startOfPeriod", Boolean.TRUE);
+                            firstEntry = false;
                         } else {
-                            boolean startOfPeriod = ((estimatedStartDate.getTime() - curPeriodStart.getTime()) >= 0);
+                            boolean startOfPeriod = ((weRange.start().getTime() - periodRange.start().getTime()) >= 0);
                             calEntry.put("startOfPeriod", Boolean.valueOf(startOfPeriod));
                         }
                         curWorkEfforts.add(calEntry);
                     }
-
-                    // if startDate is after hourEnd, continue to the next day, we haven't gotten to this one yet...
-                    if (estimatedStartDate.after(curPeriodEnd))
-                        break;
-
-                    // if completionDate is before the hourEnd, remove from list, we are done with it
-                    if (estimatedCompletionDate.before(curPeriodEnd)) {
-                        validWorkEfforts.remove(j);
-                        j--;
-                    }
                 }
-                // For calendar we want to include empty periods as well
-                // if (curWorkEfforts.size() > 0)
                 int numEntries = curWorkEfforts.size();
                 if (numEntries > maxConcurrentEntries) {
                     maxConcurrentEntries = numEntries;
                 }
-                entry.put("start", curPeriodStart);
-                entry.put("end", curPeriodEnd);
+                entry.put("start", periodRange.startStamp());
+                entry.put("end", periodRange.endStamp());
                 entry.put("calendarEntries", curWorkEfforts);
                 periods.add(entry);
             }

Modified: ofbiz/trunk/applications/workeffort/widget/CommonScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/widget/CommonScreens.xml?rev=700661&r1=700660&r2=700661&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/widget/CommonScreens.xml (original)
+++ ofbiz/trunk/applications/workeffort/widget/CommonScreens.xml Tue Sep 30 19:37:07 2008
@@ -31,6 +31,7 @@
                 <property-map resource="ContentUiLabels" map-name="uiLabelMap" global="true"/>
                 <property-map resource="ProductUiLabels" map-name="uiLabelMap" global="true"/>
                 <property-map resource="AccountingUiLabels" map-name="uiLabelMap" global="true"/>
+                <property-map resource="TemporalExpressionUiLabels" map-name="uiLabelMap" global="true"/>
 
                 <set field="layoutSettings.companyName" from-field="uiLabelMap.WorkEffortCompanyName" global="true"/>
                 <set field="layoutSettings.companySubtitle" from-field="uiLabelMap.WorkEffortCompanySubtitle" global="true"/>

Modified: ofbiz/trunk/applications/workeffort/widget/WorkEffortForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/widget/WorkEffortForms.xml?rev=700661&r1=700660&r2=700661&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/widget/WorkEffortForms.xml (original)
+++ ofbiz/trunk/applications/workeffort/widget/WorkEffortForms.xml Tue Sep 30 19:37:07 2008
@@ -109,6 +109,11 @@
         <field name="estimatedCompletionDate" position="2"/>
         <field name="actualStartDate" position="1"/>
         <field name="actualCompletionDate" position="2"/>
+        <field name="tempExprId" title="${uiLabelMap.TemporalExpression}">
+            <drop-down allow-empty="true">
+                <entity-options key-field-name="tempExprId" description="${tempExprId}" entity-name="TemporalExpression"/>
+            </drop-down>
+        </field>
         
 
         <field name="workEffortParentId"><lookup target-form-name="LookupWorkEffort"/></field>
@@ -1076,4 +1081,4 @@
             <hyperlink also-hidden="false" description="${uiLabelMap.CommonDelete}" target="deleteAgreementWorkEffortAppl?agreementId=${agreementId}&amp;agreementItemSeqId=${agreementItemSeqId}&amp;workEffortId=${workEffortId}"/>
         </field>
     </form>
-</forms>
\ No newline at end of file
+</forms>