Author: sichen
Date: Thu Jan  4 11:29:28 2007
New Revision: 492700

URL: http://svn.apache.org/viewvc?view=rev&rev=492700
Log:
Refactored getWorkEffortEventsByPeriod to get the work efforts for a given 
Collection of partyIds.

Modified:
    ofbiz/trunk/applications/workeffort/servicedef/services.xml
    
ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java

Modified: ofbiz/trunk/applications/workeffort/servicedef/services.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/servicedef/services.xml?view=diff&rev=492700&r1=492699&r2=492700
==============================================================================
--- ofbiz/trunk/applications/workeffort/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/workeffort/servicedef/services.xml Thu Jan  4 
11:29:28 2007
@@ -152,8 +152,11 @@
     <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
-               If filterOutCanceledEvents is set to Boolean(true) then 
workEfforts with currentStatusId=EVENT_CANCELLED will not be 
returned.</description>
+          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>
         <attribute name="partyId" type="String" mode="IN" optional="true"/>
+        <attribute name="partyIds" type="java.util.Collection" mode="IN" 
optional="true"/>
         <attribute name="facilityId" type="String" mode="IN" optional="true"/>
         <attribute name="fixedAssetId" type="String" mode="IN" 
optional="true"/>
         <attribute name="start" type="java.sql.Timestamp" mode="IN" 
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=492700&r1=492699&r2=492700
==============================================================================
--- 
ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java
 (original)
+++ 
ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java
 Thu Jan  4 11:29:28 2007
@@ -244,6 +244,12 @@
     } 
         
     private static List getWorkEffortEvents(DispatchContext ctx, Timestamp 
startStamp, Timestamp endStamp, String partyId, String facilityId, String 
fixedAssetId) {
+        Set partyIds = new HashSet();
+        partyIds.add(partyId);
+        return getWorkEffortEvents(ctx, startStamp, endStamp, partyIds, 
facilityId, fixedAssetId);
+    }
+
+    private static List getWorkEffortEvents(DispatchContext ctx, Timestamp 
startStamp, Timestamp endStamp, Collection partyIds, String facilityId, String 
fixedAssetId) {
         GenericDelegator delegator = ctx.getDelegator();
         List validWorkEfforts = new ArrayList();
         try {
@@ -251,8 +257,8 @@
                     new EntityExpr("estimatedCompletionDate", 
EntityOperator.GREATER_THAN_EQUAL_TO, startStamp),
                     new EntityExpr("estimatedStartDate", 
EntityOperator.LESS_THAN, endStamp));
             List typesList = UtilMisc.toList(new 
EntityExpr("workEffortTypeId", EntityOperator.EQUALS, "EVENT"));
-            if (UtilValidate.isNotEmpty(partyId)) {
-                entityExprList.add(new EntityExpr("partyId", 
EntityOperator.EQUALS, partyId));
+            if (partyIds != null && partyIds.size() > 0) {
+                entityExprList.add(new EntityExpr("partyId", 
EntityOperator.IN, partyIds));
             }
             if (UtilValidate.isNotEmpty(facilityId)) {
                 entityExprList.add(new EntityExpr("facilityId", 
EntityOperator.EQUALS, facilityId));
@@ -271,7 +277,7 @@
             entityExprList.add(typesCondition);
 
             List tempWorkEfforts = null;
-            if (UtilValidate.isNotEmpty(partyId)) {
+            if (partyIds != null && partyIds.size() > 0) {
                 tempWorkEfforts = 
delegator.findByAnd("WorkEffortAndPartyAssign", entityExprList, 
UtilMisc.toList("estimatedStartDate"));
             } else {
                 tempWorkEfforts = delegator.findByAnd("WorkEffort", 
entityExprList, UtilMisc.toList("estimatedStartDate"));
@@ -310,6 +316,7 @@
         Integer periodInteger = (Integer) context.get("periodSeconds");
 
         String partyId = (String) context.get("partyId");
+        Collection partyIds = (Collection) context.get("partyIds");
         String facilityId = (String) context.get("facilityId");
         String fixedAssetId = (String) context.get("fixedAssetId");
         Boolean filterOutCanceledEvents = (Boolean) 
context.get("filterOutCanceledEvents");
@@ -332,24 +339,25 @@
         startStamp.setNanos(0);
         // Get the WorkEfforts
         List validWorkEfforts = null;
-        String partyIdToUse = null;
+        Collection partyIdsToUse = partyIds;
+        if (partyIdsToUse == null) partyIdsToUse = new HashSet();
         
         if (UtilValidate.isNotEmpty(partyId)) {
             if (partyId.equals(userLogin.getString("partyId")) || 
security.hasEntityPermission("WORKEFFORTMGR", "_VIEW", userLogin)) {
-                partyIdToUse = partyId;
+                partyIdsToUse.add(partyId);
             } else {
                 return ServiceUtil.returnError("You do not have permission to 
view information for party with ID [" + partyId + "], you must be logged in as 
a user associated with this party, or have the WORKEFFORTMGR_VIEW or 
WORKEFFORTMGR_ADMIN permissions.");
             }
         } else {
             // if a facilityId or a fixedAssetId are not specified, don't set 
a default partyId...
             if (UtilValidate.isEmpty(facilityId) && 
UtilValidate.isEmpty(fixedAssetId)) {
-                partyIdToUse = userLogin.getString("partyId");
+                partyIdsToUse.add(userLogin.getString("partyId"));
             }
         }
                 
         // Use the View Entity
-        if (UtilValidate.isNotEmpty(partyIdToUse) || 
UtilValidate.isNotEmpty(facilityId) || UtilValidate.isNotEmpty(fixedAssetId)) {
-            validWorkEfforts = getWorkEffortEvents(ctx, startStamp, endStamp, 
partyIdToUse, facilityId, fixedAssetId);
+        if (partyIdsToUse.size() > 0 || UtilValidate.isNotEmpty(facilityId) || 
UtilValidate.isNotEmpty(fixedAssetId)) {
+            validWorkEfforts = getWorkEffortEvents(ctx, startStamp, endStamp, 
partyIdsToUse, facilityId, fixedAssetId);
         }
         if (filterOutCanceledEvents.booleanValue()) {
                validWorkEfforts = 
EntityUtil.filterOutByCondition(validWorkEfforts, new 
EntityExpr("currentStatusId", EntityOperator.EQUALS, "EVENT_CANCELLED"));


Reply via email to