svn commit: r548384 - in /ofbiz/trunk/applications/workeffort: servicedef/ src/org/ofbiz/workeffort/workeffort/ webapp/workeffort/WEB-INF/actions/calendar/

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

svn commit: r548384 - in /ofbiz/trunk/applications/workeffort: servicedef/ src/org/ofbiz/workeffort/workeffort/ webapp/workeffort/WEB-INF/actions/calendar/

adrianc
Author: adrianc
Date: Mon Jun 18 08:47:20 2007
New Revision: 548384

URL: http://svn.apache.org/viewvc?view=rev&rev=548384
Log:
Workeffort calendar bug fix - OFBIZ-1069.

Modified:
    ofbiz/trunk/applications/workeffort/servicedef/services.xml
    ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java
    ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/day.bsh
    ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/month.bsh
    ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/upcoming.bsh
    ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/week.bsh

Modified: ofbiz/trunk/applications/workeffort/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/servicedef/services.xml?view=diff&rev=548384&r1=548383&r2=548384
==============================================================================
--- ofbiz/trunk/applications/workeffort/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/workeffort/servicedef/services.xml Mon Jun 18 08:47:20 2007
@@ -168,7 +168,8 @@
     </service>    
     <service name="getWorkEffortEventsByPeriod" auth="true" engine="java"
             location="org.ofbiz.workeffort.workeffort.WorkEffortServices" invoke="getWorkEffortEventsByPeriod">
-        <description>Get WorkEffort Events by a period spcified by periodSeconds attribute. Return a Map with periodStart as the key and a Collection of events for that period as value
+        <description>Get WorkEffort Events by a period specified by periodType attribute (one of the
+          java.util.Calendar field values). Return a Map with periodStart as the key and a Collection of events for that period as value
           If filterOutCanceledEvents is set to Boolean(true) then workEfforts with currentStatusId=EVENT_CANCELLED will not be returned.
           To limit the events to a particular partyId, specify the partyId.  To limit the events to a set of partyIds, specify a Collection of partyIds.
         </description>
@@ -178,7 +179,7 @@
         <attribute name="fixedAssetId" type="String" mode="IN" optional="true"/>
         <attribute name="start" type="java.sql.Timestamp" mode="IN" optional="false"/>
         <attribute name="numPeriods" type="java.lang.Integer" mode="IN" optional="false"/>
-        <attribute name="periodSeconds" type="java.lang.Integer" mode="IN" optional="false"/>
+        <attribute name="periodType" type="java.lang.Integer" mode="IN" optional="false"/>
         <attribute name="filterOutCanceledEvents" type="java.lang.Boolean" mode="IN" optional="true"/>
         <attribute name="periods" type="java.util.List" mode="OUT" optional="false"/>
         <attribute name="maxConcurrentEntries" type="java.lang.Integer" mode="OUT" optional="false"/>

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?view=diff&rev=548384&r1=548383&r2=548384
==============================================================================
--- ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java (original)
+++ ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java Mon Jun 18 08:47:20 2007
@@ -27,8 +27,10 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.TimeZone;
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilDateTime;
@@ -330,10 +332,10 @@
     public static Map getWorkEffortEventsByPeriod(DispatchContext ctx, Map context) {
         Security security = ctx.getSecurity();
         GenericValue userLogin = (GenericValue) context.get("userLogin");    
+        Locale locale = (Locale) context.get("locale");
         
         Timestamp startDay = (Timestamp) context.get("start");
         Integer numPeriodsInteger = (Integer) context.get("numPeriods");
-        Integer periodInteger = (Integer) context.get("periodSeconds");
 
         String partyId = (String) context.get("partyId");
         Collection partyIds = (Collection) context.get("partyIds");
@@ -347,16 +349,23 @@
         //To be returned, the max concurrent entries for a single period
         int maxConcurrentEntries = 0;
                 
-        long period = periodInteger.intValue()*1000;
+        TimeZone curTz = TimeZone.getDefault();
+
+        Integer periodTypeObject = (Integer) context.get("periodType");
+        int periodType = 0;
+        if (periodTypeObject != null) {
+            periodType = periodTypeObject.intValue();
+        }
         
         int numPeriods = 0;
         if(numPeriodsInteger != null) numPeriods = numPeriodsInteger.intValue();
         
         // get a timestamp (date) for the beginning of today and for beginning of numDays+1 days from now
-        Timestamp startStamp = UtilDateTime.getDayStart(startDay);          
-        Timestamp endStamp = new Timestamp(startStamp.getTime()+(period*(numPeriods+1)));
+        Timestamp startStamp = UtilDateTime.getDayStart(startDay, curTz, locale);
+        Timestamp endStamp = UtilDateTime.adjustTimestamp(startStamp, periodType, 1, curTz, locale);
+        long periodLen = endStamp.getTime() - startStamp.getTime();
+        endStamp = UtilDateTime.adjustTimestamp(startStamp, periodType, numPeriods, curTz, locale);
         
-        startStamp.setNanos(0);
         // Get the WorkEfforts
         List validWorkEfforts = null;
         Collection partyIdsToUse = partyIds;
@@ -389,8 +398,8 @@
         
             // For each day in the set we check all work efforts to see if they fall within range
             for (int i = 0; i < numPeriods; i++) {
-                Timestamp curPeriodStart = new Timestamp(startStamp.getTime()+(i*period));
-                Timestamp curPeriodEnd = new Timestamp(curPeriodStart.getTime()+period);
+                Timestamp curPeriodStart = UtilDateTime.adjustTimestamp(startStamp, periodType, i, curTz, locale);
+                Timestamp curPeriodEnd = UtilDateTime.adjustTimestamp(curPeriodStart, periodType, 1, curTz, locale);
                 List curWorkEfforts = new ArrayList();
                 Map entry = new HashMap();
                 for (int j = 0; j < validWorkEfforts.size(); j++) {
@@ -410,7 +419,7 @@
                         calEntry.put("workEffort",workEffort);
                                               
                         long length = ((estimatedCompletionDate.after(endStamp) ? endStamp.getTime() : estimatedCompletionDate.getTime()) - (estimatedStartDate.before(startStamp) ? startStamp.getTime() : estimatedStartDate.getTime()));
-                        int periodSpan = (int) Math.ceil((double) length / period);                                                
+                        int periodSpan = (int) Math.ceil((double) length / periodLen);                                                
                         calEntry.put("periodSpan", new Integer(periodSpan));
 
                         if(i == 0) calEntry.put("startOfPeriod", Boolean.TRUE); //If this is the first priod any valid entry is starting here

Modified: ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/day.bsh
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/day.bsh?view=diff&rev=548384&r1=548383&r2=548384
==============================================================================
--- ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/day.bsh (original)
+++ ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/day.bsh Mon Jun 18 08:47:20 2007
@@ -55,7 +55,7 @@
 Timestamp prev = UtilDateTime.getDayStart(start,-1);
 Timestamp next = UtilDateTime.getDayStart(start,1);
 
-Map serviceCtx = UtilMisc.toMap("userLogin", userLogin,"start",start,"numPeriods",new Integer(24),"periodSeconds",new Integer(3600));
+Map serviceCtx = UtilMisc.toMap("userLogin", userLogin,"start",start,"numPeriods",new Integer(24),"periodType",new Integer(Calendar.HOUR));
 serviceCtx.put("partyId", partyId);
 serviceCtx.put("facilityId", facilityId);
 serviceCtx.put("fixedAssetId", fixedAssetId);

Modified: ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/month.bsh
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/month.bsh?view=diff&rev=548384&r1=548383&r2=548384
==============================================================================
--- ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/month.bsh (original)
+++ ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/month.bsh Mon Jun 18 08:47:20 2007
@@ -70,7 +70,7 @@
 numDays += prevMonthDays;
 getFrom = new Timestamp(tempCal.getTime().getTime());
 
-serviceCtx = UtilMisc.toMap("userLogin", userLogin, "start", getFrom,"numPeriods", new Integer(numDays), "periodSeconds", new Integer(3600*24));
+serviceCtx = UtilMisc.toMap("userLogin", userLogin, "start", getFrom,"numPeriods", new Integer(numDays), "periodType", new Integer(Calendar.DATE));
 serviceCtx.put("partyId", partyId);
 serviceCtx.put("facilityId", facilityId);
 serviceCtx.put("fixedAssetId", fixedAssetId);

Modified: ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/upcoming.bsh
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/upcoming.bsh?view=diff&rev=548384&r1=548383&r2=548384
==============================================================================
--- ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/upcoming.bsh (original)
+++ ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/upcoming.bsh Mon Jun 18 08:47:20 2007
@@ -39,7 +39,7 @@
     eventsParam = "partyId=" + partyId;
 }
 
-Map serviceCtx = UtilMisc.toMap("userLogin", userLogin,"start", start,"numPeriods",new Integer(7),"periodSeconds",new Integer(3600*24));
+Map serviceCtx = UtilMisc.toMap("userLogin", userLogin,"start", start,"numPeriods",new Integer(7),"periodType",new Integer(Calendar.DATE));
 serviceCtx.put("partyId", partyId);
 serviceCtx.put("facilityId", facilityId);
 serviceCtx.put("fixedAssetId", fixedAssetId);

Modified: ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/week.bsh
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/week.bsh?view=diff&rev=548384&r1=548383&r2=548384
==============================================================================
--- ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/week.bsh (original)
+++ ofbiz/trunk/applications/workeffort/webapp/workeffort/WEB-INF/actions/calendar/week.bsh Mon Jun 18 08:47:20 2007
@@ -58,7 +58,7 @@
 Timestamp next = UtilDateTime.getDayStart(start,7);
 Timestamp end = UtilDateTime.getDayStart(start,6);
 
-Map serviceCtx = UtilMisc.toMap("userLogin", userLogin,"start",start,"numPeriods",new Integer(7),"periodSeconds",new Integer(3600*24));
+Map serviceCtx = UtilMisc.toMap("userLogin", userLogin,"start",start,"numPeriods",new Integer(7),"periodType",new Integer(Calendar.DATE));
 serviceCtx.put("partyId", partyId);
 serviceCtx.put("facilityId", facilityId);
 serviceCtx.put("fixedAssetId", fixedAssetId);