Author: jaz
Date: Wed Apr 18 14:52:58 2007 New Revision: 530173 URL: http://svn.apache.org/viewvc?view=rev&rev=530173 Log: changed a few fields to use like; and changed so most fields can be forced to use like with * or % Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java?view=diff&rev=530173&r1=530172&r2=530173 ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java Wed Apr 18 14:52:58 2007 @@ -24,10 +24,7 @@ import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; -import org.ofbiz.entity.condition.EntityCondition; -import org.ofbiz.entity.condition.EntityConditionList; -import org.ofbiz.entity.condition.EntityExpr; -import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.condition.*; import org.ofbiz.entity.model.DynamicViewEntity; import org.ofbiz.entity.model.ModelKeyMap; import org.ofbiz.entity.util.EntityFindOptions; @@ -100,220 +97,224 @@ String orderId = (String) context.get("orderId"); if (UtilValidate.isNotEmpty(orderId)) { paramList.add("orderId=" + orderId); - conditions.add(new EntityExpr("orderId", EntityOperator.EQUALS, orderId)); - } else { - // the base order header fields - List orderTypeList = (List) context.get("orderTypeId"); - if (orderTypeList != null) { - Iterator i = orderTypeList.iterator(); - List orExprs = FastList.newInstance(); - while (i.hasNext()) { - String orderTypeId = (String) i.next(); - paramList.add("orderTypeId=" + orderTypeId); + conditions.add(makeExpr("orderId", orderId)); + } - if (!"PURCHASE_ORDER".equals(orderTypeId) || ("PURCHASE_ORDER".equals(orderTypeId) && canViewPo)) { - orExprs.add(new EntityExpr("orderTypeId", EntityOperator.EQUALS, orderTypeId)); - } - } - } + // the base order header fields + List orderTypeList = (List) context.get("orderTypeId"); + if (orderTypeList != null) { + Iterator i = orderTypeList.iterator(); + List orExprs = FastList.newInstance(); + while (i.hasNext()) { + String orderTypeId = (String) i.next(); + paramList.add("orderTypeId=" + orderTypeId); - String orderName = (String) context.get("orderName"); - if (UtilValidate.isNotEmpty(orderName)) { - paramList.add("orderName=" + orderName); - conditions.add(new EntityExpr("orderName", EntityOperator.LIKE, "%" + orderName + "%")); - } - - List orderStatusList = (List) context.get("orderStatusId"); - if (orderStatusList != null) { - Iterator i = orderStatusList.iterator(); - List orExprs = FastList.newInstance(); - while (i.hasNext()) { - String orderStatusId = (String) i.next(); - paramList.add("orderStatusId=" + orderStatusId); - if ("PENDING".equals(orderStatusId)) { - List pendExprs = FastList.newInstance(); - pendExprs.add(new EntityExpr("statusId", EntityOperator.EQUALS, "ORDER_CREATED")); - pendExprs.add(new EntityExpr("statusId", EntityOperator.EQUALS, "ORDER_PROCESSING")); - pendExprs.add(new EntityExpr("statusId", EntityOperator.EQUALS, "ORDER_APPROVED")); - orExprs.add(new EntityConditionList(pendExprs, EntityOperator.OR)); - } else { - orExprs.add(new EntityExpr("statusId", EntityOperator.EQUALS, orderStatusId)); - } + if (!"PURCHASE_ORDER".equals(orderTypeId) || ("PURCHASE_ORDER".equals(orderTypeId) && canViewPo)) { + orExprs.add(new EntityExpr("orderTypeId", EntityOperator.EQUALS, orderTypeId)); } - conditions.add(new EntityConditionList(orExprs, EntityOperator.OR)); } + } - List productStoreList = (List) context.get("productStoreId"); - if (productStoreList != null) { - Iterator i = productStoreList.iterator(); - List orExprs = FastList.newInstance(); - while (i.hasNext()) { - String productStoreId = (String) i.next(); - paramList.add("productStoreId=" + productStoreId); - orExprs.add(new EntityExpr("productStoreId", EntityOperator.EQUALS, productStoreId)); - } - conditions.add(new EntityConditionList(orExprs, EntityOperator.OR)); - } + String orderName = (String) context.get("orderName"); + if (UtilValidate.isNotEmpty(orderName)) { + paramList.add("orderName=" + orderName); + conditions.add(makeExpr("orderName", orderName, true)); + } - List webSiteList = (List) context.get("orderWebSiteId"); - if (webSiteList != null) { - Iterator i = webSiteList.iterator(); - List orExprs = FastList.newInstance(); - while (i.hasNext()) { - String webSiteId = (String) i.next(); - paramList.add("webSiteId=" + webSiteId); - orExprs.add(new EntityExpr("webSiteId", EntityOperator.EQUALS, webSiteId)); - } - conditions.add(new EntityConditionList(orExprs, EntityOperator.OR)); + List orderStatusList = (List) context.get("orderStatusId"); + if (orderStatusList != null) { + Iterator i = orderStatusList.iterator(); + List orExprs = FastList.newInstance(); + while (i.hasNext()) { + String orderStatusId = (String) i.next(); + paramList.add("orderStatusId=" + orderStatusId); + if ("PENDING".equals(orderStatusId)) { + List pendExprs = FastList.newInstance(); + pendExprs.add(new EntityExpr("statusId", EntityOperator.EQUALS, "ORDER_CREATED")); + pendExprs.add(new EntityExpr("statusId", EntityOperator.EQUALS, "ORDER_PROCESSING")); + pendExprs.add(new EntityExpr("statusId", EntityOperator.EQUALS, "ORDER_APPROVED")); + orExprs.add(new EntityConditionList(pendExprs, EntityOperator.OR)); + } else { + orExprs.add(new EntityExpr("statusId", EntityOperator.EQUALS, orderStatusId)); + } + } + conditions.add(new EntityConditionList(orExprs, EntityOperator.OR)); + } + + List productStoreList = (List) context.get("productStoreId"); + if (productStoreList != null) { + Iterator i = productStoreList.iterator(); + List orExprs = FastList.newInstance(); + while (i.hasNext()) { + String productStoreId = (String) i.next(); + paramList.add("productStoreId=" + productStoreId); + orExprs.add(new EntityExpr("productStoreId", EntityOperator.EQUALS, productStoreId)); } + conditions.add(new EntityConditionList(orExprs, EntityOperator.OR)); + } - List saleChannelList = (List) context.get("salesChannelEnumId"); - if (saleChannelList != null) { - Iterator i = saleChannelList.iterator(); - List orExprs = FastList.newInstance(); - while (i.hasNext()) { - String salesChannelEnumId = (String) i.next(); - paramList.add("salesChannelEnumId=" + salesChannelEnumId); - orExprs.add(new EntityExpr("salesChannelEnumId", EntityOperator.EQUALS, salesChannelEnumId)); - } - conditions.add(new EntityConditionList(orExprs, EntityOperator.OR)); + List webSiteList = (List) context.get("orderWebSiteId"); + if (webSiteList != null) { + Iterator i = webSiteList.iterator(); + List orExprs = FastList.newInstance(); + while (i.hasNext()) { + String webSiteId = (String) i.next(); + paramList.add("webSiteId=" + webSiteId); + orExprs.add(new EntityExpr("webSiteId", EntityOperator.EQUALS, webSiteId)); } + conditions.add(new EntityConditionList(orExprs, EntityOperator.OR)); + } - String createdBy = (String) context.get("createdBy"); - if (UtilValidate.isNotEmpty(createdBy)) { - paramList.add("createdBy=" + createdBy); - conditions.add(new EntityExpr("createdBy", EntityOperator.EQUALS, createdBy)); + List saleChannelList = (List) context.get("salesChannelEnumId"); + if (saleChannelList != null) { + Iterator i = saleChannelList.iterator(); + List orExprs = FastList.newInstance(); + while (i.hasNext()) { + String salesChannelEnumId = (String) i.next(); + paramList.add("salesChannelEnumId=" + salesChannelEnumId); + orExprs.add(new EntityExpr("salesChannelEnumId", EntityOperator.EQUALS, salesChannelEnumId)); } + conditions.add(new EntityConditionList(orExprs, EntityOperator.OR)); + } - String terminalId = (String) context.get("terminalId"); - if (UtilValidate.isNotEmpty(terminalId)) { - paramList.add("terminalId=" + terminalId); - conditions.add(new EntityExpr("terminalId", EntityOperator.EQUALS, terminalId)); - } + String createdBy = (String) context.get("createdBy"); + if (UtilValidate.isNotEmpty(createdBy)) { + paramList.add("createdBy=" + createdBy); + conditions.add(makeExpr("createdBy", createdBy)); + } - String transactionId = (String) context.get("transactionId"); - if (UtilValidate.isNotEmpty(transactionId)) { - paramList.add("transactionId=" + transactionId); - conditions.add(new EntityExpr("transactionId", EntityOperator.EQUALS, transactionId)); - } + String terminalId = (String) context.get("terminalId"); + if (UtilValidate.isNotEmpty(terminalId)) { + paramList.add("terminalId=" + terminalId); + conditions.add(makeExpr("terminalId", terminalId)); + } - String externalId = (String) context.get("externalId"); - if (UtilValidate.isNotEmpty(externalId)) { - paramList.add("externalId=" + externalId); - conditions.add(new EntityExpr("externalId", EntityOperator.EQUALS, externalId)); - } + String transactionId = (String) context.get("transactionId"); + if (UtilValidate.isNotEmpty(transactionId)) { + paramList.add("transactionId=" + transactionId); + conditions.add(makeExpr("transactionId", transactionId)); + } - String internalCode = (String) context.get("internalCode"); - if (UtilValidate.isNotEmpty(internalCode)) { - paramList.add("internalCode=" + internalCode); - conditions.add(new EntityExpr("internalCode", EntityOperator.EQUALS, internalCode)); - } + String externalId = (String) context.get("externalId"); + if (UtilValidate.isNotEmpty(externalId)) { + paramList.add("externalId=" + externalId); + conditions.add(makeExpr("externalId", externalId)); + } - String dateField = "Y".equals(useEntryDate) ? "entryDate" : "orderDate"; - String minDate = (String) context.get("minDate"); - if (UtilValidate.isNotEmpty(minDate) && minDate.length() > 8) { - minDate = minDate.trim(); - if (minDate.length() < 14) minDate = minDate + " " + "00:00:00.000"; - paramList.add("minDate=" + minDate); + String internalCode = (String) context.get("internalCode"); + if (UtilValidate.isNotEmpty(internalCode)) { + paramList.add("internalCode=" + internalCode); + conditions.add(makeExpr("internalCode", internalCode)); + } - try { - Object converted = ObjectType.simpleTypeConvert(minDate, "Timestamp", null, null); - if (converted != null) { - conditions.add(new EntityExpr(dateField, EntityOperator.GREATER_THAN_EQUAL_TO, converted)); - } - } catch (GeneralException e) { - Debug.logWarning(e.getMessage(), module); + String dateField = "Y".equals(useEntryDate) ? "entryDate" : "orderDate"; + String minDate = (String) context.get("minDate"); + if (UtilValidate.isNotEmpty(minDate) && minDate.length() > 8) { + minDate = minDate.trim(); + if (minDate.length() < 14) minDate = minDate + " " + "00:00:00.000"; + paramList.add("minDate=" + minDate); + + try { + Object converted = ObjectType.simpleTypeConvert(minDate, "Timestamp", null, null); + if (converted != null) { + conditions.add(new EntityExpr(dateField, EntityOperator.GREATER_THAN_EQUAL_TO, converted)); } + } catch (GeneralException e) { + Debug.logWarning(e.getMessage(), module); } + } - String maxDate = (String) context.get("maxDate"); - if (UtilValidate.isNotEmpty(minDate) && maxDate.length() > 8) { - maxDate = maxDate.trim(); - if (maxDate.length() < 14) maxDate = maxDate + " " + "23:59:59.999"; - paramList.add("maxDate=" + maxDate); + String maxDate = (String) context.get("maxDate"); + if (UtilValidate.isNotEmpty(minDate) && maxDate.length() > 8) { + maxDate = maxDate.trim(); + if (maxDate.length() < 14) maxDate = maxDate + " " + "23:59:59.999"; + paramList.add("maxDate=" + maxDate); - try { - Object converted = ObjectType.simpleTypeConvert(maxDate, "Timestamp", null, null); - if (converted != null) { - conditions.add(new EntityExpr("orderDate", EntityOperator.LESS_THAN_EQUAL_TO, converted)); - } - } catch (GeneralException e) { - Debug.logWarning(e.getMessage(), module); + try { + Object converted = ObjectType.simpleTypeConvert(maxDate, "Timestamp", null, null); + if (converted != null) { + conditions.add(new EntityExpr("orderDate", EntityOperator.LESS_THAN_EQUAL_TO, converted)); } + } catch (GeneralException e) { + Debug.logWarning(e.getMessage(), module); } + } - // party (role) fields - String userLoginId = (String) context.get("userLoginId"); - String partyId = (String) context.get("partyId"); - List roleTypeList = (List) context.get("roleTypeId"); + // party (role) fields + String userLoginId = (String) context.get("userLoginId"); + String partyId = (String) context.get("partyId"); + List roleTypeList = (List) context.get("roleTypeId"); - if (UtilValidate.isNotEmpty(userLoginId) && UtilValidate.isEmpty(partyId)) { - GenericValue ul = null; - try { - ul = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", userLoginId)); - } catch (GenericEntityException e) { - Debug.logWarning(e.getMessage(), module); - } - if (ul != null) { - partyId = ul.getString("partyId"); - } + if (UtilValidate.isNotEmpty(userLoginId) && UtilValidate.isEmpty(partyId)) { + GenericValue ul = null; + try { + ul = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", userLoginId)); + } catch (GenericEntityException e) { + Debug.logWarning(e.getMessage(), module); } - - // add the role data to the view - if (roleTypeList != null || partyId != null) { - dve.addMemberEntity("OT", "OrderRole"); - dve.addAlias("OT", "partyId"); - dve.addAlias("OT", "roleTypeId"); - dve.addViewLink("OH", "OT", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("orderId", "orderId"))); + if (ul != null) { + partyId = ul.getString("partyId"); } + } - if (UtilValidate.isNotEmpty(partyId)) { - paramList.add("partyId=" + partyId); - fieldsToSelect.add("partyId"); - conditions.add(new EntityExpr("partyId", EntityOperator.EQUALS, partyId)); - } + // add the role data to the view + if (roleTypeList != null || partyId != null) { + dve.addMemberEntity("OT", "OrderRole"); + dve.addAlias("OT", "partyId"); + dve.addAlias("OT", "roleTypeId"); + dve.addViewLink("OH", "OT", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("orderId", "orderId"))); + } - if (roleTypeList != null) { - fieldsToSelect.add("roleTypeId"); - Iterator i = roleTypeList.iterator(); - List orExprs = FastList.newInstance(); - while (i.hasNext()) { - String roleTypeId = (String) i.next(); - paramList.add("roleTypeId=" + roleTypeId); - orExprs.add(new EntityExpr("roleTypeId", EntityOperator.EQUALS, roleTypeId)); - } - conditions.add(new EntityConditionList(orExprs, EntityOperator.OR)); - } - - // order item fields - String correspondingPoId = (String) context.get("correspondingPoId"); - String subscriptionId = (String) context.get("subscriptionId"); - String productId = (String) context.get("productId"); - String budgetId = (String) context.get("budgetId"); - String quoteId = (String) context.get("quoteId"); + if (UtilValidate.isNotEmpty(partyId)) { + paramList.add("partyId=" + partyId); + fieldsToSelect.add("partyId"); + conditions.add(makeExpr("partyId", partyId)); + } - if (correspondingPoId != null || subscriptionId != null || productId != null || budgetId != null || quoteId != null) { - dve.addMemberEntity("OI", "OrderItem"); - dve.addAlias("OI", "correspondingPoId"); - dve.addAlias("OI", "subscriptionId"); - dve.addAlias("OI", "productId"); - dve.addAlias("OI", "budgetId"); - dve.addAlias("OI", "quoteId"); - dve.addViewLink("OH", "OI", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("orderId", "orderId"))); + if (roleTypeList != null) { + fieldsToSelect.add("roleTypeId"); + Iterator i = roleTypeList.iterator(); + List orExprs = FastList.newInstance(); + while (i.hasNext()) { + String roleTypeId = (String) i.next(); + paramList.add("roleTypeId=" + roleTypeId); + orExprs.add(makeExpr("roleTypeId", roleTypeId)); } + conditions.add(new EntityConditionList(orExprs, EntityOperator.OR)); + } - if (UtilValidate.isNotEmpty(correspondingPoId)) { - paramList.add("correspondingPoId=" + correspondingPoId); - conditions.add(new EntityExpr("correspondingPoId", EntityOperator.EQUALS, correspondingPoId)); - } + // order item fields + String correspondingPoId = (String) context.get("correspondingPoId"); + String subscriptionId = (String) context.get("subscriptionId"); + String productId = (String) context.get("productId"); + String budgetId = (String) context.get("budgetId"); + String quoteId = (String) context.get("quoteId"); - if (UtilValidate.isNotEmpty(subscriptionId)) { - paramList.add("subscriptionId=" + subscriptionId); - conditions.add(new EntityExpr("subscriptionId", EntityOperator.EQUALS, subscriptionId)); - } + if (correspondingPoId != null || subscriptionId != null || productId != null || budgetId != null || quoteId != null) { + dve.addMemberEntity("OI", "OrderItem"); + dve.addAlias("OI", "correspondingPoId"); + dve.addAlias("OI", "subscriptionId"); + dve.addAlias("OI", "productId"); + dve.addAlias("OI", "budgetId"); + dve.addAlias("OI", "quoteId"); + dve.addViewLink("OH", "OI", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("orderId", "orderId"))); + } - if (UtilValidate.isNotEmpty(productId)) { - paramList.add("productId=" + productId); + if (UtilValidate.isNotEmpty(correspondingPoId)) { + paramList.add("correspondingPoId=" + correspondingPoId); + conditions.add(makeExpr("correspondingPoId", correspondingPoId)); + } + + if (UtilValidate.isNotEmpty(subscriptionId)) { + paramList.add("subscriptionId=" + subscriptionId); + conditions.add(makeExpr("subscriptionId", subscriptionId)); + } + + if (UtilValidate.isNotEmpty(productId)) { + paramList.add("productId=" + productId); + if (productId.startsWith("%") || productId.startsWith("*") || productId.endsWith("%") || productId.endsWith("*")) { + conditions.add(makeExpr("productId", productId)); + } else { GenericValue product = null; try { product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId)); @@ -344,122 +345,122 @@ } else { conditions.add(new EntityExpr("productId", EntityOperator.EQUALS, productId)); } - } + } } + } - if (UtilValidate.isNotEmpty(budgetId)) { - paramList.add("budgetId=" + budgetId); - conditions.add(new EntityExpr("budgetId", EntityOperator.EQUALS, budgetId)); - } + if (UtilValidate.isNotEmpty(budgetId)) { + paramList.add("budgetId=" + budgetId); + conditions.add(makeExpr("budgetId", budgetId)); + } - if (UtilValidate.isNotEmpty(quoteId)) { - paramList.add("quoteId=" + quoteId); - conditions.add(new EntityExpr("quoteId", EntityOperator.EQUALS, quoteId)); - } + if (UtilValidate.isNotEmpty(quoteId)) { + paramList.add("quoteId=" + quoteId); + conditions.add(makeExpr("quoteId", quoteId)); + } - // payment preference fields - String billingAccountId = (String) context.get("billingAccountId"); - String finAccountId = (String) context.get("finAccountId"); - String cardNumber = (String) context.get("cardNumber"); - String accountNumber = (String) context.get("accountNumber"); + // payment preference fields + String billingAccountId = (String) context.get("billingAccountId"); + String finAccountId = (String) context.get("finAccountId"); + String cardNumber = (String) context.get("cardNumber"); + String accountNumber = (String) context.get("accountNumber"); - if (billingAccountId != null || finAccountId != null || cardNumber != null || accountNumber != null) { - dve.addMemberEntity("OP", "OrderPaymentPreference"); - dve.addAlias("OP", "billingAccountId"); - dve.addAlias("OP", "finAccountId"); - dve.addAlias("OP", "paymentMethodId"); - dve.addViewLink("OH", "OP", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("orderId", "orderId"))); - } + if (billingAccountId != null || finAccountId != null || cardNumber != null || accountNumber != null) { + dve.addMemberEntity("OP", "OrderPaymentPreference"); + dve.addAlias("OP", "billingAccountId"); + dve.addAlias("OP", "finAccountId"); + dve.addAlias("OP", "paymentMethodId"); + dve.addViewLink("OH", "OP", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("orderId", "orderId"))); + } - // search by billing account ID - if (UtilValidate.isNotEmpty(billingAccountId)) { - paramList.add("billingAccountId=" + billingAccountId); - conditions.add(new EntityExpr("billingAccountId", EntityOperator.EQUALS, billingAccountId)); - } + // search by billing account ID + if (UtilValidate.isNotEmpty(billingAccountId)) { + paramList.add("billingAccountId=" + billingAccountId); + conditions.add(makeExpr("billingAccountId", billingAccountId)); + } - // search by fin account ID - if (UtilValidate.isNotEmpty(finAccountId)) { - paramList.add("finAccountId=" + finAccountId); - conditions.add(new EntityExpr("finAccountId", EntityOperator.EQUALS, finAccountId)); - } + // search by fin account ID + if (UtilValidate.isNotEmpty(finAccountId)) { + paramList.add("finAccountId=" + finAccountId); + conditions.add(makeExpr("finAccountId", finAccountId)); + } - // search by card number - if (UtilValidate.isNotEmpty(cardNumber)) { - dve.addMemberEntity("CC", "CreditCard"); - dve.addAlias("CC", "cardNumber"); - dve.addViewLink("OP", "CC", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("paymentMethodId", "paymentMethodId"))); + // search by card number + if (UtilValidate.isNotEmpty(cardNumber)) { + dve.addMemberEntity("CC", "CreditCard"); + dve.addAlias("CC", "cardNumber"); + dve.addViewLink("OP", "CC", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("paymentMethodId", "paymentMethodId"))); - paramList.add("cardNumber=" + cardNumber); - conditions.add(new EntityExpr("cardNumber", EntityOperator.EQUALS, cardNumber)); - } + paramList.add("cardNumber=" + cardNumber); + conditions.add(makeExpr("cardNumber", cardNumber)); + } - // search by eft account number - if (UtilValidate.isNotEmpty(accountNumber)) { - dve.addMemberEntity("EF", "EftAccount"); - dve.addAlias("EF", "accountNumber"); - dve.addViewLink("OP", "EF", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("paymentMethodId", "paymentMethodId"))); + // search by eft account number + if (UtilValidate.isNotEmpty(accountNumber)) { + dve.addMemberEntity("EF", "EftAccount"); + dve.addAlias("EF", "accountNumber"); + dve.addViewLink("OP", "EF", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("paymentMethodId", "paymentMethodId"))); - paramList.add("accountNumber=" + accountNumber); - conditions.add(new EntityExpr("accountNumber", EntityOperator.EQUALS, accountNumber)); - } + paramList.add("accountNumber=" + accountNumber); + conditions.add(makeExpr("accountNumber", accountNumber)); + } - // shipment/inventory item - String inventoryItemId = (String) context.get("inventoryItemId"); - String softIdentifier = (String) context.get("softIdentifier"); - String serialNumber = (String) context.get("serialNumber"); - String shipmentId = (String) context.get("shipmentId"); + // shipment/inventory item + String inventoryItemId = (String) context.get("inventoryItemId"); + String softIdentifier = (String) context.get("softIdentifier"); + String serialNumber = (String) context.get("serialNumber"); + String shipmentId = (String) context.get("shipmentId"); - if (shipmentId != null || inventoryItemId != null || softIdentifier != null || serialNumber != null) { - dve.addMemberEntity("II", "ItemIssuance"); - dve.addAlias("II", "shipmentId"); - dve.addAlias("II", "inventoryItemId"); - dve.addViewLink("OH", "II", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("orderId", "orderId"))); + if (shipmentId != null || inventoryItemId != null || softIdentifier != null || serialNumber != null) { + dve.addMemberEntity("II", "ItemIssuance"); + dve.addAlias("II", "shipmentId"); + dve.addAlias("II", "inventoryItemId"); + dve.addViewLink("OH", "II", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("orderId", "orderId"))); - if (softIdentifier != null || serialNumber != null) { - dve.addMemberEntity("IV", "InventoryItem"); - dve.addAlias("IV", "softIdentifier"); - dve.addAlias("IV", "serialNumber"); - dve.addViewLink("II", "IV", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("inventoryItemId", "inventoryItemId"))); - } + if (softIdentifier != null || serialNumber != null) { + dve.addMemberEntity("IV", "InventoryItem"); + dve.addAlias("IV", "softIdentifier"); + dve.addAlias("IV", "serialNumber"); + dve.addViewLink("II", "IV", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("inventoryItemId", "inventoryItemId"))); } + } - if (UtilValidate.isNotEmpty(inventoryItemId)) { - paramList.add("inventoryItemId=" + inventoryItemId); - conditions.add(new EntityExpr("inventoryItemId", EntityOperator.EQUALS, inventoryItemId)); - } + if (UtilValidate.isNotEmpty(inventoryItemId)) { + paramList.add("inventoryItemId=" + inventoryItemId); + conditions.add(makeExpr("inventoryItemId", inventoryItemId)); + } - if (UtilValidate.isNotEmpty(softIdentifier)) { - paramList.add("softIdentifier=" + softIdentifier); - conditions.add(new EntityExpr("softIdentifier", EntityOperator.EQUALS, softIdentifier)); - } + if (UtilValidate.isNotEmpty(softIdentifier)) { + paramList.add("softIdentifier=" + softIdentifier); + conditions.add(makeExpr("softIdentifier", softIdentifier, true)); + } - if (UtilValidate.isNotEmpty(serialNumber)) { - paramList.add("serialNumber=" + serialNumber); - conditions.add(new EntityExpr("serialNumber", EntityOperator.EQUALS, serialNumber)); - } + if (UtilValidate.isNotEmpty(serialNumber)) { + paramList.add("serialNumber=" + serialNumber); + conditions.add(makeExpr("serialNumber", serialNumber, true)); + } - if (UtilValidate.isNotEmpty(shipmentId)) { - paramList.add("shipmentId=" + shipmentId); - conditions.add(new EntityExpr("shipmentId", EntityOperator.EQUALS, shipmentId)); - } + if (UtilValidate.isNotEmpty(shipmentId)) { + paramList.add("shipmentId=" + shipmentId); + conditions.add(makeExpr("shipmentId", shipmentId)); + } - // back order checking - String hasBackOrders = (String) context.get("hasBackOrders"); - if (UtilValidate.isNotEmpty(hasBackOrders)) { - dve.addMemberEntity("IR", "OrderItemShipGrpInvRes"); - dve.addAlias("IR", "quantityNotAvailable"); - dve.addViewLink("OH", "IR", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("orderId", "orderId"))); + // back order checking + String hasBackOrders = (String) context.get("hasBackOrders"); + if (UtilValidate.isNotEmpty(hasBackOrders)) { + dve.addMemberEntity("IR", "OrderItemShipGrpInvRes"); + dve.addAlias("IR", "quantityNotAvailable"); + dve.addViewLink("OH", "IR", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("orderId", "orderId"))); - paramList.add("hasBackOrders=" + hasBackOrders); - if ("Y".equals(hasBackOrders)) { - conditions.add(new EntityExpr("quantityNotAvailable", EntityOperator.NOT_EQUAL, null)); - conditions.add(new EntityExpr("quantityNotAvailable", EntityOperator.GREATER_THAN, new Double(0))); - } else if ("N".equals(hasBackOrders)) { - List orExpr = FastList.newInstance(); - orExpr.add(new EntityExpr("quantityNotAvailable", EntityOperator.EQUALS, null)); - orExpr.add(new EntityExpr("quantityNotAvailable", EntityOperator.EQUALS, new Double(0))); - conditions.add(new EntityConditionList(orExpr, EntityOperator.OR)); - } + paramList.add("hasBackOrders=" + hasBackOrders); + if ("Y".equals(hasBackOrders)) { + conditions.add(new EntityExpr("quantityNotAvailable", EntityOperator.NOT_EQUAL, null)); + conditions.add(new EntityExpr("quantityNotAvailable", EntityOperator.GREATER_THAN, new Double(0))); + } else if ("N".equals(hasBackOrders)) { + List orExpr = FastList.newInstance(); + orExpr.add(new EntityExpr("quantityNotAvailable", EntityOperator.EQUALS, null)); + orExpr.add(new EntityExpr("quantityNotAvailable", EntityOperator.EQUALS, new Double(0))); + conditions.add(new EntityConditionList(orExpr, EntityOperator.OR)); } } @@ -620,8 +621,38 @@ result.put("filterPartiallyReceivedPOsList", filterPartiallyReceivedPOs); } - protected boolean validateField(String field) { - boolean notEmpty = UtilValidate.isNotEmpty(field); - return notEmpty && !"ANY".equals(field); + protected static EntityExpr makeExpr(String fieldName, String value) { + return makeExpr(fieldName, value, false); + } + + protected static EntityExpr makeExpr(String fieldName, String value, boolean forceLike) { + EntityComparisonOperator op = forceLike ? EntityOperator.LIKE : EntityOperator.EQUALS; + + if (value.startsWith("*")) { + op = EntityOperator.LIKE; + value = "%" + value.substring(1); + } + else if (value.startsWith("%")) { + op = EntityOperator.LIKE; + } + + if (value.endsWith("*")) { + op = EntityOperator.LIKE; + value = value.substring(0, value.length() - 1) + "%"; + } + else if (value.endsWith("%")) { + op = EntityOperator.LIKE; + } + + if (forceLike) { + if (!value.startsWith("%")) { + value = "%" + value; + } + if (!value.endsWith("%")) { + value = value + "%"; + } + } + + return new EntityExpr(fieldName, op, value); } } |
Free forum by Nabble | Edit this page |