A patch from Nicolas Malin "Refactoring product search by id" (https://issues.apache.org/jira/browse/OFBIZ-2027) - OFBIZ-2027

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk/specialpurpose@709726 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2008-11-01 17:19:32 +00:00
parent dda419d243
commit e608ca2bf8
2 changed files with 6 additions and 32 deletions
@@ -32,6 +32,7 @@ import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.product.product.ProductWorker;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
@@ -41,39 +42,19 @@ public class FacilityServices {
public static final String module = FacilityServices.class.getName();
public static Map findProductsById(DispatchContext dctx, Map context) {
public static Map findProductsById(DispatchContext dctx, Map context) {
GenericDelegator delegator = dctx.getDelegator();
String facilityId = (String) context.get("facilityId");
String idValue = (String) context.get("idValue");
GenericValue product = null;
List productsFound = null;
List<GenericValue> productsFound = null;
GenericValue productItem = null;
if (UtilValidate.isNotEmpty(idValue)) {
// First lets find the productId from the Sku(s)
try {
productsFound = delegator.findByAnd("GoodIdentificationAndProduct",
UtilMisc.toMap("idValue", idValue), UtilMisc.toList("productId"));
} catch (GenericEntityException e) {
Debug.logError(e, module);
throw new GeneralRuntimeException(e.getMessage());
}
}
// Now do a direct lookup..
productItem = null;
try {
productItem = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", idValue));
productsFound = ProductWorker.findProductsById(delegator, idValue, null, false, true);
} catch (GenericEntityException e) {
Debug.logError(e, module);
throw new GeneralRuntimeException(e.getMessage());
}
if (productItem != null) {
if (productsFound == null) {
productsFound = new ArrayList();
}
productsFound.add(productItem);
}
// Send back the results
Map result = ServiceUtil.returnSuccess();
+2 -9
View File
@@ -63,6 +63,7 @@ import org.ofbiz.pos.screen.PosScreen;
import org.ofbiz.pos.screen.SaveSale;
import org.ofbiz.product.config.ProductConfigWrapper;
import org.ofbiz.product.config.ProductConfigWrapper.ConfigOption;
import org.ofbiz.product.product.ProductWorker;
import org.ofbiz.product.store.ProductStoreWorker;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
@@ -192,15 +193,7 @@ public class PosTransaction implements Serializable {
}
public List lookupItem(String sku) throws GeneralException {
// first check for the product
GenericValue product = session.getDelegator().findByPrimaryKey("Product", UtilMisc.toMap("productId", sku));
if (product != null) {
return UtilMisc.toList(product);
} else {
// not found; so we move on to GoodIdentification
return session.getDelegator().findByAnd("GoodIdentificationAndProduct",
UtilMisc.toMap("idValue", sku), UtilMisc.toList("productId"));
}
return ProductWorker.findProductsById( session.getDelegator(), sku, null);
}
public String getOrderId() {