Modified: ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java?rev=1635399&r1=1635398&r2=1635399&view=diff ============================================================================== --- ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java (original) +++ ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java Thu Oct 30 06:10:58 2014 @@ -44,6 +44,7 @@ import org.ofbiz.entity.GenericPK; 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.entity.util.EntityTypeUtil; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.manufacturing.bom.BOMNode; @@ -121,9 +122,11 @@ public class ProductionRunServices { serviceContext.put("userLogin", userLogin); dispatcher.runSync("updateWorkEffort", serviceContext); // Cancel the product promised - List<GenericValue> products = delegator.findByAnd("WorkEffortGoodStandard", - UtilMisc.toMap("workEffortId", productionRunId, "workEffortGoodStdTypeId", "PRUN_PROD_DELIV", - "statusId", "WEGS_CREATED"), null, false); + List<GenericValue> products = EntityQuery.use(delegator).from("WorkEffortGoodStandard") + .where("workEffortId", productionRunId, + "workEffortGoodStdTypeId", "PRUN_PROD_DELIV", + "statusId", "WEGS_CREATED") + .queryList(); if (!UtilValidate.isEmpty(products)) { for (GenericValue product : products) { product.set("statusId", "WEGS_CANCELLED"); @@ -142,9 +145,11 @@ public class ProductionRunServices { serviceContext.put("userLogin", userLogin); dispatcher.runSync("updateWorkEffort", serviceContext); // cancel all the components - List<GenericValue> components = delegator.findByAnd("WorkEffortGoodStandard", - UtilMisc.toMap("workEffortId", taskId, "workEffortGoodStdTypeId", "PRUNT_PROD_NEEDED", - "statusId", "WEGS_CREATED"), null, false); + List<GenericValue> components = EntityQuery.use(delegator).from("WorkEffortGoodStandard") + .where("workEffortId", taskId, + "workEffortGoodStdTypeId", "PRUNT_PROD_NEEDED", + "statusId", "WEGS_CREATED") + .queryList(); if (!UtilValidate.isEmpty(components)) { for (GenericValue component : components) { component.set("statusId", "WEGS_CANCELLED"); @@ -204,7 +209,7 @@ public class ProductionRunServices { List<GenericValue> routingTaskAssocs = null; try { // Find the product - product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), false); + product = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne(); if (product == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductNotExist", locale)); } @@ -642,7 +647,10 @@ public class ProductionRunServices { // change only the production run (header) status to PRUN_RUNNING // First check if there are production runs with precedence not still completed try { - List<GenericValue> mandatoryWorkEfforts = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortAssoc", UtilMisc.toMap("workEffortIdTo", productionRunId, "workEffortAssocTypeId", "WORK_EFF_PRECEDENCY"), null, false)); + List<GenericValue> mandatoryWorkEfforts = EntityQuery.use(delegator).from("WorkEffortAssoc") + .where("workEffortIdTo", productionRunId, + "workEffortAssocTypeId", "WORK_EFF_PRECEDENCY") + .filterByDate().queryList(); for (int i = 0; i < mandatoryWorkEfforts.size(); i++) { GenericValue mandatoryWorkEffortAssoc = mandatoryWorkEfforts.get(i); GenericValue mandatoryWorkEffort = mandatoryWorkEffortAssoc.getRelatedOne("FromWorkEffort", false); @@ -828,7 +836,9 @@ public class ProductionRunServices { if (issueAllComponents.booleanValue()) { // Issue all the components, if this task needs components and they still need to be issued try { - List<GenericValue> inventoryAssigned = delegator.findByAnd("WorkEffortInventoryAssign", UtilMisc.toMap("workEffortId", taskId), null, false); + List<GenericValue> inventoryAssigned = EntityQuery.use(delegator).from("WorkEffortInventoryAssign") + .where("workEffortId", taskId) + .queryList(); if (UtilValidate.isEmpty(inventoryAssigned)) { serviceContext.clear(); serviceContext.put("workEffortId", taskId); @@ -919,9 +929,9 @@ public class ProductionRunServices { totalCost = ZERO; } - List<GenericValue> productCostComponentCalcs = delegator.findByAnd("ProductCostComponentCalc", - UtilMisc.toMap("productId", productionRun.getProductProduced().getString("productId")), - UtilMisc.toList("sequenceNum"), false); + List<GenericValue> productCostComponentCalcs = EntityQuery.use(delegator).from("ProductCostComponentCalc") + .where("productId", productionRun.getProductProduced().get("productId")) + .orderBy("sequenceNum").queryList(); for (int i = 0; i < productCostComponentCalcs.size(); i++) { GenericValue productCostComponentCalc = productCostComponentCalcs.get(i); GenericValue costComponentCalc = productCostComponentCalc.getRelatedOne("CostComponentCalc", false); @@ -969,13 +979,14 @@ public class ProductionRunServices { String workEffortId = (String)context.get("workEffortId"); Locale locale = (Locale) context.get("locale"); try { - GenericValue workEffort = delegator.findOne("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId), false); + GenericValue workEffort = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", workEffortId).queryOne(); if (workEffort == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingWorkEffortNotExist", locale) + " " + workEffortId); } // Get all the valid CostComponents entries - List<GenericValue> costComponents = EntityUtil.filterByDate(delegator.findByAnd("CostComponent", - UtilMisc.toMap("workEffortId", workEffortId), null, false)); + List<GenericValue> costComponents = EntityQuery.use(delegator).from("CostComponent") + .where("workEffortId", workEffortId) + .filterByDate().queryList(); result.put("costComponents", costComponents); // TODO: before doing these totals we should convert the cost components' costs to the // base currency uom of the owner of the facility in which the task is running @@ -1004,8 +1015,10 @@ public class ProductionRunServices { String workEffortId = (String)context.get("workEffortId"); Locale locale = (Locale) context.get("locale"); try { - List<GenericValue> tasks = delegator.findByAnd("WorkEffort", - UtilMisc.toMap("workEffortParentId", workEffortId), UtilMisc.toList("workEffortId"), false); + List<GenericValue> tasks = EntityQuery.use(delegator).from("WorkEffort") + .where("workEffortParentId", workEffortId) + .orderBy("workEffortId") + .queryList(); BigDecimal totalCost = ZERO; Map<String, Object> outputMap = dispatcher.runSync("getWorkEffortCosts", UtilMisc.<String, Object>toMap("userLogin", userLogin, "workEffortId", workEffortId)); @@ -1033,7 +1046,7 @@ public class ProductionRunServices { // this is the id of the actual (real) production run task String productionRunTaskId = (String)context.get("productionRunTaskId"); try { - GenericValue workEffort = delegator.findOne("WorkEffort", UtilMisc.toMap("workEffortId", productionRunTaskId), false); + GenericValue workEffort = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", productionRunTaskId).queryOne(); if (UtilValidate.isEmpty(workEffort)) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunTaskNotFound", UtilMisc.toMap("productionRunTaskId", productionRunTaskId), locale)); } @@ -1049,18 +1062,19 @@ public class ProductionRunServices { actualTotalMilliSeconds += actualSetupMillis.doubleValue(); actualTotalMilliSeconds += actualMilliSeconds.doubleValue(); // Get the template (aka routing task) of the work effort - GenericValue routingTaskAssoc = EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("WorkEffortAssoc", - UtilMisc.toMap("workEffortIdTo", productionRunTaskId, - "workEffortAssocTypeId", "WORK_EFF_TEMPLATE"), null, false))); + GenericValue routingTaskAssoc = EntityQuery.use(delegator).from("WorkEffortAssoc") + .where("workEffortIdTo", productionRunTaskId, + "workEffortAssocTypeId", "WORK_EFF_TEMPLATE") + .filterByDate().queryFirst(); GenericValue routingTask = null; - if (UtilValidate.isNotEmpty(routingTaskAssoc)) { + if (routingTaskAssoc != null) { routingTask = routingTaskAssoc.getRelatedOne("FromWorkEffort", false); } // Get all the valid CostComponentCalc entries - List<GenericValue> workEffortCostCalcs = delegator.findByAnd("WorkEffortCostCalc", - UtilMisc.toMap("workEffortId", productionRunTaskId), null, false); - workEffortCostCalcs = EntityUtil.filterByDate(workEffortCostCalcs); + List<GenericValue> workEffortCostCalcs = EntityQuery.use(delegator).from("WorkEffortCostCalc") + .where("workEffortId", productionRunTaskId) + .filterByDate().queryList(); for (GenericValue workEffortCostCalc : workEffortCostCalcs) { GenericValue costComponentCalc = workEffortCostCalc.getRelatedOne("CostComponentCalc", false); @@ -1139,8 +1153,8 @@ public class ProductionRunServices { // materials costs: these are the costs derived from the materials used by the production run task try { Map<String, BigDecimal> materialsCostByCurrency = FastMap.newInstance(); - for (GenericValue inventoryConsumed : delegator.findByAnd("WorkEffortAndInventoryAssign", - UtilMisc.toMap("workEffortId", productionRunTaskId), null, false)) { + for (GenericValue inventoryConsumed : EntityQuery.use(delegator).from("WorkEffortAndInventoryAssign") + .where("workEffortId", productionRunTaskId).queryList()) { BigDecimal quantity = inventoryConsumed.getBigDecimal("quantity"); BigDecimal unitCost = inventoryConsumed.getBigDecimal("unitCost"); if (UtilValidate.isEmpty(unitCost) || UtilValidate.isEmpty(quantity)) { @@ -1294,7 +1308,7 @@ public class ProductionRunServices { try { // Find the product - GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), false); + GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne(); if (product == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductNotExist", locale)); } @@ -1368,7 +1382,7 @@ public class ProductionRunServices { try { // Find the product - GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), false); + GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne(); if (product == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductNotExist", locale)); } @@ -1437,7 +1451,7 @@ public class ProductionRunServices { // The routing task is loaded GenericValue routingTask = null; try { - routingTask = delegator.findOne("WorkEffort", UtilMisc.toMap("workEffortId", routingTaskId), false); + routingTask = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", routingTaskId).queryOne(); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingRoutingTaskNotExists", locale)); @@ -1503,8 +1517,9 @@ public class ProductionRunServices { // copy date valid WorkEffortPartyAssignments from the routing task to the run task List<GenericValue> workEffortPartyAssignments = null; try { - workEffortPartyAssignments = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortPartyAssignment", - UtilMisc.toMap("workEffortId", routingTaskId), null, false)); + workEffortPartyAssignments = EntityQuery.use(delegator).from("WorkEffortPartyAssignment") + .where("workEffortId", routingTaskId) + .filterByDate().queryList(); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); } @@ -1607,7 +1622,7 @@ public class ProductionRunServices { if (UtilValidate.isNotEmpty(lotId)) { try { // Find the lot - GenericValue lot = delegator.findOne("Lot", UtilMisc.toMap("lotId", lotId), false); + GenericValue lot = EntityQuery.use(delegator).from("Lot").where("lotId", lotId).queryOne(); if (lot == null) { if (createLotIfNeeded.booleanValue()) { lot = delegator.makeValue("Lot", UtilMisc.toMap("lotId", lotId, "creationDate", UtilDateTime.nowTimestamp())); @@ -1960,17 +1975,20 @@ public class ProductionRunServices { // If less than passed quantity then return an error message. try { BigDecimal totalIssued = BigDecimal.ZERO; - for (GenericValue issuance : delegator.findByAnd("WorkEffortAndInventoryAssign", - UtilMisc.toMap("workEffortId", productionRunTaskId, "productId", productId), null, false)) { + for (GenericValue issuance : EntityQuery.use(delegator).from("WorkEffortAndInventoryAssign") + .where("workEffortId", productionRunTaskId, "productId", productId).queryList()) { BigDecimal issued = issuance.getBigDecimal("quantity"); if (issued != null) { totalIssued = totalIssued.add(issued); } } BigDecimal totalReturned = BigDecimal.ZERO; - for (GenericValue returned : delegator.findByAnd("WorkEffortAndInventoryProduced", - UtilMisc.toMap("workEffortId", productionRunTaskId, "productId", productId), null, false)) { - GenericValue returnDetail = EntityUtil.getFirst(delegator.findByAnd("InventoryItemDetail", UtilMisc.toMap("inventoryItemId", returned.getString("inventoryItemId")), UtilMisc.toList("inventoryItemDetailSeqId"), false)); + for (GenericValue returned : EntityQuery.use(delegator).from("WorkEffortAndInventoryProduced") + .where("workEffortId", productionRunTaskId, "productId", productId).queryList()) { + GenericValue returnDetail = EntityQuery.use(delegator).from("InventoryItemDetail") + .where("inventoryItemId", returned.get("inventoryItemId")) + .orderBy("inventoryItemDetailSeqId") + .queryFirst(); if (returnDetail != null) { BigDecimal qtyReturned = returnDetail.getBigDecimal("quantityOnHandDiff"); if (qtyReturned != null) { @@ -2092,7 +2110,10 @@ public class ProductionRunServices { for (GenericValue component : components) { BigDecimal totalRequiredMaterialQuantity = component.getBigDecimal("estimatedQuantity").multiply(totalQuantityProduced).divide(quantityToProduce, rounding); // now get the units that have been already issued and subtract them - List<GenericValue> issuances = delegator.findByAnd("WorkEffortAndInventoryAssign", UtilMisc.toMap("workEffortId", workEffortId, "productId", component.getString("productId")), null, false); + List<GenericValue> issuances = EntityQuery.use(delegator).from("WorkEffortAndInventoryAssign") + .where("workEffortId", workEffortId, + "productId", component.get("productId")) + .queryList(); BigDecimal totalIssued = BigDecimal.ZERO; for (GenericValue issuance : issuances) { BigDecimal issued = issuance.getBigDecimal("quantity"); @@ -2187,7 +2208,7 @@ public class ProductionRunServices { String requirementId = (String)context.get("requirementId"); GenericValue requirement = null; try { - requirement = delegator.findOne("Requirement", UtilMisc.toMap("requirementId", requirementId), false); + requirement = EntityQuery.use(delegator).from("Requirement").where("requirementId", requirementId).queryOne(); } catch (GenericEntityException gee) { } @@ -2218,7 +2239,7 @@ public class ProductionRunServices { GenericValue requirement = null; try { - requirement = delegator.findOne("Requirement", UtilMisc.toMap("requirementId", requirementId), false); + requirement = EntityQuery.use(delegator).from("Requirement").where("requirementId", requirementId).queryOne(); } catch (GenericEntityException gee) { } if (requirement == null) { @@ -2344,9 +2365,10 @@ public class ProductionRunServices { // check if a bom exists List<GenericValue> bomList = null; try { - bomList = delegator.findByAnd("ProductAssoc", - UtilMisc.toMap("productId", componentProductId, "productAssocTypeId", "MANUF_COMPONENT"), null, false); - bomList = EntityUtil.filterByDate(bomList, UtilDateTime.nowTimestamp()); + bomList = EntityQuery.use(delegator).from("ProductAssoc") + .where("productId", componentProductId, + "productAssocTypeId", "MANUF_COMPONENT") + .filterByDate().queryList(); } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunTryToGetBomListError", locale)); } @@ -2441,7 +2463,7 @@ public class ProductionRunServices { // hasn't been reserved and ATP not yet decreased boolean isImmediatelyFulfilled = false; try { - GenericValue order = delegator.findOne("OrderHeader", UtilMisc.toMap("orderId", orderId), false); + GenericValue order = EntityQuery.use(delegator).from("OrderHeader").where("orderId", orderId).queryOne(); GenericValue productStore = delegator.getRelatedOne("ProductStore", order, false); isImmediatelyFulfilled = "Y".equals(productStore.getString("isImmediatelyFulfilled")); } catch (GenericEntityException e) { @@ -2450,7 +2472,7 @@ public class ProductionRunServices { GenericValue orderItem = null; try { - orderItem = delegator.findOne("OrderItem", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId), false); + orderItem = EntityQuery.use(delegator).from("OrderItem").where("orderId", orderId, "orderItemSeqId", orderItemSeqId).queryOne(); } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunForMarketingPackagesCreationError", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId, "errorString", e.getMessage()), locale)); } @@ -2568,9 +2590,9 @@ public class ProductionRunServices { try { GenericValue orderItem = null; if (UtilValidate.isNotEmpty(shipGroupSeqId)) { - orderItem = delegator.findOne("OrderItemShipGroupAssoc", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId, "shipGroupSeqId", shipGroupSeqId), false); + orderItem = EntityQuery.use(delegator).from("OrderItemShipGroupAssoc").where("orderId", orderId, "orderItemSeqId", orderItemSeqId, "shipGroupSeqId", shipGroupSeqId).queryOne(); } else { - orderItem = delegator.findOne("OrderItem", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId), false); + orderItem = EntityQuery.use(delegator).from("OrderItem").where("orderId", orderId, "orderItemSeqId", orderItemSeqId).queryOne(); } if (orderItem == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceOrder, "OrderErrorOrderItemNotFound", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", ""), locale)); @@ -2584,7 +2606,7 @@ public class ProductionRunServices { } } else { try { - orderItems = delegator.findByAnd("OrderItem", UtilMisc.toMap("orderId", orderId), null, false); + orderItems = EntityQuery.use(delegator).from("OrderItem").where("orderId", orderId).queryList(); if (orderItems == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceOrder, "OrderErrorOrderItemNotFound", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", ""), locale)); } @@ -2626,13 +2648,16 @@ public class ProductionRunServices { try { List<GenericValue> existingProductionRuns = null; if (UtilValidate.isNotEmpty(shipGroupSeqId)) { - existingProductionRuns = delegator.findByAnd("WorkOrderItemFulfillment", - UtilMisc.toMap("orderId", orderItemOrShipGroupAssoc.getString("orderId"), - "orderItemSeqId", orderItemOrShipGroupAssoc.getString("orderItemSeqId"), "shipGroupSeqId", shipGroupSeqId), null, true); + existingProductionRuns = EntityQuery.use(delegator).from("WorkOrderItemFulfillment") + .where("orderId", orderItemOrShipGroupAssoc.get("orderId"), + "orderItemSeqId", orderItemOrShipGroupAssoc.get("orderItemSeqId"), + "shipGroupSeqId", shipGroupSeqId) + .cache().queryList(); } else { - existingProductionRuns = delegator.findByAnd("WorkOrderItemFulfillment", - UtilMisc.toMap("orderId", orderItemOrShipGroupAssoc.getString("orderId"), - "orderItemSeqId", orderItemOrShipGroupAssoc.getString("orderItemSeqId")), null, true); + existingProductionRuns = EntityQuery.use(delegator).from("WorkOrderItemFulfillment") + .where("orderId", orderItemOrShipGroupAssoc.get("orderId"), + "orderItemSeqId", orderItemOrShipGroupAssoc.get("orderItemSeqId")) + .cache().queryList(); } if (UtilValidate.isNotEmpty(existingProductionRuns)) { Debug.logWarning("Production Run for order item [" + orderItemOrShipGroupAssoc.getString("orderId") + "/" + orderItemOrShipGroupAssoc.getString("orderItemSeqId") + "] and ship group [" + shipGroupSeqId + "] already exists.", module); @@ -2712,7 +2737,7 @@ public class ProductionRunServices { try { Map<String, Object> serviceContext = FastMap.newInstance(); Map<String, Object> resultService = null; - GenericValue task = delegator.findOne("WorkEffort", UtilMisc.toMap("workEffortId", taskId), false); + GenericValue task = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", taskId).queryOne(); String currentStatusId = task.getString("currentStatusId"); String prevStatusId = ""; while (!"PRUN_COMPLETED".equals(currentStatusId)) { @@ -2913,9 +2938,10 @@ public class ProductionRunServices { findOutgoingProductionRunsStatusConds.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.EQUALS, "PRUN_RUNNING")); findOutgoingProductionRunsConds.add(EntityCondition.makeCondition(findOutgoingProductionRunsStatusConds, EntityOperator.OR)); - List<GenericValue> outgoingProductionRuns = delegator.findList("WorkEffortAndGoods", - EntityCondition.makeCondition(findOutgoingProductionRunsConds, EntityOperator.AND), null, - UtilMisc.toList("-estimatedStartDate"), null, false); + List<GenericValue> outgoingProductionRuns = EntityQuery.use(delegator).from("WorkEffortAndGoods") + .where(findOutgoingProductionRunsConds) + .orderBy("-estimatedStartDate") + .queryList(); if (outgoingProductionRuns != null) { for (int i = 0; i < outgoingProductionRuns.size(); i++) { GenericValue outgoingProductionRun = outgoingProductionRuns.get(i); @@ -2945,7 +2971,7 @@ public class ProductionRunServices { } */ try { - GenericValue inventoryItem = delegator.findOne("InventoryItem", UtilMisc.toMap("inventoryItemId", inventoryItemId), false); + GenericValue inventoryItem = EntityQuery.use(delegator).from("InventoryItem").where("inventoryItemId", inventoryItemId).queryOne(); if (inventoryItem == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceProduct, "ProductInventoryItemNotFound", UtilMisc.toMap("inventoryItemId", inventoryItemId), locale)); } @@ -2985,8 +3011,8 @@ public class ProductionRunServices { BigDecimal quantity = (BigDecimal)context.get("quantity"); List<String> inventoryItemIds = FastList.newInstance(); try { - GenericValue inventoryItem = delegator.findOne("InventoryItem", - UtilMisc.toMap("inventoryItemId", inventoryItemId), false); + GenericValue inventoryItem = EntityQuery.use(delegator).from("InventoryItem") + .where("inventoryItemId", inventoryItemId).queryOne(); if (inventoryItem == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunCannotDecomposingInventoryItem", UtilMisc.toMap("inventoryItemId", inventoryItemId), locale)); } @@ -3086,9 +3112,11 @@ public class ProductionRunServices { Map<String, TreeMap<Timestamp, Object>> products = FastMap.newInstance(); try { - List<GenericValue> resultList = delegator.findByAnd("WorkEffortAndGoods", - UtilMisc.toMap("workEffortGoodStdTypeId", "PRUN_PROD_DELIV", - "statusId", "WEGS_CREATED", "workEffortTypeId", "PROD_ORDER_HEADER"), null, false); + List<GenericValue> resultList = EntityQuery.use(delegator).from("WorkEffortAndGoods") + .where("workEffortGoodStdTypeId", "PRUN_PROD_DELIV", + "statusId", "WEGS_CREATED", + "workEffortTypeId", "PROD_ORDER_HEADER") + .queryList(); for (GenericValue genericResult : resultList) { if ("PRUN_CLOSED".equals(genericResult.getString("currentStatusId")) || "PRUN_CREATED".equals(genericResult.getString("currentStatusId"))) { @@ -3127,9 +3155,10 @@ public class ProductionRunServices { } // Approved purchase orders - resultList = delegator.findByAnd("OrderHeaderAndItems", - UtilMisc.toMap("orderTypeId", "PURCHASE_ORDER", - "itemStatusId", "ITEM_APPROVED"), UtilMisc.toList("orderId"), false); + resultList = EntityQuery.use(delegator).from("OrderHeaderAndItems") + .where("orderTypeId", "PURCHASE_ORDER", + "itemStatusId", "ITEM_APPROVED") + .orderBy("orderId").queryList(); String orderId = null; GenericValue orderDeliverySchedule = null; for (GenericValue genericResult : resultList) { @@ -3138,7 +3167,7 @@ public class ProductionRunServices { orderDeliverySchedule = null; orderId = newOrderId; try { - orderDeliverySchedule = delegator.findOne("OrderDeliverySchedule", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", "_NA_"), false); + orderDeliverySchedule = EntityQuery.use(delegator).from("OrderDeliverySchedule").where("orderId", orderId, "orderItemSeqId", "_NA_").queryOne(); } catch (GenericEntityException e) { } } @@ -3146,7 +3175,7 @@ public class ProductionRunServices { BigDecimal orderQuantity = genericResult.getBigDecimal("quantity"); GenericValue orderItemDeliverySchedule = null; try { - orderItemDeliverySchedule = delegator.findOne("OrderDeliverySchedule", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", genericResult.getString("orderItemSeqId")), false); + orderItemDeliverySchedule = EntityQuery.use(delegator).from("OrderDeliverySchedule").where("orderId", orderId, "orderItemSeqId", genericResult.getString("orderItemSeqId")).queryOne(); } catch (GenericEntityException e) { } Timestamp estimatedShipDate = null; @@ -3180,13 +3209,16 @@ public class ProductionRunServices { backordersCondList.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.GREATER_THAN, BigDecimal.ZERO)); //backordersCondList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "ITEM_CREATED"), EntityOperator.OR, EntityCondition.makeCondition("statusId", EntityOperator.LESS_THAN, "ITEM_APPROVED"))); - List<GenericValue> backorders = delegator.findList("OrderItemAndShipGrpInvResAndItem", - EntityCondition.makeCondition(backordersCondList, EntityOperator.AND), null, - UtilMisc.toList("shipBeforeDate"), null, false); + List<GenericValue> backorders = EntityQuery.use(delegator).from("OrderItemAndShipGrpInvResAndItem") + .where(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.NOT_EQUAL, null), + EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.GREATER_THAN, BigDecimal.ZERO)) + .orderBy("shipBeforeDate").queryList(); for (GenericValue genericResult : backorders) { String productId = genericResult.getString("productId"); - GenericValue orderItemShipGroup = delegator.findOne("OrderItemShipGroup", UtilMisc.toMap("orderId", genericResult.get("orderId"), - "shipGroupSeqId", genericResult.get("shipGroupSeqId")), false); + GenericValue orderItemShipGroup = EntityQuery.use(delegator).from("OrderItemShipGroup") + .where("orderId", genericResult.get("orderId"), + "shipGroupSeqId", genericResult.get("shipGroupSeqId")) + .queryOne(); Timestamp requiredByDate = orderItemShipGroup.getTimestamp("shipByDate"); BigDecimal quantityNotAvailable = genericResult.getBigDecimal("quantityNotAvailable"); @@ -3211,11 +3243,12 @@ public class ProductionRunServices { if (remainingQty.compareTo(quantityNotAvailableRem) >= 0) { remainingQty = remainingQty.subtract(quantityNotAvailableRem); currentDateMap.put("remainingQty", remainingQty); - GenericValue orderItemShipGrpInvRes = delegator.findOne("OrderItemShipGrpInvRes", - UtilMisc.toMap("orderId", genericResult.getString("orderId"), - "shipGroupSeqId", genericResult.getString("shipGroupSeqId"), - "orderItemSeqId", genericResult.getString("orderItemSeqId"), - "inventoryItemId", genericResult.getString("inventoryItemId")), false); + GenericValue orderItemShipGrpInvRes = EntityQuery.use(delegator).from("OrderItemShipGrpInvRes"). + where("orderId", genericResult.get("orderId"), + "shipGroupSeqId", genericResult.get("shipGroupSeqId"), + "orderItemSeqId", genericResult.get("orderItemSeqId"), + "inventoryItemId", genericResult.get("inventoryItemId")) + .queryOne(); orderItemShipGrpInvRes.set("promisedDatetime", currentDate); orderItemShipGrpInvRes.store(); // TODO: set the reservation
Modified: ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/InventoryEventPlannedServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/InventoryEventPlannedServices.java?rev=1635399&r1=1635398&r2=1635399&view=diff ============================================================================== --- ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/InventoryEventPlannedServices.java (original) +++ ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/InventoryEventPlannedServices.java Thu Oct 30 06:10:58 2014 @@ -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.service.DispatchContext; import org.ofbiz.service.ServiceUtil; @@ -66,7 +67,7 @@ public class InventoryEventPlannedServic public static void createOrUpdateMrpEvent(Map<String, Object> mrpEventKeyMap, BigDecimal newQuantity, String facilityId, String eventName, boolean isLate, Delegator delegator) throws GenericEntityException { GenericValue mrpEvent = null; - mrpEvent = delegator.findOne("MrpEvent", mrpEventKeyMap, false); + mrpEvent = EntityQuery.use(delegator).from("MrpEvent").where(mrpEventKeyMap).queryOne(); if (mrpEvent == null) { mrpEvent = delegator.makeValue("MrpEvent", mrpEventKeyMap); mrpEvent.put("quantity", newQuantity.doubleValue()); Modified: ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java?rev=1635399&r1=1635398&r2=1635399&view=diff ============================================================================== --- ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java (original) +++ ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java Thu Oct 30 06:10:58 2014 @@ -25,7 +25,6 @@ import java.util.List; import java.util.ListIterator; import java.util.Locale; import java.util.Map; -import java.util.Set; import javolution.util.FastList; import javolution.util.FastMap; @@ -40,9 +39,8 @@ 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.condition.EntityExpr; -import org.ofbiz.entity.condition.EntityFieldMap; import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.manufacturing.bom.BOMNode; import org.ofbiz.order.order.OrderReadHelper; @@ -77,7 +75,7 @@ public class MrpServices { List<GenericValue> listResult = null; try { - listResult = delegator.findList("MrpEvent", null, null, null, null, false); + listResult = EntityQuery.use(delegator).from("MrpEvent").queryList(); //int numOfRecordsRemoved = delegator.removeByCondition("MrpEvent", null); } catch (GenericEntityException e) { Debug.logError(e,"Error : findList(\"MrpEvent\", null, null, null, null, false)", module); @@ -96,7 +94,10 @@ public class MrpServices { listResult = null; List<GenericValue> listResultRoles = FastList.newInstance(); try { - listResult = delegator.findByAnd("Requirement", UtilMisc.toMap("requirementTypeId", "PRODUCT_REQUIREMENT", "statusId", "REQ_PROPOSED"), null, false); + listResult = EntityQuery.use(delegator).from("Requirement") + .where("requirementTypeId", "PRODUCT_REQUIREMENT", + "statusId", "REQ_PROPOSED") + .queryList(); } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpEventFindError", locale)); } @@ -114,7 +115,10 @@ public class MrpServices { } listResult = null; try { - listResult = delegator.findByAnd("Requirement", UtilMisc.toMap("requirementTypeId", "INTERNAL_REQUIREMENT", "statusId", "REQ_PROPOSED"), null, false); + listResult = EntityQuery.use(delegator).from("Requirement") + .where("requirementTypeId", "INTERNAL_REQUIREMENT", + "statusId", "REQ_PROPOSED") + .queryList(); } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpEventFindError", locale)); } @@ -142,13 +146,13 @@ public class MrpServices { notAssignedDate = new Timestamp(calendar.getTimeInMillis()); } resultList = null; - parameters = UtilMisc.<String, Object>toMap("orderTypeId", "SALES_ORDER", "oiStatusId", "ITEM_APPROVED"); - parameters.put("facilityId", facilityId); try { - resultList = delegator.findByAnd("OrderHeaderItemAndShipGroup", parameters, UtilMisc.toList("orderId"), false); + resultList = EntityQuery.use(delegator).from("OrderHeaderItemAndShipGroup") + .where("orderTypeId", "SALES_ORDER", + "oiStatusId", "ITEM_APPROVED", + "facilityId", facilityId) + .orderBy("orderId").queryList(); } catch (GenericEntityException e) { - Debug.logError(e, "Error : findByAnd(\"OrderItem\", parameters\")", module); - Debug.logError(e, "Error : parameters = "+parameters,module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpEventFindError", locale)); } for (GenericValue genericResult : resultList) { @@ -203,10 +207,12 @@ public class MrpServices { // Loads all the approved product requirements (po requirements) // ---------------------------------------- resultList = null; - parameters = UtilMisc.<String, Object>toMap("requirementTypeId", "PRODUCT_REQUIREMENT", - "statusId", "REQ_APPROVED", "facilityId", facilityId); try { - resultList = delegator.findByAnd("Requirement", parameters, null, false); + resultList = EntityQuery.use(delegator).from("Requirement") + .where("requirementTypeId", "PRODUCT_REQUIREMENT", + "statusId", "REQ_APPROVED", + "facilityId", facilityId) + .queryList(); } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpEventFindError", locale)); } @@ -236,13 +242,19 @@ public class MrpServices { String orderId = null; GenericValue orderDeliverySchedule = null; try { - List<GenericValue> facilityContactMechs = EntityUtil.filterByDate(delegator.findByAnd("FacilityContactMech", UtilMisc.toMap("facilityId", facilityId), null, false)); + List<GenericValue> facilityContactMechs = EntityQuery.use(delegator).from("FacilityContactMech") + .where("facilityId", facilityId) + .filterByDate().queryList(); List<String> facilityContactMechIds = EntityUtil.getFieldListFromEntityList(facilityContactMechs, "contactMechId", true); - List<EntityExpr> searchConditions = UtilMisc.toList(EntityCondition.makeCondition("orderTypeId", EntityOperator.EQUALS, "PURCHASE_ORDER"), - EntityCondition.makeCondition("oiStatusId", EntityOperator.EQUALS, "ITEM_APPROVED"), - EntityCondition.makeCondition("contactMechId", EntityOperator.IN, facilityContactMechIds)); - Set<String> fieldsToSelect = UtilMisc.toSet("orderId", "orderItemSeqId", "productId", "quantity", "cancelQuantity", "oiEstimatedDeliveryDate"); - resultList = delegator.findList("OrderHeaderItemAndShipGroup", EntityCondition.makeCondition(searchConditions, EntityOperator.AND), fieldsToSelect, UtilMisc.toList("orderDate"), null, false); + + resultList = EntityQuery.use(delegator) + .select("orderId", "orderItemSeqId", "productId", "quantity", "cancelQuantity", "oiEstimatedDeliveryDate") + .from("OrderHeaderItemAndShipGroup") + .where(EntityCondition.makeCondition("orderTypeId", EntityOperator.EQUALS, "PURCHASE_ORDER"), + EntityCondition.makeCondition("oiStatusId", EntityOperator.EQUALS, "ITEM_APPROVED"), + EntityCondition.makeCondition("contactMechId", EntityOperator.IN, facilityContactMechIds)) + .orderBy("orderDate") + .queryList(); } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpEventFindError", locale)); @@ -253,7 +265,7 @@ public class MrpServices { orderDeliverySchedule = null; orderId = newOrderId; try { - orderDeliverySchedule = delegator.findOne("OrderDeliverySchedule", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", "_NA_"), false); + orderDeliverySchedule = EntityQuery.use(delegator).from("OrderDeliverySchedule").where("orderId", orderId, "orderItemSeqId", "_NA_").queryOne(); } catch (GenericEntityException e) { } } @@ -280,7 +292,7 @@ public class MrpServices { GenericValue orderItemDeliverySchedule = null; try { - orderItemDeliverySchedule = delegator.findOne("OrderDeliverySchedule", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", genericResult.getString("orderItemSeqId")), false); + orderItemDeliverySchedule = EntityQuery.use(delegator).from("OrderDeliverySchedule").where("orderId", orderId, "orderItemSeqId", genericResult.getString("orderItemSeqId")).queryOne(); } catch (GenericEntityException e) { } Timestamp estimatedShipDate = null; @@ -307,10 +319,12 @@ public class MrpServices { // PRODUCTION Run: components // ---------------------------------------- resultList = null; - parameters = UtilMisc.<String, Object>toMap("workEffortGoodStdTypeId", "PRUNT_PROD_NEEDED", - "statusId", "WEGS_CREATED", "facilityId", facilityId); try { - resultList = delegator.findByAnd("WorkEffortAndGoods", parameters, null, false); + resultList = EntityQuery.use(delegator).from("WorkEffortAndGoods") + .where("workEffortGoodStdTypeId", "PRUNT_PROD_NEEDED", + "statusId", "WEGS_CREATED", + "facilityId", facilityId) + .queryList(); for (GenericValue genericResult : resultList) { if ("PRUN_CLOSED".equals(genericResult.getString("currentStatusId")) || "PRUN_COMPLETED".equals(genericResult.getString("currentStatusId")) || @@ -320,7 +334,9 @@ public class MrpServices { String productId = genericResult.getString("productId"); // get the inventory already consumed BigDecimal consumedInventoryTotal = BigDecimal.ZERO; - List<GenericValue> consumedInventoryItems = delegator.findByAnd("WorkEffortAndInventoryAssign", UtilMisc.toMap("workEffortId", genericResult.getString("workEffortId"), "productId", productId), null, false); + List<GenericValue> consumedInventoryItems = EntityQuery.use(delegator).from("WorkEffortAndInventoryAssign") + .where("workEffortId", genericResult.get("workEffortId"), "productId", productId) + .queryList(); for (GenericValue consumedInventoryItem : consumedInventoryItems) { consumedInventoryTotal = consumedInventoryTotal.add(consumedInventoryItem.getBigDecimal("quantity")); } @@ -342,10 +358,13 @@ public class MrpServices { // PRODUCTION Run: product produced // ---------------------------------------- resultList = null; - parameters = UtilMisc.<String, Object>toMap("workEffortGoodStdTypeId", "PRUN_PROD_DELIV", - "statusId", "WEGS_CREATED", "workEffortTypeId", "PROD_ORDER_HEADER", "facilityId", facilityId); try { - resultList = delegator.findByAnd("WorkEffortAndGoods", parameters, null, false); + resultList = EntityQuery.use(delegator).from("WorkEffortAndGoods") + .where("workEffortGoodStdTypeId", "PRUN_PROD_DELIV", + "statusId", "WEGS_CREATED", + "workEffortTypeId", "PROD_ORDER_HEADER", + "facilityId", facilityId) + .queryList(); for (GenericValue genericResult : resultList) { if ("PRUN_CLOSED".equals(genericResult.getString("currentStatusId")) || "PRUN_COMPLETED".equals(genericResult.getString("currentStatusId")) || @@ -384,7 +403,9 @@ public class MrpServices { resultList = null; parameters = UtilMisc.<String, Object>toMap("facilityId", facilityId); try { - resultList = delegator.findByAnd("ProductFacility", parameters, null, false); + resultList = EntityQuery.use(delegator).from("ProductFacility") + .where("facilityId", facilityId) + .queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Unable to retrieve ProductFacility records.", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpCannotFindProductFacility", locale)); @@ -396,8 +417,9 @@ public class MrpServices { minimumStock = BigDecimal.ZERO; } try { - EntityFieldMap ecl = EntityCondition.makeCondition(UtilMisc.toMap("mrpId", mrpId, "productId", productId), EntityOperator.AND); - long numOfEvents = delegator.findCountByCondition("MrpEvent", ecl, null, null); + long numOfEvents = EntityQuery.use(delegator).from("MrpEvent") + .where("mrpId", mrpId, "productId", productId) + .queryCount(); if (numOfEvents > 0) { continue; } @@ -423,13 +445,15 @@ public class MrpServices { resultList = null; GenericValue facility = null; try { - facility = delegator.findOne("Facility", UtilMisc.toMap("facilityId", facilityId), false); + facility = EntityQuery.use(delegator).from("Facility").where("facilityId", facilityId).queryOne(); } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpEventFindError", locale)); } String partyId = (String)facility.get("ownerPartyId"); try { - resultList = delegator.findByAnd("SalesForecast", UtilMisc.toMap("organizationPartyId", partyId), null, false); + resultList = EntityQuery.use(delegator).from("SalesForecast") + .where("organizationPartyId", partyId) + .queryList(); } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpCannotFindSalesForecasts", locale)); } @@ -437,7 +461,7 @@ public class MrpServices { String customTimePeriodId = genericResult.getString("customTimePeriodId"); GenericValue customTimePeriod = null; try { - customTimePeriod = delegator.findOne("CustomTimePeriod", UtilMisc.toMap("customTimePeriodId", customTimePeriodId), false); + customTimePeriod = EntityQuery.use(delegator).from("CustomTimePeriod").where("customTimePeriodId", customTimePeriodId).queryOne(); } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpCannotFindCustomTimePeriod", locale)); } @@ -447,7 +471,9 @@ public class MrpServices { } else { List<GenericValue> salesForecastDetails = null; try { - salesForecastDetails = delegator.findByAnd("SalesForecastDetail", UtilMisc.toMap("salesForecastId", genericResult.getString("salesForecastId")), null, false); + salesForecastDetails = EntityQuery.use(delegator).from("SalesForecastDetail") + .where("salesForecastId", genericResult.get("salesForecastId")) + .queryList(); } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpCannotFindSalesForecastDetails", locale)); } @@ -590,7 +616,7 @@ public class MrpServices { } if (UtilValidate.isEmpty(facilityId)) { try { - GenericValue facilityGroup = delegator.findOne("FacilityGroup", UtilMisc.toMap("facilityGroupId", facilityGroupId), false); + GenericValue facilityGroup = EntityQuery.use(delegator).from("FacilityGroup").where("facilityGroupId", facilityGroupId).queryOne(); if (UtilValidate.isEmpty(facilityGroup)) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpFacilityGroupIsNotValid", UtilMisc.toMap("facilityGroupId", facilityGroupId), locale)); } @@ -661,7 +687,10 @@ public class MrpServices { filterByConditions = EntityCondition.makeCondition("billOfMaterialLevel", EntityOperator.EQUALS, Long.valueOf(bomLevel)); } try { - listInventoryEventForMRP = delegator.findList("MrpEventView", filterByConditions, null, UtilMisc.toList("productId", "eventDate"), null, false); + listInventoryEventForMRP = EntityQuery.use(delegator).from("MrpEventView") + .where(filterByConditions) + .orderBy("productId", "eventDate") + .queryList(); } catch (GenericEntityException e) { Long bomLevelToString = new Long(bomLevel); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpErrorForBomLevel", UtilMisc.toMap("bomLevel", bomLevelToString.toString(), "errorString", e.getMessage()), locale)); @@ -750,7 +779,7 @@ public class MrpServices { String routingId = (String)serviceResponse.get("workEffortId"); if (routingId != null) { try { - routing = delegator.findOne("WorkEffort", UtilMisc.toMap("workEffortId", routingId), false); + routing = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", routingId).queryOne(); } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingMrpCannotFindProductForEvent", locale)); } Modified: ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/routing/RoutingServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/routing/RoutingServices.java?rev=1635399&r1=1635398&r2=1635399&view=diff ============================================================================== --- ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/routing/RoutingServices.java (original) +++ ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/routing/RoutingServices.java Thu Oct 30 06:10:58 2014 @@ -29,6 +29,7 @@ import org.ofbiz.base.util.UtilPropertie import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.manufacturing.jobshopmgt.ProductionRun; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.LocalDispatcher; @@ -68,7 +69,7 @@ public class RoutingServices { GenericValue task = null; try { - task = delegator.findOne("WorkEffort", UtilMisc.toMap("workEffortId", taskId), false); + task = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", taskId).queryOne(); } catch (GenericEntityException gee) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingRoutingErrorFindingTask", UtilMisc.toMap("taskId", taskId), locale)); } Modified: ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/techdata/TechDataServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/techdata/TechDataServices.java?rev=1635399&r1=1635398&r2=1635399&view=diff ============================================================================== --- ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/techdata/TechDataServices.java (original) +++ ofbiz/branches/json-integration-refactoring/applications/manufacturing/src/org/ofbiz/manufacturing/techdata/TechDataServices.java Thu Oct 30 06:10:58 2014 @@ -39,6 +39,7 @@ import org.ofbiz.entity.condition.Entity import org.ofbiz.entity.condition.EntityConditionList; import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.ServiceUtil; @@ -81,9 +82,11 @@ public class TechDataServices { constraints.add(EntityCondition.makeCondition("currentStatusId", EntityOperator.EQUALS, "ROU_ACTIVE")); constraints.add(EntityCondition.makeCondition("workEffortTypeId", EntityOperator.EQUALS, "ROU_TASK")); - EntityConditionList<EntityExpr> ecl = EntityCondition.makeCondition(constraints, EntityOperator.AND); try { - listRoutingTask = delegator.findList("WorkEffort", ecl, null, UtilMisc.toList("workEffortName"), null, false); + listRoutingTask = EntityQuery.use(delegator).from("WorkEffort") + .where(constraints) + .orderBy("workEffortName") + .queryList(); } catch (GenericEntityException e) { Debug.logWarning(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingTechDataWorkEffortNotExist", UtilMisc.toMap("errorString", e.toString()), locale)); @@ -124,7 +127,10 @@ public class TechDataServices { List<GenericValue> listRoutingTaskAssoc = null; try { - listRoutingTaskAssoc = delegator.findByAnd("WorkEffortAssoc",UtilMisc.toMap("workEffortIdFrom", workEffortIdFrom,"sequenceNum",sequenceNum), UtilMisc.toList("fromDate"), false); + listRoutingTaskAssoc = EntityQuery.use(delegator).from("WorkEffortAssoc") + .where("workEffortIdFrom", workEffortIdFrom,"sequenceNum",sequenceNum) + .orderBy("fromDate") + .queryList(); } catch (GenericEntityException e) { Debug.logWarning(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingTechDataWorkEffortAssocNotExist", UtilMisc.toMap("errorString", e.toString()), locale)); @@ -197,7 +203,7 @@ public class TechDataServices { if (techDataCalendar == null) { try { Delegator delegator = routingTask.getDelegator(); - techDataCalendar = delegator.findOne("TechDataCalendar",UtilMisc.toMap("calendarId","DEFAULT"), false); + techDataCalendar = EntityQuery.use(delegator).from("TechDataCalendar").where("calendarId", "DEFAULT").queryOne(); } catch (GenericEntityException e) { Debug.logError("Pb reading TechDataCalendar DEFAULT"+e.getMessage(), module); } Modified: ofbiz/branches/json-integration-refactoring/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java?rev=1635399&r1=1635398&r2=1635399&view=diff ============================================================================== --- ofbiz/branches/json-integration-refactoring/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java (original) +++ ofbiz/branches/json-integration-refactoring/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java Thu Oct 30 06:10:58 2014 @@ -19,7 +19,6 @@ package org.ofbiz.marketing.marketing; import java.sql.Timestamp; -import java.util.List; import java.util.Locale; import java.util.Map; @@ -31,9 +30,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.condition.EntityCondition; -import org.ofbiz.entity.condition.EntityOperator; -import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; @@ -67,33 +64,32 @@ public class MarketingServices { try { // locate the contact list - Map<String, Object> input = UtilMisc.<String, Object>toMap("contactListId", contactListId); - GenericValue contactList = delegator.findOne("ContactList", input, false); + GenericValue contactList = EntityQuery.use(delegator).from("ContactList").where("contactListId", contactListId).queryOne(); if (contactList == null) { - String error = UtilProperties.getMessage(resourceMarketing, "MarketingContactListNotFound", input, locale); + String error = UtilProperties.getMessage(resourceMarketing, "MarketingContactListNotFound", UtilMisc.<String, Object>toMap("contactListId", contactListId), locale); return ServiceUtil.returnError(error); } // perform actions as the system user - GenericValue userLogin = delegator.findOne("UserLogin", UtilMisc.toMap("userLoginId", "system"), true); + GenericValue userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", "system").cache().queryOne(); // associate the email with anonymous user TODO: do we need a custom contact mech purpose type, say MARKETING_EMAIL? if (partyId == null) { // Check existing email - List<EntityCondition> conds = UtilMisc.<EntityCondition>toList(EntityCondition.makeCondition("infoString", EntityOperator.EQUALS, email)); - conds.add(EntityCondition.makeCondition("contactMechTypeId", EntityOperator.EQUALS, "EMAIL_ADDRESS")); - conds.add(EntityCondition.makeCondition("contactMechPurposeTypeId", EntityOperator.EQUALS, "PRIMARY_EMAIL")); - conds.add(EntityUtil.getFilterByDateExpr("purposeFromDate", "purposeThruDate")); - conds.add(EntityUtil.getFilterByDateExpr()); - List<GenericValue> contacts = delegator.findList("PartyContactDetailByPurpose", EntityCondition.makeCondition(conds), null, UtilMisc.toList("-fromDate"), null, false); - if (UtilValidate.isNotEmpty(contacts)) { - GenericValue contact = EntityUtil.getFirst(contacts); + GenericValue contact = EntityQuery.use(delegator).from("PartyContactDetailByPurpose") + .where("infoString", email, + "contactMechTypeId", "EMAIL_ADDRESS", + "contactMechPurposeTypeId", "PRIMARY_EMAIL") + .orderBy("-fromDate") + .filterByDate("fromDate", "thruDate", "purposeFromDate", "purposeThruDate") + .queryFirst(); + if (contact != null) { partyId = contact.getString("partyId"); } else { partyId = "_NA_"; } } - input = UtilMisc.toMap("userLogin", userLogin, "emailAddress", email, "partyId", partyId, "fromDate", fromDate, "contactMechPurposeTypeId", "OTHER_EMAIL"); + Map<String, Object> input = UtilMisc.toMap("userLogin", userLogin, "emailAddress", email, "partyId", partyId, "fromDate", fromDate, "contactMechPurposeTypeId", "OTHER_EMAIL"); Map<String, Object> serviceResults = dispatcher.runSync("createPartyEmailAddress", input); if (ServiceUtil.isError(serviceResults)) { throw new GenericServiceException(ServiceUtil.getErrorMessage(serviceResults)); Modified: ofbiz/branches/json-integration-refactoring/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java?rev=1635399&r1=1635398&r2=1635399&view=diff ============================================================================== --- ofbiz/branches/json-integration-refactoring/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java (original) +++ ofbiz/branches/json-integration-refactoring/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java Thu Oct 30 06:10:58 2014 @@ -38,6 +38,7 @@ import org.ofbiz.webapp.website.WebSiteW 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.EntityUtilProperties; import org.ofbiz.product.category.CategoryWorker; @@ -61,7 +62,7 @@ public class TrackingCodeEvents { Delegator delegator = (Delegator) request.getAttribute("delegator"); GenericValue trackingCode; try { - trackingCode = delegator.findOne("TrackingCode", UtilMisc.toMap("trackingCodeId", trackingCodeId), true); + trackingCode = EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId", trackingCodeId).cache().queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Error looking up TrackingCode with trackingCodeId [" + trackingCodeId + "], ignoring this trackingCodeId", module); return "error"; @@ -98,7 +99,7 @@ public class TrackingCodeEvents { Delegator delegator = (Delegator) request.getAttribute("delegator"); GenericValue trackingCode; try { - trackingCode = delegator.findOne("TrackingCode", UtilMisc.toMap("trackingCodeId", trackingCodeId), true); + trackingCode = EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId", trackingCodeId).cache().queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Error looking up TrackingCode with trackingCodeId [" + trackingCodeId + "], ignoring this trackingCodeId", module); return "error"; @@ -114,7 +115,7 @@ public class TrackingCodeEvents { if (UtilValidate.isNotEmpty(dtc)) { GenericValue defaultTrackingCode = null; try { - defaultTrackingCode = delegator.findOne("TrackingCode", UtilMisc.toMap("trackingCodeId", dtc), true); + defaultTrackingCode = EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId", dtc).cache().queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Error looking up Default values TrackingCode with trackingCodeId [" + dtc + "], not using the dtc value for new TrackingCode defaults", module); } @@ -209,7 +210,7 @@ public class TrackingCodeEvents { String webSiteId = WebSiteWorker.getWebSiteId(request); if (webSiteId != null) { try { - GenericValue webSite = delegator.findOne("WebSite", UtilMisc.toMap("webSiteId", webSiteId), true); + GenericValue webSite = EntityQuery.use(delegator).from("WebSite").where("webSiteId", webSiteId).cache().queryOne(); if (webSite != null) { cookieDomain = webSite.getString("cookieDomain"); } @@ -320,7 +321,7 @@ public class TrackingCodeEvents { String trackingCodeId = cookies[i].getValue(); GenericValue trackingCode; try { - trackingCode = delegator.findOne("TrackingCode", UtilMisc.toMap("trackingCodeId", trackingCodeId), true); + trackingCode = EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId", trackingCodeId).cache().queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Error looking up TrackingCode with trackingCodeId [" + trackingCodeId + "], ignoring this trackingCodeId", module); continue; @@ -382,7 +383,7 @@ public class TrackingCodeEvents { // find the tracking code object GenericValue trackingCode = null; try { - trackingCode = delegator.findOne("TrackingCode", UtilMisc.toMap("trackingCodeId", trackingCodeId), true); + trackingCode = EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId", trackingCodeId).cache().queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Error looking up TrackingCode with trackingCodeId [" + trackingCodeId + "], ignoring this trackingCodeId", module); } @@ -480,7 +481,7 @@ public class TrackingCodeEvents { } GenericValue trackingCode = null; try { - trackingCode = delegator.findOne("TrackingCode", UtilMisc.toMap("trackingCodeId", trackingCodeId), true); + trackingCode = EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId", trackingCodeId).cache().queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Error looking up TrackingCode with trackingCodeId [" + trackingCodeId + "], ignoring this trackingCodeId", module); } Modified: ofbiz/branches/json-integration-refactoring/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java?rev=1635399&r1=1635398&r2=1635399&view=diff ============================================================================== --- ofbiz/branches/json-integration-refactoring/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java (original) +++ ofbiz/branches/json-integration-refactoring/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java Thu Oct 30 06:10:58 2014 @@ -27,12 +27,10 @@ import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.util.Iterator; -import java.util.List; import java.util.Locale; import java.util.Map; import javolution.util.FastMap; - import net.wimpi.pim.Pim; import net.wimpi.pim.contact.basicimpl.AddressImpl; import net.wimpi.pim.contact.basicimpl.EmailAddressImpl; @@ -61,7 +59,7 @@ import org.ofbiz.entity.GenericEntityExc import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.condition.EntityOperator; -import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.party.party.PartyHelper; import org.ofbiz.party.party.PartyWorker; import org.ofbiz.service.DispatchContext; @@ -116,23 +114,19 @@ public class VCard { serviceCtx.put("city", workAddress.getCity()); serviceCtx.put("postalCode", workAddress.getPostalCode()); - List<GenericValue> countryGeoList = null; - List<GenericValue> stateGeoList = null; - EntityCondition cond = EntityCondition.makeCondition(UtilMisc.toList( - EntityCondition.makeCondition("geoTypeId", EntityOperator.EQUALS, "COUNTRY"), - EntityCondition.makeCondition("geoName", EntityOperator.LIKE, workAddress.getCountry())), EntityOperator.AND); - countryGeoList = delegator.findList("Geo", cond, null, null, null, true); - if (!countryGeoList.isEmpty()) { - GenericValue countryGeo = EntityUtil.getFirst(countryGeoList); + GenericValue countryGeo = EntityQuery.use(delegator).from("Geo") + .where(EntityCondition.makeCondition("geoTypeId", EntityOperator.EQUALS, "COUNTRY"), + EntityCondition.makeCondition("geoName", EntityOperator.LIKE, workAddress.getCountry())) + .cache().queryFirst(); + if (countryGeo != null) { serviceCtx.put("countryGeoId", countryGeo.get("geoId")); } - EntityCondition condition = EntityCondition.makeCondition(UtilMisc.toList( - EntityCondition.makeCondition("geoTypeId", EntityOperator.EQUALS, "STATE"), - EntityCondition.makeCondition("geoName", EntityOperator.LIKE, workAddress.getRegion())), EntityOperator.AND); - stateGeoList = delegator.findList("Geo", condition, null, null, null, true); - if (!stateGeoList.isEmpty()) { - GenericValue stateGeo = EntityUtil.getFirst(stateGeoList); + GenericValue stateGeo = EntityQuery.use(delegator).from("Geo") + .where(EntityCondition.makeCondition("geoTypeId", EntityOperator.EQUALS, "STATE"), + EntityCondition.makeCondition("geoName", EntityOperator.LIKE, workAddress.getRegion())) + .cache().queryFirst(); + if (stateGeo != null) { serviceCtx.put("stateProvinceGeoId", stateGeo.get("geoId")); } } Modified: ofbiz/branches/json-integration-refactoring/applications/order/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/order/servicedef/services.xml?rev=1635399&r1=1635398&r2=1635399&view=diff ============================================================================== --- ofbiz/branches/json-integration-refactoring/applications/order/servicedef/services.xml (original) +++ ofbiz/branches/json-integration-refactoring/applications/order/servicedef/services.xml Thu Oct 30 06:10:58 2014 @@ -1147,4 +1147,11 @@ under the License. <auto-attributes mode="IN" entity-name="OrderItemGroupOrder" include="pk" optional="false"/> </service> + <service name="countProductQuantityOrdered" engine="java" + location="org.ofbiz.order.order.OrderServices" invoke="countProductQuantityOrdered" auth="true"> + <description>count Product Quantity Ordered</description> + <attribute name="productId" type="String" mode="IN" optional="false"/> + <attribute name="quantity" type="BigDecimal" mode="IN" optional="false"/> + </service> + </services> Modified: ofbiz/branches/json-integration-refactoring/applications/order/src/org/ofbiz/order/OrderManagerEvents.java URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/order/src/org/ofbiz/order/OrderManagerEvents.java?rev=1635399&r1=1635398&r2=1635399&view=diff ============================================================================== --- ofbiz/branches/json-integration-refactoring/applications/order/src/org/ofbiz/order/OrderManagerEvents.java (original) +++ ofbiz/branches/json-integration-refactoring/applications/order/src/org/ofbiz/order/OrderManagerEvents.java Thu Oct 30 06:10:58 2014 @@ -44,6 +44,7 @@ import org.ofbiz.entity.condition.Entity import org.ofbiz.entity.condition.EntityConditionList; import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.order.order.OrderChangeHelper; import org.ofbiz.service.GenericServiceException; @@ -137,7 +138,7 @@ public class OrderManagerEvents { GenericValue orderHeader = null; List<GenericValue> orderRoles = null; try { - orderHeader = delegator.findOne("OrderHeader", UtilMisc.toMap("orderId", orderId), false); + orderHeader = EntityQuery.use(delegator).from("OrderHeader").where("orderId", orderId).queryOne(); orderRoles = delegator.findList("OrderRole", EntityCondition.makeCondition("orderId", EntityOperator.EQUALS, orderId), null, null, null, false); } catch (GenericEntityException e) { Debug.logError(e, "Problems reading order header from datasource.", module); Modified: ofbiz/branches/json-integration-refactoring/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java?rev=1635399&r1=1635398&r2=1635399&view=diff ============================================================================== --- ofbiz/branches/json-integration-refactoring/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java (original) +++ ofbiz/branches/json-integration-refactoring/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java Thu Oct 30 06:10:58 2014 @@ -33,10 +33,8 @@ 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.condition.EntityConditionList; -import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; -import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.entity.util.EntityQuery; /** * A package of methods for improving efficiency of financial accounts services @@ -113,8 +111,9 @@ public class FinAccountHelper { newAccountCode.append(char_pool[r.nextInt(char_pool.length)]); } - List<GenericValue> existingAccountsWithCode = delegator.findByAnd("FinAccount", UtilMisc.toMap("finAccountCode", newAccountCode.toString()), null, false); - if (existingAccountsWithCode.size() == 0) { + GenericValue existingAccountWithCode = EntityQuery.use(delegator).from("FinAccount") + .where("finAccountCode", newAccountCode.toString()).queryFirst(); + if (existingAccountWithCode == null) { foundUniqueNewCode = true; } @@ -141,9 +140,9 @@ public class FinAccountHelper { finAccountCode = finAccountCode.toUpperCase().replaceAll("[^0-9A-Z]", ""); // now look for the account - List<GenericValue> accounts = delegator.findByAnd("FinAccount", UtilMisc.toMap("finAccountCode", finAccountCode), null, false); - accounts = EntityUtil.filterByDate(accounts); - + List<GenericValue> accounts = EntityQuery.use(delegator).from("FinAccount") + .where("finAccountCode", finAccountCode) + .filterByDate().queryList(); if (UtilValidate.isEmpty(accounts)) { // OK to display - not a code anyway Debug.logWarning("No fin account found for account code [" + finAccountCode + "]", module); @@ -173,24 +172,26 @@ public class FinAccountHelper { BigDecimal decrementTotal = ZERO; // decrease balance // find the sum of all transactions which increase the value - EntityConditionList<EntityCondition> incrementConditions = EntityCondition.makeCondition(UtilMisc.toList( - EntityCondition.makeCondition("finAccountId", EntityOperator.EQUALS, finAccountId), - EntityCondition.makeCondition("transactionDate", EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime), - EntityCondition.makeCondition(UtilMisc.toList( - EntityCondition.makeCondition("finAccountTransTypeId", EntityOperator.EQUALS, "DEPOSIT"), - EntityCondition.makeCondition("finAccountTransTypeId", EntityOperator.EQUALS, "ADJUSTMENT")), - EntityOperator.OR)), - EntityOperator.AND); - List<GenericValue> transSums = delegator.findList("FinAccountTransSum", incrementConditions, UtilMisc.toSet("amount"), null, null, false); + List<GenericValue> transSums = EntityQuery.use(delegator) + .select("amount") + .from("FinAccountTransSum") + .where(EntityCondition.makeCondition("finAccountId", EntityOperator.EQUALS, finAccountId), + EntityCondition.makeCondition("transactionDate", EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime), + EntityCondition.makeCondition(UtilMisc.toList( + EntityCondition.makeCondition("finAccountTransTypeId", EntityOperator.EQUALS, "DEPOSIT"), + EntityCondition.makeCondition("finAccountTransTypeId", EntityOperator.EQUALS, "ADJUSTMENT")), + EntityOperator.OR)) + .queryList(); incrementTotal = addFirstEntryAmount(incrementTotal, transSums, "amount", (decimals+1), rounding); // now find sum of all transactions with decrease the value - EntityConditionList<EntityExpr> decrementConditions = EntityCondition.makeCondition(UtilMisc.toList( - EntityCondition.makeCondition("finAccountId", EntityOperator.EQUALS, finAccountId), - EntityCondition.makeCondition("transactionDate", EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime), - EntityCondition.makeCondition("finAccountTransTypeId", EntityOperator.EQUALS, "WITHDRAWAL")), - EntityOperator.AND); - transSums = delegator.findList("FinAccountTransSum", decrementConditions, UtilMisc.toSet("amount"), null, null, false); + transSums = EntityQuery.use(delegator) + .select("amount") + .from("FinAccountTransSum") + .where(EntityCondition.makeCondition("finAccountId", EntityOperator.EQUALS, finAccountId), + EntityCondition.makeCondition("transactionDate", EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime), + EntityCondition.makeCondition("finAccountTransTypeId", EntityOperator.EQUALS, "WITHDRAWAL")) + .queryList(); decrementTotal = addFirstEntryAmount(decrementTotal, transSums, "amount", (decimals+1), rounding); // the net balance is just the incrementTotal minus the decrementTotal @@ -211,13 +212,12 @@ public class FinAccountHelper { BigDecimal netBalance = getBalance(finAccountId, asOfDateTime, delegator); // find sum of all authorizations which are not expired and which were authorized before as of time - EntityConditionList<EntityCondition> authorizationConditions = EntityCondition.makeCondition(UtilMisc.toList( - EntityCondition.makeCondition("finAccountId", EntityOperator.EQUALS, finAccountId), - EntityCondition.makeCondition("authorizationDate", EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime), - EntityUtil.getFilterByDateExpr(asOfDateTime)), - EntityOperator.AND); - - List<GenericValue> authSums = delegator.findList("FinAccountAuthSum", authorizationConditions, UtilMisc.toSet("amount"), null, null, false); + List<GenericValue> authSums = EntityQuery.use(delegator) + .select("amount") + .from("FinAccountAuthSum") + .where(EntityCondition.makeCondition("finAccountId", EntityOperator.EQUALS, finAccountId), + EntityCondition.makeCondition("authorizationDate", EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime)) + .queryList(); BigDecimal authorizationsTotal = addFirstEntryAmount(ZERO, authSums, "amount", (decimals+1), rounding); @@ -239,7 +239,7 @@ public class FinAccountHelper { public static boolean validatePin(Delegator delegator, String finAccountId, String pinNumber) { GenericValue finAccount = null; try { - finAccount = delegator.findOne("FinAccount", UtilMisc.toMap("finAccountId", finAccountId), false); + finAccount = EntityQuery.use(delegator).from("FinAccount").where("finAccountId", finAccountId).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, module); } @@ -296,7 +296,7 @@ public class FinAccountHelper { } private static boolean checkIsNumberInDatabase(Delegator delegator, String number) throws GenericEntityException { - GenericValue finAccount = delegator.findOne("FinAccount", UtilMisc.toMap("finAccountId", number), false); + GenericValue finAccount = EntityQuery.use(delegator).from("FinAccount").where("finAccountId", number).queryOne(); return finAccount == null; } Propchange: ofbiz/branches/json-integration-refactoring/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java ------------------------------------------------------------------------------ Merged /ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java:r1634077-1635397