Author: adrianc
Date: Thu Oct 9 16:42:44 2008 New Revision: 703293 URL: http://svn.apache.org/viewvc?rev=703293&view=rev Log: WorkEffort improvements: WorkEffortServices.getWorkEffortEventsByPeriod will return work efforts that have a null estimatedCompletionDate. Moved the code that removed duplicate work efforts to a separate method so it can be reused. Modified: ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortWorker.java 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=703293&r1=703292&r2=703293&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 Thu Oct 9 16:42:44 2008 @@ -481,8 +481,9 @@ if (entityExprList == null) { entityExprList = getDefaultWorkEffortExprList(partyIds, facilityId, fixedAssetId, workEffortTypeId); } - entityExprList.add(EntityCondition.makeCondition("estimatedCompletionDate", EntityOperator.GREATER_THAN_EQUAL_TO, startStamp)); entityExprList.add(EntityCondition.makeCondition("estimatedStartDate", EntityOperator.LESS_THAN, endStamp)); + List<EntityCondition> completionExprList = UtilMisc.<EntityCondition>toList(EntityCondition.makeCondition("estimatedCompletionDate", EntityOperator.GREATER_THAN_EQUAL_TO, startStamp), EntityCondition.makeCondition("estimatedCompletionDate", EntityOperator.EQUALS, null)); + entityExprList.add(EntityCondition.makeCondition(completionExprList, EntityJoinOperator.OR)); if (filterOutCanceledEvents.booleanValue()) { entityExprList.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.NOT_EQUAL, "EVENT_CANCELLED")); } @@ -497,23 +498,7 @@ } else { tempWorkEfforts = delegator.findList("WorkEffort", ecl, null, UtilMisc.toList("estimatedStartDate"), null, false); } - - // This block needs to be here to filter duplicate workeffort ids when - // more than one of the selected party ids is assigned to the WorkEffort - - Set<String> tempWeKeys = FastSet.newInstance(); - Iterator<GenericValue> tempWorkEffortIter = tempWorkEfforts.iterator(); - while (tempWorkEffortIter.hasNext()) { - GenericValue tempWorkEffort = tempWorkEffortIter.next(); - String tempWorkEffortId = tempWorkEffort.getString("workEffortId"); - if (tempWeKeys.contains(tempWorkEffortId)) { - tempWorkEffortIter.remove(); - } else { - tempWeKeys.add(tempWorkEffortId); - } - } - - validWorkEfforts = UtilMisc.makeListWritable(tempWorkEfforts); + validWorkEfforts = WorkEffortWorker.removeDuplicateWorkEfforts(tempWorkEfforts); } catch (GenericEntityException e) { Debug.logWarning(e, module); } Modified: ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortWorker.java?rev=703293&r1=703292&r2=703293&view=diff ============================================================================== --- ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortWorker.java (original) +++ ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortWorker.java Thu Oct 9 16:42:44 2008 @@ -22,10 +22,12 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Set; import javax.servlet.jsp.PageContext; import javolution.util.FastList; +import javolution.util.FastSet; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilMisc; @@ -41,9 +43,8 @@ import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ModelService; -/** - * WorkEffortWorker - Worker class to reduce code in JSPs & make it more reusable - */ + +/** WorkEffortWorker - Work Effort worker class. */ public class WorkEffortWorker { public static final String module = WorkEffortWorker.class.getName(); @@ -161,8 +162,8 @@ } } - public static List getLowestLevelWorkEfforts(GenericDelegator delegator, String workEffortId, String workEffortAssocTypeId) { - List workEfforts = FastList.newInstance(); + public static List<GenericValue> getLowestLevelWorkEfforts(GenericDelegator delegator, String workEffortId, String workEffortAssocTypeId) { + List<GenericValue> workEfforts = FastList.newInstance(); try { EntityConditionList exprsLevelFirst = EntityCondition.makeCondition(UtilMisc.toList( EntityCondition.makeCondition("workEffortIdFrom", workEffortId), @@ -174,12 +175,12 @@ EntityCondition.makeCondition("workEffortAssocTypeId", workEffortAssocTypeId)), EntityOperator.AND); List<GenericValue> childWEAssocsLevelNext = delegator.findList("WorkEffortAssoc", exprsLevelNext, null, null, null, true); while (UtilValidate.isNotEmpty(childWEAssocsLevelNext)) { - List tempWorkEffortList = FastList.newInstance(); + List<GenericValue> tempWorkEffortList = FastList.newInstance(); for (GenericValue childWEAssocLevelNext : childWEAssocsLevelNext) { EntityConditionList exprsLevelNth = EntityCondition.makeCondition(UtilMisc.toList( EntityCondition.makeCondition("workEffortIdFrom", childWEAssocLevelNext.get("workEffortIdTo")), EntityCondition.makeCondition("workEffortAssocTypeId", workEffortAssocTypeId)), EntityOperator.AND); - List childWEAssocsLevelNth = delegator.findList("WorkEffortAssoc", exprsLevelNth, null, null, null, true); + List<GenericValue> childWEAssocsLevelNth = delegator.findList("WorkEffortAssoc", exprsLevelNth, null, null, null, true); if (UtilValidate.isNotEmpty(childWEAssocsLevelNth)) { tempWorkEffortList.addAll(childWEAssocsLevelNth); } @@ -194,4 +195,19 @@ } return workEfforts; } -} \ No newline at end of file + + public static List<GenericValue> removeDuplicateWorkEfforts(List<GenericValue> workEfforts) { + Set<String> keys = FastSet.newInstance(); + Set<GenericValue> exclusions = FastSet.newInstance(); + for (GenericValue workEffort : workEfforts) { + String workEffortId = workEffort.getString("workEffortId"); + if (keys.contains(workEffortId)) { + exclusions.add(workEffort); + } else { + keys.add(workEffortId); + } + } + workEfforts.removeAll(exclusions); + return workEfforts; + } +} |
Free forum by Nabble | Edit this page |