From 223d0566f79a2faea427ea3e082b4f04af367e7a Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Mon, 7 Jun 2010 11:28:57 +0000 Subject: [PATCH] Revert r949820, was not complete git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@952187 13f79535-47bb-0310-9956-ffa450edef68 --- .../party/party/PartyRelationshipHelper.java | 87 ++++++++++--------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/applications/party/src/org/ofbiz/party/party/PartyRelationshipHelper.java b/applications/party/src/org/ofbiz/party/party/PartyRelationshipHelper.java index 6fcf0b3341..d7752a7f04 100644 --- a/applications/party/src/org/ofbiz/party/party/PartyRelationshipHelper.java +++ b/applications/party/src/org/ofbiz/party/party/PartyRelationshipHelper.java @@ -19,14 +19,21 @@ package org.ofbiz.party.party; +import java.sql.Timestamp; import java.util.List; import java.util.Map; +import javolution.util.FastList; + import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; -import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.entity.condition.EntityCondition; +import org.ofbiz.entity.condition.EntityOperator; /** * PartyRelationshipHelper @@ -35,48 +42,44 @@ public class PartyRelationshipHelper { public static final String module = PartyRelationshipHelper.class.getName(); - /** - * Return A List of the active Party Relationships - * - * @param delegator - * @param partyRelationshipValues Map containing the input parameters - * @return List of the active Party Relationships - */ - public static List getPartyRelationships(Delegator delegator, Map partyRelationshipValues) { - return getPartyRelationships(delegator, partyRelationshipValues, true); - } - - /** - * Return A List of the Party Relationships - * - * @param delegator - * @param partyRelationshipValues Map containing the input parameters - * @param activeOnly - * @return List of the active Party Relationships - */ - public static List getPartyRelationships(Delegator delegator, Map partyRelationshipValues, boolean activeOnly) { - List partyRelationships = null; - try { - partyRelationships = delegator.findByAndCache("PartyRelationship", partyRelationshipValues); - if (activeOnly){ - partyRelationships = EntityUtil.filterByDate(partyRelationships); - } - } catch (GenericEntityException e) { - Debug.logError(e, "Problem finding PartyRelationships. ", module); - } - - return partyRelationships; - } - - @Deprecated - /** - * Return A List of the active Party Relationships (ie with valid from and thru dates) - * - * @param delegator needed Delegator - * @param partyRelationshipValues Map containing the input parameters (primaries keys + partyRelationshipTypeId) - * @return List of the active Party Relationships + /** Return A List of the active Party Relationships (ie with valid from and thru dates) + *@param delegator needed Delegator + *@param partyRelationshipValues Map containing the input parameters (primaries keys + partyRelationshipTypeId) + *@return List of the active Party Relationships */ public static List getActivePartyRelationships(Delegator delegator, Map partyRelationshipValues) { - return getPartyRelationships(delegator, partyRelationshipValues, true); + String partyIdFrom = (String) partyRelationshipValues.get("partyIdFrom") ; + String partyIdTo = (String) partyRelationshipValues.get("partyIdTo") ; + String roleTypeIdFrom = (String) partyRelationshipValues.get("roleTypeIdFrom") ; + String roleTypeIdTo = (String) partyRelationshipValues.get("roleTypeIdTo") ; + String partyRelationshipTypeId = (String) partyRelationshipValues.get("partyRelationshipTypeId") ; + Timestamp fromDate = UtilDateTime.nowTimestamp(); + + List condList = FastList.newInstance(); + condList.add(EntityCondition.makeCondition("partyIdFrom", partyIdFrom)); + condList.add(EntityCondition.makeCondition("partyIdTo", partyIdTo)); + condList.add(EntityCondition.makeCondition("roleTypeIdFrom", roleTypeIdFrom)); + condList.add(EntityCondition.makeCondition("roleTypeIdTo", roleTypeIdTo)); + condList.add(EntityCondition.makeCondition("partyRelationshipTypeId", partyRelationshipTypeId)); + condList.add(EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, fromDate)); + EntityCondition thruCond = EntityCondition.makeCondition(UtilMisc.toList( + EntityCondition.makeCondition("thruDate", null), + EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN, fromDate)), + EntityOperator.OR); + condList.add(thruCond); + EntityCondition condition = EntityCondition.makeCondition(condList); + + List partyRelationships = null; + try { + partyRelationships = delegator.findList("PartyRelationship", condition, null, null, null, false); + } catch (GenericEntityException e) { + Debug.logError(e, "Problem finding PartyRelationships. ", module); + return null; + } + if (UtilValidate.isNotEmpty(partyRelationships)) { + return partyRelationships; + } else { + return null; + } } }