From 96dd60965eb3cdad2b003892821fcbe0cdd893e2 Mon Sep 17 00:00:00 2001 From: Scott Gray Date: Wed, 16 Sep 2009 00:58:07 +0000 Subject: [PATCH] Added date filtering to getProductFeatureByApplTypeId and cleaned up the method a little git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@815581 13f79535-47bb-0310-9956-ffa450edef68 --- .../ofbiz/product/product/ProductWorker.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/applications/product/src/org/ofbiz/product/product/ProductWorker.java b/applications/product/src/org/ofbiz/product/product/ProductWorker.java index 4482a377f8..b76e4c299e 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductWorker.java +++ b/applications/product/src/org/ofbiz/product/product/ProductWorker.java @@ -43,6 +43,8 @@ import org.ofbiz.common.geo.GeoWorker; import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.condition.EntityCondition; +import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.product.config.ProductConfigWrapper; import org.ofbiz.product.config.ProductConfigWrapper.ConfigOption; @@ -448,23 +450,24 @@ public class ProductWorker { if (product == null) { return null; } - List features = FastList.newInstance(); + List features = null; try { if (product != null) { List productAppls; - if (productFeatureApplTypeId == null) { - productAppls = product.getRelated("ProductFeatureAppl"); - } else { - productAppls = product.getRelatedByAnd("ProductFeatureAppl", - UtilMisc.toMap("productFeatureApplTypeId", productFeatureApplTypeId)); + List condList = UtilMisc.toList( + EntityCondition.makeCondition("productId", product.getString("productId")), + EntityUtil.getFilterByDateExpr() + ); + if (productFeatureApplTypeId != null) { + condList.add(EntityCondition.makeCondition("productFeatureApplTypeId", productFeatureApplTypeId)); } - for (GenericValue productAppl: productAppls) { - features.add(productAppl.getRelatedOne("ProductFeature")); - } - features = EntityUtil.orderBy(features, UtilMisc.toList("description")); + EntityCondition cond = EntityCondition.makeCondition(condList); + productAppls = product.getDelegator().findList("ProductFeatureAppl", cond, null, UtilMisc.toList("description"), null, false); + features = EntityUtil.getRelated("ProductFeature", productAppls); } } catch (GenericEntityException e) { Debug.logError(e, module); + features = FastList.newInstance(); } return features; }