From f67ad0317d1e0d2d2db10ca729d5c8b659de2acd Mon Sep 17 00:00:00 2001 From: Ashish Vijaywargiya Date: Sat, 22 Nov 2014 11:26:20 +0000 Subject: [PATCH] Applied product folder related changes from jira issue - OFBIZ-5844 - Convert java files to EntityQuery. Thanks Arun for the contribution. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1641044 13f79535-47bb-0310-9956-ffa450edef68 --- .../ofbiz/product/catalog/CatalogWorker.java | 15 +-- .../product/category/CatalogUrlFilter.java | 18 ++-- .../product/category/CatalogUrlServlet.java | 3 +- .../category/CategoryContentWrapper.java | 2 +- .../product/category/CategoryServices.java | 22 ++--- .../product/category/CategoryWorker.java | 20 ++-- .../ProductConfigItemContentWrapper.java | 9 +- .../product/config/ProductConfigWorker.java | 8 +- .../product/config/ProductConfigWrapper.java | 7 +- .../product/feature/ParametricSearch.java | 10 +- .../feature/ProductFeatureServices.java | 7 +- .../product/imagemanagement/FrameImage.java | 3 +- .../ImageManagementHelper.java | 5 +- .../ImageManagementServices.java | 11 +-- .../product/imagemanagement/ReplaceImage.java | 15 ++- .../product/inventory/InventoryServices.java | 56 +++++------- .../product/inventory/InventoryWorker.java | 9 +- .../ofbiz/product/price/PriceServices.java | 79 +++++++--------- .../ofbiz/product/product/KeywordIndex.java | 12 +-- .../product/ProductContentWrapper.java | 7 +- .../ofbiz/product/product/ProductEvents.java | 43 +++------ .../product/ProductPromoContentWrapper.java | 3 +- .../ofbiz/product/product/ProductSearch.java | 28 +++--- .../product/product/ProductSearchEvents.java | 13 +-- .../product/product/ProductSearchSession.java | 57 ++++++------ .../product/product/ProductServices.java | 53 +++++------ .../product/product/ProductUtilServices.java | 60 ++++++------ .../ofbiz/product/product/ProductWorker.java | 91 +++++++++++-------- .../ofbiz/product/product/VariantEvents.java | 2 +- .../ofbiz/product/promo/PromoServices.java | 3 +- .../ImportProductHelper.java | 4 +- .../product/store/ProductStoreEvents.java | 9 +- .../product/store/ProductStoreWorker.java | 26 +++--- .../subscription/SubscriptionServices.java | 17 ++-- .../shipment/packing/PackingSession.java | 8 +- .../shipment/packing/PackingSessionLine.java | 6 +- .../shipment/picklist/PickListServices.java | 10 +- .../shipment/shipment/ShipmentServices.java | 55 ++++++----- .../shipment/thirdparty/dhl/DhlServices.java | 10 +- .../thirdparty/fedex/FedexServices.java | 7 +- .../shipment/thirdparty/ups/UpsServices.java | 28 +++--- .../thirdparty/usps/UspsServices.java | 33 +++---- .../shipment/verify/VerifyPickSession.java | 8 +- .../shipment/verify/VerifyPickSessionRow.java | 4 +- .../weightPackage/WeightPackageServices.java | 3 +- .../weightPackage/WeightPackageSession.java | 2 +- 46 files changed, 443 insertions(+), 458 deletions(-) diff --git a/applications/product/src/org/ofbiz/product/catalog/CatalogWorker.java b/applications/product/src/org/ofbiz/product/catalog/CatalogWorker.java index 69ef1c389b..dd27d7beaa 100644 --- a/applications/product/src/org/ofbiz/product/catalog/CatalogWorker.java +++ b/applications/product/src/org/ofbiz/product/catalog/CatalogWorker.java @@ -73,7 +73,7 @@ public class CatalogWorker { List catalogs = null; Delegator delegator = (Delegator) request.getAttribute("delegator"); try { - catalogs = delegator.findList("ProdCatalog", null, null, UtilMisc.toList("catalogName"), null, false); + catalogs = EntityQuery.use(delegator).from("ProdCatalog").orderBy("catalogName").queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Error looking up all catalogs", module); } @@ -93,7 +93,7 @@ public class CatalogWorker { public static List getStoreCatalogs(Delegator delegator, String productStoreId) { try { - return EntityUtil.filterByDate(delegator.findByAnd("ProductStoreCatalog", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("sequenceNum", "prodCatalogId"), true), true); + return EntityQuery.use(delegator).from("ProductStoreCatalog").where("productStoreId", productStoreId).orderBy("sequenceNum", "prodCatalogId").cache(true).filterByDate().queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Error looking up store catalogs for store with id " + productStoreId, module); } @@ -117,7 +117,7 @@ public class CatalogWorker { } try { - return EntityUtil.filterByDate(delegator.findByAnd("ProdCatalogRole", UtilMisc.toMap("partyId", partyId, "roleTypeId", "CUSTOMER"), UtilMisc.toList("sequenceNum", "prodCatalogId"), true), true); + return EntityQuery.use(delegator).from("ProdCatalogRole").where("partyId", partyId, "roleTypeId", "CUSTOMER").orderBy("sequenceNum", "prodCatalogId").cache(true).filterByDate().queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Error looking up ProdCatalog Roles for party with id " + partyId, module); } @@ -131,9 +131,12 @@ public class CatalogWorker { public static List getProdCatalogCategories(Delegator delegator, String prodCatalogId, String prodCatalogCategoryTypeId) { try { - List prodCatalogCategories = EntityUtil.filterByDate(delegator.findByAnd("ProdCatalogCategory", - UtilMisc.toMap("prodCatalogId", prodCatalogId), - UtilMisc.toList("sequenceNum", "productCategoryId"), true), true); + List prodCatalogCategories = EntityQuery.use(delegator).from("ProdCatalogCategory") + .where("prodCatalogId", prodCatalogId) + .orderBy("sequenceNum", "productCategoryId") + .cache(true) + .filterByDate() + .queryList(); if (UtilValidate.isNotEmpty(prodCatalogCategoryTypeId) && prodCatalogCategories != null) { prodCatalogCategories = EntityUtil.filterByAnd(prodCatalogCategories, diff --git a/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java b/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java index 9dbc32a7bd..6cbcc65b4e 100644 --- a/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java +++ b/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java @@ -91,11 +91,11 @@ public class CatalogUrlFilter extends ContextFilter { List productContentConds = FastList.newInstance(); productContentConds.add(EntityCondition.makeCondition("productContentTypeId", "ALTERNATIVE_URL")); productContentConds.add(EntityUtil.getFilterByDateExpr()); - List productContentInfos = delegator.findList("ProductContentAndInfo", EntityCondition.makeCondition(productContentConds), null, UtilMisc.toList("-fromDate"), null, true); + List productContentInfos = EntityQuery.use(delegator).from("ProductContentAndInfo").where(productContentConds).orderBy("-fromDate").cache(true).queryList(); if (UtilValidate.isNotEmpty(productContentInfos)) { for (GenericValue productContentInfo : productContentInfos){ String contentId = (String) productContentInfo.get("contentId"); - List ContentAssocDataResourceViewTos = delegator.findByAnd("ContentAssocDataResourceViewTo", UtilMisc.toMap("contentIdStart", contentId, "caContentAssocTypeId", "ALTERNATE_LOCALE", "drDataResourceTypeId", "ELECTRONIC_TEXT"), null, true); + List ContentAssocDataResourceViewTos = EntityQuery.use(delegator).where("ContentAssocDataResourceViewTo").where("contentIdStart", contentId, "caContentAssocTypeId", "ALTERNATE_LOCALE", "drDataResourceTypeId", "ELECTRONIC_TEXT").cache(true).queryList(); if (UtilValidate.isNotEmpty(ContentAssocDataResourceViewTos)){ for (GenericValue ContentAssocDataResourceViewTo : ContentAssocDataResourceViewTos) { GenericValue ElectronicText = ContentAssocDataResourceViewTo.getRelatedOne("ElectronicText", true); @@ -116,7 +116,7 @@ public class CatalogUrlFilter extends ContextFilter { } } if (UtilValidate.isEmpty(productId)) { - List contentDataResourceViews = delegator.findByAnd("ContentDataResourceView", UtilMisc.toMap("contentId", contentId, "drDataResourceTypeId", "ELECTRONIC_TEXT"), null, true); + List contentDataResourceViews = EntityQuery.use(delegator).where("ContentDataResourceView").where("contentId", contentId, "drDataResourceTypeId", "ELECTRONIC_TEXT").cache(true).queryList(); for (GenericValue contentDataResourceView : contentDataResourceViews) { GenericValue ElectronicText = contentDataResourceView.getRelatedOne("ElectronicText", true); if (UtilValidate.isNotEmpty(ElectronicText)) { @@ -146,11 +146,11 @@ public class CatalogUrlFilter extends ContextFilter { List productCategoryContentConds = FastList.newInstance(); productCategoryContentConds.add(EntityCondition.makeCondition("prodCatContentTypeId", "ALTERNATIVE_URL")); productCategoryContentConds.add(EntityUtil.getFilterByDateExpr()); - List productCategoryContentInfos = delegator.findList("ProductCategoryContentAndInfo", EntityCondition.makeCondition(productCategoryContentConds), null, UtilMisc.toList("-fromDate"), null, true); + List productCategoryContentInfos = EntityQuery.use(delegator).from("ProductCategoryContentAndInfo").where(productCategoryContentConds).orderBy("-fromDate").cache(true).queryList(); if (UtilValidate.isNotEmpty(productCategoryContentInfos)) { for (GenericValue productCategoryContentInfo : productCategoryContentInfos){ String contentId = (String) productCategoryContentInfo.get("contentId"); - List ContentAssocDataResourceViewTos = delegator.findByAnd("ContentAssocDataResourceViewTo", UtilMisc.toMap("contentIdStart", contentId, "caContentAssocTypeId", "ALTERNATE_LOCALE", "drDataResourceTypeId", "ELECTRONIC_TEXT"), null, true); + List ContentAssocDataResourceViewTos = EntityQuery.use(delegator).from("ContentAssocDataResourceViewTo").where("contentIdStart", contentId, "caContentAssocTypeId", "ALTERNATE_LOCALE", "drDataResourceTypeId", "ELECTRONIC_TEXT").cache(true).queryList(); if (UtilValidate.isNotEmpty(ContentAssocDataResourceViewTos)){ for (GenericValue ContentAssocDataResourceViewTo : ContentAssocDataResourceViewTos) { GenericValue ElectronicText = ContentAssocDataResourceViewTo.getRelatedOne("ElectronicText", true); @@ -173,7 +173,7 @@ public class CatalogUrlFilter extends ContextFilter { } } if (UtilValidate.isEmpty(productCategoryId)) { - List contentDataResourceViews = delegator.findByAnd("ContentDataResourceView", UtilMisc.toMap("contentId", contentId, "drDataResourceTypeId", "ELECTRONIC_TEXT"), null, true); + List contentDataResourceViews = EntityQuery.use(delegator).from("ContentDataResourceView").where("contentId", contentId, "drDataResourceTypeId", "ELECTRONIC_TEXT").cache(true).queryList(); for (GenericValue contentDataResourceView : contentDataResourceViews) { GenericValue ElectronicText = contentDataResourceView.getRelatedOne("ElectronicText", true); if (UtilValidate.isNotEmpty(ElectronicText)) { @@ -211,7 +211,7 @@ public class CatalogUrlFilter extends ContextFilter { List conds = FastList.newInstance(); conds.add(EntityCondition.makeCondition("productId", productId)); conds.add(EntityUtil.getFilterByDateExpr()); - List productCategoryMembers = delegator.findList("ProductCategoryMember", EntityCondition.makeCondition(conds), UtilMisc.toSet("productCategoryId"), UtilMisc.toList("-fromDate"), null, true); + List productCategoryMembers = EntityQuery.use(delegator).select("productCategoryId").from("ProductCategoryMember").where(conds).orderBy("-fromDate").cache(true).queryList(); if (UtilValidate.isNotEmpty(productCategoryMembers)) { GenericValue productCategoryMember = EntityUtil.getFirst(productCategoryMembers); productCategoryId = productCategoryMember.getString("productCategoryId"); @@ -236,7 +236,7 @@ public class CatalogUrlFilter extends ContextFilter { List rolllupConds = FastList.newInstance(); rolllupConds.add(EntityCondition.makeCondition("productId", productId)); rolllupConds.add(EntityUtil.getFilterByDateExpr()); - List productCategoryMembers = delegator.findList("ProductCategoryMember", EntityCondition.makeCondition(rolllupConds), null, UtilMisc.toList("-fromDate"), null, true); + List productCategoryMembers = EntityQuery.use(delegator).from("ProductCategoryMember").where(rolllupConds).orderBy("-fromDate").cache(true).queryList(); for (GenericValue productCategoryMember : productCategoryMembers) { String trailCategoryId = productCategoryMember.getString("productCategoryId"); if (trailCategoryIds.contains(trailCategoryId)) { @@ -260,7 +260,7 @@ public class CatalogUrlFilter extends ContextFilter { List rolllupConds = FastList.newInstance(); rolllupConds.add(EntityCondition.makeCondition("productCategoryId", parentProductCategoryId)); rolllupConds.add(EntityUtil.getFilterByDateExpr()); - List productCategoryRollups = delegator.findList("ProductCategoryRollup", EntityCondition.makeCondition(rolllupConds), null, UtilMisc.toList("-fromDate"), null, true); + List productCategoryRollups = EntityQuery.use(delegator).from("ProductCategoryRollup").where(rolllupConds).orderBy("-fromDate").cache(true).queryList(); if (UtilValidate.isNotEmpty(productCategoryRollups)) { // add only categories that belong to the top category to trail for (GenericValue productCategoryRollup : productCategoryRollups) { diff --git a/applications/product/src/org/ofbiz/product/category/CatalogUrlServlet.java b/applications/product/src/org/ofbiz/product/category/CatalogUrlServlet.java index 3fbaf342c3..691e18482c 100644 --- a/applications/product/src/org/ofbiz/product/category/CatalogUrlServlet.java +++ b/applications/product/src/org/ofbiz/product/category/CatalogUrlServlet.java @@ -36,6 +36,7 @@ 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.util.EntityQuery; /** * ControlServlet.java - Master servlet for the web application. @@ -84,7 +85,7 @@ public class CatalogUrlServlet extends HttpServlet { String productId = null; try { String lastPathElement = pathElements.get(pathElements.size() - 1); - if (lastPathElement.startsWith("p_") || delegator.findOne("Product", UtilMisc.toMap("productId", lastPathElement), true) != null) { + if (lastPathElement.startsWith("p_") || EntityQuery.use(delegator).from("Product").where("productId", lastPathElement).cache(true).queryOne() != null) { if (lastPathElement.startsWith("p_")) { productId = lastPathElement.substring(2); } else { diff --git a/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java b/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java index 942cd4d5e0..a73e52d1f4 100644 --- a/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java +++ b/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java @@ -141,7 +141,7 @@ public class CategoryContentWrapper implements ContentWrapper { } } - List categoryContentList = delegator.findByAnd("ProductCategoryContent", UtilMisc.toMap("productCategoryId", productCategoryId, "prodCatContentTypeId", prodCatContentTypeId), UtilMisc.toList("-fromDate"), true); + List categoryContentList = EntityQuery.use(delegator).from("ProductCategoryContent").where("productCategoryId", productCategoryId, "prodCatContentTypeId", prodCatContentTypeId).orderBy("-fromDate").cache(true).queryList(); categoryContentList = EntityUtil.filterByDate(categoryContentList); GenericValue categoryContent = EntityUtil.getFirst(categoryContentList); if (categoryContent != null) { diff --git a/applications/product/src/org/ofbiz/product/category/CategoryServices.java b/applications/product/src/org/ofbiz/product/category/CategoryServices.java index 90cb1c84de..2a81c999d3 100644 --- a/applications/product/src/org/ofbiz/product/category/CategoryServices.java +++ b/applications/product/src/org/ofbiz/product/category/CategoryServices.java @@ -105,7 +105,7 @@ public class CategoryServices { List productCategoryMembers; try { productCategory = EntityQuery.use(delegator).from("ProductCategory").where("productCategoryId", categoryId).cache().queryOne(); - productCategoryMembers = delegator.findByAnd(entityName, UtilMisc.toMap("productCategoryId", categoryId), orderByFields, true); + productCategoryMembers = EntityQuery.use(delegator).from(entityName).where("productCategoryId", categoryId).orderBy(orderByFields).cache(true).queryList(); } catch (GenericEntityException e) { Debug.logInfo(e, "Error finding previous/next product info: " + e.toString(), module); return ServiceUtil.returnFailure(UtilProperties.getMessage(resourceError, "categoryservices.error_find_next_products", UtilMisc.toMap("errMessage", e.getMessage()), locale)); @@ -276,7 +276,7 @@ public class CategoryServices { try { String productStoreId = (String) context.get("productStoreId"); if (UtilValidate.isNotEmpty(productStoreId)) { - GenericValue productStore = delegator.findOne("ProductStore", UtilMisc.toMap("productStoreId", productStoreId), false); + GenericValue productStore = EntityQuery.use(delegator).from("ProductStore").where("productStoreId", productStoreId).queryOne(); if (productStore != null && "N".equals(productStore.getString("showOutOfStockProducts"))) { filterOutOfStock = true; } @@ -288,7 +288,7 @@ public class CategoryServices { if (productCategory != null) { try { if (useCacheForMembers) { - productCategoryMembers = delegator.findByAnd(entityName, UtilMisc.toMap("productCategoryId", productCategoryId), orderByFields, true); + productCategoryMembers = EntityQuery.use(delegator).from(entityName).where("productCategoryId", productCategoryId).orderBy(orderByFields).cache(true).queryList(); if (activeOnly) { productCategoryMembers = EntityUtil.filterByDate(productCategoryMembers, true); } @@ -351,10 +351,8 @@ public class CategoryServices { EntityCondition mainCond = EntityCondition.makeCondition(mainCondList, EntityOperator.AND); // set distinct on - EntityFindOptions findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, false); - findOpts.setMaxRows(highIndex); // using list iterator - EntityListIterator pli = delegator.find(entityName, mainCond, null, null, orderByFields, findOpts); + EntityListIterator pli = EntityQuery.use(delegator).from(entityName).where(mainCond).orderBy(orderByFields).cursorScrollInsensitive().maxRows(highIndex).queryIterator(); // get the partial list for this page if (limitView) { @@ -455,17 +453,16 @@ public class CategoryServices { List sortList = org.ofbiz.base.util.UtilMisc.toList("sequenceNum", "title"); try { - GenericValue category = delegator.findOne(entityName ,UtilMisc.toMap(primaryKeyName, productCategoryId), false); + GenericValue category = EntityQuery.use(delegator).from(entityName).where(primaryKeyName, productCategoryId).queryOne(); if (UtilValidate.isNotEmpty(category)) { if (isCatalog.equals("true") && isCategoryType.equals("false")) { CategoryWorker.getRelatedCategories(request, "ChildCatalogList", CatalogWorker.getCatalogTopCategoryId(request, productCategoryId), true); childOfCats = EntityUtil.filterByDate((List) request.getAttribute("ChildCatalogList")); } else if(isCatalog.equals("false") && isCategoryType.equals("false")){ - childOfCats = EntityUtil.filterByDate(delegator.findByAnd("ProductCategoryRollupAndChild", UtilMisc.toMap( - "parentProductCategoryId", productCategoryId ), null, false)); + childOfCats = EntityQuery.use(delegator).from("ProductCategoryRollupAndChild").where("parentProductCategoryId", productCategoryId).filterByDate().queryList(); } else { - childOfCats = EntityUtil.filterByDate(delegator.findByAnd("ProdCatalogCategory", UtilMisc.toMap("prodCatalogId", productCategoryId), null, false)); + childOfCats = EntityQuery.use(delegator).from("ProdCatalogCategory").where("prodCatalogId", productCategoryId).filterByDate().queryList(); } if (UtilValidate.isNotEmpty(childOfCats)) { @@ -481,11 +478,10 @@ public class CategoryServices { List childList = null; // Get the child list of chosen category - childList = EntityUtil.filterByDate(delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap( - "parentProductCategoryId", catId), null, false)); + childList = EntityQuery.use(delegator).from("ProductCategoryRollup").where("parentProductCategoryId", catId).filterByDate().queryList(); // Get the chosen category information for the categoryContentWrapper - GenericValue cate = delegator.findOne("ProductCategory" ,UtilMisc.toMap("productCategoryId",catId), false); + GenericValue cate = EntityQuery.use(delegator).from("ProductCategory").where("productCategoryId",catId).queryOne(); // If chosen category's child exists, then put the arrow before category icon if (UtilValidate.isNotEmpty(childList)) { diff --git a/applications/product/src/org/ofbiz/product/category/CategoryWorker.java b/applications/product/src/org/ofbiz/product/category/CategoryWorker.java index 4dca17b517..b7563198c6 100644 --- a/applications/product/src/org/ofbiz/product/category/CategoryWorker.java +++ b/applications/product/src/org/ofbiz/product/category/CategoryWorker.java @@ -90,7 +90,7 @@ public class CategoryWorker { Collection results = FastList.newInstance(); try { - Collection allCategories = delegator.findList("ProductCategory", null, null, null, null, false); + Collection allCategories = EntityQuery.use(delegator).from("ProductCategory").queryList(); for (GenericValue curCat: allCategories) { Collection parentCats = curCat.getRelated("CurrentProductCategoryRollup", null, null, true); @@ -148,9 +148,7 @@ public class CategoryWorker { List rollups = null; try { - rollups = delegator.findByAnd("ProductCategoryRollup", - UtilMisc.toMap("parentProductCategoryId", parentId), - UtilMisc.toList("sequenceNum"), true); + rollups = EntityQuery.use(delegator).from("ProductCategoryRollup").where("parentProductCategoryId", parentId).orderBy("sequenceNum").cache(true).queryList(); if (limitView) { rollups = EntityUtil.filterByDate(rollups, true); } @@ -213,7 +211,7 @@ public class CategoryWorker { Delegator delegator = category.getDelegator(); long count = 0; try { - count = delegator.findCountByCondition("ProductCategoryMember", buildCountCondition("productCategoryId", category.getString("productCategoryId")), null, null); + count = EntityQuery.use(delegator).from("ProductCategoryMember").where("productCategoryId", category.getString("productCategoryId")).queryCount(); } catch (GenericEntityException e) { Debug.logError(e, module); } @@ -225,7 +223,7 @@ public class CategoryWorker { Delegator delegator = category.getDelegator(); long count = 0; try { - count = delegator.findCountByCondition("ProductCategoryRollup", buildCountCondition("parentProductCategoryId", category.getString("productCategoryId")), null, null); + count = EntityQuery.use(delegator).from("ProductCategoryRollup").where("parentProductCategoryId", category.getString("productCategoryId")).queryCount(); } catch (GenericEntityException e) { Debug.logError(e, module); } @@ -363,8 +361,11 @@ public class CategoryWorker { if (productCategoryId == null) return false; if (UtilValidate.isEmpty(productId)) return false; - List productCategoryMembers = EntityUtil.filterByDate(delegator.findByAnd("ProductCategoryMember", - UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId), null, true), true); + List productCategoryMembers = EntityQuery.use(delegator).from("ProductCategoryMember") + .where("productCategoryId", productCategoryId, "productId", productId) + .cache(true) + .filterByDate() + .queryList(); if (UtilValidate.isEmpty(productCategoryMembers)) { //before giving up see if this is a variant product, and if so look up the virtual product and check it... GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productId).cache().queryOne(); @@ -451,8 +452,7 @@ public class CategoryWorker { List rolllupConds = FastList.newInstance(); rolllupConds.add(EntityCondition.makeCondition("productCategoryId", parentProductCategoryId)); rolllupConds.add(EntityUtil.getFilterByDateExpr()); - List productCategoryRollups = delegator.findList("ProductCategoryRollup", - EntityCondition.makeCondition(rolllupConds), null, UtilMisc.toList("sequenceNum"), null, true); + List productCategoryRollups = EntityQuery.use(delegator).from("ProductCategoryRollup").where(rolllupConds).orderBy("sequenceNum").cache(true).queryList(); if (UtilValidate.isNotEmpty(productCategoryRollups)) { // add only categories that belong to the top category to trail for (GenericValue productCategoryRollup : productCategoryRollups) { diff --git a/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java b/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java index fd2ad87382..e3c5034e4d 100644 --- a/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java +++ b/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java @@ -162,9 +162,12 @@ public class ProductConfigItemContentWrapper implements java.io.Serializable { } } - List productConfigItemContentList = delegator.findByAnd("ProdConfItemContent", UtilMisc.toMap("configItemId", configItemId, "confItemContentTypeId", confItemContentTypeId), UtilMisc.toList("-fromDate"), true); - productConfigItemContentList = EntityUtil.filterByDate(productConfigItemContentList); - GenericValue productConfigItemContent = EntityUtil.getFirst(productConfigItemContentList); + GenericValue productConfigItemContent = EntityQuery.use(delegator).from("ProdConfItemContent") + .where("configItemId", configItemId, "confItemContentTypeId", confItemContentTypeId) + .orderBy("-fromDate") + .cache(true) + .filterByDate() + .queryFirst(); if (productConfigItemContent != null) { // when rendering the product config item content, always include the ProductConfigItem and ProdConfItemContent records that this comes from Map inContext = FastMap.newInstance(); diff --git a/applications/product/src/org/ofbiz/product/config/ProductConfigWorker.java b/applications/product/src/org/ofbiz/product/config/ProductConfigWorker.java index ddfbbcc62a..08068dfa38 100644 --- a/applications/product/src/org/ofbiz/product/config/ProductConfigWorker.java +++ b/applications/product/src/org/ofbiz/product/config/ProductConfigWorker.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Enumeration; + import javax.servlet.http.HttpServletRequest; import javolution.util.FastList; @@ -35,6 +36,7 @@ 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.EntityQuery; import org.ofbiz.product.catalog.CatalogWorker; import org.ofbiz.product.config.ProductConfigWrapper.ConfigItem; import org.ofbiz.product.config.ProductConfigWrapper.ConfigOption; @@ -210,7 +212,7 @@ public class ProductConfigWorker { configItemId = ci.getConfigItemAssoc().getString("configItemId"); sequenceNum = ci.getConfigItemAssoc().getLong("sequenceNum"); try { - List configs = delegator.findByAnd("ProductConfigConfig", UtilMisc.toMap("configItemId",configItemId,"sequenceNum", sequenceNum), null, false); + List configs = EntityQuery.use(delegator).from("ProductConfigConfig").where("configItemId",configItemId,"sequenceNum", sequenceNum).queryList(); for (GenericValue productConfigConfig: configs) { for (ConfigOption oneOption: selectedOptions) { String configOptionId = oneOption.configOption.getString("configOptionId"); @@ -233,9 +235,9 @@ public class ProductConfigWorker { for (GenericValue productConfigConfig: configsToCheck) { String tempConfigId = productConfigConfig.getString("configId"); try { - List tempResult = delegator.findByAnd("ProductConfigConfig", UtilMisc.toMap("configId",tempConfigId), null, false); + List tempResult = EntityQuery.use(delegator).from("ProductConfigConfig").where("configId",tempConfigId).queryList(); if (tempResult.size() == selectedOptionSize && configsToCheck.containsAll(tempResult)) { - List configOptionProductOptions = delegator.findByAnd("ConfigOptionProductOption", UtilMisc.toMap("configId",tempConfigId), null, false); + List configOptionProductOptions = EntityQuery.use(delegator).from("ConfigOptionProductOption").where("configId",tempConfigId).queryList(); if (UtilValidate.isNotEmpty(configOptionProductOptions)) { // check for variant product equality diff --git a/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java b/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java index 0004e029d3..ebd2f5801d 100644 --- a/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java +++ b/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java @@ -125,8 +125,7 @@ public class ProductConfigWrapper implements Serializable { } questions = FastList.newInstance(); if ("AGGREGATED".equals(product.getString("productTypeId")) || "AGGREGATED_SERVICE".equals(product.getString("productTypeId"))) { - List questionsValues = delegator.findByAnd("ProductConfig", UtilMisc.toMap("productId", productId), UtilMisc.toList("sequenceNum"), false); - questionsValues = EntityUtil.filterByDate(questionsValues); + List questionsValues = EntityQuery.use(delegator).from("ProductConfig").where("productId", productId).orderBy("sequenceNum").filterByDate().queryList(); Set itemIds = FastSet.newInstance(); for (GenericValue questionsValue: questionsValues) { ConfigItem oneQuestion = new ConfigItem(questionsValue); @@ -137,7 +136,7 @@ public class ProductConfigWrapper implements Serializable { itemIds.add(oneQuestion.getConfigItem().getString("configItemId")); } questions.add(oneQuestion); - List configOptions = delegator.findByAnd("ProductConfigOption", UtilMisc.toMap("configItemId", oneQuestion.getConfigItemAssoc().getString("configItemId")), UtilMisc.toList("sequenceNum"), false); + List configOptions = EntityQuery.use(delegator).from("ProductConfigOption").where("configItemId", oneQuestion.getConfigItemAssoc().getString("configItemId")).orderBy("sequenceNum").queryList(); for (GenericValue configOption: configOptions) { ConfigOption option = new ConfigOption(delegator, dispatcher, configOption, oneQuestion, catalogId, webSiteId, currencyUomId, autoUserLogin); oneQuestion.addOption(option); @@ -151,7 +150,7 @@ public class ProductConfigWrapper implements Serializable { //configure ProductConfigWrapper according to ProductConfigConfig entity if (UtilValidate.isNotEmpty(configId)) { this.configId = configId; - List productConfigConfig = delegator.findByAnd("ProductConfigConfig", UtilMisc.toMap("configId", configId), null, false); + List productConfigConfig = EntityQuery.use(delegator).from("ProductConfigConfig").where("configId", configId).queryList(); if (UtilValidate.isNotEmpty(productConfigConfig)) { for (GenericValue pcc: productConfigConfig) { String configItemId = pcc.getString("configItemId"); diff --git a/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java b/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java index e008ac4c6a..57c1e6cd6d 100644 --- a/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java +++ b/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java @@ -64,11 +64,11 @@ public class ParametricSearch { public static Map> makeCategoryFeatureLists(String productCategoryId, Delegator delegator, int perTypeMaxSize) { Map> productFeaturesByTypeMap = FastMap.newInstance(); try { - List productFeatureCategoryAppls = delegator.findByAnd("ProductFeatureCategoryAppl", UtilMisc.toMap("productCategoryId", productCategoryId), null, true); + List productFeatureCategoryAppls = EntityQuery.use(delegator).from("ProductFeatureCategoryAppl").where("productCategoryId", productCategoryId).cache(true).queryList(); productFeatureCategoryAppls = EntityUtil.filterByDate(productFeatureCategoryAppls, true); if (productFeatureCategoryAppls != null) { for (GenericValue productFeatureCategoryAppl: productFeatureCategoryAppls) { - List productFeatures = delegator.findByAnd("ProductFeature", UtilMisc.toMap("productFeatureCategoryId", productFeatureCategoryAppl.get("productFeatureCategoryId")), null, true); + List productFeatures = EntityQuery.use(delegator).from("ProductFeature").where("productFeatureCategoryId", productFeatureCategoryAppl.get("productFeatureCategoryId")).cache(true).queryList(); for (GenericValue productFeature: productFeatures) { String productFeatureTypeId = productFeature.getString("productFeatureTypeId"); Map featuresByType = productFeaturesByTypeMap.get(productFeatureTypeId); @@ -87,11 +87,11 @@ public class ParametricSearch { } try { - List productFeatureCatGrpAppls = delegator.findByAnd("ProductFeatureCatGrpAppl", UtilMisc.toMap("productCategoryId", productCategoryId), null, true); + List productFeatureCatGrpAppls = EntityQuery.use(delegator).from("ProductFeatureCatGrpAppl").where("productCategoryId", productCategoryId).cache(true).queryList(); productFeatureCatGrpAppls = EntityUtil.filterByDate(productFeatureCatGrpAppls, true); if (productFeatureCatGrpAppls != null) { for (GenericValue productFeatureCatGrpAppl: productFeatureCatGrpAppls) { - List productFeatureGroupAppls = delegator.findByAnd("ProductFeatureGroupAppl", UtilMisc.toMap("productFeatureGroupId", productFeatureCatGrpAppl.get("productFeatureGroupId")), null, true); + List productFeatureGroupAppls = EntityQuery.use(delegator).from("ProductFeatureGroupAppl").where("productFeatureGroupId", productFeatureCatGrpAppl.get("productFeatureGroupId")).cache(true).queryList(); for (GenericValue productFeatureGroupAppl: productFeatureGroupAppls) { GenericValue productFeature = EntityQuery.use(delegator).from("ProductFeature").where("productFeatureId", productFeatureGroupAppl.get("productFeatureId")).cache().queryOne(); @@ -128,7 +128,7 @@ public class ParametricSearch { Map> productFeaturesByTypeMap = FastMap.newInstance(); try { Set typesWithOverflowMessages = FastSet.newInstance(); - EntityListIterator productFeatureEli = delegator.find("ProductFeature", null, null, null, UtilMisc.toList("description"), null); + EntityListIterator productFeatureEli = EntityQuery.use(delegator).from("ProductFeature").orderBy("description").queryIterator(); GenericValue productFeature = null; while ((productFeature = productFeatureEli.next()) != null) { String productFeatureTypeId = productFeature.getString("productFeatureTypeId"); diff --git a/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java b/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java index f09197fc12..ea07130e60 100644 --- a/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java +++ b/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java @@ -36,6 +36,7 @@ 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.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; @@ -93,7 +94,7 @@ public class ProductFeatureServices { try { // get all product features in this feature category - List allFeatures = delegator.findByAnd(entityToSearch, UtilMisc.toMap(fieldToSearch, valueToSearch), orderBy, false); + List allFeatures = EntityQuery.use(delegator).from(entityToSearch).where(fieldToSearch, valueToSearch).orderBy(orderBy).queryList(); if (entityToSearch.equals("ProductFeatureAndAppl") && productFeatureApplTypeId != null) allFeatures = EntityUtil.filterByAnd(allFeatures, UtilMisc.toMap("productFeatureApplTypeId", productFeatureApplTypeId)); @@ -141,7 +142,7 @@ public class ProductFeatureServices { * see if it has every single feature in the list of productFeatureAppls as a STANDARD_FEATURE. If so, then * it qualifies and add it to the list of existingVariantProductIds. */ - List productAssocs = EntityUtil.filterByDate(delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT"), null, false)); + List productAssocs = EntityQuery.use(delegator).from("ProductAssoc").where("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT").filterByDate().queryList(); for (GenericValue productAssoc: productAssocs) { //for each associated product, if it has all standard features, display it's productId @@ -153,7 +154,7 @@ public class ProductFeatureServices { //Debug.logInfo("Using findByMap: " + findByMap); - List standardProductFeatureAndAppls = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAppl", findByMap, null, false)); + List standardProductFeatureAndAppls = EntityQuery.use(delegator).from("ProductFeatureAppl").where(findByMap).filterByDate().queryList(); if (UtilValidate.isEmpty(standardProductFeatureAndAppls)) { // Debug.logInfo("Does NOT have this standard feature"); hasAllFeatures = false; diff --git a/applications/product/src/org/ofbiz/product/imagemanagement/FrameImage.java b/applications/product/src/org/ofbiz/product/imagemanagement/FrameImage.java index 901e469099..d5098756f3 100644 --- a/applications/product/src/org/ofbiz/product/imagemanagement/FrameImage.java +++ b/applications/product/src/org/ofbiz/product/imagemanagement/FrameImage.java @@ -412,8 +412,7 @@ public class FrameImage { String frameDataResourceId = null; try { - List contentDataResources = delegator.findByAnd("ContentDataResourceView", UtilMisc.toMap("contentId", frameContentId), null, false); - GenericValue contentDataResource = EntityUtil.getFirst(contentDataResources); + GenericValue contentDataResource = EntityQuery.use(delegator).from("ContentDataResourceView").where("contentId", frameContentId).queryFirst(); frameDataResourceId = contentDataResource.getString("dataResourceId"); } catch (Exception e) { request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); diff --git a/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementHelper.java b/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementHelper.java index 05fbdc14d9..bb05907730 100644 --- a/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementHelper.java +++ b/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementHelper.java @@ -29,6 +29,7 @@ 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.EntityQuery; import org.ofbiz.entity.util.EntityUtil; public class ImageManagementHelper { @@ -40,14 +41,14 @@ public class ImageManagementHelper { if (request == null) return internalImageUrl; try { Delegator delegator = (Delegator) request.getAttribute("delegator"); - List defaultImageList = delegator.findByAnd("ProductContentAndInfo", UtilMisc.toMap("productId", productId, "productContentTypeId", "DEFAULT_IMAGE", "statusId", "IM_APPROVED", "drIsPublic", "N"), UtilMisc.toList("sequenceNum"), false); + List defaultImageList = EntityQuery.use(delegator).from("ProductContentAndInfo").where("productId", productId, "productContentTypeId", "DEFAULT_IMAGE", "statusId", "IM_APPROVED", "drIsPublic", "N").orderBy("sequenceNum").queryList(); if (UtilValidate.isNotEmpty(defaultImageList)) { GenericValue productContent = EntityUtil.getFirst(defaultImageList); if (UtilValidate.isNotEmpty(productContent.get("drObjectInfo"))) { internalImageUrl = (String) productContent.get("drObjectInfo"); } } else { - List productContentList = delegator.findByAnd("ProductContentAndInfo", UtilMisc.toMap("productId", productId, "productContentTypeId", "IMAGE", "statusId", "IM_APPROVED", "drIsPublic", "N"), UtilMisc.toList("sequenceNum"), false); + List productContentList = EntityQuery.use(delegator).from("ProductContentAndInfo").where("productId", productId, "productContentTypeId", "IMAGE", "statusId", "IM_APPROVED", "drIsPublic", "N").orderBy("sequenceNum").queryList(); if (UtilValidate.isNotEmpty(productContentList)) { GenericValue productContent = EntityUtil.getFirst(productContentList); if (UtilValidate.isNotEmpty(productContent.get("drObjectInfo"))) { diff --git a/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java b/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java index 586b29bea3..24d20d1f84 100644 --- a/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java +++ b/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java @@ -131,7 +131,7 @@ public class ImageManagementServices { List fileExtension = FastList.newInstance(); try { - fileExtension = delegator.findByAnd("FileExtension", UtilMisc.toMap("mimeTypeId", fileContentType ), null, false); + fileExtension = EntityQuery.use(delegator).from("FileExtension").where("mimeTypeId", fileContentType).queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); @@ -543,7 +543,7 @@ public class ImageManagementServices { List fileExtensionThumb = FastList.newInstance(); try { - fileExtensionThumb = delegator.findByAnd("FileExtension", UtilMisc.toMap("mimeTypeId", fileContentType), null, false); + fileExtensionThumb = EntityQuery.use(delegator).from("FileExtension").where("mimeTypeId", fileContentType).queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); @@ -795,8 +795,7 @@ public class ImageManagementServices { String imageUrl = imageServerUrl + "/" + productId + "/" + filenameToUse; try { - List productContentList = delegator.findByAnd("ProductContentAndInfo", UtilMisc.toMap("productId", productId, "contentId", contentId, "productContentTypeId", "IMAGE"), null, false); - GenericValue productContent = EntityUtil.getFirst(productContentList); + GenericValue productContent = EntityQuery.use(delegator).from("ProductContentAndInfo").where("productId", productId, "contentId", contentId, "productContentTypeId", "IMAGE").queryFirst(); String dataResourceName = (String) productContent.get("drDataResourceName"); String mimeType = filenameToUse.substring(filenameToUse.lastIndexOf(".")); @@ -848,12 +847,12 @@ public class ImageManagementServices { } } - List contentAssocList = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentId, "contentAssocTypeId", "IMAGE_THUMBNAIL"), null, false); + List contentAssocList = EntityQuery.use(delegator).from("ContentAssoc").where("contentId", contentId, "contentAssocTypeId", "IMAGE_THUMBNAIL").queryList(); if (contentAssocList.size() > 0) { for (int i = 0; i < contentAssocList.size(); i++) { GenericValue contentAssoc = contentAssocList.get(i); - List dataResourceAssocList = delegator.findByAnd("ContentDataResourceView", UtilMisc.toMap("contentId", contentAssoc.get("contentIdTo")), null, false); + List dataResourceAssocList = EntityQuery.use(delegator).from("ContentDataResourceView").where("contentId", contentAssoc.get("contentIdTo")).queryList(); GenericValue dataResourceAssoc = EntityUtil.getFirst(dataResourceAssocList); String drDataResourceNameAssoc = (String) dataResourceAssoc.get("drDataResourceName"); diff --git a/applications/product/src/org/ofbiz/product/imagemanagement/ReplaceImage.java b/applications/product/src/org/ofbiz/product/imagemanagement/ReplaceImage.java index 3531f238a2..184cb8b69b 100644 --- a/applications/product/src/org/ofbiz/product/imagemanagement/ReplaceImage.java +++ b/applications/product/src/org/ofbiz/product/imagemanagement/ReplaceImage.java @@ -34,6 +34,7 @@ import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.LocalDispatcher; @@ -79,19 +80,16 @@ public class ReplaceImage{ BufferedImage bufImg = ImageIO.read(new File(imageServerPath + "/" + productId + "/" + dataResourceNameReplace)); ImageIO.write(bufImg, "jpg", new File(imageServerPath + "/" + productId + "/" + dataResourceNameExist)); - List contentAssocReplaceList = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentIdReplace, "contentAssocTypeId", "IMAGE_THUMBNAIL"), null, false); + List contentAssocReplaceList = EntityQuery.use(delegator).from("ContentAssoc").where("contentId", contentIdReplace, "contentAssocTypeId", "IMAGE_THUMBNAIL").queryList(); if (contentAssocReplaceList.size() > 0) { for (int i = 0; i < contentAssocReplaceList.size(); i++) { GenericValue contentAssocReplace = contentAssocReplaceList.get(i); - List dataResourceAssocReplaceList = delegator.findByAnd("ContentDataResourceView", UtilMisc.toMap("contentId", contentAssocReplace.get("contentIdTo")), null, false); - GenericValue dataResourceAssocReplace = EntityUtil.getFirst(dataResourceAssocReplaceList); + GenericValue dataResourceAssocReplace = EntityQuery.use(delegator).from("ContentDataResourceView").where("contentId", contentAssocReplace.get("contentIdTo")).queryFirst(); - List contentAssocExistList = delegator.findByAnd("ContentAssoc", UtilMisc.toMap("contentId", contentIdExist, "contentAssocTypeId", "IMAGE_THUMBNAIL", "mapKey", contentAssocReplace.get("mapKey")), null, false); - GenericValue contentAssocExist = EntityUtil.getFirst(contentAssocExistList); + GenericValue contentAssocExist = EntityQuery.use(delegator).from("ContentAssoc").where("contentId", contentIdExist, "contentAssocTypeId", "IMAGE_THUMBNAIL", "mapKey", contentAssocReplace.get("mapKey")).queryFirst(); - List dataResourceAssocExistList = delegator.findByAnd("ContentDataResourceView", UtilMisc.toMap("contentId", contentAssocExist.get("contentIdTo")), null, false); - GenericValue dataResourceAssocExist = EntityUtil.getFirst(dataResourceAssocExistList); + GenericValue dataResourceAssocExist = EntityQuery.use(delegator).from("ContentDataResourceView").where("contentId", contentAssocExist.get("contentIdTo")).queryFirst(); if (UtilValidate.isNotEmpty(dataResourceAssocExist)) { BufferedImage bufImgAssocReplace = ImageIO.read(new File(imageServerPath + "/" + productId + "/" + dataResourceAssocReplace.get("drDataResourceName"))); @@ -104,8 +102,7 @@ public class ReplaceImage{ } } - List productContentList = delegator.findByAnd("ProductContent", UtilMisc.toMap("productId", productId, "contentId", contentIdReplace, "productContentTypeId", "IMAGE"), null, false); - GenericValue productContent = EntityUtil.getFirst(productContentList); + GenericValue productContent = EntityQuery.use(delegator).from("ProductContent").where("productId", productId, "contentId", contentIdReplace, "productContentTypeId", "IMAGE").queryFirst(); if (productContent != null) { Map productContentCtx = FastMap.newInstance(); diff --git a/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java b/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java index 31606b1d4d..9a106c96a2 100644 --- a/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java +++ b/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java @@ -226,8 +226,7 @@ public class InventoryServices { Locale locale = (Locale) context.get("locale"); try { - inventoryTransfer = delegator.findOne("InventoryTransfer", - UtilMisc.toMap("inventoryTransferId", inventoryTransferId), false); + inventoryTransfer = EntityQuery.use(delegator).from("InventoryTransfer").where("inventoryTransferId", inventoryTransferId).queryOne(); inventoryItem = inventoryTransfer.getRelatedOne("InventoryItem", false); destinationFacility = inventoryTransfer.getRelatedOne("ToFacility", false); } catch (GenericEntityException e) { @@ -339,8 +338,7 @@ public class InventoryServices { Locale locale = (Locale) context.get("locale"); try { - inventoryTransfer = delegator.findOne("InventoryTransfer", - UtilMisc.toMap("inventoryTransferId", inventoryTransferId), false); + inventoryTransfer = EntityQuery.use(delegator).from("InventoryTransfer").where("inventoryTransferId", inventoryTransferId).queryOne(); if (UtilValidate.isEmpty(inventoryTransfer)) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductInventoryItemTransferNotFound", @@ -429,8 +427,7 @@ public class InventoryServices { // find all inventory items w/ a negative ATP List inventoryItems = null; try { - EntityExpr ee = EntityCondition.makeCondition("availableToPromiseTotal", EntityOperator.LESS_THAN, BigDecimal.ZERO); - inventoryItems = delegator.findList("InventoryItem", ee, null, null, null, false); + inventoryItems = EntityQuery.use(delegator).from("InventoryItem").where(EntityCondition.makeCondition("availableToPromiseTotal", EntityOperator.LESS_THAN, BigDecimal.ZERO)).queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Trouble getting inventory items", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, @@ -454,8 +451,7 @@ public class InventoryServices { exprs.add(EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "SHIPMENT_DELIVERED")); exprs.add(EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "SHIPMENT_CANCELLED")); - EntityConditionList ecl = EntityCondition.makeCondition(exprs, EntityOperator.AND); - shipmentAndItems = delegator.findList("ShipmentAndItem", ecl, null, UtilMisc.toList("estimatedArrivalDate"), null, false); + shipmentAndItems = EntityQuery.use(delegator).from("ShipmentAndItem").where(EntityCondition.makeCondition(exprs, EntityOperator.AND)).orderBy("estimatedArrivalDate").queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Problem getting ShipmentAndItem records", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, @@ -593,8 +589,7 @@ public class InventoryServices { List orderItemShipGroups = null; try { - orderItemShipGroups= delegator.findByAnd("OrderItemShipGroup", - UtilMisc.toMap("orderId", orderId), null, false); + orderItemShipGroups= EntityQuery.use(delegator).from("OrderItemShipGroup").where("orderId", orderId).queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Cannot get OrderItemShipGroups from orderId" + orderId, module); } @@ -603,12 +598,7 @@ public class InventoryServices { List orderItems = FastList.newInstance(); List orderItemShipGroupAssoc = null; try { - orderItemShipGroupAssoc = - delegator.findByAnd("OrderItemShipGroupAssoc", - UtilMisc.toMap("shipGroupSeqId", - orderItemShipGroup.get("shipGroupSeqId"), - "orderId", - orderId), null, false); + orderItemShipGroupAssoc = EntityQuery.use(delegator).from("OrderItemShipGroupAssoc").where("shipGroupSeqId", orderItemShipGroup.get("shipGroupSeqId"), "orderId", orderId).queryList(); for (GenericValue assoc: orderItemShipGroupAssoc) { GenericValue orderItem = assoc.getRelatedOne("OrderItem", false); @@ -784,9 +774,9 @@ public class InventoryServices { List facilities = null; try { if (facilityId != null) { - facilities = delegator.findByAnd("Facility", UtilMisc.toMap("facilityId", facilityId), null, false); + facilities = EntityQuery.use(delegator).from("Facility").where("facilityId", facilityId).queryList(); } else { - facilities = delegator.findList("Facility", null, null, null, null, false); + facilities = EntityQuery.use(delegator).from("Facility").queryList(); } } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, @@ -921,7 +911,7 @@ public class InventoryServices { List productPrices = null; try { - productPrices = delegator.findByAnd("ProductPrice", UtilMisc.toMap("productId",productId), UtilMisc.toList("-fromDate"), true); + productPrices = EntityQuery.use(delegator).from("ProductPrice").where("productId",productId).orderBy("-fromDate").cache(true).queryList(); } catch (GenericEntityException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -979,17 +969,16 @@ public class InventoryServices { // Make a query against the sales usage view entity EntityListIterator salesUsageIt = null; try { - salesUsageIt = delegator.findListIteratorByCondition(salesUsageViewEntity, - EntityCondition.makeCondition( - UtilMisc.toList( - EntityCondition.makeCondition("facilityId", EntityOperator.EQUALS, facilityId), - EntityCondition.makeCondition("productId", EntityOperator.EQUALS, productId), - EntityCondition.makeCondition("statusId", EntityOperator.IN, UtilMisc.toList("ORDER_COMPLETED", "ORDER_APPROVED", "ORDER_HELD")), - EntityCondition.makeCondition("orderTypeId", EntityOperator.EQUALS, "SALES_ORDER"), - EntityCondition.makeCondition("orderDate", EntityOperator.GREATER_THAN_EQUAL_TO, checkTime) - ), - EntityOperator.AND), - null, null, null, null); + EntityCondition cond = EntityCondition.makeCondition( + UtilMisc.toList( + EntityCondition.makeCondition("facilityId", EntityOperator.EQUALS, facilityId), + EntityCondition.makeCondition("productId", EntityOperator.EQUALS, productId), + EntityCondition.makeCondition("statusId", EntityOperator.IN, UtilMisc.toList("ORDER_COMPLETED", "ORDER_APPROVED", "ORDER_HELD")), + EntityCondition.makeCondition("orderTypeId", EntityOperator.EQUALS, "SALES_ORDER"), + EntityCondition.makeCondition("orderDate", EntityOperator.GREATER_THAN_EQUAL_TO, checkTime) + ), + EntityOperator.AND); + salesUsageIt = EntityQuery.use(delegator).from(salesUsageViewEntity).where(cond).queryIterator(); } catch (GenericEntityException e2) { // TODO Auto-generated catch block e2.printStackTrace(); @@ -1017,16 +1006,15 @@ public class InventoryServices { // Make a query against the production usage view entity EntityListIterator productionUsageIt = null; try { - productionUsageIt = delegator.findListIteratorByCondition(productionUsageViewEntity, - EntityCondition.makeCondition( + EntityCondition conditions = EntityCondition.makeCondition( UtilMisc.toList( EntityCondition.makeCondition("facilityId", EntityOperator.EQUALS, facilityId), EntityCondition.makeCondition("productId", EntityOperator.EQUALS, productId), EntityCondition.makeCondition("workEffortTypeId", EntityOperator.EQUALS, "PROD_ORDER_TASK"), EntityCondition.makeCondition("actualCompletionDate", EntityOperator.GREATER_THAN_EQUAL_TO, checkTime) ), - EntityOperator.AND), - null, null, null, null); + EntityOperator.AND); + productionUsageIt = EntityQuery.use(delegator).from(productionUsageViewEntity).where(conditions).queryIterator(); } catch (GenericEntityException e1) { // TODO Auto-generated catch block e1.printStackTrace(); diff --git a/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java b/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java index d9b86e7ae3..c8a121b838 100644 --- a/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java +++ b/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java @@ -36,6 +36,7 @@ import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.condition.EntityConditionList; import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.util.EntityQuery; public class InventoryWorker { @@ -57,8 +58,10 @@ public class InventoryWorker { EntityCondition.makeCondition("itemStatusId", EntityOperator.NOT_EQUAL, "ITEM_REJECTED")); purchaseOrderConditions.add(EntityCondition.makeCondition("orderTypeId", EntityOperator.EQUALS, "PURCHASE_ORDER")); purchaseOrderConditions.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, productId)); - List purchaseOrders = delegator.findList("OrderHeaderAndItems", EntityCondition.makeCondition(purchaseOrderConditions, EntityOperator.AND), - null, UtilMisc.toList("estimatedDeliveryDate DESC", "orderDate"), null, false); + List purchaseOrders = EntityQuery.use(delegator).from("OrderHeaderAndItems") + .where(EntityCondition.makeCondition(purchaseOrderConditions, EntityOperator.AND)) + .orderBy("estimatedDeliveryDate DESC", "orderDate") + .queryList(); return purchaseOrders; } catch (GenericEntityException ex) { Debug.logError("Unable to find outstanding purchase orders for product [" + productId + "] due to " + ex.getMessage() + " - returning null", module); @@ -123,7 +126,7 @@ public class InventoryWorker { Map results = FastMap.newInstance(); try { - List orderedProducts = delegator.findList("OrderItemQuantityReportGroupByProduct", conditions, fieldsToSelect, null, null, false); + List orderedProducts = EntityQuery.use(delegator).select(fieldsToSelect).from("OrderItemQuantityReportGroupByProduct").where(conditions).queryList(); for (GenericValue value: orderedProducts) { results.put(value.getString("productId"), value.getBigDecimal("quantityOpen")); } diff --git a/applications/product/src/org/ofbiz/product/price/PriceServices.java b/applications/product/src/org/ofbiz/product/price/PriceServices.java index 29c4d7464b..163efab267 100644 --- a/applications/product/src/org/ofbiz/product/price/PriceServices.java +++ b/applications/product/src/org/ofbiz/product/price/PriceServices.java @@ -123,7 +123,7 @@ public class PriceServices { productStoreGroupId = productStore.getString("primaryStoreGroupId"); } else { // no ProductStore.primaryStoreGroupId, try ProductStoreGroupMember - List productStoreGroupMemberList = delegator.findByAnd("ProductStoreGroupMember", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("sequenceNum", "-fromDate"), true); + List productStoreGroupMemberList = EntityQuery.use(delegator).from("ProductStoreGroupMember").where("productStoreId", productStoreId).orderBy("sequenceNum", "-fromDate").cache(true).queryList(); productStoreGroupMemberList = EntityUtil.filterByDate(productStoreGroupMemberList, true); if (productStoreGroupMemberList.size() > 0) { GenericValue productStoreGroupMember = EntityUtil.getFirst(productStoreGroupMemberList); @@ -176,7 +176,7 @@ public class PriceServices { List virtualProductPrices = null; if (virtualProductId != null) { try { - virtualProductPrices = delegator.findByAnd("ProductPrice", UtilMisc.toMap("productId", virtualProductId, "currencyUomId", currencyDefaultUomId, "productStoreGroupId", productStoreGroupId), UtilMisc.toList("-fromDate"), true); + virtualProductPrices = EntityQuery.use(delegator).from("ProductPrice").where("productId", virtualProductId, "currencyUomId", currencyDefaultUomId, "productStoreGroupId", productStoreGroupId).orderBy("-fromDate").cache(true).queryList(); } catch (GenericEntityException e) { Debug.logError(e, "An error occurred while getting the product prices", module); } @@ -222,7 +222,7 @@ public class PriceServices { // for prices, get all ProductPrice entities for this productId and currencyUomId List productPrices = null; try { - productPrices = delegator.findList("ProductPrice", productPriceEc, null, UtilMisc.toList("-fromDate"), null, true); + productPrices = EntityQuery.use(delegator).from("ProductPrice").where(productPriceEc).orderBy("-fromDate").cache(true).queryList(); } catch (GenericEntityException e) { Debug.logError(e, "An error occurred while getting the product prices", module); } @@ -238,8 +238,7 @@ public class PriceServices { // ProductPrice entity. if (UtilValidate.isNotEmpty(agreementId)) { try { - List agreementPrices = delegator.findByAnd("AgreementItemAndProductAppl", UtilMisc.toMap("agreementId", agreementId, "productId", productId, "currencyUomId", currencyDefaultUomId), null, false); - GenericValue agreementPriceValue = EntityUtil.getFirst(agreementPrices); + GenericValue agreementPriceValue = EntityQuery.use(delegator).from("AgreementItemAndProductAppl").where("agreementId", agreementId, "productId", productId, "currencyUomId", currencyDefaultUomId).queryFirst(); if (agreementPriceValue != null && agreementPriceValue.get("price") != null) { defaultPriceValue = agreementPriceValue; } @@ -266,12 +265,12 @@ public class PriceServices { //use the cache to find the variant with the lowest default price try { - List variantAssocList = EntityUtil.filterByDate(delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", product.get("productId"), "productAssocTypeId", "PRODUCT_VARIANT"), UtilMisc.toList("-fromDate"), true)); + List variantAssocList = EntityQuery.use(delegator).from("ProductAssoc").where("productId", product.get("productId"), "productAssocTypeId", "PRODUCT_VARIANT").orderBy("-fromDate").cache(true).filterByDate().queryList(); BigDecimal minDefaultPrice = null; List variantProductPrices = null; for (GenericValue variantAssoc: variantAssocList) { String curVariantProductId = variantAssoc.getString("productIdTo"); - List curVariantPriceList = EntityUtil.filterByDate(delegator.findByAnd("ProductPrice", UtilMisc.toMap("productId", curVariantProductId), UtilMisc.toList("-fromDate"), true), nowTimestamp); + List curVariantPriceList = EntityQuery.use(delegator).from("ProductPrice").where("productId", curVariantProductId).orderBy("-fromDate").cache(true).filterByDate(nowTimestamp).queryList(); List tempDefaultPriceList = EntityUtil.filterByAnd(curVariantPriceList, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); GenericValue curDefaultPriceValue = EntityUtil.getFirst(tempDefaultPriceList); if (curDefaultPriceValue != null) { @@ -430,7 +429,7 @@ public class PriceServices { quantityProductPriceRules = FastList.newInstance(); nonQuantityProductPriceRules = FastList.newInstance(); for (GenericValue productPriceRule: allProductPriceRules) { - List productPriceCondList = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("productPriceRuleId", productPriceRule.get("productPriceRuleId")), null, true); + List productPriceCondList = EntityQuery.use(delegator).from("ProductPriceCond").where("productPriceRuleId", productPriceRule.get("productPriceRuleId")).cache(true).queryList(); boolean foundQuantityInputParam = false; // only consider a rule if all conditions except the quantity condition are true @@ -655,7 +654,7 @@ public class PriceServices { // by productCategoryId // for we will always include any rules that go by category, shouldn't be too many to iterate through each time and will save on cache entries // note that we always want to put the category, quantity, etc ones that find all rules with these conditions in separate cache lists so that they can be easily cleared - Collection productCategoryIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_CAT_ID"), null, true); + Collection productCategoryIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PROD_CAT_ID").cache(true).queryList(); if (UtilValidate.isNotEmpty(productCategoryIdConds)) { for (GenericValue productCategoryIdCond: productCategoryIdConds) { productPriceRuleIds.add(productCategoryIdCond.getString("productPriceRuleId")); @@ -663,7 +662,7 @@ public class PriceServices { } // by productFeatureId - Collection productFeatureIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_FEAT_ID"), null, true); + Collection productFeatureIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PROD_FEAT_ID").cache(true).queryList(); if (UtilValidate.isNotEmpty(productFeatureIdConds)) { for (GenericValue productFeatureIdCond: productFeatureIdConds) { productPriceRuleIds.add(productFeatureIdCond.getString("productPriceRuleId")); @@ -673,7 +672,7 @@ public class PriceServices { // by quantity -- should we really do this one, ie is it necessary? // we could say that all rules with quantity on them must have one of these other values // but, no we'll do it the other way, any that have a quantity will always get compared - Collection quantityConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_QUANTITY"), null, true); + Collection quantityConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_QUANTITY").cache(true).queryList(); if (UtilValidate.isNotEmpty(quantityConds)) { for (GenericValue quantityCond: quantityConds) { productPriceRuleIds.add(quantityCond.getString("productPriceRuleId")); @@ -681,7 +680,7 @@ public class PriceServices { } // by roleTypeId - Collection roleTypeIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_ROLE_TYPE"), null, true); + Collection roleTypeIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_ROLE_TYPE").cache(true).queryList(); if (UtilValidate.isNotEmpty(roleTypeIdConds)) { for (GenericValue roleTypeIdCond: roleTypeIdConds) { productPriceRuleIds.add(roleTypeIdCond.getString("productPriceRuleId")); @@ -693,7 +692,7 @@ public class PriceServices { // later: (by partyClassificationTypeId) // by listPrice - Collection listPriceConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_LIST_PRICE"), null, true); + Collection listPriceConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_LIST_PRICE").cache(true).queryList(); if (UtilValidate.isNotEmpty(listPriceConds)) { for (GenericValue listPriceCond: listPriceConds) { productPriceRuleIds.add(listPriceCond.getString("productPriceRuleId")); @@ -703,7 +702,7 @@ public class PriceServices { // ------- These are all of them that DO depend on the current inputs ------- // by productId - Collection productIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", productId), null, true); + Collection productIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", productId).cache(true).queryList(); if (UtilValidate.isNotEmpty(productIdConds)) { for (GenericValue productIdCond: productIdConds) { productPriceRuleIds.add(productIdCond.getString("productPriceRuleId")); @@ -712,7 +711,7 @@ public class PriceServices { // by virtualProductId, if not null if (virtualProductId != null) { - Collection virtualProductIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", virtualProductId), null, true); + Collection virtualProductIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", virtualProductId).cache(true).queryList(); if (UtilValidate.isNotEmpty(virtualProductIdConds)) { for (GenericValue virtualProductIdCond: virtualProductIdConds) { productPriceRuleIds.add(virtualProductIdCond.getString("productPriceRuleId")); @@ -722,7 +721,7 @@ public class PriceServices { // by prodCatalogId - which is optional in certain cases if (UtilValidate.isNotEmpty(prodCatalogId)) { - Collection prodCatalogIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_CLG_ID", "condValue", prodCatalogId), null, true); + Collection prodCatalogIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PROD_CLG_ID", "condValue", prodCatalogId).cache(true).queryList(); if (UtilValidate.isNotEmpty(prodCatalogIdConds)) { for (GenericValue prodCatalogIdCond: prodCatalogIdConds) { productPriceRuleIds.add(prodCatalogIdCond.getString("productPriceRuleId")); @@ -732,7 +731,7 @@ public class PriceServices { // by productStoreGroupId if (UtilValidate.isNotEmpty(productStoreGroupId)) { - Collection storeGroupConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_SGRP_ID", "condValue", productStoreGroupId), null, true); + Collection storeGroupConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PROD_SGRP_ID", "condValue", productStoreGroupId).cache(true).queryList(); if (UtilValidate.isNotEmpty(storeGroupConds)) { for (GenericValue storeGroupCond: storeGroupConds) { productPriceRuleIds.add(storeGroupCond.getString("productPriceRuleId")); @@ -742,7 +741,7 @@ public class PriceServices { // by webSiteId if (UtilValidate.isNotEmpty(webSiteId)) { - Collection webSiteIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_WEBSITE_ID", "condValue", webSiteId), null, true); + Collection webSiteIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_WEBSITE_ID", "condValue", webSiteId).cache(true).queryList(); if (UtilValidate.isNotEmpty(webSiteIdConds)) { for (GenericValue webSiteIdCond: webSiteIdConds) { productPriceRuleIds.add(webSiteIdCond.getString("productPriceRuleId")); @@ -752,7 +751,7 @@ public class PriceServices { // by partyId if (UtilValidate.isNotEmpty(partyId)) { - Collection partyIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PARTY_ID", "condValue", partyId), null, true); + Collection partyIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_PARTY_ID", "condValue", partyId).cache(true).queryList(); if (UtilValidate.isNotEmpty(partyIdConds)) { for (GenericValue partyIdCond: partyIdConds) { productPriceRuleIds.add(partyIdCond.getString("productPriceRuleId")); @@ -761,7 +760,7 @@ public class PriceServices { } // by currencyUomId - Collection currencyUomIdConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_CURRENCY_UOMID", "condValue", currencyUomId), null, true); + Collection currencyUomIdConds = EntityQuery.use(delegator).from("ProductPriceCond").where("inputParamEnumId", "PRIP_CURRENCY_UOMID", "condValue", currencyUomId).cache(true).queryList(); if (UtilValidate.isNotEmpty(currencyUomIdConds)) { for (GenericValue currencyUomIdCond: currencyUomIdConds) { productPriceRuleIds.add(currencyUomIdCond.getString("productPriceRuleId")); @@ -780,7 +779,7 @@ public class PriceServices { // EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN, UtilDateTime.nowTimestamp())); // productPriceRules = delegator.findByOr("ProductPriceRule", pprExprs); - productPriceRules = delegator.findList("ProductPriceRule", null, null, null, null, true); + productPriceRules = EntityQuery.use(delegator).from("ProductPriceRule").cache(true).queryList(); if (productPriceRules == null) productPriceRules = FastList.newInstance(); } @@ -830,7 +829,7 @@ public class PriceServices { // check all conditions boolean allTrue = true; StringBuilder condsDescription = new StringBuilder(); - List productPriceConds = delegator.findByAnd("ProductPriceCond", UtilMisc.toMap("productPriceRuleId", productPriceRuleId), null, true); + List productPriceConds = EntityQuery.use(delegator).from("ProductPriceCond").where("productPriceRuleId", productPriceRuleId).cache(true).queryList(); for (GenericValue productPriceCond: productPriceConds) { totalConds++; @@ -872,7 +871,7 @@ public class PriceServices { isSale = true; } - List productPriceActions = delegator.findByAnd("ProductPriceAction", UtilMisc.toMap("productPriceRuleId", productPriceRuleId), null, true); + List productPriceActions = EntityQuery.use(delegator).from("ProductPriceAction").where("productPriceRuleId", productPriceRuleId).cache(true).queryList(); for (GenericValue productPriceAction: productPriceActions) { totalActions++; @@ -1052,10 +1051,12 @@ public class PriceServices { } else if ("PRIP_PROD_CAT_ID".equals(productPriceCond.getString("inputParamEnumId"))) { // if a ProductCategoryMember exists for this productId and the specified productCategoryId String productCategoryId = productPriceCond.getString("condValue"); - List productCategoryMembers = delegator.findByAnd("ProductCategoryMember", - UtilMisc.toMap("productId", productId, "productCategoryId", productCategoryId), null, true); // and from/thru date within range - productCategoryMembers = EntityUtil.filterByDate(productCategoryMembers, nowTimestamp, null, null, true); + List productCategoryMembers = EntityQuery.use(delegator).from("ProductCategoryMember") + .where("productId", productId, "productCategoryId", productCategoryId) + .cache(true) + .filterByDate(nowTimestamp) + .queryList(); // then 0 (equals), otherwise 1 (not equals) if (UtilValidate.isNotEmpty(productCategoryMembers)) { compare = 0; @@ -1067,10 +1068,8 @@ public class PriceServices { // NOTE: this is important becuase of the common scenario where a virtual product is a member of a category but the variants will typically NOT be // NOTE: we may want to parameterize this in the future, ie with an indicator on the ProductPriceCond entity if (compare == 1 && UtilValidate.isNotEmpty(virtualProductId)) { - List virtualProductCategoryMembers = delegator.findByAnd("ProductCategoryMember", - UtilMisc.toMap("productId", virtualProductId, "productCategoryId", productCategoryId), null, true); // and from/thru date within range - virtualProductCategoryMembers = EntityUtil.filterByDate(virtualProductCategoryMembers, nowTimestamp, null, null, true); + List virtualProductCategoryMembers = EntityQuery.use(delegator).from("ProductCategoryMember").where("productId", virtualProductId, "productCategoryId", productCategoryId).cache(true).filterByDate(nowTimestamp).queryList(); if (UtilValidate.isNotEmpty(virtualProductCategoryMembers)) { // we found a member record? great, then this condition is satisfied compare = 0; @@ -1081,10 +1080,8 @@ public class PriceServices { // if a ProductFeatureAppl exists for this productId and the specified productFeatureId String productFeatureId = productPriceCond.getString("condValue"); - List productFeatureAppls = delegator.findByAnd("ProductFeatureAppl", - UtilMisc.toMap("productId", productId, "productFeatureId", productFeatureId), null, true); // and from/thru date within range - productFeatureAppls = EntityUtil.filterByDate(productFeatureAppls, nowTimestamp, null, null, true); + List productFeatureAppls = EntityQuery.use(delegator).from("ProductFeatureAppl").where("productId", productId, "productFeatureId", productFeatureId).cache(true).filterByDate(nowTimestamp).queryList(); // then 0 (equals), otherwise 1 (not equals) if (UtilValidate.isNotEmpty(productFeatureAppls)) { compare = 0; @@ -1135,9 +1132,8 @@ public class PriceServices { // look for PartyRelationship with // partyRelationshipTypeId=GROUP_ROLLUP, the partyIdTo is // the group member, so the partyIdFrom is the groupPartyId - List partyRelationshipList = delegator.findByAnd("PartyRelationship", UtilMisc.toMap("partyIdFrom", groupPartyId, "partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP"), null, true); // and from/thru date within range - partyRelationshipList = EntityUtil.filterByDate(partyRelationshipList, nowTimestamp, null, null, true); + List partyRelationshipList = EntityQuery.use(delegator).from("PartyRelationship").where("partyIdFrom", groupPartyId, "partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP").cache(true).filterByDate(nowTimestamp).queryList(); // then 0 (equals), otherwise 1 (not equals) if (UtilValidate.isNotEmpty(partyRelationshipList)) { compare = 0; @@ -1152,9 +1148,8 @@ public class PriceServices { } else { String partyClassificationGroupId = productPriceCond.getString("condValue"); // find any PartyClassification - List partyClassificationList = delegator.findByAnd("PartyClassification", UtilMisc.toMap("partyId", partyId, "partyClassificationGroupId", partyClassificationGroupId), null, true); // and from/thru date within range - partyClassificationList = EntityUtil.filterByDate(partyClassificationList, nowTimestamp, null, null, true); + List partyClassificationList = EntityQuery.use(delegator).from("PartyClassification").where("partyId", partyId, "partyClassificationGroupId", partyClassificationGroupId).cache(true).filterByDate(nowTimestamp).queryList(); // then 0 (equals), otherwise 1 (not equals) if (UtilValidate.isNotEmpty(partyClassificationList)) { compare = 0; @@ -1165,8 +1160,7 @@ public class PriceServices { } else if ("PRIP_ROLE_TYPE".equals(productPriceCond.getString("inputParamEnumId"))) { if (partyId != null) { // if a PartyRole exists for this partyId and the specified roleTypeId - GenericValue partyRole = delegator.findOne("PartyRole", - UtilMisc.toMap("partyId", partyId, "roleTypeId", productPriceCond.getString("condValue")), true); + GenericValue partyRole = EntityQuery.use(delegator).from("PartyRole").where("partyId", partyId, "roleTypeId", productPriceCond.getString("condValue")).cache(true).queryOne(); // then 0 (equals), otherwise 1 (not equals) if (partyRole != null) { @@ -1210,8 +1204,7 @@ public class PriceServices { } private static int checkConditionPartyHierarchy(Delegator delegator, Timestamp nowTimestamp, String groupPartyId, String partyId) throws GenericEntityException{ - List partyRelationshipList = delegator.findByAnd("PartyRelationship", UtilMisc.toMap("partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP"), null, true); - partyRelationshipList = EntityUtil.filterByDate(partyRelationshipList, nowTimestamp, null, null, true); + List partyRelationshipList = EntityQuery.use(delegator).from("PartyRelationship").where("partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP").cache(true).filterByDate(nowTimestamp).queryList(); for (GenericValue genericValue : partyRelationshipList) { String partyIdFrom = (String)genericValue.get("partyIdFrom"); if (partyIdFrom.equals(groupPartyId)) { @@ -1297,16 +1290,14 @@ public class PriceServices { if (!validPriceFound) { List prices = null; try { - prices = delegator.findByAnd("ProductPrice", UtilMisc.toMap("productId", productId, - "productPricePurposeId", "PURCHASE"), UtilMisc.toList("-fromDate"), false); + prices = EntityQuery.use(delegator).from("ProductPrice").where("productId", productId, "productPricePurposeId", "PURCHASE").orderBy("-fromDate").queryList(); // if no prices are found; find the prices of the parent product if (UtilValidate.isEmpty(prices)) { GenericValue parentProduct = ProductWorker.getParentProduct(productId, delegator); if (parentProduct != null) { String parentProductId = parentProduct.getString("productId"); - prices = delegator.findByAnd("ProductPrice", UtilMisc.toMap("productId", parentProductId, - "productPricePurposeId", "PURCHASE"), UtilMisc.toList("-fromDate"), false); + prices = EntityQuery.use(delegator).from("ProductPrice").where("productId", parentProductId, "productPricePurposeId", "PURCHASE").orderBy("-fromDate").queryList(); } } } catch (GenericEntityException e) { diff --git a/applications/product/src/org/ofbiz/product/product/KeywordIndex.java b/applications/product/src/org/ofbiz/product/product/KeywordIndex.java index e70b87560c..c13d1709e3 100644 --- a/applications/product/src/org/ofbiz/product/product/KeywordIndex.java +++ b/applications/product/src/org/ofbiz/product/product/KeywordIndex.java @@ -38,6 +38,7 @@ import org.ofbiz.content.data.DataResourceWorker; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; /** @@ -117,7 +118,7 @@ public class KeywordIndex { !"0".equals(UtilProperties.getPropertyValue("prodsearch", "index.weight.ProductFeatureAndAppl.abbrev", "0")) || !"0".equals(UtilProperties.getPropertyValue("prodsearch", "index.weight.ProductFeatureAndAppl.idCode", "0"))) { // get strings from attributes and features - List productFeatureAndAppls = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId), null, false); + List productFeatureAndAppls = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId).queryList(); for (GenericValue productFeatureAndAppl: productFeatureAndAppls) { addWeightedKeywordSourceString(productFeatureAndAppl, "description", strings); addWeightedKeywordSourceString(productFeatureAndAppl, "abbrev", strings); @@ -128,7 +129,7 @@ public class KeywordIndex { // ProductAttribute if (!"0".equals(UtilProperties.getPropertyValue("prodsearch", "index.weight.ProductAttribute.attrName", "0")) || !"0".equals(UtilProperties.getPropertyValue("prodsearch", "index.weight.ProductAttribute.attrValue", "0"))) { - List productAttributes = delegator.findByAnd("ProductAttribute", UtilMisc.toMap("productId", productId), null, false); + List productAttributes = EntityQuery.use(delegator).from("ProductAttribute").where("productId", productId).queryList(); for (GenericValue productAttribute: productAttributes) { addWeightedKeywordSourceString(productAttribute, "attrName", strings); addWeightedKeywordSourceString(productAttribute, "attrValue", strings); @@ -137,7 +138,7 @@ public class KeywordIndex { // GoodIdentification if (!"0".equals(UtilProperties.getPropertyValue("prodsearch", "index.weight.GoodIdentification.idValue", "0"))) { - List goodIdentifications = delegator.findByAnd("GoodIdentification", UtilMisc.toMap("productId", productId), null, false); + List goodIdentifications = EntityQuery.use(delegator).from("GoodIdentification").where("productId", productId).queryList(); for (GenericValue goodIdentification: goodIdentifications) { addWeightedKeywordSourceString(goodIdentification, "idValue", strings); } @@ -146,8 +147,7 @@ public class KeywordIndex { // Variant Product IDs if ("Y".equals(product.getString("isVirtual"))) { if (!"0".equals(UtilProperties.getPropertyValue("prodsearch", "index.weight.Variant.Product.productId", "0"))) { - List variantProductAssocs = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT"), null, false); - variantProductAssocs = EntityUtil.filterByDate(variantProductAssocs); + List variantProductAssocs = EntityQuery.use(delegator).from("ProductAssoc").where("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT").filterByDate().queryList(); for (GenericValue variantProductAssoc: variantProductAssocs) { int weight = 1; try { @@ -172,7 +172,7 @@ public class KeywordIndex { Debug.logWarning("Could not parse weight number: " + e.toString(), module); } - List productContentAndInfos = delegator.findByAnd("ProductContentAndInfo", UtilMisc.toMap("productId", productId, "productContentTypeId", productContentTypeId), null, false); + List productContentAndInfos = EntityQuery.use(delegator).from("ProductContentAndInfo").where("productId", productId, "productContentTypeId", productContentTypeId).queryList(); for (GenericValue productContentAndInfo: productContentAndInfos) { addWeightedDataResourceString(productContentAndInfo, weight, strings, delegator, product); diff --git a/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java b/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java index c8f1d53160..b87827210e 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java +++ b/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java @@ -33,7 +33,6 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilHttp; -import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.GeneralRuntimeException; import org.ofbiz.base.util.cache.UtilCache; @@ -178,13 +177,11 @@ public class ProductContentWrapper implements ContentWrapper { } } - List productContentList = delegator.findByAnd("ProductContent", UtilMisc.toMap("productId", productId, "productContentTypeId", productContentTypeId), UtilMisc.toList("-fromDate"), true); - productContentList = EntityUtil.filterByDate(productContentList); + List productContentList = EntityQuery.use(delegator).from("ProductContent").where("productId", productId, "productContentTypeId", productContentTypeId).orderBy("-fromDate").cache(true).filterByDate().queryList(); if (UtilValidate.isEmpty(productContentList) && ("Y".equals(product.getString("isVariant")))) { GenericValue parent = ProductWorker.getParentProduct(productId, delegator); if (UtilValidate.isNotEmpty(parent)) { - productContentList = delegator.findByAnd("ProductContent", UtilMisc.toMap("productId", parent.get("productId"), "productContentTypeId", productContentTypeId), UtilMisc.toList("-fromDate"), true); - productContentList = EntityUtil.filterByDate(productContentList); + productContentList = EntityQuery.use(delegator).from("ProductContent").where("productId", parent.get("productId"), "productContentTypeId", productContentTypeId).orderBy("-fromDate").cache(true).filterByDate().queryList(); } } GenericValue productContent = EntityUtil.getFirst(productContentList); diff --git a/applications/product/src/org/ofbiz/product/product/ProductEvents.java b/applications/product/src/org/ofbiz/product/product/ProductEvents.java index 4e5130db94..eac49f9cbb 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductEvents.java +++ b/applications/product/src/org/ofbiz/product/product/ProductEvents.java @@ -120,10 +120,10 @@ public class ProductEvents { beganTx = TransactionUtil.begin(7200); try { if (Debug.infoOn()) { - long count = delegator.findCountByCondition("Product", condition, null, null); + long count = EntityQuery.use(delegator).from("Product").where(condition).queryCount(); Debug.logInfo("========== Found " + count + " products to index ==========", module); } - entityListIterator = delegator.find("Product", condition, null, null, null, null); + entityListIterator = EntityQuery.use(delegator).from("Product").where(condition).queryIterator(); } catch (GenericEntityException gee) { Debug.logWarning(gee, gee.getMessage(), module); Map messageMap = UtilMisc.toMap("gee", gee.toString()); @@ -281,7 +281,7 @@ public class ProductEvents { GenericValue productAssoc = null; try { - productAssoc = delegator.findOne(tempProductAssoc.getEntityName(), tempProductAssoc.getPrimaryKey(), false); + productAssoc = EntityQuery.use(delegator).from(tempProductAssoc.getEntityName()).where(tempProductAssoc.getPrimaryKey()).queryOne(); } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); productAssoc = null; @@ -354,7 +354,7 @@ public class ProductEvents { GenericValue productAssoc = null; try { - productAssoc = delegator.findOne(tempProductAssoc.getEntityName(), tempProductAssoc.getPrimaryKey(), false); + productAssoc = EntityQuery.use(delegator).from(tempProductAssoc.getEntityName()).where(tempProductAssoc.getPrimaryKey()).queryOne(); } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); productAssoc = null; @@ -454,7 +454,7 @@ public class ProductEvents { BigDecimal ntwt = parseBigDecimalForEntity(request.getParameter("~ntwt")); BigDecimal grams = parseBigDecimalForEntity(request.getParameter("~grams")); - List currentProductFeatureAndAppls = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE"), null, false), true); + List currentProductFeatureAndAppls = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE").filterByDate().queryList(); setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ozUS", "AMOUNT", floz); setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ml", "AMOUNT", ml); setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "WT_g", "AMOUNT", grams); @@ -484,7 +484,7 @@ public class ProductEvents { BigDecimal ntwt = parseBigDecimalForEntity(request.getParameter("~ntwt" + attribIdx)); BigDecimal grams = parseBigDecimalForEntity(request.getParameter("~grams" + attribIdx)); - List currentProductFeatureAndAppls = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE"), null, false), true); + List currentProductFeatureAndAppls = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE").filterByDate().queryList(); setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ozUS", "AMOUNT", floz); setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ml", "AMOUNT", ml); setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "WT_g", "AMOUNT", grams); @@ -557,7 +557,7 @@ public class ProductEvents { // NOTE: if numberSpecified is null then foundOneEqual will always be false, so need to check both if (numberSpecified != null && !foundOneEqual) { String productFeatureId = null; - List existingProductFeatureList = delegator.findByAnd("ProductFeature", UtilMisc.toMap("productFeatureTypeId", productFeatureTypeId, "numberSpecified", numberSpecified, "uomId", uomId), null, false); + List existingProductFeatureList = EntityQuery.use(delegator).from("ProductFeature").where("productFeatureTypeId", productFeatureTypeId, "numberSpecified", numberSpecified, "uomId", uomId).queryList(); if (existingProductFeatureList.size() > 0) { GenericValue existingProductFeature = existingProductFeatureList.get(0); productFeatureId = existingProductFeature.getString("productFeatureId"); @@ -670,8 +670,7 @@ public class ProductEvents { GenericValue productFeatureAndAppl = null; Set descriptionsForThisType = FastSet.newInstance(); - List productFeatureAndApplList = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, - "productFeatureApplTypeId", productFeatureApplTypeId, "productFeatureTypeId", productFeatureTypeId), null, false), true); + List productFeatureAndApplList = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", productFeatureApplTypeId, "productFeatureTypeId", productFeatureTypeId).filterByDate().queryList(); if (productFeatureAndApplList.size() > 0) { Iterator productFeatureAndApplIter = productFeatureAndApplList.iterator(); while (productFeatureAndApplIter.hasNext()) { @@ -723,7 +722,7 @@ public class ProductEvents { // see if a feature exists with the type and description specified (if doesn't exist will create later) String productFeatureId = null; - List existingProductFeatureList = delegator.findByAnd("ProductFeature", UtilMisc.toMap("productFeatureTypeId", productFeatureTypeId, "description", description), null, false); + List existingProductFeatureList = EntityQuery.use(delegator).from("ProductFeature").where("productFeatureTypeId", productFeatureTypeId, "description", description).queryList(); if (existingProductFeatureList.size() > 0) { GenericValue existingProductFeature = existingProductFeatureList.get(0); productFeatureId = existingProductFeature.getString("productFeatureId"); @@ -748,8 +747,7 @@ public class ProductEvents { } // check to see if the productFeatureId is already attached to the virtual or variant, if not attach them... - List specificProductFeatureApplList = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAppl", UtilMisc.toMap("productId", productId, - "productFeatureApplTypeId", productFeatureApplTypeId, "productFeatureId", productFeatureId), null, false), true); + List specificProductFeatureApplList = EntityQuery.use(delegator).from("ProductFeatureAppl").where("productId", productId, "productFeatureApplTypeId", productFeatureApplTypeId, "productFeatureId", productFeatureId).filterByDate().queryList(); if (specificProductFeatureApplList.size() == 0) { delegator.create("ProductFeatureAppl", @@ -831,10 +829,7 @@ public class ProductEvents { if (categoryIds != null) { for (String categoryId: categoryIds) { try { - List catMembs = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap( - "productCategoryId", categoryId, - "productId", productId), null, false); - catMembs = EntityUtil.filterByDate(catMembs); + List catMembs = EntityQuery.use(delegator).from("ProductCategoryMember").where("productCategoryId", categoryId, "productId", productId).filterByDate().queryList(); if (catMembs.size() == 0) { delegator.create("ProductCategoryMember", UtilMisc.toMap("productCategoryId", categoryId, "productId", productId, "fromDate", fromDate)); @@ -859,9 +854,7 @@ public class ProductEvents { thruDate = UtilDateTime.nowTimestamp().toString(); } try { - List prodCatMembs = delegator.findByAnd("ProductCategoryMember", - UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId), null, false); - prodCatMembs = EntityUtil.filterByDate(prodCatMembs); + List prodCatMembs = EntityQuery.use(delegator).from("ProductCategoryMember").where("productCategoryId", productCategoryId, "productId", productId).filterByDate().queryList(); if (prodCatMembs.size() > 0) { // there is one to modify GenericValue prodCatMemb = prodCatMembs.get(0); @@ -890,10 +883,7 @@ public class ProductEvents { try { for (String productFeatureId: productFeatureIdArray) { if (!productFeatureId.equals("~~any~~")) { - List featureAppls = delegator.findByAnd("ProductFeatureAppl", - UtilMisc.toMap("productId", productId, - "productFeatureId", productFeatureId, - "productFeatureApplTypeId", productFeatureApplTypeId), null, false); + List featureAppls = EntityQuery.use(delegator).from("ProductFeatureAppl").where("productId", productId, "productFeatureId", productFeatureId, "productFeatureApplTypeId", productFeatureApplTypeId).queryList(); if (featureAppls.size() == 0) { // no existing application for this delegator.create("ProductFeatureAppl", @@ -963,9 +953,7 @@ public class ProductEvents { if ("Y".equals(productStore.getString("requireCustomerRole"))) { List productStoreRoleList = null; try { - productStoreRoleList = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("productStoreId", productStore.get("productStoreId"), - "partyId", userLogin.get("partyId"), "roleTypeId", "CUSTOMER"), null, false); - productStoreRoleList = EntityUtil.filterByDate(productStoreRoleList, true); + productStoreRoleList = EntityQuery.use(delegator).from("ProductStoreRole").where("productStoreId", productStore.get("productStoreId"), "partyId", userLogin.get("partyId"), "roleTypeId", "CUSTOMER").filterByDate().queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Database error finding CUSTOMER ProductStoreRole records, required by the ProductStore with ID [" + productStore.getString("productStoreId") + "]", module); } @@ -1000,8 +988,7 @@ public class ProductEvents { GenericValue productStoreEmail = null; try { - productStoreEmail = delegator.findOne("ProductStoreEmailSetting", - UtilMisc.toMap("productStoreId", productStoreId, "emailType", emailType), false); + productStoreEmail = EntityQuery.use(delegator).from("ProductStoreEmailSetting").where("productStoreId", productStoreId, "emailType", emailType).queryOne(); } catch (GenericEntityException e) { String errMsg = "Unable to get product store email setting for tell-a-friend: " + e.toString(); Debug.logError(e, errMsg, module); diff --git a/applications/product/src/org/ofbiz/product/product/ProductPromoContentWrapper.java b/applications/product/src/org/ofbiz/product/product/ProductPromoContentWrapper.java index f3e65be3a3..884b6ad2ac 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductPromoContentWrapper.java +++ b/applications/product/src/org/ofbiz/product/product/ProductPromoContentWrapper.java @@ -172,9 +172,8 @@ public class ProductPromoContentWrapper implements ContentWrapper { List exprs = new ArrayList(); exprs.add(EntityCondition.makeCondition("productPromoId", EntityOperator.EQUALS, productPromoId)); exprs.add(EntityCondition.makeCondition("productPromoContentTypeId", EntityOperator.EQUALS, productPromoContentTypeId)); - List orderBy = UtilMisc.toList("-fromDate"); - List productPromoContentList = delegator.findList("ProductPromoContent", EntityCondition.makeCondition(exprs, EntityOperator.AND), null, orderBy, null, true); + List productPromoContentList = EntityQuery.use(delegator).from("ProductPromoContent").where(EntityCondition.makeCondition(exprs, EntityOperator.AND)).orderBy("-fromDate").cache(true).queryList(); GenericValue productPromoContent = null; if (UtilValidate.isNotEmpty(productPromoContentList)) { productPromoContent = EntityUtil.getFirst(EntityUtil.filterByDate(productPromoContentList)); diff --git a/applications/product/src/org/ofbiz/product/product/ProductSearch.java b/applications/product/src/org/ofbiz/product/product/ProductSearch.java index d488f6835d..1cfc29aac3 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductSearch.java +++ b/applications/product/src/org/ofbiz/product/product/ProductSearch.java @@ -122,7 +122,7 @@ public class ProductSearch { // now find all sub-categories, filtered by effective dates, and call this routine for them try { - List productCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId", productCategoryId), null, true); + List productCategoryRollupList = EntityQuery.use(delegator).from("ProductCategoryRollup").where("parentProductCategoryId", productCategoryId).cache(true).queryList(); for (GenericValue productCategoryRollup: productCategoryRollupList) { String subProductCategoryId = productCategoryRollup.getString("productCategoryId"); if (productCategoryIdSet.contains(subProductCategoryId)) { @@ -662,21 +662,23 @@ public class ProductSearch { } dynamicViewEntity.addAlias("PROD", "mainProductId", "productId", null, null, Boolean.valueOf(productIdGroupBy), null); - EntityCondition whereCondition = EntityCondition.makeCondition(entityConditionList, EntityOperator.AND); - EntityFindOptions efo = new EntityFindOptions(); - efo.setDistinct(true); - efo.setResultSetType(EntityFindOptions.TYPE_SCROLL_INSENSITIVE); - if (maxResults != null) { - int queryMaxResults = maxResults; - if (resultOffset != null) { - queryMaxResults += resultOffset - 1; - } - efo.setMaxRows(queryMaxResults); - } EntityListIterator eli = null; try { - eli = delegator.findListIteratorByCondition(dynamicViewEntity, whereCondition, null, fieldsToSelect, orderByList, efo); + int queryMaxResults = 0; + if (maxResults != null) { + queryMaxResults = maxResults; + if (resultOffset != null) { + queryMaxResults += resultOffset - 1; + } + } + eli = EntityQuery.use(delegator).select(UtilMisc.toSet(fieldsToSelect)) + .from(dynamicViewEntity).where(entityConditionList) + .orderBy(orderByList) + .distinct(true) + .maxRows(queryMaxResults) + .cursorScrollInsensitive() + .queryIterator(); } catch (GenericEntityException e) { Debug.logError(e, "Error in product search", module); return null; diff --git a/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java b/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java index ce405149f4..e938737ef9 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java +++ b/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java @@ -43,6 +43,7 @@ import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.transaction.GenericTransactionException; import org.ofbiz.entity.transaction.TransactionUtil; import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.product.product.ProductSearch.ProductSearchContext; import org.ofbiz.product.product.ProductSearch.ResultSortOrder; @@ -143,7 +144,7 @@ public class ProductSearchEvents { while ((searchResultView = eli.next()) != null) { String productId = searchResultView.getString("mainProductId"); //get all tuples that match product and category - List pcmList = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId), null, false); + List pcmList = EntityQuery.use(delegator).from("ProductCategoryMember").where("productCategoryId", productCategoryId, "productId", productId).queryList(); //set those thrudate to that specificed maybe remove then add new one for (GenericValue pcm: pcmList) { @@ -413,15 +414,11 @@ public class ProductSearchEvents { String productId = searchResultView.getString("mainProductId"); productMap.put("productId", productId); - List productFeaturesCustomRaw = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureTypeId", "HAZMAT"), null, false); - List productFeaturesCustom = EntityUtil.filterByDate(productFeaturesCustomRaw); - productMap.put("productFeatureCustom", EntityUtil.getFirst(productFeaturesCustom)); + productMap.put("productFeatureCustom", EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureTypeId", "HAZMAT").filterByDate().queryFirst()); - List productCategoriesRaw = delegator.findByAnd("ProductCategoryAndMember", UtilMisc.toMap("productId", productId), null, false); - List productCategories = EntityUtil.filterByDate(productCategoriesRaw); + List productCategories = EntityQuery.use(delegator).from("ProductCategoryAndMember").where("productId", productId).filterByDate().queryList(); productMap.put("productCategories", productCategories); - List productFeaturesRaw = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId), null, false); - List productFeatures = EntityUtil.filterByDate(productFeaturesRaw); + List productFeatures = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId).filterByDate().queryList(); productMap.put("productFeatures", productFeatures); productExportList.add(productMap); } diff --git a/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java b/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java index 64dd05f876..e02b11dbbb 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java +++ b/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java @@ -53,6 +53,7 @@ import org.ofbiz.entity.model.DynamicViewEntity; import org.ofbiz.entity.model.ModelKeyMap; import org.ofbiz.entity.util.EntityFindOptions; import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.product.catalog.CatalogWorker; import org.ofbiz.product.category.CategoryWorker; @@ -400,8 +401,7 @@ public class ProductSearchSession { if (keywords.size() > 0) { List productStoreKeywordOvrdList = null; try { - productStoreKeywordOvrdList = delegator.findByAnd("ProductStoreKeywordOvrd", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("-fromDate"), true); - productStoreKeywordOvrdList = EntityUtil.filterByDate(productStoreKeywordOvrdList, true); + productStoreKeywordOvrdList = EntityQuery.use(delegator).from("ProductStoreKeywordOvrd").where("productStoreId", productStoreId).orderBy("-fromDate").cache(true).filterByDate().queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Error reading ProductStoreKeywordOvrd list, not doing keyword override", module); } @@ -930,11 +930,16 @@ public class ProductSearchSession { addOnTopProdCondList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN, now))); addOnTopProdCondList.add(EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN, now)); addOnTopProdCondList.add(EntityCondition.makeCondition("productCategoryId", EntityOperator.EQUALS, addOnTopProdCategoryId)); - EntityFindOptions findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true); - findOpts.setMaxRows(highIndex); EntityListIterator pli = null; try { - pli = delegator.find("ProductCategoryMember", EntityCondition.makeCondition(addOnTopProdCondList, EntityOperator.AND), null, UtilMisc.toSet("productId", "sequenceNum"), UtilMisc.toList("sequenceNum"), findOpts); + pli = EntityQuery.use(delegator).select(UtilMisc.toSet("productId", "sequenceNum")) + .from("ProductCategoryMember") + .where(addOnTopProdCondList) + .orderBy("sequenceNum") + .cursorScrollInsensitive() + .distinct() + .maxRows(highIndex) + .queryIterator(); addOnTopProductCategoryMembers = pli.getPartialList(lowIndex, viewSize); addOnTopListSize = addOnTopProductCategoryMembers.size(); for (GenericValue alwaysAddProductCategoryMember: addOnTopProductCategoryMembers) { @@ -1219,7 +1224,6 @@ public class ProductSearchSession { DynamicViewEntity dynamicViewEntity = productSearchContext.dynamicViewEntity; List entityConditionList = productSearchContext.entityConditionList; - List fieldsToSelect = FastList.newInstance(); dynamicViewEntity.addMemberEntity("PFAC", "ProductFeatureAppl"); dynamicViewEntity.addAlias("PFAC", "pfacProductFeatureId", "productFeatureId", null, null, Boolean.TRUE, null); @@ -1227,8 +1231,6 @@ public class ProductSearchSession { dynamicViewEntity.addAlias("PFAC", "pfacThruDate", "thruDate", null, null, null, null); dynamicViewEntity.addAlias("PFAC", "featureCount", "productId", null, null, null, "count-distinct"); dynamicViewEntity.addViewLink("PROD", "PFAC", Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); - fieldsToSelect.add("pfacProductFeatureId"); - fieldsToSelect.add("featureCount"); entityConditionList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("pfacThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("pfacThruDate", EntityOperator.GREATER_THAN, UtilDateTime.nowTimestamp()))); entityConditionList.add(EntityCondition.makeCondition("pfacFromDate", EntityOperator.LESS_THAN, UtilDateTime.nowTimestamp())); @@ -1236,18 +1238,17 @@ public class ProductSearchSession { dynamicViewEntity.addAlias("PFC", "pfcProductFeatureTypeId", "productFeatureTypeId", null, null, Boolean.TRUE, null); dynamicViewEntity.addAlias("PFC", "pfcDescription", "description", null, null, Boolean.TRUE, null); dynamicViewEntity.addViewLink("PFAC", "PFC", Boolean.FALSE, ModelKeyMap.makeKeyMapList("productFeatureId")); - fieldsToSelect.add("pfcDescription"); - fieldsToSelect.add("pfcProductFeatureTypeId"); entityConditionList.add(EntityCondition.makeCondition("pfcProductFeatureTypeId", EntityOperator.EQUALS, productFeatureTypeId)); - EntityCondition whereCondition = EntityCondition.makeCondition(entityConditionList, EntityOperator.AND); - - EntityFindOptions efo = new EntityFindOptions(); - efo.setResultSetType(EntityFindOptions.TYPE_SCROLL_INSENSITIVE); - EntityListIterator eli = null; try { - eli = delegator.findListIteratorByCondition(dynamicViewEntity, whereCondition, null, fieldsToSelect, productSearchContext.orderByList, efo); + eli = EntityQuery.use(delegator) + .select(UtilMisc.toSet("pfacProductFeatureId", "featureCount", "pfcDescription", "pfcProductFeatureTypeId")) + .from(dynamicViewEntity) + .where(entityConditionList) + .orderBy(productSearchContext.orderByList) + .cursorScrollInsensitive() + .queryIterator(); } catch (GenericEntityException e) { Debug.logError(e, "Error in product search", module); return null; @@ -1318,14 +1319,14 @@ public class ProductSearchSession { entityConditionList.add(EntityCondition.makeCondition("ppcPrice", EntityOperator.LESS_THAN_EQUAL_TO, priceHigh)); entityConditionList.add(EntityCondition.makeCondition("ppcProductPriceTypeId", EntityOperator.EQUALS, "LIST_PRICE")); - EntityCondition whereCondition = EntityCondition.makeCondition(entityConditionList, EntityOperator.AND); - - EntityFindOptions efo = new EntityFindOptions(); - efo.setResultSetType(EntityFindOptions.TYPE_SCROLL_INSENSITIVE); - EntityListIterator eli = null; try { - eli = delegator.findListIteratorByCondition(dynamicViewEntity, whereCondition, null, fieldsToSelect, productSearchContext.orderByList, efo); + eli = EntityQuery.use(delegator).select(UtilMisc.toSet(fieldsToSelect)) + .from(dynamicViewEntity) + .where(entityConditionList) + .orderBy(productSearchContext.orderByList) + .cursorScrollInsensitive() + .queryIterator(); } catch (GenericEntityException e) { Debug.logError(e, "Error in product search", module); return 0; @@ -1384,14 +1385,14 @@ public class ProductSearchSession { ProductSearch.getAllSubCategoryIds(productCategoryId, productCategoryIdSet, delegator, productSearchContext.nowTimestamp); entityConditionList.add(EntityCondition.makeCondition("pcmcProductCategoryId", EntityOperator.IN, productCategoryIdSet)); - EntityCondition whereCondition = EntityCondition.makeCondition(entityConditionList, EntityOperator.AND); - - EntityFindOptions efo = new EntityFindOptions(); - efo.setResultSetType(EntityFindOptions.TYPE_SCROLL_INSENSITIVE); - EntityListIterator eli = null; try { - eli = delegator.findListIteratorByCondition(dynamicViewEntity, whereCondition, null, fieldsToSelect, productSearchContext.orderByList, efo); + eli = EntityQuery.use(delegator).select(UtilMisc.toSet(fieldsToSelect)) + .from(dynamicViewEntity) + .where(entityConditionList) + .orderBy(productSearchContext.orderByList) + .cursorScrollInsensitive() + .queryIterator(); } catch (GenericEntityException e) { Debug.logError(e, "Error in product search", module); return 0; diff --git a/applications/product/src/org/ofbiz/product/product/ProductServices.java b/applications/product/src/org/ofbiz/product/product/ProductServices.java index 229d80225d..5bcd39246c 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductServices.java +++ b/applications/product/src/org/ofbiz/product/product/ProductServices.java @@ -165,9 +165,7 @@ public class ProductServices { Set featureSet = new LinkedHashSet(); try { - Map fields = UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", productFeatureApplTypeId); - List order = UtilMisc.toList("sequenceNum", "productFeatureTypeId"); - List features = delegator.findByAnd("ProductFeatureAndAppl", fields, order, true); + List features = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", productFeatureApplTypeId).orderBy("sequenceNum", "productFeatureTypeId").cache(true).queryList(); for (GenericValue v: features) { featureSet.add(v.getString("productFeatureTypeId")); } @@ -297,11 +295,7 @@ public class ProductServices { // Make the selectable feature list List selectableFeatures = null; try { - Map fields = UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE"); - List sort = UtilMisc.toList("sequenceNum"); - - selectableFeatures = delegator.findByAnd("ProductFeatureAndAppl", fields, sort, true); - selectableFeatures = EntityUtil.filterByDate(selectableFeatures, true); + selectableFeatures = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE").orderBy("sequenceNum").cache(true).filterByDate().queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, @@ -374,11 +368,10 @@ public class ProductServices { try { Map fields = UtilMisc.toMap("productId", productId); - List order = UtilMisc.toList("sequenceNum", "productFeatureTypeId"); if (distinct != null) fields.put("productFeatureTypeId", distinct); if (type != null) fields.put("productFeatureApplTypeId", type); - features = delegator.findByAnd("ProductFeatureAndAppl", fields, order, true); + features = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where(fields).orderBy("sequenceNum", "productFeatureTypeId").cache(true).queryList(); result.put("productFeatures", features); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); } catch (GenericEntityException e) { @@ -517,8 +510,7 @@ public class ProductServices { EntityCondition.makeCondition("productId", productId), EntityCondition.makeCondition("productIdTo", productId) ), EntityJoinOperator.OR); - cond = EntityCondition.makeCondition(cond, EntityCondition.makeCondition("productAssocTypeId", type)); - productAssocs = delegator.findList("ProductAssoc", cond, null, orderBy, null, true); + productAssocs = EntityQuery.use(delegator).from("ProductAssoc").where(EntityCondition.makeCondition(cond, EntityCondition.makeCondition("productAssocTypeId", type))).orderBy(orderBy).cache(true).queryList(); } else { if (productIdTo == null) { productAssocs = product.getRelated("MainProductAssoc", UtilMisc.toMap("productAssocTypeId", type), orderBy, true); @@ -584,13 +576,13 @@ public class ProductServices { List features = null; try { - Map fields = UtilMisc.toMap("productId", thisItem, "productFeatureTypeId", orderKey, - "productFeatureApplTypeId", "STANDARD_FEATURE"); - List sort = UtilMisc.toList("sequenceNum"); - // get the features and filter out expired dates - features = delegator.findByAnd("ProductFeatureAndAppl", fields, sort, true); - features = EntityUtil.filterByDate(features, true); + features = EntityQuery.use(delegator).from("ProductFeatureAndAppl") + .where("productId", thisItem, "productFeatureTypeId", orderKey, "productFeatureApplTypeId", "STANDARD_FEATURE") + .orderBy("sequenceNum") + .cache(true) + .filterByDate() + .queryList(); } catch (GenericEntityException e) { throw new IllegalStateException("Problem reading relation: " + e.getMessage()); } @@ -661,20 +653,19 @@ public class ProductServices { List features = null; try { - Map fields = UtilMisc.toMap("productId", productId, "productFeatureTypeId", feature, - "productFeatureApplTypeId", "STANDARD_FEATURE"); - List sort = UtilMisc.toList("sequenceNum", "description"); - // get the features and filter out expired dates - features = delegator.findByAnd("ProductFeatureAndAppl", fields, sort, true); - features = EntityUtil.filterByDate(features, true); + features = EntityQuery.use(delegator).from("ProductFeatureAndAppl") + .where("productId", productId, "productFeatureTypeId", feature, "productFeatureApplTypeId", "STANDARD_FEATURE") + .orderBy("sequenceNum", "description") + .cache(true) + .filterByDate() + .queryList(); } catch (GenericEntityException e) { throw new IllegalStateException("Problem reading relation: " + e.getMessage()); } for (GenericValue featureAppl: features) { try { - GenericValue product = delegator.findOne("Product", - UtilMisc.toMap("productId", productId), true); + GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productId).cache(true).queryOne(); tempSample.put(featureAppl.getString("description"), product); } catch (GenericEntityException e) { @@ -715,7 +706,7 @@ public class ProductServices { return result; } // check if product exists - GenericValue variantProduct = delegator.findOne("Product",UtilMisc.toMap("productId", variantProductId), false); + GenericValue variantProduct = EntityQuery.use(delegator).from("Product").where("productId", variantProductId).queryOne(); boolean variantProductExists = (variantProduct != null); if (variantProduct == null) { //if product does not exist @@ -847,7 +838,7 @@ public class ProductServices { variantProductsById.put(variantProductId, variantProduct); } else { // is a GoodIdentification.idValue? - List goodIdentificationList = delegator.findByAnd("GoodIdentification", UtilMisc.toMap("idValue", variantProductId), null, false); + List goodIdentificationList = EntityQuery.use(delegator).from("GoodIdentification").where("idValue", variantProductId).queryList(); if (UtilValidate.isEmpty(goodIdentificationList)) { // whoops, nothing found... return error return ServiceUtil.returnError(UtilProperties.getMessage(resource, @@ -950,7 +941,7 @@ public class ProductServices { // refresh the product so we can update it GenericValue productToUpdate = null; try { - productToUpdate = delegator.findOne("Product", product.getPrimaryKey(), false); + productToUpdate = EntityQuery.use(delegator).from("Product").where(product.getPrimaryKey()).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); @@ -1006,7 +997,7 @@ public class ProductServices { List fileExtension = FastList.newInstance(); try { - fileExtension = delegator.findByAnd("FileExtension", UtilMisc.toMap("mimeTypeId", (String) context.get("_uploadedFile_contentType")), null, false); + fileExtension = EntityQuery.use(delegator).from("FileExtension").where("mimeTypeId", (String) context.get("_uploadedFile_contentType")).queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); @@ -1294,7 +1285,7 @@ public class ProductServices { List fileExtension = FastList.newInstance(); try { - fileExtension = delegator.findList("FileExtension", EntityCondition.makeCondition("mimeTypeId", EntityOperator.EQUALS, (String) context.get("_uploadedFile_contentType")), null, null, null, false); + fileExtension = EntityQuery.use(delegator).from("FileExtension").where("mimeTypeId", EntityOperator.EQUALS, (String) context.get("_uploadedFile_contentType")).queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); diff --git a/applications/product/src/org/ofbiz/product/product/ProductUtilServices.java b/applications/product/src/org/ofbiz/product/product/ProductUtilServices.java index 4b0fb145e4..56088de6dd 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductUtilServices.java +++ b/applications/product/src/org/ofbiz/product/product/ProductUtilServices.java @@ -74,7 +74,7 @@ public class ProductUtilServices { EntityCondition.makeCondition("salesDiscontinuationDate", EntityOperator.NOT_EQUAL, null), EntityCondition.makeCondition("salesDiscontinuationDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp) ), EntityOperator.AND); - EntityListIterator eliOne = delegator.find("Product", conditionOne, null, null, null, null); + EntityListIterator eliOne = EntityQuery.use(delegator).from("Product").where(conditionOne).queryIterator(); GenericValue productOne = null; int numSoFarOne = 0; while ((productOne = eliOne.next()) != null) { @@ -83,8 +83,10 @@ public class ProductUtilServices { if (virtualProduct == null) { continue; } - List passocList = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", virtualProductId, "productIdTo", productOne.get("productId"), "productAssocTypeId", "PRODUCT_VARIANT"), null, false); - passocList = EntityUtil.filterByDate(passocList); + List passocList = EntityQuery.use(delegator).from("ProductAssoc") + .where("productId", virtualProductId, "productIdTo", productOne.get("productId"), "productAssocTypeId", "PRODUCT_VARIANT") + .filterByDate() + .queryList(); if (passocList.size() > 0) { for (GenericValue passoc: passocList) { passoc.set("thruDate", nowTimestamp); @@ -104,12 +106,11 @@ public class ProductUtilServices { EntityCondition.makeCondition("isVirtual", EntityOperator.EQUALS, "Y"), EntityCondition.makeCondition(EntityCondition.makeCondition("salesDiscontinuationDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("salesDiscontinuationDate", EntityOperator.GREATER_THAN_EQUAL_TO, nowTimestamp)) ), EntityOperator.AND); - EntityListIterator eli = delegator.find("Product", condition, null, null, null, null); + EntityListIterator eli = EntityQuery.use(delegator).from("Product").where(condition).queryIterator(); GenericValue product = null; int numSoFar = 0; while ((product = eli.next()) != null) { - List passocList = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", product.get("productId"), "productAssocTypeId", "PRODUCT_VARIANT"), null, false); - passocList = EntityUtil.filterByDate(passocList); + List passocList = EntityQuery.use(delegator).from("ProductAssoc").where("productId", product.get("productId"), "productAssocTypeId", "PRODUCT_VARIANT").filterByDate().queryList(); if (passocList.size() == 0) { product.set("salesDiscontinuationDate", nowTimestamp); delegator.store(product); @@ -143,12 +144,12 @@ public class ProductUtilServices { EntityCondition.makeCondition("salesDiscontinuationDate", EntityOperator.NOT_EQUAL, null), EntityCondition.makeCondition("salesDiscontinuationDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp) ), EntityOperator.AND); - EntityListIterator eli = delegator.find("Product", condition, null, null, null, null); + EntityListIterator eli = EntityQuery.use(delegator).from("Product").where(condition).queryIterator(); GenericValue product = null; int numSoFar = 0; while ((product = eli.next()) != null) { String productId = product.getString("productId"); - List productCategoryMemberList = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productId", productId), null, false); + List productCategoryMemberList = EntityQuery.use(delegator).from("ProductCategoryMember").where("productId", productId).queryList(); if (productCategoryMemberList.size() > 0) { for (GenericValue productCategoryMember: productCategoryMemberList) { // coded this way rather than a removeByAnd so it can be easily changed... @@ -192,11 +193,11 @@ public class ProductUtilServices { EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null) ), EntityOperator.AND); EntityCondition havingCond = EntityCondition.makeCondition("productIdCount", EntityOperator.GREATER_THAN, Long.valueOf(1)); - EntityListIterator eli = delegator.findListIteratorByCondition(dve, condition, havingCond, UtilMisc.toList("productId", "productCategoryId", "productIdCount"), null, null); + EntityListIterator eli = EntityQuery.use(delegator).select("productId", "productCategoryId", "productIdCount").from(dve).where(condition).having(havingCond).queryIterator(); GenericValue pcm = null; int numSoFar = 0; while ((pcm = eli.next()) != null) { - List productCategoryMemberList = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productId", pcm.get("productId"), "productCategoryId", pcm.get("productCategoryId")), null, false); + List productCategoryMemberList = EntityQuery.use(delegator).from("ProductCategoryMember").where("productId", pcm.get("productId"), "productCategoryId", pcm.get("productCategoryId")).queryList(); if (productCategoryMemberList.size() > 1) { // remove all except the first... productCategoryMemberList.remove(0); @@ -251,7 +252,10 @@ public class ProductUtilServices { EntityCondition.makeCondition(EntityCondition.makeCondition("salesDiscontinuationDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("salesDiscontinuationDate", EntityOperator.GREATER_THAN, nowTimestamp)) ), EntityOperator.AND); EntityCondition havingCond = EntityCondition.makeCondition("productIdToCount", EntityOperator.EQUALS, Long.valueOf(1)); - EntityListIterator eliOne = delegator.findListIteratorByCondition(dve, condition, havingCond, UtilMisc.toList("productId", "productIdToCount"), null, null); + EntityListIterator eliOne = EntityQuery.use(delegator).select("productId", "productIdToCount").from(dve) + .where(condition) + .having(havingCond) + .queryIterator(); List valueList = eliOne.getCompleteList(); eliOne.close(); @@ -261,8 +265,7 @@ public class ProductUtilServices { for (GenericValue value: valueList) { // has only one variant period, is it valid? should already be discontinued if not String productId = value.getString("productId"); - List paList = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT"), null, false); - paList = EntityUtil.filterByDate(paList); + List paList = EntityQuery.use(delegator).from("ProductAssoc").where("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT").filterByDate().queryList(); // verify the query; tested on a bunch, looks good if (paList.size() != 1) { Debug.logInfo("Virtual product with ID " + productId + " should have 1 assoc, has " + paList.size(), module); @@ -286,7 +289,10 @@ public class ProductUtilServices { EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp), EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN_EQUAL_TO, nowTimestamp)) ), EntityOperator.AND); - EntityListIterator eliMulti = delegator.findListIteratorByCondition(dve, conditionWithDates, havingCond, UtilMisc.toList("productId", "productIdToCount"), null, null); + EntityListIterator eliMulti = EntityQuery.use(delegator).select("productId", "productIdToCount").from(dve) + .where(conditionWithDates) + .having(havingCond) + .queryIterator(); List valueMultiList = eliMulti.getCompleteList(); eliMulti.close(); @@ -297,7 +303,7 @@ public class ProductUtilServices { // has only one valid variant String productId = value.getString("productId"); - List paList = EntityUtil.filterByDate(delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT"), null, false)); + List paList = EntityQuery.use(delegator).from("ProductAssoc").where("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT").filterByDate().queryList(); // verify the query; tested on a bunch, looks good if (paList.size() != 1) { @@ -349,7 +355,7 @@ public class ProductUtilServices { GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne(); Debug.logInfo("Processing virtual product with one variant with ID: " + productId + " and name: " + product.getString("internalName"), module); - List paList = EntityUtil.filterByDate(delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT"), null, false)); + List paList = EntityQuery.use(delegator).from("ProductAssoc").where("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT").filterByDate().queryList(); if (paList.size() > 1) { Map messageMap = UtilMisc.toMap("productId", productId); errMsg = UtilProperties.getMessage(resourceError,"productutilservices.found_more_than_one_valid_variant_for_virtual_ID", messageMap, locale); @@ -457,7 +463,7 @@ public class ProductUtilServices { // can't just set to null, need to remove the value so it isn't a constraint in the query //findValue.set("fromDate", null); findValue.remove("fromDate"); - List existingValueList = EntityUtil.filterByDate(delegator.findByAnd(relatedEntityName, findValue, null, false), nowTimestamp); + List existingValueList = EntityQuery.use(delegator).from(relatedEntityName).where(findValue).filterByDate(nowTimestamp).queryList(); if (existingValueList.size() > 0) { if (test) { Debug.logInfo("Found " + existingValueList.size() + " existing values for related entity name: " + relatedEntityName + ", not copying, findValue is: " + findValue, module); @@ -467,7 +473,7 @@ public class ProductUtilServices { newRelatedValue.set("fromDate", nowTimestamp); } - if (delegator.findCountByCondition(relatedEntityName, EntityCondition.makeCondition(newRelatedValue.getPrimaryKey(), EntityOperator.AND), null, null) == 0) { + if (EntityQuery.use(delegator).from(relatedEntityName).where(EntityCondition.makeCondition(newRelatedValue.getPrimaryKey(), EntityOperator.AND)).queryCount() == 0) { if (test) { Debug.logInfo("Test mode, would create: " + newRelatedValue, module); } else { @@ -501,7 +507,7 @@ public class ProductUtilServices { } try { - EntityListIterator eli = delegator.find("Product", null, null, null, null, null); + EntityListIterator eli = EntityQuery.use(delegator).from("Product").queryIterator(); GenericValue product = null; int numSoFar = 0; while ((product = eli.next()) != null) { @@ -513,7 +519,7 @@ public class ProductUtilServices { if ("Y".equals(product.getString("isVirtual"))) { // find the first variant, use it's ID for the names... - List productAssocList = EntityUtil.filterByDate(delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT"), null, false)); + List productAssocList = EntityQuery.use(delegator).from("ProductAssoc").where("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT").filterByDate().queryList(); if (productAssocList.size() > 0) { GenericValue productAssoc = EntityUtil.getFirst(productAssocList); smallMap.put("productId", productAssoc.getString("productIdTo")); @@ -557,7 +563,7 @@ public class ProductUtilServices { String errMsg = null; try { - EntityListIterator eli = delegator.find("Product", EntityCondition.makeCondition("isVirtual", EntityOperator.EQUALS, "Y"), null, null, null, null); + EntityListIterator eli = EntityQuery.use(delegator).from("Product").where("isVirtual", "Y").queryIterator(); GenericValue product = null; int numSoFar = 0; while ((product = eli.next()) != null) { @@ -654,7 +660,7 @@ while (allCatIter.hasNext()) { } // do sub-categories first so all feature groups will be in place - List subCategoryList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId", productCategoryId), null, false); + List subCategoryList = EntityQuery.use(delegator).from("ProductCategoryRollup").where("parentProductCategoryId", productCategoryId).queryList(); if (doSubCategories) { for (GenericValue productCategoryRollup: subCategoryList) { attachProductFeaturesToCategory(productCategoryRollup.getString("productCategoryId"), productFeatureTypeIdsToInclude, productFeatureTypeIdsToExclude, delegator, true, nowTimestamp); @@ -663,7 +669,7 @@ while (allCatIter.hasNext()) { // now get all features for this category and make associated feature groups Map> productFeatureIdByTypeIdSetMap = FastMap.newInstance(); - List productCategoryMemberList = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", productCategoryId), null, false); + List productCategoryMemberList = EntityQuery.use(delegator).from("ProductCategoryMember").where("productCategoryId", productCategoryId).queryList(); for (GenericValue productCategoryMember: productCategoryMemberList) { String productId = productCategoryMember.getString("productId"); EntityCondition condition = EntityCondition.makeCondition(UtilMisc.toList( @@ -671,7 +677,7 @@ while (allCatIter.hasNext()) { EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp), EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN_EQUAL_TO, nowTimestamp)) ), EntityOperator.AND); - EntityListIterator productFeatureAndApplEli = delegator.find("ProductFeatureAndAppl", condition, null, null, null, null); + EntityListIterator productFeatureAndApplEli = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where(condition).queryIterator(); GenericValue productFeatureAndAppl = null; while ((productFeatureAndAppl = productFeatureAndApplEli.next()) != null) { String productFeatureId = productFeatureAndAppl.getString("productFeatureId"); @@ -721,7 +727,7 @@ while (allCatIter.hasNext()) { EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp), EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN_EQUAL_TO, nowTimestamp)) ), EntityOperator.AND); - if (delegator.findCountByCondition("ProductFeatureGroupAppl", condition, null, null) == 0) { + if (EntityQuery.use(delegator).from("ProductFeatureGroupAppl").where(condition).queryCount() == 0) { // if no valid ones, create one GenericValue productFeatureGroupAppl = delegator.makeValue("ProductFeatureGroupAppl", UtilMisc.toMap("productFeatureGroupId", productFeatureGroupId, "productFeatureId", productFeatureId, "fromDate", nowTimestamp)); productFeatureGroupAppl.create(); @@ -737,7 +743,7 @@ while (allCatIter.hasNext()) { EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp), EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN_EQUAL_TO, nowTimestamp)) ), EntityOperator.AND); - EntityListIterator productFeatureCatGrpApplEli = delegator.find("ProductFeatureCatGrpAppl", condition, null, null, null, null); + EntityListIterator productFeatureCatGrpApplEli = EntityQuery.use(delegator).from("ProductFeatureCatGrpAppl").where(condition).queryIterator(); GenericValue productFeatureCatGrpAppl = null; while ((productFeatureCatGrpAppl = productFeatureCatGrpApplEli.next()) != null) { String productFeatureGroupId = productFeatureCatGrpAppl.getString("productFeatureGroupId"); @@ -747,7 +753,7 @@ while (allCatIter.hasNext()) { EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp), EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN_EQUAL_TO, nowTimestamp)) ), EntityOperator.AND); - if (delegator.findCountByCondition("ProductFeatureCatGrpAppl", checkCondition, null, null) == 0) { + if (EntityQuery.use(delegator).from("ProductFeatureCatGrpAppl").where(checkCondition).queryCount() == 0) { // if no valid ones, create one GenericValue productFeatureGroupAppl = delegator.makeValue("ProductFeatureCatGrpAppl", UtilMisc.toMap("productFeatureGroupId", productFeatureGroupId, "productCategoryId", productCategoryId, "fromDate", nowTimestamp)); productFeatureGroupAppl.create(); diff --git a/applications/product/src/org/ofbiz/product/product/ProductWorker.java b/applications/product/src/org/ofbiz/product/product/ProductWorker.java index 748dfbe1b8..ab7345b1f5 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductWorker.java +++ b/applications/product/src/org/ofbiz/product/product/ProductWorker.java @@ -281,7 +281,7 @@ public class ProductWorker { // find all selectable features on the virtual product that are also standard features on the variant Set distFeatures = FastSet.newInstance(); - List variantDistinguishingFeatures = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", variantProduct.get("productId"), "productFeatureApplTypeId", "DISTINGUISHING_FEAT"), null, true); + List variantDistinguishingFeatures = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", variantProduct.get("productId"), "productFeatureApplTypeId", "DISTINGUISHING_FEAT").cache(true).queryList(); // Debug.logInfo("Found variantDistinguishingFeatures: " + variantDistinguishingFeatures, module); for (GenericValue variantDistinguishingFeature: EntityUtil.filterByDate(variantDistinguishingFeatures)) { @@ -290,7 +290,7 @@ public class ProductWorker { distFeatures.add(dummyFeature); } - List virtualSelectableFeatures = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", virtualProductId, "productFeatureApplTypeId", "SELECTABLE_FEATURE"), null, true); + List virtualSelectableFeatures = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", virtualProductId, "productFeatureApplTypeId", "SELECTABLE_FEATURE").cache(true).queryList(); // Debug.logInfo("Found virtualSelectableFeatures: " + virtualSelectableFeatures, module); Set virtualSelectableFeatureIds = FastSet.newInstance(); @@ -298,7 +298,7 @@ public class ProductWorker { virtualSelectableFeatureIds.add(virtualSelectableFeature.getString("productFeatureId")); } - List variantStandardFeatures = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", variantProduct.get("productId"), "productFeatureApplTypeId", "STANDARD_FEATURE"), null, true); + List variantStandardFeatures = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", variantProduct.get("productId"), "productFeatureApplTypeId", "STANDARD_FEATURE").cache(true).queryList(); // Debug.logInfo("Found variantStandardFeatures: " + variantStandardFeatures, module); for (GenericValue variantStandardFeature: EntityUtil.filterByDate(variantStandardFeatures)) { @@ -427,10 +427,14 @@ public class ProductWorker { List >> featureTypeFeatures = FastList.newInstance(); try { Delegator delegator = product.getDelegator(); - Map fields = UtilMisc.toMap("productId", product.getString("productId"), "productFeatureApplTypeId", "SELECTABLE_FEATURE"); - List order = UtilMisc.toList("productFeatureTypeId", "sequenceNum"); - List features = delegator.findByAnd("ProductFeatureAndAppl", fields, order, true); - List featuresSorted = EntityUtil.orderBy(features, order); + //List features = delegator.findByAnd("ProductFeatureAndAppl", fields, order, true); + //List featuresSorted = EntityUtil.orderBy(features, order); + List featuresSorted = EntityQuery.use(delegator) + .from("ProductFeatureAndAppl") + .where("productId", product.getString("productId"), "productFeatureApplTypeId", "SELECTABLE_FEATURE") + .orderBy("productFeatureTypeId", "sequenceNum") + .cache(true) + .queryList(); String oldType = null; List> featureList = FastList.newInstance(); for (GenericValue productFeatureAppl: featuresSorted) { @@ -440,8 +444,7 @@ public class ProductWorker { featureTypeFeatures.add(featureList); featureList = FastList.newInstance(); } - GenericValue productFeatureType = delegator.findOne("ProductFeatureType", UtilMisc.toMap("productFeatureTypeId", - productFeatureAppl.getString("productFeatureTypeId")), false); + GenericValue productFeatureType = EntityQuery.use(delegator).from("ProductFeatureType").where("productFeatureTypeId", productFeatureAppl.getString("productFeatureTypeId")).queryOne(); featureList.add(UtilMisc.toMap("productFeatureTypeId", productFeatureAppl.getString("productFeatureTypeId"), "description", productFeatureType.getString("description"))); oldType = productFeatureAppl.getString("productFeatureTypeId"); @@ -453,8 +456,10 @@ public class ProductWorker { } else { featureData.put("description", productFeatureAppl.getString("productFeatureId")); } - List productFeaturePrices = EntityUtil.filterByDate(delegator.findByAnd("ProductFeaturePrice", - UtilMisc.toMap("productFeatureId", productFeatureAppl.getString("productFeatureId"), "productPriceTypeId", "DEFAULT_PRICE"), null, false)); + List productFeaturePrices = EntityQuery.use(delegator).from("ProductFeaturePrice") + .where("productFeatureId", productFeatureAppl.getString("productFeatureId"), "productPriceTypeId", "DEFAULT_PRICE") + .filterByDate() + .queryList(); if (UtilValidate.isNotEmpty(productFeaturePrices)) { GenericValue productFeaturePrice = productFeaturePrices.get(0); if (UtilValidate.isNotEmpty(productFeaturePrice.get("price"))) { @@ -511,7 +516,7 @@ public class ProductWorker { List productFeatureAppls = null; try { - productFeatureAppls = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "OPTIONAL_FEATURE"), UtilMisc.toList("productFeatureTypeId", "sequenceNum"), false); + productFeatureAppls = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", "OPTIONAL_FEATURE").orderBy("productFeatureTypeId", "sequenceNum").queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); } @@ -709,12 +714,20 @@ public class ProductWorker { } try { - List virtualProductAssocs = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", "PRODUCT_VARIANT"), UtilMisc.toList("-fromDate"), true); - virtualProductAssocs = EntityUtil.filterByDate(virtualProductAssocs); + List virtualProductAssocs = EntityQuery.use(delegator).from("ProductAssoc") + .where("productIdTo", productId, "productAssocTypeId", "PRODUCT_VARIANT") + .orderBy("-fromDate") + .cache(true) + .filterByDate() + .queryList(); if (UtilValidate.isEmpty(virtualProductAssocs)) { //okay, not a variant, try a UNIQUE_ITEM - virtualProductAssocs = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", "UNIQUE_ITEM"), UtilMisc.toList("-fromDate"), true); - virtualProductAssocs = EntityUtil.filterByDate(virtualProductAssocs); + virtualProductAssocs = EntityQuery.use(delegator).from("ProductAssoc") + .where("productIdTo", productId, "productAssocTypeId", "UNIQUE_ITEM") + .orderBy("-fromDate") + .cache(true) + .filterByDate() + .queryList(); } if (UtilValidate.isNotEmpty(virtualProductAssocs)) { //found one, set this first as the parent product @@ -873,7 +886,7 @@ public class ProductWorker { if (UtilValidate.isNotEmpty(goodIdentificationTypeId)) { conditions.put("goodIdentificationTypeId", goodIdentificationTypeId); } - productsFound = delegator.findByAnd("GoodIdentificationAndProduct", conditions, UtilMisc.toList("productId"), true); + productsFound = EntityQuery.use(delegator).from("GoodIdentificationAndProduct").where(conditions).orderBy("productId").cache(true).queryList(); } if (! searchProductFirst) { @@ -971,15 +984,13 @@ public class ProductWorker { Set productIdSet = FastSet.newInstance(); // find associated refurb items, we want serial number for main item or any refurb items too - List refubProductAssocs = EntityUtil.filterByDate(delegator.findByAnd("ProductAssoc", - UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_REFURB"), null, false)); + List refubProductAssocs = EntityQuery.use(delegator).from("ProductAssoc").where("productId", productId, "productAssocTypeId", "PRODUCT_REFURB").filterByDate().queryList(); for (GenericValue refubProductAssoc: refubProductAssocs) { productIdSet.add(refubProductAssoc.getString("productIdTo")); } // see if this is a refurb productId to, and find product(s) it is a refurb of - List refubProductToAssocs = EntityUtil.filterByDate(delegator.findByAnd("ProductAssoc", - UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", "PRODUCT_REFURB"), null, false)); + List refubProductToAssocs = EntityQuery.use(delegator).from("ProductAssoc").where("productIdTo", productId, "productAssocTypeId", "PRODUCT_REFURB").filterByDate().queryList(); for (GenericValue refubProductToAssoc: refubProductToAssocs) { productIdSet.add(refubProductToAssoc.getString("productId")); } @@ -995,8 +1006,8 @@ public class ProductWorker { for (String paramValue: selectedFeatures) { // find incompatibilities.. - List incompatibilityVariants = delegator.findByAnd("ProductFeatureIactn", UtilMisc.toMap("productId", productId, - "productFeatureIactnTypeId","FEATURE_IACTN_INCOMP"), null, true); + List incompatibilityVariants = EntityQuery.use(delegator).from("ProductFeatureIactn") + .where("productId", productId, "productFeatureIactnTypeId","FEATURE_IACTN_INCOMP").cache(true).queryList(); for (GenericValue incompatibilityVariant: incompatibilityVariants) { String featur = incompatibilityVariant.getString("productFeatureId"); if (paramValue.equals(featur)) { @@ -1011,8 +1022,8 @@ public class ProductWorker { } } // find dependencies.. - List dependenciesVariants = delegator.findByAnd("ProductFeatureIactn", UtilMisc.toMap("productId", productId, - "productFeatureIactnTypeId","FEATURE_IACTN_DEPEND"), null, true); + List dependenciesVariants = EntityQuery.use(delegator).from("ProductFeatureIactn") + .where("productId", productId, "productFeatureIactnTypeId","FEATURE_IACTN_DEPEND").cache(true).queryList(); for (GenericValue dpVariant: dependenciesVariants) { String featur = dpVariant.getString("productFeatureId"); if (paramValue.equals(featur)) { @@ -1033,12 +1044,12 @@ public class ProductWorker { } // find variant // Debug.logInfo("=====try to find variant for product: " + productId + " and features: " + selectedFeatures); - List productAssocs = EntityUtil.filterByDate(delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId","PRODUCT_VARIANT"), null, false)); + List productAssocs = EntityQuery.use(delegator).from("ProductAssoc").where("productId", productId, "productAssocTypeId","PRODUCT_VARIANT").filterByDate().queryList(); boolean productFound = false; nextProd: for (GenericValue productAssoc: productAssocs) { for (String featureId: selectedFeatures) { - List pAppls = delegator.findByAnd("ProductFeatureAppl", UtilMisc.toMap("productId", productAssoc.getString("productIdTo"), "productFeatureId", featureId, "productFeatureApplTypeId","STANDARD_FEATURE"), null, true); + List pAppls = EntityQuery.use(delegator).from("ProductFeatureAppl").where("productId", productAssoc.getString("productIdTo"), "productFeatureId", featureId, "productFeatureApplTypeId","STANDARD_FEATURE").cache(true).queryList(); if (UtilValidate.isEmpty(pAppls)) { continue nextProd; } @@ -1071,7 +1082,7 @@ nextProd: productFeatureAppl.create(); } //add standard features too - List stdFeaturesAppls = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE"), null, false)); + List stdFeaturesAppls = EntityQuery.use(delegator).from("ProductFeatureAppl").where("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE").filterByDate().queryList(); for (GenericValue stdFeaturesAppl: stdFeaturesAppls) { stdFeaturesAppl.put("productId", product.getString("productId")); stdFeaturesAppl.create(); @@ -1080,11 +1091,12 @@ nextProd: * take the default price from the vitual product, go to the productfeature table and retrieve all the prices for the difFerent features * add these to the price of the virtual product, store the result as the default price on the variant you created. */ - List productPrices = EntityUtil.filterByDate(delegator.findByAnd("ProductPrice", UtilMisc.toMap("productId", productId), null, false)); + List productPrices = EntityQuery.use(delegator).from("ProductPrice").where("productId", productId).filterByDate().queryList(); for (GenericValue productPrice: productPrices) { for (String selectedFeaturedId: selectedFeatures) { - List productFeaturePrices = EntityUtil.filterByDate(delegator.findByAnd("ProductFeaturePrice", - UtilMisc.toMap("productFeatureId", selectedFeaturedId, "productPriceTypeId", productPrice.getString("productPriceTypeId")), null, false)); + List productFeaturePrices = EntityQuery.use(delegator).from("ProductFeaturePrice") + .where("productFeatureId", selectedFeaturedId, "productPriceTypeId", productPrice.getString("productPriceTypeId")) + .filterByDate().queryList(); if (UtilValidate.isNotEmpty(productFeaturePrices)) { GenericValue productFeaturePrice = productFeaturePrices.get(0); if (UtilValidate.isNotEmpty(productFeaturePrice)) { @@ -1105,14 +1117,14 @@ nextProd: Debug.logInfo("set the productId to: " + product.getString("productId"), module); // copy the supplier - List supplierProducts = delegator.findByAnd("SupplierProduct", UtilMisc.toMap("productId", productId), null, true); + List supplierProducts = EntityQuery.use(delegator).from("SupplierProduct").where("productId", productId).cache(true).queryList(); for (GenericValue supplierProduct: supplierProducts) { supplierProduct.set("productId", product.getString("productId")); supplierProduct.create(); } // copy the content - List productContents = delegator.findByAnd("ProductContent", UtilMisc.toMap("productId", productId), null, true); + List productContents = EntityQuery.use(delegator).from("ProductContent").where("productId", productId).cache(true).queryList(); for (GenericValue productContent: productContents) { productContent.set("productId", product.getString("productId")); productContent.create(); @@ -1143,7 +1155,7 @@ nextProd: condList.add(EntityCondition.makeCondition("productId", virtualVariantId)); } condList.add(EntityCondition.makeCondition("productAssocTypeId", "ALTERNATIVE_PACKAGE")); - alternativePackingProds = delegator.findList("ProductAssoc", EntityCondition.makeCondition(condList, EntityOperator.AND), null, null, null, true); + alternativePackingProds = EntityQuery.use(delegator).from("ProductAssoc").where(condList).cache(true).queryList(); if(UtilValidate.isNotEmpty(alternativePackingProds)) isAlternativePacking = true; } catch (GenericEntityException e) { Debug.logWarning(e, "Could not found alternative product: " + e.getMessage(), module); @@ -1157,11 +1169,10 @@ nextProd: if (isAlternativePacking) { List productAssocs = null; try { - productAssocs = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId , "productAssocTypeId", "ALTERNATIVE_PACKAGE"), null, false); + productAssocs = EntityQuery.use(delegator).from("ProductAssoc").where("productId", productId , "productAssocTypeId", "ALTERNATIVE_PACKAGE").filterByDate().queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); } - productAssocs = EntityUtil.filterByDate(productAssocs); if (productAssocs != null) { GenericValue productAssoc = EntityUtil.getFirst(productAssocs); @@ -1187,8 +1198,8 @@ nextProd: if(UtilValidate.isEmpty(productStoreId)){ return Boolean.TRUE; } - String allowDecimalStore = delegator.findOne("ProductStore", Boolean.TRUE, UtilMisc.toMap("productStoreId", productStoreId)).getString("orderDecimalQuantity"); - String allowDecimalProduct = delegator.findOne("Product", Boolean.TRUE, UtilMisc.toMap("productId", productId)).getString("orderDecimalQuantity"); + String allowDecimalStore = EntityQuery.use(delegator).from("ProductStore").where("productStoreId", productStoreId).cache(true).queryOne().getString("orderDecimalQuantity"); + String allowDecimalProduct = EntityQuery.use(delegator).from("Product").where("productId", productId).cache(true).queryOne().getString("orderDecimalQuantity"); if("N".equals(allowDecimalProduct) || (UtilValidate.isEmpty(allowDecimalProduct) && "N".equals(allowDecimalStore))){ return Boolean.FALSE; @@ -1216,7 +1227,7 @@ nextProd: for (GenericValue genericRecord : productsToFilter) { String productId = genericRecord.getString("productId"); GenericValue product = null; - product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), true); + product = EntityQuery.use(delegator).from("Product").where("productId", productId).cache(true).queryOne(); Boolean isMarketingPackage = EntityTypeUtil.hasParentType(delegator, "ProductType", "productTypeId", product.getString("productTypeId"), "parentTypeId", "MARKETING_PKG"); if ( UtilValidate.isNotEmpty(isMarketingPackage) && isMarketingPackage) { @@ -1229,7 +1240,7 @@ nextProd: productsInStock.add(genericRecord); } } else { - List facilities = delegator.findList("ProductFacility", EntityCondition.makeCondition("productId",EntityOperator.EQUALS, productId), null, null, null, false); + List facilities = EntityQuery.use(delegator).from("ProductFacility").where("productId", productId).queryList(); BigDecimal availableInventory = BigDecimal.ZERO; if (UtilValidate.isNotEmpty(facilities)) { for (GenericValue facility : facilities) { diff --git a/applications/product/src/org/ofbiz/product/product/VariantEvents.java b/applications/product/src/org/ofbiz/product/product/VariantEvents.java index 9603fc93ff..1ea6caf3b1 100644 --- a/applications/product/src/org/ofbiz/product/product/VariantEvents.java +++ b/applications/product/src/org/ofbiz/product/product/VariantEvents.java @@ -95,7 +95,7 @@ public class VariantEvents { } // check if product exists - GenericValue variantProduct = delegator.findOne("Product",UtilMisc.toMap("productId", variantProductId), false); + GenericValue variantProduct = EntityQuery.use(delegator).from("Product").where("productId", variantProductId).queryOne(); if (variantProduct == null) { //if product does not exist variantProduct = GenericValue.create(product); diff --git a/applications/product/src/org/ofbiz/product/promo/PromoServices.java b/applications/product/src/org/ofbiz/product/promo/PromoServices.java index 957dde5ff9..d5da4df489 100644 --- a/applications/product/src/org/ofbiz/product/promo/PromoServices.java +++ b/applications/product/src/org/ofbiz/product/promo/PromoServices.java @@ -138,10 +138,9 @@ public class PromoServices { condList.add(EntityCondition.makeCondition("userEntered", EntityOperator.EQUALS, "Y")); condList.add(EntityCondition.makeCondition("thruDate", EntityOperator.NOT_EQUAL, null)); condList.add(EntityCondition.makeCondition("thruDate", EntityOperator.LESS_THAN, nowTimestamp)); - EntityCondition cond = EntityCondition.makeCondition(condList, EntityOperator.AND); try { - EntityListIterator eli = delegator.find("ProductStorePromoAndAppl", cond, null, null, null, null); + EntityListIterator eli = EntityQuery.use(delegator).from("ProductStorePromoAndAppl").where(condList).queryIterator(); GenericValue productStorePromoAndAppl = null; while ((productStorePromoAndAppl = eli.next()) != null) { GenericValue productStorePromo = delegator.makeValue("ProductStorePromoAppl"); diff --git a/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductHelper.java b/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductHelper.java index e11f0fed17..b37ae25412 100644 --- a/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductHelper.java +++ b/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductHelper.java @@ -29,6 +29,7 @@ import org.ofbiz.base.util.UtilMisc; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; public class ImportProductHelper { @@ -65,8 +66,7 @@ public class ImportProductHelper { GenericValue tmpProductGV; boolean productExists = false; try { - tmpProductGV = delegator.findOne("Product", UtilMisc - .toMap("productId", productId), false); + tmpProductGV = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne(); if (tmpProductGV != null && productId.equals(tmpProductGV.getString("productId"))) productExists = true; diff --git a/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java b/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java index 7ccdd97034..57424a815c 100644 --- a/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java +++ b/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java @@ -33,6 +33,7 @@ import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; public class ProductStoreEvents { @@ -51,18 +52,16 @@ public class ProductStoreEvents { List sortList = org.ofbiz.base.util.UtilMisc.toList("sequenceNum"); try { - GenericValue productStoreGroup = delegator.findOne("ProductStoreGroup" ,UtilMisc.toMap("productStoreGroupId", parentGroupId), true); + GenericValue productStoreGroup = EntityQuery.use(delegator).from("ProductStoreGroup").where("productStoreGroupId", parentGroupId).cache(true).queryOne(); if (UtilValidate.isNotEmpty(productStoreGroup)) { - children = EntityUtil.filterByDate(delegator.findList("ProductStoreGroupRollupAndChild", - EntityCondition.makeCondition("parentGroupId", parentGroupId), null, null, null, true)); + children = EntityQuery.use(delegator).from("ProductStoreGroupRollupAndChild").where("parentGroupId", parentGroupId).cache(true).filterByDate().queryList(); if (UtilValidate.isNotEmpty(children)) { for (GenericValue child : children ) { String productStoreGroupId = child.getString("productStoreGroupId"); Map josonMap = FastMap.newInstance(); List childList = null; // Get the child list of chosen category - childList = EntityUtil.filterByDate(delegator.findList("ProductStoreGroupRollupAndChild", - EntityCondition.makeCondition("parentGroupId", productStoreGroupId), null, null, null, true)); + childList = EntityQuery.use(delegator).from("ProductStoreGroupRollupAndChild").where("parentGroupId", productStoreGroupId).cache(true).filterByDate().queryList(); if (UtilValidate.isNotEmpty(childList)) { josonMap.put("state", "closed"); diff --git a/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java b/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java index e350c93d19..e6e893ebfd 100644 --- a/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java +++ b/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java @@ -175,8 +175,7 @@ public class ProductStoreWorker { if (anyServiceType) { if (storePayment == null) { try { - List storePayments = delegator.findByAnd("ProductStorePaymentSetting", UtilMisc.toMap("productStoreId", productStoreId, "paymentMethodTypeId", paymentMethodTypeId), null, false); - storePayment = EntityUtil.getFirst(storePayments); + storePayment = EntityQuery.use(delegator).from("ProductStorePaymentSetting").where("productStoreId", productStoreId, "paymentMethodTypeId", paymentMethodTypeId).queryFirst(); } catch (GenericEntityException e) { Debug.logError(e, "Problems looking up store payment settings", module); } @@ -184,8 +183,7 @@ public class ProductStoreWorker { if (storePayment == null) { try { - List storePayments = delegator.findByAnd("ProductStorePaymentSetting", UtilMisc.toMap("productStoreId", productStoreId), null, false); - storePayment = EntityUtil.getFirst(storePayments); + storePayment = EntityQuery.use(delegator).from("ProductStorePaymentSetting").where("productStoreId", productStoreId).queryFirst(); } catch (GenericEntityException e) { Debug.logError(e, "Problems looking up store payment settings", module); } @@ -198,12 +196,14 @@ public class ProductStoreWorker { public static List getProductStoreShipmentMethods(Delegator delegator, String productStoreId, String shipmentMethodTypeId, String carrierPartyId, String carrierRoleTypeId) { // check for an external service call - Map storeFields = UtilMisc.toMap("productStoreId", productStoreId, "shipmentMethodTypeId", shipmentMethodTypeId, - "partyId", carrierPartyId, "roleTypeId", carrierRoleTypeId); List storeShipMethods = null; try { - storeShipMethods = delegator.findByAnd("ProductStoreShipmentMeth", storeFields, null, true); + storeShipMethods = EntityQuery.use(delegator).from("ProductStoreShipmentMeth") + .where("productStoreId", productStoreId, "shipmentMethodTypeId", shipmentMethodTypeId, + "partyId", carrierPartyId, "roleTypeId", carrierRoleTypeId) + .cache(true) + .queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); } @@ -224,7 +224,7 @@ public class ProductStoreWorker { } List shippingMethods = null; try { - shippingMethods = delegator.findByAnd("ProductStoreShipmentMethView", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("sequenceNumber"), true); + shippingMethods = EntityQuery.use(delegator).from("ProductStoreShipmentMethView").where("productStoreId", productStoreId).orderBy("sequenceNumber").cache(true).queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Unable to get ProductStore shipping methods", module); return null; @@ -380,7 +380,7 @@ public class ProductStoreWorker { if (UtilValidate.isNotEmpty(includeFeatures)) { List includedFeatures = null; try { - includedFeatures = delegator.findByAnd("ProductFeatureGroupAppl", UtilMisc.toMap("productFeatureGroupId", includeFeatures), null, true); + includedFeatures = EntityQuery.use(delegator).from("ProductFeatureGroupAppl").where("productFeatureGroupId", includeFeatures).cache(true).queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Unable to lookup ProductFeatureGroupAppl records for group : " + includeFeatures, module); } @@ -402,7 +402,7 @@ public class ProductStoreWorker { if (UtilValidate.isNotEmpty(excludeFeatures)) { List excludedFeatures = null; try { - excludedFeatures = delegator.findByAnd("ProductFeatureGroupAppl", UtilMisc.toMap("productFeatureGroupId", excludeFeatures), null, true); + excludedFeatures = EntityQuery.use(delegator).from("ProductFeatureGroupAppl").where("productFeatureGroupId", excludeFeatures).cache(true).queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Unable to lookup ProductFeatureGroupAppl records for group : " + excludeFeatures, module); } @@ -465,7 +465,7 @@ public class ProductStoreWorker { List surveys = FastList.newInstance(); List storeSurveys = null; try { - storeSurveys = delegator.findByAnd("ProductStoreSurveyAppl", UtilMisc.toMap("productStoreId", productStoreId, "surveyApplTypeId", surveyApplTypeId), UtilMisc.toList("sequenceNum"), true); + storeSurveys = EntityQuery.use(delegator).from("ProductStoreSurveyAppl").where("productStoreId", productStoreId, "surveyApplTypeId", surveyApplTypeId).orderBy("sequenceNum").cache(true).queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Unable to get ProductStoreSurveyAppl for store : " + productStoreId, module); return surveys; @@ -512,7 +512,7 @@ public class ProductStoreWorker { } else if (surveyAppl.get("productCategoryId") != null) { List categoryMembers = null; try { - categoryMembers = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", surveyAppl.get("productCategoryId")), null, true); + categoryMembers = EntityQuery.use(delegator).from("ProductCategoryMember").where("productCategoryId", surveyAppl.get("productCategoryId")).cache(true).queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Unable to get ProductCategoryMember records for survey application : " + surveyAppl, module); } @@ -556,7 +556,7 @@ public class ProductStoreWorker { List surveyResponse = null; try { - surveyResponse = delegator.findByAnd("SurveyResponse", UtilMisc.toMap("surveyId", surveyId, "partyId", partyId), null, false); + surveyResponse = EntityQuery.use(delegator).from("SurveyResponse").where("surveyId", surveyId, "partyId", partyId).queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); return -1; diff --git a/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java b/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java index 600cf764fd..7485aff64f 100644 --- a/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java +++ b/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java @@ -78,7 +78,7 @@ public class SubscriptionServices { Map subscriptionFindMap = UtilMisc.toMap("partyId", partyId, "subscriptionResourceId", subscriptionResourceId); // if this subscription is attached to something the customer owns, filter by that too if (UtilValidate.isNotEmpty(inventoryItemId)) subscriptionFindMap.put("inventoryItemId", inventoryItemId); - List subscriptionList = delegator.findByAnd("Subscription", subscriptionFindMap, null, false); + List subscriptionList = EntityQuery.use(delegator).from("Subscription").where(subscriptionFindMap).queryList(); // DEJ20070718 DON'T filter by date, we want to consider all subscriptions: List listFiltered = EntityUtil.filterByDate(subscriptionList, true); List listOrdered = EntityUtil.orderBy(subscriptionList, UtilMisc.toList("-fromDate")); if (listOrdered.size() > 0) { @@ -198,9 +198,11 @@ public class SubscriptionServices { orderCreatedDate = UtilDateTime.nowTimestamp(); } try { - List productSubscriptionResourceList = delegator.findByAnd("ProductSubscriptionResource", UtilMisc.toMap("productId", productId), null, true); - productSubscriptionResourceList = EntityUtil.filterByDate(productSubscriptionResourceList, orderCreatedDate, null, null, true); - productSubscriptionResourceList = EntityUtil.filterByDate(productSubscriptionResourceList, orderCreatedDate, "purchaseFromDate", "purchaseThruDate", true); + List productSubscriptionResourceList = EntityQuery.use(delegator).from("ProductSubscriptionResource") + .where("productId", productId) + .cache(true) + .filterByDate(orderCreatedDate, "fromDate", "thruDate", "purchaseFromDate", "purchaseThruDate") + .queryList(); if (productSubscriptionResourceList.size() == 0) { Debug.logError("No ProductSubscriptionResource found for productId: " + productId, module); @@ -254,7 +256,7 @@ public class SubscriptionServices { GenericValue orderHeader = null; try { - List orderRoleList = delegator.findByAnd("OrderRole", UtilMisc.toMap("orderId", orderId, "roleTypeId", "END_USER_CUSTOMER"), null, false); + List orderRoleList = EntityQuery.use(delegator).from("OrderRole").where("orderId", orderId, "roleTypeId", "END_USER_CUSTOMER").queryList(); if (orderRoleList.size() > 0) { GenericValue orderRole = orderRoleList.get(0); String partyId = (String) orderRole.get("partyId"); @@ -279,8 +281,7 @@ public class SubscriptionServices { if (UtilValidate.isEmpty(productId)) { continue; } - List productSubscriptionResourceList = delegator.findByAnd("ProductSubscriptionResource", UtilMisc.toMap("productId", productId), null, true); - List productSubscriptionResourceListFiltered = EntityUtil.filterByDate(productSubscriptionResourceList, true); + List productSubscriptionResourceListFiltered = EntityQuery.use(delegator).from("ProductSubscriptionResource").where("productId", productId).cache(true).filterByDate().queryList(); if (productSubscriptionResourceListFiltered.size() > 0) { subContext.put("subscriptionTypeId", "PRODUCT_SUBSCR"); subContext.put("productId", productId); @@ -322,7 +323,7 @@ public class SubscriptionServices { EntityCondition cond2 = EntityCondition.makeCondition("automaticExtend", EntityOperator.EQUALS, null); EntityCondition cond = EntityCondition.makeCondition(UtilMisc.toList(cond1, cond2), EntityOperator.OR); List subscriptionList = null; - subscriptionList = delegator.findList("Subscription", cond, null,null, null, false); + subscriptionList = EntityQuery.use(delegator).from("Subscription").where(cond).queryList(); if (subscriptionList != null) { for (GenericValue subscription : subscriptionList) { diff --git a/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java b/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java index eb0e3b567e..873fc3083e 100644 --- a/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java +++ b/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java @@ -728,13 +728,13 @@ public class PackingSession implements java.io.Serializable { newShipment.put("picklistBinId", picklistBinId); newShipment.put("additionalShippingCharge", additionalShippingCharge); newShipment.put("userLogin", userLogin); - GenericValue orderRoleShipTo = EntityUtil.getFirst(delegator.findByAnd("OrderRole", UtilMisc.toMap("orderId", primaryOrderId, "roleTypeId", "SHIP_TO_CUSTOMER"), null, false)); + GenericValue orderRoleShipTo = EntityQuery.use(delegator).from("OrderRole").where("orderId", primaryOrderId, "roleTypeId", "SHIP_TO_CUSTOMER").queryFirst(); if (UtilValidate.isNotEmpty(orderRoleShipTo)) { newShipment.put("partyIdTo", orderRoleShipTo.getString("partyId")); } String partyIdFrom = null; if (primaryOrderId != null) { - GenericValue orderItemShipGroup = EntityUtil.getFirst(delegator.findByAnd("OrderItemShipGroup", UtilMisc.toMap("orderId", primaryOrderId, "shipGroupSeqId", primaryShipGrp), null, false)); + GenericValue orderItemShipGroup = EntityQuery.use(delegator).from("OrderItemShipGroup").where("orderId", primaryOrderId, "shipGroupSeqId", primaryShipGrp).queryFirst(); if (UtilValidate.isNotEmpty(orderItemShipGroup.getString("vendorPartyId"))) { partyIdFrom = orderItemShipGroup.getString("vendorPartyId"); } else if (UtilValidate.isNotEmpty(orderItemShipGroup.getString("facilityId"))) { @@ -744,11 +744,11 @@ public class PackingSession implements java.io.Serializable { } } if (UtilValidate.isEmpty(partyIdFrom)) { - GenericValue orderRoleShipFrom = EntityUtil.getFirst(delegator.findByAnd("OrderRole", UtilMisc.toMap("orderId", primaryOrderId, "roleTypeId", "SHIP_FROM_VENDOR"), null, false)); + GenericValue orderRoleShipFrom = EntityQuery.use(delegator).from("OrderRole").where("orderId", primaryOrderId, "roleTypeId", "SHIP_FROM_VENDOR").queryFirst(); if (UtilValidate.isNotEmpty(orderRoleShipFrom)) { partyIdFrom = orderRoleShipFrom.getString("partyId"); } else { - orderRoleShipFrom = EntityUtil.getFirst(delegator.findByAnd("OrderRole", UtilMisc.toMap("orderId", primaryOrderId, "roleTypeId", "BILL_FROM_VENDOR"), null, false)); + orderRoleShipFrom = EntityQuery.use(delegator).from("OrderRole").where("orderId", primaryOrderId, "roleTypeId", "BILL_FROM_VENDOR").queryFirst(); partyIdFrom = orderRoleShipFrom.getString("partyId"); } } diff --git a/applications/product/src/org/ofbiz/shipment/packing/PackingSessionLine.java b/applications/product/src/org/ofbiz/shipment/packing/PackingSessionLine.java index d9f008e2af..2258a78afa 100644 --- a/applications/product/src/org/ofbiz/shipment/packing/PackingSessionLine.java +++ b/applications/product/src/org/ofbiz/shipment/packing/PackingSessionLine.java @@ -28,6 +28,7 @@ import org.ofbiz.base.util.UtilFormatOut; import org.ofbiz.base.util.Debug; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ServiceUtil; @@ -212,7 +213,10 @@ public class PackingSessionLine implements java.io.Serializable { itemLookup.put("orderItemSeqId", this.getOrderItemSeqId()); itemLookup.put("shipGroupSeqId", this.getShipGroupSeqId()); itemLookup.put("inventoryItemId", this.getInventoryItemId()); - GenericValue plItem = delegator.findOne("PicklistItem", itemLookup, false); + GenericValue plItem = EntityQuery.use(delegator) + .from("PicklistItem") + .where(itemLookup) + .queryOne(); if (plItem != null) { Debug.logInfo("Found picklist bin: " + plItem, module); BigDecimal itemQty = plItem.getBigDecimal("quantity"); diff --git a/applications/product/src/org/ofbiz/shipment/picklist/PickListServices.java b/applications/product/src/org/ofbiz/shipment/picklist/PickListServices.java index 68c9a65f46..06e6d66343 100644 --- a/applications/product/src/org/ofbiz/shipment/picklist/PickListServices.java +++ b/applications/product/src/org/ofbiz/shipment/picklist/PickListServices.java @@ -33,6 +33,7 @@ import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.ServiceUtil; @@ -66,11 +67,12 @@ public class PickListServices { EntityCondition idCond = EntityCondition.makeCondition(conditionList1, EntityOperator.OR); conditionList2.add(idCond); - EntityCondition cond = EntityCondition.makeCondition(conditionList2, EntityOperator.AND); - // run the query try { - orderHeaderList = delegator.findList("OrderHeader", cond, null, UtilMisc.toList("+orderDate"), null, false); + orderHeaderList = EntityQuery.use(delegator).from("OrderHeader") + .where(conditionList2) + .orderBy("orderDate") + .queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); @@ -89,7 +91,7 @@ public class PickListServices { // lookup the items in the bin List items; try { - items = delegator.findByAnd("PicklistItem", UtilMisc.toMap("picklistBinId", picklistBinId), null, false); + items = EntityQuery.use(delegator).from("PicklistItem").where("picklistBinId", picklistBinId).queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); throw e; diff --git a/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java b/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java index 62716a9359..7a96f967d2 100644 --- a/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java +++ b/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java @@ -273,7 +273,10 @@ public class ShipmentServices { Collection estimates = null; try { - estimates = delegator.findList("ShipmentCostEstimate", estFieldsCond, null, null, null, true); + estimates = EntityQuery.use(delegator).from("ShipmentCostEstimate") + .where(estFieldsCond) + .cache(true) + .queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, @@ -302,8 +305,10 @@ public class ShipmentServices { } else if (shippingPostalCode != null) { String countryGeoId = null; try { - EntityCondition cond =EntityCondition.makeCondition(UtilMisc.toMap("geoTypeId", "COUNTRY", "geoCode", shippingCountryCode)); - GenericValue countryGeo = EntityUtil.getFirst(delegator.findList("Geo", cond, null, null, null, true)); + GenericValue countryGeo = EntityQuery.use(delegator).from("Geo") + .where("geoTypeId", "COUNTRY", "geoCode", shippingCountryCode) + .cache(true) + .queryFirst(); if (countryGeo != null) { countryGeoId = countryGeo.getString("geoId"); } @@ -562,9 +567,11 @@ public class ShipmentServices { GenericValue appl = null; Map fields = UtilMisc.toMap("productFeatureGroupId", featureGroupId, "productFeatureId", featureId); try { - List appls = delegator.findByAnd("ProductFeatureGroupAppl", fields, null, true); - appls = EntityUtil.filterByDate(appls); - appl = EntityUtil.getFirst(appls); + appl = EntityQuery.use(delegator).from("ProductFeatureGroupAppl") + .where("productFeatureGroupId", featureGroupId, "productFeatureId", featureId) + .cache(true) + .filterByDate() + .queryFirst(); } catch (GenericEntityException e) { Debug.logError(e, "Unable to lookup feature/group" + fields, module); } @@ -722,20 +729,18 @@ public class ShipmentServices { Delegator delegator = dctx.getDelegator(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); - List orderBy = UtilMisc.toList("shipmentId", "shipmentPackageSeqId", "voidIndicator"); Map shipmentMap = FastMap.newInstance(); EntityListIterator eli = null; try { - eli = delegator.find("OdbcPackageIn", null, null, null, orderBy, null); + eli = EntityQuery.use(delegator).from("OdbcPackageIn").orderBy("shipmentId", "shipmentPackageSeqId", "voidIndicator").queryIterator(); GenericValue pkgInfo; while ((pkgInfo = eli.next()) != null) { String packageSeqId = pkgInfo.getString("shipmentPackageSeqId"); String shipmentId = pkgInfo.getString("shipmentId"); // locate the shipment package - GenericValue shipmentPackage = delegator.findOne("ShipmentPackage", - UtilMisc.toMap("shipmentId", shipmentId, "shipmentPackageSeqId", packageSeqId), false); + GenericValue shipmentPackage = EntityQuery.use(delegator).from("ShipmentPackage").where("shipmentId", shipmentId, "shipmentPackageSeqId", packageSeqId).queryOne(); if (shipmentPackage != null) { if ("00001".equals(packageSeqId)) { @@ -777,7 +782,9 @@ public class ShipmentServices { // first update the weight of the package GenericValue pkg = null; try { - pkg = delegator.findOne("ShipmentPackage", pkgCtx, false); + pkg = EntityQuery.use(delegator).from("ShipmentPackage") + .where(pkgCtx) + .queryOne(); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); @@ -802,7 +809,7 @@ public class ShipmentServices { pkgCtx.put("shipmentRouteSegmentId", "00001"); GenericValue pkgRtSeg = null; try { - pkgRtSeg = delegator.findOne("ShipmentPackageRouteSeg", pkgCtx, false); + pkgRtSeg = EntityQuery.use(delegator).from("ShipmentPackageRouteSeg").where(pkgCtx).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); @@ -910,7 +917,7 @@ public class ShipmentServices { GenericValue userLogin = (GenericValue) context.get("userLogin"); try { - List shipmentReceipts = delegator.findByAnd("ShipmentReceipt", UtilMisc.toMap("shipmentId", shipmentId), null, false); + List shipmentReceipts = EntityQuery.use(delegator).from("ShipmentReceipt").where("shipmentId", shipmentId).queryList(); if (shipmentReceipts.size() == 0) return ServiceUtil.returnSuccess(); // If there are shipment receipts, the shipment must have been shipped, so set the shipment status to PURCH_SHIP_SHIPPED if it's only PURCH_SHIP_CREATED @@ -922,7 +929,7 @@ public class ShipmentServices { } } - List shipmentAndItems = delegator.findByAnd("ShipmentAndItem", UtilMisc.toMap("shipmentId", shipmentId, "statusId", "PURCH_SHIP_SHIPPED"), null, false); + List shipmentAndItems = EntityQuery.use(delegator).from("ShipmentAndItem").where("shipmentId", shipmentId, "statusId", "PURCH_SHIP_SHIPPED").queryList(); if (shipmentAndItems.size() == 0) { return ServiceUtil.returnSuccess(); } @@ -1018,8 +1025,10 @@ public class ShipmentServices { // get the carrierPartyId try { - GenericValue shipmentRouteSegment = delegator.findOne("ShipmentRouteSegment", - UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), true); + GenericValue shipmentRouteSegment = EntityQuery.use(delegator).from("ShipmentRouteSegment") + .where("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId) + .cache(true) + .queryOne(); carrierPartyId = shipmentRouteSegment.getString("carrierPartyId"); } catch (GenericEntityException e) { Debug.logError(e, module); @@ -1083,7 +1092,7 @@ public class ShipmentServices { return ServiceUtil.returnError(errorMessage); } - List packageContents = delegator.findByAnd("PackedQtyVsOrderItemQuantity", UtilMisc.toMap("shipmentId", shipmentId, "shipmentPackageSeqId", shipmentPackageSeqId), null, false); + List packageContents = EntityQuery.use(delegator).from("PackedQtyVsOrderItemQuantity").where("shipmentId", shipmentId, "shipmentPackageSeqId", shipmentPackageSeqId).queryList(); for (GenericValue packageContent: packageContents) { String orderId = packageContent.getString("orderId"); String orderItemSeqId = packageContent.getString("orderItemSeqId"); @@ -1244,14 +1253,10 @@ public class ShipmentServices { String shipmentMethodTypeId = primaryOrderItemShipGroup.getString("shipmentMethodTypeId"); String carrierPartyId = primaryOrderItemShipGroup.getString("carrierPartyId"); String carrierRoleTypeId = primaryOrderItemShipGroup.getString("carrierRoleTypeId"); - List conditions = FastList.newInstance(); - conditions.add(EntityCondition.makeCondition("productStoreId", EntityOperator.EQUALS, productStoreId)); - conditions.add(EntityCondition.makeCondition("shipmentMethodTypeId", EntityOperator.EQUALS, shipmentMethodTypeId)); - conditions.add(EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, carrierPartyId)); - conditions.add(EntityCondition.makeCondition("roleTypeId", EntityOperator.EQUALS, carrierRoleTypeId)); - EntityConditionList ecl = EntityCondition.makeCondition(conditions, EntityOperator.AND); - List productStoreShipmentMeths = delegator.findList("ProductStoreShipmentMeth", ecl, null, null, null, false); - GenericValue productStoreShipmentMeth = EntityUtil.getFirst(productStoreShipmentMeths); + GenericValue productStoreShipmentMeth = EntityQuery.use(delegator).from("ProductStoreShipmentMeth") + .where("productStoreId",productStoreId, "shipmentMethodTypeId", shipmentMethodTypeId, + "partyId", carrierPartyId, "roleTypeId", carrierRoleTypeId) + .queryFirst(); if (UtilValidate.isNotEmpty(productStoreShipmentMeth)) { shipmentGatewayConfig.put("shipmentGatewayConfigId", productStoreShipmentMeth.getString("shipmentGatewayConfigId")); shipmentGatewayConfig.put("configProps", productStoreShipmentMeth.getString("configProps")); diff --git a/applications/product/src/org/ofbiz/shipment/thirdparty/dhl/DhlServices.java b/applications/product/src/org/ofbiz/shipment/thirdparty/dhl/DhlServices.java index c773000ce2..77fb0b67ad 100644 --- a/applications/product/src/org/ofbiz/shipment/thirdparty/dhl/DhlServices.java +++ b/applications/product/src/org/ofbiz/shipment/thirdparty/dhl/DhlServices.java @@ -170,8 +170,9 @@ public class DhlServices { // translate shipmentMethodTypeId to DHL service code String dhlShipmentDetailCode = null; try { - GenericValue carrierShipmentMethod = delegator.findOne("CarrierShipmentMethod", UtilMisc.toMap("shipmentMethodTypeId", shipmentMethodTypeId, - "partyId", carrierPartyId, "roleTypeId", "CARRIER"), false); + GenericValue carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod") + .where("shipmentMethodTypeId", shipmentMethodTypeId, "partyId", carrierPartyId, "roleTypeId", "CARRIER") + .queryOne(); if (carrierShipmentMethod == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentDhlNoCarrierShipmentMethod", @@ -711,8 +712,9 @@ public class DhlServices { // translate shipmentMethodTypeId to DHL service code String shipmentMethodTypeId = shipmentRouteSegment.getString("shipmentMethodTypeId"); String dhlShipmentDetailCode = null; - GenericValue carrierShipmentMethod = delegator.findOne("CarrierShipmentMethod", UtilMisc.toMap("shipmentMethodTypeId", shipmentMethodTypeId, - "partyId", "DHL", "roleTypeId", "CARRIER"), false); + GenericValue carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod") + .where("shipmentMethodTypeId", shipmentMethodTypeId, "partyId", "DHL", "roleTypeId", "CARRIER") + .queryOne(); if (carrierShipmentMethod == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentDhlNoCarrierShipmentMethod", diff --git a/applications/product/src/org/ofbiz/shipment/thirdparty/fedex/FedexServices.java b/applications/product/src/org/ofbiz/shipment/thirdparty/fedex/FedexServices.java index 4133a377b9..a023f8eb52 100644 --- a/applications/product/src/org/ofbiz/shipment/thirdparty/fedex/FedexServices.java +++ b/applications/product/src/org/ofbiz/shipment/thirdparty/fedex/FedexServices.java @@ -203,9 +203,10 @@ public class FedexServices { } // Get the contact information for the company - List partyContactDetails = delegator.findByAnd("PartyContactDetailByPurpose", UtilMisc.toMap("partyId", companyPartyId), null, false); - partyContactDetails = EntityUtil.filterByDate(partyContactDetails); - partyContactDetails = EntityUtil.filterByDate(partyContactDetails, UtilDateTime.nowTimestamp(), "purposeFromDate", "purposeThruDate", true); + List partyContactDetails = EntityQuery.use(delegator).from("PartyContactDetailByPurpose") + .where("partyId", companyPartyId) + .filterByDate(UtilDateTime.nowTimestamp(), "fromDate", "thruDate", "purposeFromDate", "purposeThruDate") + .queryList(); // Get the first valid postal address (address1, city, postalCode and countryGeoId are required by Fedex) List postalAddressConditions = FastList.newInstance(); diff --git a/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java b/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java index c101a8c81a..825d48a4cf 100644 --- a/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java +++ b/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java @@ -201,8 +201,7 @@ public class UpsServices { UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } - Map findCarrierShipmentMethodMap = UtilMisc.toMap("partyId", shipmentRouteSegment.get("carrierPartyId"), "roleTypeId", "CARRIER", "shipmentMethodTypeId", shipmentRouteSegment.get("shipmentMethodTypeId")); - GenericValue carrierShipmentMethod = delegator.findOne("CarrierShipmentMethod", findCarrierShipmentMethodMap, false); + GenericValue carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod").where("partyId", shipmentRouteSegment.get("carrierPartyId"), "roleTypeId", "CARRIER", "shipmentMethodTypeId", shipmentRouteSegment.get("shipmentMethodTypeId")).queryOne(); if (carrierShipmentMethod == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentCarrierShipmentMethodNotFound", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId, "carrierPartyId", shipmentRouteSegment.get("carrierPartyId"), "shipmentMethodTypeId", shipmentRouteSegment.get("shipmentMethodTypeId")), locale)); @@ -241,7 +240,8 @@ public class UpsServices { if (allowCOD) { // Get the paymentMethodTypeIds of all the orderPaymentPreferences involved with the shipment - List opps = delegator.findList("OrderPaymentPreference", EntityCondition.makeCondition("orderId", EntityOperator.IN, orderIdSet), null, null, null, false); + List opps = EntityQuery.use(delegator).from("OrderPaymentPreference") + .where(EntityCondition.makeCondition("orderId", EntityOperator.IN, orderIdSet)).queryList(); List paymentMethodTypeIds = EntityUtil.getFieldListFromEntityList(opps, "paymentMethodTypeId", true); if (paymentMethodTypeIds.size() > 1 || ! paymentMethodTypeIds.contains("EXT_COD")) { @@ -2078,8 +2078,9 @@ public class UpsServices { // locate the CarrierShipmentMethod record GenericValue carrierShipmentMethod = null; try { - carrierShipmentMethod = delegator.findOne("CarrierShipmentMethod", UtilMisc.toMap("shipmentMethodTypeId", - shipmentMethodTypeId, "partyId", carrierPartyId, "roleTypeId", carrierRoleTypeId), false); + carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod") + .where("shipmentMethodTypeId", shipmentMethodTypeId, "partyId", carrierPartyId, "roleTypeId", carrierRoleTypeId) + .queryOne(); } catch (GenericEntityException e) { Debug.logError(e, module); } @@ -2481,8 +2482,9 @@ public class UpsServices { UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } - Map findCarrierShipmentMethodMap = UtilMisc.toMap("partyId", shipmentRouteSegment.get("carrierPartyId"), "roleTypeId", "CARRIER", "shipmentMethodTypeId", shipmentRouteSegment.get("shipmentMethodTypeId")); - GenericValue carrierShipmentMethod = delegator.findOne("CarrierShipmentMethod", findCarrierShipmentMethodMap, false); + GenericValue carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod") + .where("partyId", shipmentRouteSegment.get("carrierPartyId"), "roleTypeId", "CARRIER", "shipmentMethodTypeId", shipmentRouteSegment.get("shipmentMethodTypeId")) + .queryOne(); if (carrierShipmentMethod == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentCarrierShipmentMethodNotFound", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId, "carrierPartyId", shipmentRouteSegment.get("carrierPartyId"), "shipmentMethodTypeId", shipmentRouteSegment.get("shipmentMethodTypeId")), locale)); @@ -2798,10 +2800,9 @@ public class UpsServices { try { if (shipmentRouteSegmentId != null) { - shipmentRouteSegment = delegator.findOne("ShipmentRouteSegment", false, UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId)); + shipmentRouteSegment = EntityQuery.use(delegator).from("ShipmentRouteSegment").where("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId).queryOne(); } else { - List shipmentRouteSegments = delegator.findList("ShipmentRouteSegment", EntityCondition.makeCondition("shipmentId", EntityOperator.EQUALS, shipmentId), null, null, null, false); - shipmentRouteSegment = EntityUtil.getFirst(shipmentRouteSegments); + shipmentRouteSegment = EntityQuery.use(delegator).from("ShipmentRouteSegment").where(EntityCondition.makeCondition("shipmentId", EntityOperator.EQUALS, shipmentId)).queryFirst(); } if (shipmentRouteSegment == null) { @@ -3096,12 +3097,13 @@ public class UpsServices { GenericValue carrierShipmentMethod = null; // Filtering out rates of shipping methods which are not configured in ProductStoreShipmentMeth entity. try { - List productStoreShipmentMethods = delegator.findByAnd("ProductStoreShipmentMethView", UtilMisc.toMap("productStoreId", productStoreId), null, false); + List productStoreShipmentMethods = EntityQuery.use(delegator).from("ProductStoreShipmentMethView").where("productStoreId", productStoreId).queryList(); for (GenericValue productStoreShipmentMethod :productStoreShipmentMethods) { if ("UPS".equals(productStoreShipmentMethod.get("partyId"))) { Map thisUpsRateCodeMap = FastMap.newInstance(); - carrierShipmentMethod = delegator.findOne("CarrierShipmentMethod", false, UtilMisc.toMap("shipmentMethodTypeId", - productStoreShipmentMethod.getString("shipmentMethodTypeId"), "partyId", productStoreShipmentMethod.getString("partyId"), "roleTypeId", productStoreShipmentMethod.getString("roleTypeId"))); + carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod") + .where("shipmentMethodTypeId", productStoreShipmentMethod.getString("shipmentMethodTypeId"), "partyId", productStoreShipmentMethod.getString("partyId"), "roleTypeId", productStoreShipmentMethod.getString("roleTypeId")) + .queryOne(); String serviceCode = carrierShipmentMethod.getString("carrierServiceCode"); for (String thisServiceCode : upsRateCodeMap.keySet()) { if (serviceCode.equals(thisServiceCode)) { diff --git a/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServices.java b/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServices.java index e849cd5194..bdc8c8f0f7 100644 --- a/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServices.java +++ b/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServices.java @@ -106,8 +106,7 @@ public class UspsServices { GenericValue facilityContactMech = ContactMechWorker.getFacilityContactMechByPurpose(delegator, productStore.getString("inventoryFacilityId"), UtilMisc.toList("SHIP_ORIG_LOCATION", "PRIMARY_LOCATION")); if (facilityContactMech != null) { try { - GenericValue shipFromAddress = delegator.findOne("PostalAddress", - UtilMisc.toMap("contactMechId", facilityContactMech.getString("contactMechId")), false); + GenericValue shipFromAddress = EntityQuery.use(delegator).from("PostalAddress").where("contactMechId", facilityContactMech.getString("contactMechId")).queryOne(); if (shipFromAddress != null) { originationZip = shipFromAddress.getString("postalCode"); } @@ -146,9 +145,9 @@ public class UspsServices { // get the service code String serviceCode = null; try { - GenericValue carrierShipmentMethod = delegator.findOne("CarrierShipmentMethod", - UtilMisc.toMap("shipmentMethodTypeId", (String) context.get("shipmentMethodTypeId"), - "partyId", (String) context.get("carrierPartyId"), "roleTypeId", (String) context.get("carrierRoleTypeId")), false); + GenericValue carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod") + .where("shipmentMethodTypeId", (String) context.get("shipmentMethodTypeId"), "partyId", (String) context.get("carrierPartyId"), "roleTypeId", (String) context.get("carrierRoleTypeId")) + .queryOne(); if (carrierShipmentMethod != null) { serviceCode = carrierShipmentMethod.getString("carrierServiceCode").toUpperCase(); } @@ -315,9 +314,9 @@ public class UspsServices { // get the service code String serviceCode = null; try { - GenericValue carrierShipmentMethod = delegator.findOne("CarrierShipmentMethod", - UtilMisc.toMap("shipmentMethodTypeId", (String) context.get("shipmentMethodTypeId"), - "partyId", (String) context.get("carrierPartyId"), "roleTypeId", (String) context.get("carrierRoleTypeId")), false); + GenericValue carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod") + .where("shipmentMethodTypeId", (String) context.get("shipmentMethodTypeId"), "partyId", (String) context.get("carrierPartyId"), "roleTypeId", (String) context.get("carrierRoleTypeId")) + .queryOne(); if (carrierShipmentMethod != null) { serviceCode = carrierShipmentMethod.getString("carrierServiceCode"); } @@ -934,8 +933,7 @@ public class UspsServices { } try { - GenericValue shipmentRouteSegment = delegator.findOne("ShipmentRouteSegment", - UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), false); + GenericValue shipmentRouteSegment = EntityQuery.use(delegator).from("ShipmentRouteSegment").where("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId).queryOne(); if (shipmentRouteSegment == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "ProductShipmentRouteSegmentNotFound", @@ -991,8 +989,7 @@ public class UspsServices { String shipmentMethodTypeId = shipmentRouteSegment.getString("shipmentMethodTypeId"); String partyId = shipmentRouteSegment.getString("carrierPartyId"); - GenericValue carrierShipmentMethod = delegator.findOne("CarrierShipmentMethod", - UtilMisc.toMap("partyId", partyId, "roleTypeId", "CARRIER", "shipmentMethodTypeId", shipmentMethodTypeId), false); + GenericValue carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod").where("partyId", partyId, "roleTypeId", "CARRIER", "shipmentMethodTypeId", shipmentMethodTypeId).queryOne(); if (carrierShipmentMethod == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsNoCarrierShipmentMethod", @@ -1241,8 +1238,7 @@ public class UspsServices { "ProductShipmentNotFoundId", locale) + shipmentId); } - GenericValue shipmentRouteSegment = delegator.findOne("ShipmentRouteSegment", - UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), false); + GenericValue shipmentRouteSegment = EntityQuery.use(delegator).from("ShipmentRouteSegment").where("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId).queryOne(); if (shipmentRouteSegment == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "ProductShipmentRouteSegmentNotFound", @@ -1286,8 +1282,7 @@ public class UspsServices { String shipmentMethodTypeId = shipmentRouteSegment.getString("shipmentMethodTypeId"); String partyId = shipmentRouteSegment.getString("carrierPartyId"); - GenericValue carrierShipmentMethod = delegator.findOne("CarrierShipmentMethod", - UtilMisc.toMap("partyId", partyId, "roleTypeId", "CARRIER", "shipmentMethodTypeId", shipmentMethodTypeId), false); + GenericValue carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod").where("partyId", partyId, "roleTypeId", "CARRIER", "shipmentMethodTypeId", shipmentMethodTypeId).queryOne(); if (carrierShipmentMethod == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsNoCarrierShipmentMethod", @@ -1369,8 +1364,7 @@ public class UspsServices { } if (!"WT_oz".equals(weightUomId)) { // attempt a conversion to pounds - GenericValue uomConversion = delegator.findOne("UomConversion", - UtilMisc.toMap("uomId", weightUomId, "uomIdTo", "WT_oz"), false); + GenericValue uomConversion = EntityQuery.use(delegator).from("UomConversion").where("uomId", weightUomId, "uomIdTo", "WT_oz").queryOne(); if (uomConversion == null || UtilValidate.isEmpty(uomConversion.getString("conversionFactor"))) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsWeightUnsupported", @@ -1443,8 +1437,7 @@ public class UspsServices { String shipmentId = (String) context.get("shipmentId"); String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId"); - GenericValue shipmentRouteSegment = delegator.findOne("ShipmentRouteSegment", - UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), false); + GenericValue shipmentRouteSegment = EntityQuery.use(delegator).from("ShipmentRouteSegment").where("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId).queryOne(); List shipmentPackageRouteSegList = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId"), false); diff --git a/applications/product/src/org/ofbiz/shipment/verify/VerifyPickSession.java b/applications/product/src/org/ofbiz/shipment/verify/VerifyPickSession.java index a01dcfa19f..61ecc499bc 100644 --- a/applications/product/src/org/ofbiz/shipment/verify/VerifyPickSession.java +++ b/applications/product/src/org/ofbiz/shipment/verify/VerifyPickSession.java @@ -394,12 +394,12 @@ public class VerifyPickSession implements Serializable { newShipment.put("shipmentTypeId", "OUTGOING_SHIPMENT"); newShipment.put("statusId", "SHIPMENT_SCHEDULED"); newShipment.put("userLogin", this.getUserLogin()); - GenericValue orderRoleShipTo = EntityUtil.getFirst(delegator.findByAnd("OrderRole", UtilMisc.toMap("orderId", orderId, "roleTypeId", "SHIP_TO_CUSTOMER"), null, false)); + GenericValue orderRoleShipTo = EntityQuery.use(delegator).from("OrderRole").where("orderId", orderId, "roleTypeId", "SHIP_TO_CUSTOMER").queryFirst(); if (UtilValidate.isNotEmpty(orderRoleShipTo)) { newShipment.put("partyIdTo", orderRoleShipTo.getString("partyId")); } String partyIdFrom = null; - GenericValue orderItemShipGroup = EntityUtil.getFirst(delegator.findByAnd("OrderItemShipGroup", UtilMisc.toMap("orderId", orderId, "shipGroupSeqId", line.getShipGroupSeqId()), null, false)); + GenericValue orderItemShipGroup = EntityQuery.use(delegator).from("OrderItemShipGroup").where("orderId", orderId, "shipGroupSeqId", line.getShipGroupSeqId()).queryFirst(); if (UtilValidate.isNotEmpty(orderItemShipGroup.getString("vendorPartyId"))) { partyIdFrom = orderItemShipGroup.getString("vendorPartyId"); } else if (UtilValidate.isNotEmpty(orderItemShipGroup.getString("facilityId"))) { @@ -409,11 +409,11 @@ public class VerifyPickSession implements Serializable { } } if (UtilValidate.isEmpty(partyIdFrom)) { - GenericValue orderRoleShipFrom = EntityUtil.getFirst(delegator.findByAnd("OrderRole", UtilMisc.toMap("orderId", orderId, "roleTypeId", "SHIP_FROM_VENDOR"), null, false)); + GenericValue orderRoleShipFrom = EntityQuery.use(delegator).from("OrderRole").where("orderId", orderId, "roleTypeId", "SHIP_FROM_VENDOR").queryFirst(); if (UtilValidate.isNotEmpty(orderRoleShipFrom)) { partyIdFrom = orderRoleShipFrom.getString("partyId"); } else { - orderRoleShipFrom = EntityUtil.getFirst(delegator.findByAnd("OrderRole", UtilMisc.toMap("orderId", orderId, "roleTypeId", "BILL_FROM_VENDOR"), null, false)); + orderRoleShipFrom = EntityQuery.use(delegator).from("OrderRole").where("orderId", orderId, "roleTypeId", "BILL_FROM_VENDOR").queryFirst(); partyIdFrom = orderRoleShipFrom.getString("partyId"); } } diff --git a/applications/product/src/org/ofbiz/shipment/verify/VerifyPickSessionRow.java b/applications/product/src/org/ofbiz/shipment/verify/VerifyPickSessionRow.java index 8cc901143e..6b3102b034 100644 --- a/applications/product/src/org/ofbiz/shipment/verify/VerifyPickSessionRow.java +++ b/applications/product/src/org/ofbiz/shipment/verify/VerifyPickSessionRow.java @@ -23,6 +23,7 @@ import java.io.Serializable; import java.math.BigDecimal; import java.util.Locale; import java.util.Map; + import javolution.util.FastMap; import org.ofbiz.base.util.GeneralException; @@ -30,6 +31,7 @@ import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ServiceUtil; @@ -159,7 +161,7 @@ public class VerifyPickSessionRow implements Serializable { picklistItemMap.put("shipGroupSeqId", this.getShipGroupSeqId()); picklistItemMap.put("inventoryItemId", this.getInventoryItemId()); - GenericValue picklistItem = delegator.findOne("PicklistItem", picklistItemMap, true); + GenericValue picklistItem = EntityQuery.use(delegator).from("PicklistItem").where(picklistItemMap).cache(true).queryOne(); if (UtilValidate.isNotEmpty(picklistItem)) { BigDecimal itemQty = picklistItem.getBigDecimal("quantity"); if (itemQty.compareTo(quantity) == 0) { diff --git a/applications/product/src/org/ofbiz/shipment/weightPackage/WeightPackageServices.java b/applications/product/src/org/ofbiz/shipment/weightPackage/WeightPackageServices.java index 03f9394265..3e568aaaae 100644 --- a/applications/product/src/org/ofbiz/shipment/weightPackage/WeightPackageServices.java +++ b/applications/product/src/org/ofbiz/shipment/weightPackage/WeightPackageServices.java @@ -31,6 +31,7 @@ import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.ServiceUtil; @@ -64,7 +65,7 @@ public class WeightPackageServices { } try { // Checked no of packages, it should not be greater than ordered quantity - List orderItems = delegator.findByAnd("OrderItem", UtilMisc.toMap("orderId", orderId, "statusId", "ITEM_APPROVED"), null, false); + List orderItems = EntityQuery.use(delegator).from("OrderItem").where("orderId", orderId, "statusId", "ITEM_APPROVED").queryList(); BigDecimal orderedItemQty = ZERO; for (GenericValue orderItem : orderItems) { orderedItemQty = orderedItemQty.add(orderItem.getBigDecimal("quantity")); diff --git a/applications/product/src/org/ofbiz/shipment/weightPackage/WeightPackageSession.java b/applications/product/src/org/ofbiz/shipment/weightPackage/WeightPackageSession.java index 7463c3ee18..8aaca7ba9c 100644 --- a/applications/product/src/org/ofbiz/shipment/weightPackage/WeightPackageSession.java +++ b/applications/product/src/org/ofbiz/shipment/weightPackage/WeightPackageSession.java @@ -353,7 +353,7 @@ public class WeightPackageSession implements Serializable { protected BigDecimal upsShipmentConfirm() throws GeneralException { Delegator delegator = this.getDelegator(); BigDecimal actualCost = ZERO; - List shipmentRouteSegments = delegator.findByAnd("ShipmentRouteSegment", UtilMisc.toMap("shipmentId", shipmentId), null, false); + List shipmentRouteSegments = EntityQuery.use(delegator).from("ShipmentRouteSegment").where("shipmentId", shipmentId).queryList(); if (UtilValidate.isNotEmpty(shipmentRouteSegments)) { for (GenericValue shipmentRouteSegment : shipmentRouteSegments) { Map shipmentRouteSegmentMap = FastMap.newInstance();