You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by le...@apache.org on 2014/10/30 05:16:34 UTC
svn commit: r1635380 [1/2] - in
/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing: bom/
jobshopmgt/ mrp/ routing/ techdata/
Author: lektran
Date: Thu Oct 30 04:16:33 2014
New Revision: 1635380
URL: http://svn.apache.org/r1635380
Log:
Convert manufacturing app's java files to EntityQuery
Modified:
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMHelper.java
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRun.java
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunHelper.java
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/InventoryEventPlannedServices.java
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/routing/RoutingServices.java
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/techdata/TechDataServices.java
Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMHelper.java?rev=1635380&r1=1635379&r2=1635380&view=diff
==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMHelper.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMHelper.java Thu Oct 30 04:16:33 2014
@@ -28,7 +28,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.EntityUtil;
+import org.ofbiz.entity.util.EntityQuery;
import org.ofbiz.service.LocalDispatcher;
/** Helper class containing static method useful when dealing
@@ -64,9 +64,10 @@ public class BOMHelper {
// If the date is null, set it to today.
if (inDate == null) inDate = new Date();
int maxDepth = 0;
- List<GenericValue> productNodesList = delegator.findByAnd("ProductAssoc",
- UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", bomType), null, true);
- productNodesList = EntityUtil.filterByDate(productNodesList, inDate);
+ List<GenericValue> productNodesList = EntityQuery.use(delegator).from("ProductAssoc")
+ .where("productIdTo", productId,
+ "productAssocTypeId", bomType)
+ .cache().filterByDate(inDate).queryList();
int depth = 0;
for (GenericValue oneNode : productNodesList) {
depth = 0;
@@ -107,9 +108,10 @@ public class BOMHelper {
productIdKeys = tree.getAllProductsId();
productIdKeys.add(productIdKey);
}
- List<GenericValue> productNodesList = delegator.findByAnd("ProductAssoc",
- UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", bomType), null, true);
- productNodesList = EntityUtil.filterByDate(productNodesList, inDate);
+ List<GenericValue> productNodesList = EntityQuery.use(delegator).from("ProductAssoc")
+ .where("productIdTo", productId,
+ "productAssocTypeId", bomType)
+ .cache().filterByDate(inDate).queryList();
GenericValue duplicatedNode = null;
for (GenericValue oneNode : productNodesList) {
for (int i = 0; i < productIdKeys.size(); i++) {
@@ -133,11 +135,16 @@ public class BOMHelper {
String shipmentId = request.getParameter("shipmentId");
try {
- List<GenericValue> shipmentPlans = delegator.findByAnd("OrderShipment", UtilMisc.toMap("shipmentId", shipmentId), null, false);
+ List<GenericValue> shipmentPlans = EntityQuery.use(delegator).from("OrderShipment")
+ .where("shipmentId", shipmentId).queryList();
for (GenericValue shipmentPlan : shipmentPlans) {
GenericValue orderItem = shipmentPlan.getRelatedOne("OrderItem", false);
- List<GenericValue> productionRuns = delegator.findByAnd("WorkOrderItemFulfillment", UtilMisc.toMap("orderId", shipmentPlan.getString("orderId"), "orderItemSeqId", shipmentPlan.getString("orderItemSeqId"), "shipGroupSeqId", shipmentPlan.getString("shipGroupSeqId")), null, true);
+ List<GenericValue> productionRuns = EntityQuery.use(delegator).from("WorkOrderItemFulfillment")
+ .where("orderId", shipmentPlan.get("orderId"),
+ "orderItemSeqId", shipmentPlan.get("orderItemSeqId"),
+ "shipGroupSeqId", shipmentPlan.get("shipGroupSeqId"))
+ .cache().queryList();
if (UtilValidate.isNotEmpty(productionRuns)) {
Debug.logError("Production Run for order item (" + orderItem.getString("orderId") + "/" + orderItem.getString("orderItemSeqId") + ") not created.", module);
continue;
Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java?rev=1635380&r1=1635379&r2=1635380&view=diff
==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java Thu Oct 30 04:16:33 2014
@@ -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.manufacturing.mrp.ProposedOrder;
import org.ofbiz.service.GenericServiceException;
@@ -85,7 +86,7 @@ public class BOMNode {
}
public BOMNode(String productId, Delegator delegator, LocalDispatcher dispatcher, GenericValue userLogin) throws GenericEntityException {
- this(delegator.findOne("Product", UtilMisc.toMap("productId", productId), false), dispatcher, userLogin);
+ this(EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne(), dispatcher, userLogin);
}
protected void loadChildren(String partBomTypeId, Date inDate, List<GenericValue> productFeatures, int type) throws GenericEntityException {
@@ -96,19 +97,19 @@ public class BOMNode {
if (inDate == null) inDate = new Date();
bomTypeId = partBomTypeId;
// Delegator delegator = product.getDelegator();
- List<GenericValue> rows = delegator.findByAnd("ProductAssoc",
- UtilMisc.toMap("productId", product.get("productId"),
- "productAssocTypeId", partBomTypeId),
- UtilMisc.toList("sequenceNum","productIdTo ASC"), false);
- rows = EntityUtil.filterByDate(rows, inDate);
+ List<GenericValue> rows = EntityQuery.use(delegator).from("ProductAssoc")
+ .where("productId", product.get("productId"),
+ "productAssocTypeId", partBomTypeId)
+ .orderBy("sequenceNum", "productIdTo")
+ .filterByDate(inDate).queryList();
if ((UtilValidate.isEmpty(rows)) && substitutedNode != null) {
// If no child is found and this is a substituted node
// we try to search for substituted node's children.
- rows = delegator.findByAnd("ProductAssoc",
- UtilMisc.toMap("productId", substitutedNode.getProduct().get("productId"),
- "productAssocTypeId", partBomTypeId),
- UtilMisc.toList("sequenceNum"), false);
- rows = EntityUtil.filterByDate(rows, inDate);
+ rows = EntityQuery.use(delegator).from("ProductAssoc")
+ .where("productId", substitutedNode.getProduct().get("productId"),
+ "productAssocTypeId", partBomTypeId)
+ .orderBy("sequenceNum")
+ .filterByDate(inDate).queryList();
}
children = FastList.newInstance();
children.addAll(rows);
@@ -225,38 +226,40 @@ public class BOMNode {
// If the part is VIRTUAL and
// productFeatures and productPartRules are not null
// we have to substitute the part with the right part's variant
- List<GenericValue> productPartRules = delegator.findByAnd("ProductManufacturingRule",
- UtilMisc.toMap("productId", productIdForRules,
- "productIdFor", node.get("productId"),
- "productIdIn", node.get("productIdTo")), null, false);
+ List<GenericValue> productPartRules = EntityQuery.use(delegator).from("ProductManufacturingRule")
+ .where("productId", productIdForRules,
+ "productIdFor", node.get("productId"),
+ "productIdIn", node.get("productIdTo"))
+ .filterByDate(inDate).queryList();
if (substitutedNode != null) {
- productPartRules.addAll(delegator.findByAnd("ProductManufacturingRule",
- UtilMisc.toMap("productId", productIdForRules,
- "productIdFor", substitutedNode.getProduct().getString("productId"),
- "productIdIn", node.get("productIdTo")), null, false));
+ productPartRules.addAll(EntityQuery.use(delegator).from("ProductManufacturingRule")
+ .where("productId", productIdForRules,
+ "productIdFor", substitutedNode.getProduct().get("productId"),
+ "productIdIn", node.get("productIdTo"))
+ .filterByDate(inDate).queryList());
}
- productPartRules = EntityUtil.filterByDate(productPartRules, inDate);
newNode = substituteNode(oneChildNode, productFeatures, productPartRules);
if (newNode.equals(oneChildNode)) {
// If no substitution has been done (no valid rule applied),
// we try to search for a generic link-rule
- List<GenericValue> genericLinkRules = delegator.findByAnd("ProductManufacturingRule",
- UtilMisc.toMap("productIdFor", node.get("productId"),
- "productIdIn", node.get("productIdTo")), null, false);
+ List<GenericValue> genericLinkRules = EntityQuery.use(delegator).from("ProductManufacturingRule")
+ .where("productIdFor", node.get("productId"),
+ "productIdIn", node.get("productIdTo"))
+ .filterByDate(inDate).queryList();
if (substitutedNode != null) {
- genericLinkRules.addAll(delegator.findByAnd("ProductManufacturingRule",
- UtilMisc.toMap("productIdFor", substitutedNode.getProduct().getString("productId"),
- "productIdIn", node.get("productIdTo")), null, false));
+ genericLinkRules.addAll(EntityQuery.use(delegator).from("ProductManufacturingRule")
+ .where("productIdFor", substitutedNode.getProduct().get("productId"),
+ "productIdIn", node.get("productIdTo"))
+ .filterByDate(inDate).queryList());
}
- genericLinkRules = EntityUtil.filterByDate(genericLinkRules, inDate);
newNode = substituteNode(oneChildNode, productFeatures, genericLinkRules);
if (newNode.equals(oneChildNode)) {
// If no substitution has been done (no valid rule applied),
// we try to search for a generic node-rule
- List<GenericValue> genericNodeRules = delegator.findByAnd("ProductManufacturingRule",
- UtilMisc.toMap("productIdIn", node.get("productIdTo")),
- UtilMisc.toList("ruleSeqId"), false);
- genericNodeRules = EntityUtil.filterByDate(genericNodeRules, inDate);
+ List<GenericValue> genericNodeRules = EntityQuery.use(delegator).from("ProductManufacturingRule")
+ .where("productIdIn", node.get("productIdTo"))
+ .orderBy("ruleSeqId")
+ .filterByDate(inDate).queryList();
newNode = null;
newNode = substituteNode(oneChildNode, productFeatures, genericNodeRules);
if (newNode.equals(oneChildNode)) {
@@ -321,19 +324,19 @@ public class BOMNode {
bomTypeId = partBomTypeId;
// Delegator delegator = product.getDelegator();
- List<GenericValue> rows = delegator.findByAnd("ProductAssoc",
- UtilMisc.toMap("productIdTo", product.get("productId"),
- "productAssocTypeId", partBomTypeId),
- UtilMisc.toList("sequenceNum"), false);
- rows = EntityUtil.filterByDate(rows, inDate);
+ List<GenericValue> rows = EntityQuery.use(delegator).from("ProductAssoc")
+ .where("productIdTo", product.get("productId"),
+ "productAssocTypeId", partBomTypeId)
+ .orderBy("sequenceNum")
+ .filterByDate(inDate).queryList();
if ((UtilValidate.isEmpty(rows)) && substitutedNode != null) {
// If no parent is found and this is a substituted node
// we try to search for substituted node's parents.
- rows = delegator.findByAnd("ProductAssoc",
- UtilMisc.toMap("productIdTo", substitutedNode.getProduct().get("productId"),
- "productAssocTypeId", partBomTypeId),
- UtilMisc.toList("sequenceNum"), false);
- rows = EntityUtil.filterByDate(rows, inDate);
+ rows = EntityQuery.use(delegator).from("ProductAssoc")
+ .where("productIdTo", substitutedNode.getProduct().get("productId"),
+ "productAssocTypeId", partBomTypeId)
+ .orderBy("sequenceNum")
+ .filterByDate(inDate).queryList();
}
children = FastList.newInstance();
children.addAll(rows);
Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java?rev=1635380&r1=1635379&r2=1635380&view=diff
==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java Thu Oct 30 04:16:33 2014
@@ -37,7 +37,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.EntityUtil;
+import org.ofbiz.entity.util.EntityQuery;
import org.ofbiz.order.order.OrderReadHelper;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.GenericServiceException;
@@ -82,7 +82,8 @@ public class BOMServices {
List<String> bomTypes = FastList.newInstance();
if (bomType == null) {
try {
- List<GenericValue> bomTypesValues = delegator.findByAnd("ProductAssocType", UtilMisc.toMap("parentTypeId", "PRODUCT_COMPONENT"), null, false);
+ List<GenericValue> bomTypesValues = EntityQuery.use(delegator).from("ProductAssocType")
+ .where("parentTypeId", "PRODUCT_COMPONENT").queryList();
for (GenericValue bomTypesValue : bomTypesValues) {
bomTypes.add(bomTypesValue.getString("productAssocTypeId"));
}
@@ -135,19 +136,20 @@ public class BOMServices {
Long llc = null;
try {
- GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), false);
+ GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne();
Map<String, Object> depthResult = dispatcher.runSync("getMaxDepth",
UtilMisc.toMap("productId", productId, "bomType", "MANUF_COMPONENT"));
llc = (Long)depthResult.get("depth");
// If the product is a variant of a virtual, then the billOfMaterialLevel cannot be
// lower than the billOfMaterialLevel of the virtual product.
- List<GenericValue> virtualProducts = delegator.findByAnd("ProductAssoc",
- UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", "PRODUCT_VARIANT"), null, false);
- virtualProducts = EntityUtil.filterByDate(virtualProducts);
+ List<GenericValue> virtualProducts = EntityQuery.use(delegator).from("ProductAssoc")
+ .where("productIdTo", productId,
+ "productAssocTypeId", "PRODUCT_VARIANT")
+ .filterByDate().queryList();
int virtualMaxDepth = 0;
for (GenericValue oneVirtualProductAssoc : virtualProducts) {
int virtualDepth = 0;
- GenericValue virtualProduct = delegator.findOne("Product", UtilMisc.toMap("productId", oneVirtualProductAssoc.getString("productId")), false);
+ GenericValue virtualProduct = EntityQuery.use(delegator).from("Product").where("productId", oneVirtualProductAssoc.getString("productId")).queryOne();
if (virtualProduct.get("billOfMaterialLevel") != null) {
virtualDepth = virtualProduct.getLong("billOfMaterialLevel").intValue();
} else {
@@ -181,11 +183,12 @@ public class BOMServices {
}
}
if (alsoVariants.booleanValue()) {
- List<GenericValue> variantProducts = delegator.findByAnd("ProductAssoc",
- UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT"), null, false);
- variantProducts = EntityUtil.filterByDate(variantProducts, true);
+ List<GenericValue> variantProducts = EntityQuery.use(delegator).from("ProductAssoc")
+ .where("productId", productId,
+ "productAssocTypeId", "PRODUCT_VARIANT")
+ .filterByDate().queryList();
for (GenericValue oneVariantProductAssoc : variantProducts) {
- GenericValue variantProduct = delegator.findOne("Product", UtilMisc.toMap("productId", oneVariantProductAssoc.getString("productId")), false);
+ GenericValue variantProduct = EntityQuery.use(delegator).from("Product").where("productId", oneVariantProductAssoc.getString("productId")).queryOne();
variantProduct.set("billOfMaterialLevel", llc);
variantProduct.store();
}
@@ -210,8 +213,7 @@ public class BOMServices {
Locale locale = (Locale) context.get("locale");
try {
- List<GenericValue> products = delegator.findList("Product", null, null,
- UtilMisc.toList("isVirtual DESC"), null, false);
+ List<GenericValue> products = EntityQuery.use(delegator).from("Product").orderBy("isVirtual DESC").queryList();
Long zero = Long.valueOf(0);
List<GenericValue> allProducts = FastList.newInstance();
for (GenericValue product : products) {
@@ -473,7 +475,7 @@ public class BOMServices {
String shipmentId = (String) context.get("shipmentId");
try {
- List<GenericValue> packages = delegator.findByAnd("ShipmentPackage", UtilMisc.toMap("shipmentId", shipmentId), null, false);
+ List<GenericValue> packages = EntityQuery.use(delegator).from("ShipmentPackage").where("shipmentId", shipmentId).queryList();
if (!UtilValidate.isEmpty(packages)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingBomPackageAlreadyFound", locale));
}
@@ -483,7 +485,7 @@ public class BOMServices {
// ShipmentItems are loaded
List<GenericValue> shipmentItems = null;
try {
- shipmentItems = delegator.findByAnd("ShipmentItem", UtilMisc.toMap("shipmentId", shipmentId), null, false);
+ shipmentItems = EntityQuery.use(delegator).from("ShipmentItem").where("shipmentId", shipmentId).queryList();
} catch (GenericEntityException gee) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingBomErrorLoadingShipmentItems", locale));
}
@@ -491,13 +493,15 @@ public class BOMServices {
Map<String, Object> partyOrderShipments = FastMap.newInstance();
for (GenericValue shipmentItem : shipmentItems) {
// Get the OrderShipments
- List<GenericValue> orderShipments = null;
+ GenericValue orderShipment = null;
try {
- orderShipments = delegator.findByAnd("OrderShipment", UtilMisc.toMap("shipmentId", shipmentId, "shipmentItemSeqId", shipmentItem.getString("shipmentItemSeqId")), null, false);
+ orderShipment = EntityQuery.use(delegator).from("OrderShipment")
+ .where("shipmentId", shipmentId,
+ "shipmentItemSeqId", shipmentItem.get("shipmentItemSeqId"))
+ .queryFirst();
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale));
}
- GenericValue orderShipment = org.ofbiz.entity.util.EntityUtil.getFirst(orderShipments);
if (orderShipment != null && !orderReadHelpers.containsKey(orderShipment.getString("orderId"))) {
orderReadHelpers.put(orderShipment.getString("orderId"), new OrderReadHelper(delegator, orderShipment.getString("orderId")));
}
@@ -575,7 +579,7 @@ public class BOMServices {
if (!boxTypes.containsKey(boxTypeId)) {
GenericValue boxType = null;
try {
- boxType = delegator.findOne("ShipmentBoxType", UtilMisc.toMap("shipmentBoxTypeId", boxTypeId), false);
+ boxType = EntityQuery.use(delegator).from("ShipmentBoxType").where("shipmentBoxTypeId", boxTypeId).queryOne();
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale));
}
@@ -604,7 +608,7 @@ public class BOMServices {
if (!boxTypes.containsKey(boxTypeId)) {
GenericValue boxType = null;
try {
- boxType = delegator.findOne("ShipmentBoxType", UtilMisc.toMap("shipmentBoxTypeId", boxTypeId), false);
+ boxType = EntityQuery.use(delegator).from("ShipmentBoxType").where("shipmentBoxTypeId", boxTypeId).queryOne();
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale));
}
Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java?rev=1635380&r1=1635379&r2=1635380&view=diff
==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java Thu Oct 30 04:16:33 2014
@@ -31,6 +31,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.product.store.ProductStoreWorker;
import org.ofbiz.service.LocalDispatcher;
@@ -97,27 +98,28 @@ public class BOMTree {
this.delegator = delegator;
this.dispatcher = dispatcher;
- inputProduct = delegator.findOne("Product", UtilMisc.toMap("productId", productId), false);
+ inputProduct = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne();
String productIdForRules = productId;
// The selected product features are loaded
- List<GenericValue> productFeaturesAppl = delegator.findByAnd("ProductFeatureAppl",
- UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE"), null, false);
+ List<GenericValue> productFeaturesAppl = EntityQuery.use(delegator).from("ProductFeatureAppl")
+ .where("productId", productId,
+ "productFeatureApplTypeId", "STANDARD_FEATURE")
+ .queryList();
List<GenericValue> productFeatures = FastList.newInstance();
GenericValue oneProductFeatureAppl = null;
for (int i = 0; i < productFeaturesAppl.size(); i++) {
oneProductFeatureAppl = productFeaturesAppl.get(i);
- productFeatures.add(delegator.findOne("ProductFeature",
- UtilMisc.toMap("productFeatureId", oneProductFeatureAppl.getString("productFeatureId")), false));
-
+ productFeatures.add(oneProductFeatureAppl.getRelatedOne("ProductFeature", false));
}
// If the product is manufactured as a different product,
// load the new product
GenericValue manufacturedAsProduct = manufacturedAsProduct(productId, inDate);
// We load the information about the product that needs to be manufactured
// from Product entity
- GenericValue product = delegator.findOne("Product",
- UtilMisc.toMap("productId", (manufacturedAsProduct != null? manufacturedAsProduct.getString("productIdTo"): productId)), false);
+ GenericValue product = EntityQuery.use(delegator).from("Product")
+ .where("productId", (manufacturedAsProduct != null? manufacturedAsProduct.getString("productIdTo"): productId))
+ .queryOne();
if (product == null) return;
BOMNode originalNode = new BOMNode(product, dispatcher, userLogin);
originalNode.setTree(this);
@@ -133,8 +135,9 @@ public class BOMTree {
// load the new product
productIdForRules = virtualProduct.getString("productId");
manufacturedAsProduct = manufacturedAsProduct(virtualProduct.getString("productId"), inDate);
- product = delegator.findOne("Product",
- UtilMisc.toMap("productId", (manufacturedAsProduct != null? manufacturedAsProduct.getString("productIdTo"): virtualProduct.get("productId"))), false);
+ product = EntityQuery.use(delegator).from("Product")
+ .where("productId", (manufacturedAsProduct != null? manufacturedAsProduct.getString("productIdTo"): virtualProduct.get("productId")))
+ .queryOne();
}
}
if (product == null) return;
@@ -162,15 +165,10 @@ public class BOMTree {
}
private GenericValue manufacturedAsProduct(String productId, Date inDate) throws GenericEntityException {
- List<GenericValue> manufacturedAsProducts = delegator.findByAnd("ProductAssoc",
- UtilMisc.toMap("productId", productId,
- "productAssocTypeId", "PRODUCT_MANUFACTURED"), null, false);
- manufacturedAsProducts = EntityUtil.filterByDate(manufacturedAsProducts, inDate);
- GenericValue manufacturedAsProduct = null;
- if (UtilValidate.isNotEmpty(manufacturedAsProducts)) {
- manufacturedAsProduct = EntityUtil.getFirst(manufacturedAsProducts);
- }
- return manufacturedAsProduct;
+ return EntityQuery.use(delegator).from("ProductAssoc")
+ .where("productId", productId,
+ "productAssocTypeId", "PRODUCT_MANUFACTURED")
+ .filterByDate(inDate).queryFirst();
}
private boolean hasBom(GenericValue product, Date inDate) throws GenericEntityException {
@@ -333,7 +331,7 @@ public class BOMTree {
if (root != null) {
if (UtilValidate.isEmpty(facilityId)) {
if (orderId != null) {
- GenericValue order = delegator.findOne("OrderHeader", UtilMisc.toMap("orderId", orderId), false);
+ GenericValue order = EntityQuery.use(delegator).from("OrderHeader").where("orderId", orderId).queryOne();
String productStoreId = order.getString("productStoreId");
if (productStoreId != null) {
GenericValue productStore = ProductStoreWorker.getProductStore(productStoreId, delegator);
@@ -344,7 +342,7 @@ public class BOMTree {
}
if (facilityId == null && shipmentId != null) {
- GenericValue shipment = delegator.findOne("Shipment", UtilMisc.toMap("shipmentId", shipmentId), false);
+ GenericValue shipment = EntityQuery.use(delegator).from("Shipment").where("shipmentId", shipmentId).queryOne();
facilityId = shipment.getString("originFacilityId");
}
}
Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRun.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRun.java?rev=1635380&r1=1635379&r2=1635380&view=diff
==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRun.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRun.java Thu Oct 30 04:16:33 2014
@@ -33,6 +33,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.manufacturing.techdata.TechDataServices;
import org.ofbiz.service.LocalDispatcher;
@@ -76,11 +77,11 @@ public class ProductionRun {
try {
if (! UtilValidate.isEmpty(productionRunId)) {
this.dispatcher = dispatcher;
- GenericValue workEffort = delegator.findOne("WorkEffort", UtilMisc.toMap("workEffortId", productionRunId), false);
+ GenericValue workEffort = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", productionRunId).queryOne();
if (workEffort != null) {
// If this is a task, get the parent production run
if (workEffort.getString("workEffortTypeId") != null && "PROD_ORDER_TASK".equals(workEffort.getString("workEffortTypeId"))) {
- workEffort = delegator.findOne("WorkEffort", UtilMisc.toMap("workEffortId", workEffort.getString("workEffortParentId")), false);
+ workEffort = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", workEffort.getString("workEffortParentId")).queryOne();
}
}
this.productionRun = workEffort;
Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunHelper.java?rev=1635380&r1=1635379&r2=1635380&view=diff
==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunHelper.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunHelper.java Thu Oct 30 04:16:33 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.entity.util.EntityUtil;
import org.ofbiz.service.LocalDispatcher;
@@ -57,7 +58,7 @@ public class ProductionRunHelper {
try {
if (productionRunId != null) {
- GenericValue productionRun = delegator.findOne("WorkEffort", UtilMisc.toMap("workEffortId", productionRunId), false);
+ GenericValue productionRun = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", productionRunId).queryOne();
if (productionRun != null) {
List<GenericValue> productionRunProducts = productionRun.getRelated("WorkEffortGoodStandard", UtilMisc.toMap("workEffortGoodStdTypeId", "PRUN_PROD_DELIV"),null, false);
GenericValue productionRunProduct = EntityUtil.getFirst(productionRunProducts);
@@ -77,17 +78,20 @@ public class ProductionRunHelper {
}
public static boolean hasTask(Delegator delegator, String taskName, String workEffortId) throws GenericEntityException {
- List<GenericValue> tasks = delegator.findByAnd("WorkEffort",
- UtilMisc.toMap("workEffortParentId", workEffortId,
+ List<GenericValue> tasks = EntityQuery.use(delegator).from("WorkEffort")
+ .where("workEffortParentId", workEffortId,
"workEffortTypeId", "PROD_ORDER_TASK",
- "workEffortName", taskName), null, false);
+ "workEffortName", taskName)
+ .queryList();
return (UtilValidate.isNotEmpty(tasks));
}
public static void getLinkedProductionRuns(Delegator delegator, LocalDispatcher dispatcher, String productionRunId, List<ProductionRun> productionRuns) throws GenericEntityException {
productionRuns.add(new ProductionRun(productionRunId, delegator, dispatcher));
- List<GenericValue> linkedWorkEfforts = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortAssoc",
- UtilMisc.toMap("workEffortIdTo", productionRunId, "workEffortAssocTypeId", "WORK_EFF_PRECEDENCY"), null, false));
+ List<GenericValue> linkedWorkEfforts = EntityQuery.use(delegator).from("WorkEffortAssoc")
+ .where("workEffortIdTo", productionRunId,
+ "workEffortAssocTypeId", "WORK_EFF_PRECEDENCY")
+ .filterByDate().queryList();
for (int i = 0; i < linkedWorkEfforts.size(); i++) {
GenericValue link = linkedWorkEfforts.get(i);
getLinkedProductionRuns(delegator, dispatcher, link.getString("workEffortIdFrom"), productionRuns);
@@ -95,8 +99,9 @@ public class ProductionRunHelper {
}
public static String getRootProductionRun(Delegator delegator, String productionRunId) throws GenericEntityException {
- List<GenericValue> linkedWorkEfforts = delegator.findByAnd("WorkEffortAssoc", UtilMisc.toMap("workEffortIdFrom", productionRunId, "workEffortAssocTypeId", "WORK_EFF_PRECEDENCY"), null, false);
- GenericValue linkedWorkEffort = EntityUtil.getFirst(linkedWorkEfforts);
+ GenericValue linkedWorkEffort = EntityQuery.use(delegator).from("WorkEffortAssoc")
+ .where("workEffortIdFrom", productionRunId, "workEffortAssocTypeId", "WORK_EFF_PRECEDENCY")
+ .queryFirst();
if (linkedWorkEffort != null) {
productionRunId = getRootProductionRun(delegator, linkedWorkEffort.getString("workEffortIdTo"));
}
Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java?rev=1635380&r1=1635379&r2=1635380&view=diff
==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java Thu Oct 30 04:16:33 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/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/InventoryEventPlannedServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/InventoryEventPlannedServices.java?rev=1635380&r1=1635379&r2=1635380&view=diff
==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/InventoryEventPlannedServices.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/InventoryEventPlannedServices.java Thu Oct 30 04:16:33 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());