You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mb...@apache.org on 2017/12/15 20:33:57 UTC
svn commit: r1818329 [3/3] -
/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/
Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartEvents.java?rev=1818329&r1=1818328&r2=1818329&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartEvents.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartEvents.java Fri Dec 15 20:33:56 2017
@@ -111,7 +111,7 @@ public class ShoppingCartEvents {
if (!productPromoCode.isEmpty()) {
String productPromoId = productPromoCode.getString("productPromoId");
GenericValue productPromoAction = null;
- Map<String, String> productPromoActionMap = new HashMap<String, String>();
+ Map<String, String> productPromoActionMap = new HashMap<>();
productPromoActionMap.put("productPromoId", productPromoId);
productPromoActionMap.put("productPromoRuleId", "01");
productPromoActionMap.put("productPromoActionSeqId", "01");
@@ -206,7 +206,7 @@ public class ShoppingCartEvents {
// not used right now: Map attributes = null;
String catalogId = CatalogWorker.getCurrentCatalogId(request);
Locale locale = UtilHttp.getLocale(request);
-
+
// Get the parameters as a MAP, remove the productId and quantity params.
Map<String, Object> paramMap = UtilHttp.getCombinedMap(request);
@@ -297,10 +297,9 @@ public class ShoppingCartEvents {
request.setAttribute("product_id", productId);
request.setAttribute("_EVENT_MESSAGE_", UtilProperties.getMessage(resource_error, "cart.addToCart.configureProductBeforeAddingToCart", locale));
return "product";
- } else {
- // load the Config Id
- ProductConfigWorker.storeProductConfigWrapper(configWrapper, delegator);
}
+ // load the Config Id
+ ProductConfigWorker.storeProductConfigWrapper(configWrapper, delegator);
}
@@ -309,7 +308,7 @@ public class ShoppingCartEvents {
if ("VV_FEATURETREE".equals(ProductWorker.getProductVirtualVariantMethod(delegator, productId))) {
// get the selected features.
- List<String> selectedFeatures = new LinkedList<String>();
+ List<String> selectedFeatures = new LinkedList<>();
Enumeration<String> paramNames = UtilGenerics.cast(request.getParameterNames());
while (paramNames.hasMoreElements()) {
String paramName = paramNames.nextElement();
@@ -353,7 +352,7 @@ public class ShoppingCartEvents {
if (priceStr == null) {
priceStr = "0"; // default price is 0
}
-
+
if ("ASSET_USAGE_OUT_IN".equals(ProductWorker.getProductTypeId(delegator, productId))) {
if (paramMap.containsKey("numberOfDay")) {
numberOfDay = (String) paramMap.remove("numberOfDay");
@@ -361,13 +360,15 @@ public class ShoppingCartEvents {
reservEnd = UtilDateTime.addDaysToTimestamp(reservStart, Integer.parseInt(numberOfDay));
}
}
-
+
// get the renting data
if ("ASSET_USAGE".equals(ProductWorker.getProductTypeId(delegator, productId)) || "ASSET_USAGE_OUT_IN".equals(ProductWorker.getProductTypeId(delegator, productId))) {
if (paramMap.containsKey("reservStart")) {
reservStartStr = (String) paramMap.remove("reservStart");
- if (reservStartStr.length() == 10) // only date provided, no time string?
+ if (reservStartStr.length() == 10)
+ {
reservStartStr += " 00:00:00.000000000"; // should have format: yyyy-mm-dd hh:mm:ss.fffffffff
+ }
if (reservStartStr.length() > 0) {
try {
reservStart = java.sql.Timestamp.valueOf(reservStartStr);
@@ -378,13 +379,17 @@ public class ShoppingCartEvents {
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "cart.addToCart.rental.startDate", locale));
return "error";
}
- } else reservStart = null;
+ } else {
+ reservStart = null;
+ }
}
if (paramMap.containsKey("reservEnd")) {
reservEndStr = (String) paramMap.remove("reservEnd");
- if (reservEndStr.length() == 10) // only date provided, no time string?
+ if (reservEndStr.length() == 10)
+ {
reservEndStr += " 00:00:00.000000000"; // should have format: yyyy-mm-dd hh:mm:ss.fffffffff
+ }
if (reservEndStr.length() > 0) {
try {
reservEnd = java.sql.Timestamp.valueOf(reservEndStr);
@@ -394,7 +399,9 @@ public class ShoppingCartEvents {
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "cart.addToCart.rental.endDate", locale));
return "error";
}
- } else reservEnd = null;
+ } else {
+ reservEnd = null;
+ }
}
if (reservStart != null && reservEnd != null) {
@@ -461,7 +468,7 @@ public class ShoppingCartEvents {
// parse the quantity
try {
quantity = (BigDecimal) ObjectType.simpleTypeConvert(quantityStr, "BigDecimal", null, locale);
- //For quantity we should test if we allow to add decimal quantity for this product an productStore :
+ //For quantity we should test if we allow to add decimal quantity for this product an productStore :
// if not and if quantity is in decimal format then return error.
if(! ProductWorker.isDecimalQuantityOrderAllowed(delegator, productId, cart.getProductStoreId())){
BigDecimal remainder = quantity.remainder(BigDecimal.ONE);
@@ -510,7 +517,9 @@ public class ShoppingCartEvents {
// get the ship before date (handles both yyyy-mm-dd input and full timestamp)
shipBeforeDateStr = (String) paramMap.remove("shipBeforeDate");
if (UtilValidate.isNotEmpty(shipBeforeDateStr)) {
- if (shipBeforeDateStr.length() == 10) shipBeforeDateStr += " 00:00:00.000";
+ if (shipBeforeDateStr.length() == 10) {
+ shipBeforeDateStr += " 00:00:00.000";
+ }
try {
shipBeforeDate = java.sql.Timestamp.valueOf(shipBeforeDateStr);
} catch (IllegalArgumentException e) {
@@ -522,7 +531,9 @@ public class ShoppingCartEvents {
// get the ship after date (handles both yyyy-mm-dd input and full timestamp)
shipAfterDateStr = (String) paramMap.remove("shipAfterDate");
if (UtilValidate.isNotEmpty(shipAfterDateStr)) {
- if (shipAfterDateStr.length() == 10) shipAfterDateStr += " 00:00:00.000";
+ if (shipAfterDateStr.length() == 10) {
+ shipAfterDateStr += " 00:00:00.000";
+ }
try {
shipAfterDate = java.sql.Timestamp.valueOf(shipAfterDateStr);
} catch (IllegalArgumentException e) {
@@ -577,7 +588,7 @@ public class ShoppingCartEvents {
EntityCondition.makeCondition(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, productId), EntityOperator.OR, EntityCondition.makeCondition("productIdTo", EntityOperator.EQUALS, productId)),
EntityCondition.makeCondition("productAssocTypeId", EntityOperator.EQUALS, "PRODUCT_INCOMPATABLE")), EntityOperator.AND);
productAssocs = EntityQuery.use(delegator).from("ProductAssoc").where(cond).filterByDate().queryList();
- List<String> productList = new LinkedList<String>();
+ List<String> productList = new LinkedList<>();
for (GenericValue productAssoc : productAssocs) {
if (productId.equals(productAssoc.getString("productId"))) {
productList.add(productAssoc.getString("productIdTo"));
@@ -617,7 +628,7 @@ public class ShoppingCartEvents {
Debug.logError(e.getMessage(), module);
}
}
-
+
// check for alternative packing
if(ProductWorker.isAlternativePacking(delegator, productId , parentProductId)){
GenericValue parentProduct = null;
@@ -661,13 +672,11 @@ public class ShoppingCartEvents {
// Determine where to send the browser
if (controlDirective.equals(ERROR)) {
return "error";
- } else {
- if (cart.viewCartOnAdd()) {
- return "viewcart";
- } else {
- return "success";
- }
}
+ if (cart.viewCartOnAdd()) {
+ return "viewcart";
+ }
+ return "success";
}
public static String addToCartFromOrder(HttpServletRequest request, HttpServletResponse response) {
@@ -689,9 +698,8 @@ public class ShoppingCartEvents {
//Determine where to send the browser
if (controlDirective.equals(ERROR)) {
return "error";
- } else {
- return "success";
}
+ return "success";
}
/** Adds all products in a category according to quantity request parameter
@@ -715,9 +723,8 @@ public class ShoppingCartEvents {
//Determine where to send the browser
if (controlDirective.equals(ERROR)) {
return "error";
- } else {
- return "success";
}
+ return "success";
}
public static String quickInitPurchaseOrder(HttpServletRequest request, HttpServletResponse response) {
@@ -726,7 +733,7 @@ public class ShoppingCartEvents {
HttpSession session = request.getSession();
Locale locale = UtilHttp.getLocale(request);
String supplierPartyId = request.getParameter("supplierPartyId_o_0");
-
+
// check the preferred currency of the supplier, if set, use that for the cart, otherwise use system defaults.
ShoppingCart cart = null;
try {
@@ -739,7 +746,7 @@ public class ShoppingCartEvents {
} catch (GenericEntityException e) {
Debug.logError(e.getMessage(), module);
}
-
+
// TODO: the code below here needs some cleanups
String billToCustomerPartyId = request.getParameter("billToCustomerPartyId_o_0");
if (UtilValidate.isEmpty(billToCustomerPartyId) && UtilValidate.isEmpty(supplierPartyId)) {
@@ -810,9 +817,8 @@ public class ShoppingCartEvents {
//Determine where to send the browser
if (controlDirective.equals(ERROR)) {
return "error";
- } else {
- return "success";
}
+ return "success";
}
/** Adds all products in a category according to default quantity on ProductCategoryMember
@@ -838,16 +844,16 @@ public class ShoppingCartEvents {
//Determine where to send the browser
if (controlDirective.equals(ERROR)) {
return "error";
- } else {
- totalQuantity = (BigDecimal)result.get("totalQuantity");
- Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("totalQuantity", UtilFormatOut.formatQuantity(totalQuantity.doubleValue()));
-
- request.setAttribute("_EVENT_MESSAGE_",
- UtilProperties.getMessage(resource_error, "cart.add_category_defaults",
- messageMap, locale));
-
- return "success";
}
+ totalQuantity = (BigDecimal) result.get("totalQuantity");
+ Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("totalQuantity", UtilFormatOut.formatQuantity(
+ totalQuantity.doubleValue()));
+
+ request.setAttribute("_EVENT_MESSAGE_",
+ UtilProperties.getMessage(resource_error, "cart.add_category_defaults",
+ messageMap, locale));
+
+ return "success";
}
/** Delete an item from the shopping cart. */
@@ -865,9 +871,8 @@ public class ShoppingCartEvents {
//Determine where to send the browser
if (controlDirective.equals(ERROR)) {
return "error";
- } else {
- return "success";
}
+ return "success";
}
/** Update the items in the shopping cart. */
@@ -892,9 +897,8 @@ public class ShoppingCartEvents {
//Determine where to send the browser
if (controlDirective.equals(ERROR)) {
return "error";
- } else {
- return "success";
}
+ return "success";
}
/** Empty the shopping cart. */
@@ -907,7 +911,7 @@ public class ShoppingCartEvents {
GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
if (userLogin != null && "anonymous".equals(userLogin.get("userLoginId"))) {
Locale locale = UtilHttp.getLocale(session);
-
+
// here we want to do a full logout, but not using the normal logout stuff because it saves things in the UserLogin record that we don't want changed for the anonymous user
session.invalidate();
session = request.getSession(true);
@@ -983,7 +987,7 @@ public class ShoppingCartEvents {
}
List<ShoppingCart> cartList = UtilGenerics.checkList(session.getAttribute("shoppingCartList"));
if (UtilValidate.isEmpty(cartList)) {
- cartList = new LinkedList<ShoppingCart>();
+ cartList = new LinkedList<>();
session.setAttribute("shoppingCartList", cartList);
}
ShoppingCart currentCart = (ShoppingCart) session.getAttribute("shoppingCart");
@@ -1126,7 +1130,7 @@ public class ShoppingCartEvents {
ShoppingCart cart = getCartObject(request);
String partyId = request.getParameter("additionalPartyId");
String roleTypeId[] = request.getParameterValues("additionalRoleTypeId");
- List<String> eventList = new LinkedList<String>();
+ List<String> eventList = new LinkedList<>();
Locale locale = UtilHttp.getLocale(request);
int i;
@@ -1158,7 +1162,7 @@ public class ShoppingCartEvents {
ShoppingCart cart = getCartObject(request);
String partyId = request.getParameter("additionalPartyId");
String roleTypeId[] = request.getParameterValues("additionalRoleTypeId");
- List<String> eventList = new LinkedList<String>();
+ List<String> eventList = new LinkedList<>();
Locale locale = UtilHttp.getLocale(request);
int i;
@@ -1222,12 +1226,10 @@ public class ShoppingCartEvents {
request.setAttribute("_ERROR_MESSAGE_", errMsg.toString());
if (result.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_SUCCESS)) {
return NON_CRITICAL_ERROR;
- } else {
- return ERROR;
}
- } else {
- return NO_ERROR;
+ return ERROR;
}
+ return NO_ERROR;
}
/** Assign agreement **/
@@ -1462,7 +1464,7 @@ public class ShoppingCartEvents {
cart.removeAdjustmentByType("PROMOTION_ADJUSTMENT");
String shipGroupSeqId = null;
long groupIndex = cart.getShipInfoSize();
- List<GenericValue> orderAdjustmentList = new ArrayList<GenericValue>();
+ List<GenericValue> orderAdjustmentList = new ArrayList<>();
List<GenericValue> orderAdjustments = cart.getAdjustments();
try {
orderAdjustmentList = EntityQuery.use(delegator).from("OrderAdjustment").where("orderId", orderId).queryList();
@@ -1471,7 +1473,7 @@ public class ShoppingCartEvents {
}
for (long itr = 1; itr <= groupIndex; itr++) {
shipGroupSeqId = UtilFormatOut.formatPaddedNumber(itr, 5);
- List<GenericValue> duplicateAdjustmentList = new ArrayList<GenericValue>();
+ List<GenericValue> duplicateAdjustmentList = new ArrayList<>();
for (GenericValue adjustment: orderAdjustmentList) {
if ("PROMOTION_ADJUSTMENT".equals(adjustment.get("orderAdjustmentTypeId"))) {
cart.addAdjustment(adjustment);
@@ -1692,11 +1694,10 @@ public class ShoppingCartEvents {
if (thisParty == null) {
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderCouldNotLocateTheSelectedParty", locale));
return "error";
- } else {
- cart.setOrderPartyId(partyId);
- if ("PURCHASE_ORDER".equals(cart.getOrderType())) {
- cart.setBillFromVendorPartyId(partyId);
- }
+ }
+ cart.setOrderPartyId(partyId);
+ if ("PURCHASE_ORDER".equals(cart.getOrderType())) {
+ cart.setBillFromVendorPartyId(partyId);
}
} else if (partyId != null && partyId.length() == 0) {
cart.setOrderPartyId("_NA_");
@@ -1704,7 +1705,9 @@ public class ShoppingCartEvents {
}
} else {
partyId = cart.getPartyId();
- if (partyId != null && "_NA_".equals(partyId)) partyId = null;
+ if (partyId != null && "_NA_".equals(partyId)) {
+ partyId = null;
+ }
}
return "success";
@@ -1732,7 +1735,7 @@ public class ShoppingCartEvents {
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
Delegator delegator = (Delegator) request.getAttribute("delegator");
ShoppingCart cart = getCartObject(request);
- List<GenericValue> manualPromotions = new LinkedList<GenericValue>();
+ List<GenericValue> manualPromotions = new LinkedList<>();
// iterate through the context and find all keys that start with "productPromoId_"
Map<String, Object> context = UtilHttp.getParameterMap(request);
@@ -1812,7 +1815,7 @@ public class ShoppingCartEvents {
}
try {
- //For quantity we should test if we allow to add decimal quantity for this product an productStore :
+ //For quantity we should test if we allow to add decimal quantity for this product an productStore :
// if not and if quantity is in decimal format then return error.
if(! ProductWorker.isDecimalQuantityOrderAllowed(delegator, productId, cart.getProductStoreId())){
BigDecimal remainder = quantity.remainder(BigDecimal.ONE);
@@ -1905,7 +1908,7 @@ public class ShoppingCartEvents {
// set the agreement if specified otherwise set the currency
if (UtilValidate.isNotEmpty(agreementId)) {
result = cartHelper.selectAgreement(agreementId);
- }
+ }
if (UtilValidate.isNotEmpty(cart.getCurrency()) && UtilValidate.isNotEmpty(currencyUomId)) {
result = cartHelper.setCurrency(currencyUomId);
}
@@ -1942,15 +1945,21 @@ public class ShoppingCartEvents {
// set the default ship before and after dates if supplied
try {
if (UtilValidate.isNotEmpty(shipBeforeDateStr)) {
- if (shipBeforeDateStr.length() == 10) shipBeforeDateStr += " 00:00:00.000";
+ if (shipBeforeDateStr.length() == 10) {
+ shipBeforeDateStr += " 00:00:00.000";
+ }
cart.setDefaultShipBeforeDate(java.sql.Timestamp.valueOf(shipBeforeDateStr));
}
if (UtilValidate.isNotEmpty(shipAfterDateStr)) {
- if (shipAfterDateStr.length() == 10) shipAfterDateStr += " 00:00:00.000";
+ if (shipAfterDateStr.length() == 10) {
+ shipAfterDateStr += " 00:00:00.000";
+ }
cart.setDefaultShipAfterDate(java.sql.Timestamp.valueOf(shipAfterDateStr));
}
if (UtilValidate.isNotEmpty(cancelBackOrderDateStr)) {
- if (cancelBackOrderDateStr.length() == 10) cancelBackOrderDateStr += " 00:00:00.000";
+ if (cancelBackOrderDateStr.length() == 10) {
+ cancelBackOrderDateStr += " 00:00:00.000";
+ }
cart.setCancelBackOrderDate(java.sql.Timestamp.valueOf(cancelBackOrderDateStr));
}
} catch (IllegalArgumentException e) {
@@ -2060,7 +2069,7 @@ public class ShoppingCartEvents {
", quantity = " + quantity + ", itemType = " + itemType + " and itemDescription = " + itemDescription, module);
HttpSession session = request.getSession();
GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
- Map<String, Object> appendOrderItemMap = new HashMap<String, Object>();
+ Map<String, Object> appendOrderItemMap = new HashMap<>();
appendOrderItemMap.put("productId", productId);
appendOrderItemMap.put("quantity", quantity);
appendOrderItemMap.put("orderId", orderId);
Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartHelper.java?rev=1818329&r1=1818328&r2=1818329&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartHelper.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartHelper.java Fri Dec 15 20:33:56 2017
@@ -180,11 +180,12 @@ public class ShoppingCartHelper {
}
// Create a HashMap of product attributes - From ShoppingCartItem.attributeNames[]
- for (int namesIdx = 0; namesIdx < ShoppingCartItem.attributeNames.length; namesIdx++) {
- if (attributes == null)
- attributes = new HashMap<String, Object>();
- if (context.containsKey(ShoppingCartItem.attributeNames[namesIdx])) {
- attributes.put(ShoppingCartItem.attributeNames[namesIdx], context.get(ShoppingCartItem.attributeNames[namesIdx]));
+ for (String attributeName : ShoppingCartItem.attributeNames) {
+ if (attributes == null) {
+ attributes = new HashMap<>();
+ }
+ if (context.containsKey(attributeName)) {
+ attributes.put(attributeName, context.get(attributeName));
}
}
@@ -205,7 +206,7 @@ public class ShoppingCartHelper {
// Get the additional features selected for the product (if any)
Map<String, Object> selectedFeatures = UtilHttp.makeParamMapWithPrefix(context, null, "FT", null);
- Map<String, GenericValue> additionalFeaturesMap = new HashMap<String, GenericValue>();
+ Map<String, GenericValue> additionalFeaturesMap = new HashMap<>();
for (Entry<String, Object> entry : selectedFeatures.entrySet()) {
String selectedFeatureType = entry.getKey();
String selectedFeatureValue = (String) entry.getValue();
@@ -227,7 +228,7 @@ public class ShoppingCartHelper {
}
// get order item attributes
- Map<String, String> orderItemAttributes = new HashMap<String, String>();
+ Map<String, String> orderItemAttributes = new HashMap<>();
String orderItemAttributePrefix = EntityUtilProperties.getPropertyValue("order", "order.item.attr.prefix", delegator);
for (Entry<String, ? extends Object> entry : context.entrySet()) {
if (entry.getKey().contains(orderItemAttributePrefix) && UtilValidate.isNotEmpty(entry.getValue())) {
@@ -276,7 +277,7 @@ public class ShoppingCartHelper {
}
public Map<String, Object> addToCartFromOrder(String catalogId, String orderId, String[] itemIds, boolean addAll, String itemGroupNumber) {
- List<String> errorMsgs = new ArrayList<String>();
+ List<String> errorMsgs = new ArrayList<>();
Map<String, Object> result;
String errMsg = null;
@@ -320,8 +321,9 @@ public class ShoppingCartHelper {
orderItemTypeId = orderItem.getString("orderItemTypeId");
productId = orderItem.getString("productId");
// do not store rental items
- if ("RENTAL_ORDER_ITEM".equals(orderItemTypeId))
+ if ("RENTAL_ORDER_ITEM".equals(orderItemTypeId)) {
continue;
+ }
if (UtilValidate.isNotEmpty(productId) && orderItem.get("quantity") != null) {
BigDecimal amount = orderItem.getBigDecimal("selectedAmount");
ProductConfigWrapper configWrapper = null;
@@ -341,9 +343,7 @@ public class ShoppingCartHelper {
this.cart.addOrIncreaseItem(UtilValidate.isNotEmpty(aggregatedProdId) ? aggregatedProdId : productId, amount, orderItem.getBigDecimal("quantity"),
null, null, null, null, null, null, null, catalogId, configWrapper, orderItemTypeId, itemGroupNumber, null, dispatcher);
noItems = false;
- } catch (CartItemModifyException e) {
- errorMsgs.add(e.getMessage());
- } catch (ItemNotFoundException e) {
+ } catch (CartItemModifyException | ItemNotFoundException e) {
errorMsgs.add(e.getMessage());
}
}
@@ -393,7 +393,7 @@ public class ShoppingCartHelper {
String quantStr = null;
String itemGroupNumberToUse = itemGroupNumber;
String originalProductId = null;
- if (entry.getKey() instanceof String) {
+ if (UtilValidate.isNotEmpty(entry.getKey())) {
String key = entry.getKey();
int ignIndex = key.indexOf(ignSeparator);
if (ignIndex > 0) {
@@ -440,7 +440,7 @@ public class ShoppingCartHelper {
}
try {
- //For quantity we should test if we allow to add decimal quantity for this product an productStore :
+ //For quantity we should test if we allow to add decimal quantity for this product an productStore :
// if not and if quantity is in decimal format then return error.
if(! ProductWorker.isDecimalQuantityOrderAllowed(delegator, productId, cart.getProductStoreId())){
BigDecimal remainder = quantity.remainder(BigDecimal.ONE);
@@ -460,11 +460,11 @@ public class ShoppingCartHelper {
}
try {
- if (Debug.verboseOn()) Debug.logVerbose("Bulk Adding to cart [" + quantity + "] of [" + productId + "] in Item Group [" + itemGroupNumber + "]", module);
+ if (Debug.verboseOn()) {
+ Debug.logVerbose("Bulk Adding to cart [" + quantity + "] of [" + productId + "] in Item Group [" + itemGroupNumber + "]", module);
+ }
this.cart.addOrIncreaseItem(productId, null, quantity, null, null, null, null, null, null, null, catalogId, null, null, itemGroupNumberToUse, originalProductId, dispatcher);
- } catch (CartItemModifyException e) {
- return ServiceUtil.returnError(e.getMessage());
- } catch (ItemNotFoundException e) {
+ } catch (CartItemModifyException | ItemNotFoundException e) {
return ServiceUtil.returnError(e.getMessage());
}
}
@@ -519,8 +519,8 @@ public class ShoppingCartHelper {
Debug.logError(gee, module);
}
if (requirement == null) {
- return ServiceUtil.returnFailure(UtilProperties.getMessage(resource,
- "OrderRequirementDoesNotExists",
+ return ServiceUtil.returnFailure(UtilProperties.getMessage(resource,
+ "OrderRequirementDoesNotExists",
UtilMisc.toMap("requirementId", requirementId), cart.getLocale()));
}
@@ -542,18 +542,20 @@ public class ShoppingCartHelper {
}
}
if (requirementAlreadyInCart) {
- if (Debug.warningOn()) Debug.logWarning(UtilProperties.getMessage(resource_error, "OrderTheRequirementIsAlreadyInTheCartNotAdding", UtilMisc.toMap("requirementId",requirementId), cart.getLocale()), module);
+ if (Debug.warningOn()) {
+ Debug.logWarning(UtilProperties.getMessage(resource_error, "OrderTheRequirementIsAlreadyInTheCartNotAdding", UtilMisc.toMap("requirementId",requirementId), cart.getLocale()), module);
+ }
continue;
}
try {
- if (Debug.verboseOn()) Debug.logVerbose("Bulk Adding to cart requirement [" + quantity + "] of [" + productId + "]", module);
+ if (Debug.verboseOn()) {
+ Debug.logVerbose("Bulk Adding to cart requirement [" + quantity + "] of [" + productId + "]", module);
+ }
int index = this.cart.addOrIncreaseItem(productId, null, quantity, null, null, null, requirement.getTimestamp("requiredByDate"), null, null, null, catalogId, null, null, itemGroupNumber, null, dispatcher);
ShoppingCartItem sci = this.cart.items().get(index);
sci.setRequirementId(requirementId);
- } catch (CartItemModifyException e) {
- return ServiceUtil.returnError(e.getMessage());
- } catch (ItemNotFoundException e) {
+ } catch (CartItemModifyException | ItemNotFoundException e) {
return ServiceUtil.returnError(e.getMessage());
}
}
@@ -570,7 +572,7 @@ public class ShoppingCartHelper {
* quantity is 0, do not add
*/
public Map<String, Object> addCategoryDefaults(String catalogId, String categoryId, String itemGroupNumber) {
- List<String> errorMsgs = new ArrayList<String>();
+ List<String> errorMsgs = new ArrayList<>();
Map<String, Object> result = null;
String errMsg = null;
@@ -610,9 +612,7 @@ public class ShoppingCartHelper {
null, quantity, null, null, null, null, null, null, null,
catalogId, null, null, itemGroupNumber, null, dispatcher);
totalQuantity = totalQuantity.add(quantity);
- } catch (CartItemModifyException e) {
- errorMsgs.add(e.getMessage());
- } catch (ItemNotFoundException e) {
+ } catch (CartItemModifyException | ItemNotFoundException e) {
errorMsgs.add(e.getMessage());
}
}
@@ -631,7 +631,7 @@ public class ShoppingCartHelper {
/** Delete an item from the shopping cart. */
public Map<String, Object> deleteFromCart(Map<String, ? extends Object> context) {
Map<String, Object> result = null;
- List<String> errorMsgs = new ArrayList<String>();
+ List<String> errorMsgs = new ArrayList<>();
for (String o : context.keySet()) {
if (o.toUpperCase(Locale.getDefault()).startsWith("DELETE")) {
try {
@@ -664,8 +664,8 @@ public class ShoppingCartHelper {
locale = this.cart.getLocale();
}
- List<ShoppingCartItem> deleteList = new ArrayList<ShoppingCartItem>();
- List<String> errorMsgs = new ArrayList<String>();
+ List<ShoppingCartItem> deleteList = new ArrayList<>();
+ List<String> errorMsgs = new ArrayList<>();
BigDecimal oldQuantity;
String oldDescription = "";
@@ -693,7 +693,9 @@ public class ShoppingCartHelper {
BigDecimal quantity = BigDecimal.ONE.negate();
String itemDescription = "";
String itemComment = "";
- if (quantString != null) quantString = quantString.trim();
+ if (quantString != null) {
+ quantString = quantString.trim();
+ }
// get the cart item
ShoppingCartItem item = this.cart.findCartItem(index);
@@ -737,15 +739,17 @@ public class ShoppingCartHelper {
} else if (parameterName.startsWith("shipBeforeDate")) {
if (UtilValidate.isNotEmpty(quantString)) {
// input is either yyyy-mm-dd or a full timestamp
- if (quantString.length() == 10)
+ if (quantString.length() == 10) {
quantString += " 00:00:00.000";
+ }
item.setShipBeforeDate(Timestamp.valueOf(quantString));
}
} else if (parameterName.startsWith("shipAfterDate")) {
if (UtilValidate.isNotEmpty(quantString)) {
// input is either yyyy-mm-dd or a full timestamp
- if (quantString.length() == 10)
+ if (quantString.length() == 10) {
quantString += " 00:00:00.000";
+ }
item.setShipAfterDate(Timestamp.valueOf(quantString));
}
} else if (parameterName.startsWith("amount")) {
@@ -765,7 +769,7 @@ public class ShoppingCartHelper {
}
} else {
quantity = (BigDecimal) ObjectType.simpleTypeConvert(quantString, "BigDecimal", null, locale);
- //For quantity we should test if we allow to add decimal quantity for this product an productStore :
+ //For quantity we should test if we allow to add decimal quantity for this product an productStore :
// if not and if quantity is in decimal format then return error.
if (!ProductWorker.isDecimalQuantityOrderAllowed(delegator, item.getProductId(), cart.getProductStoreId()) && parameterName.startsWith("update")) {
BigDecimal remainder = quantity.remainder(BigDecimal.ONE);
@@ -776,7 +780,7 @@ public class ShoppingCartHelper {
return result;
}
quantity = quantity.setScale(0, UtilNumber.getBigDecimalRoundingMode("order.rounding"));
- }
+ }
else {
quantity = quantity.setScale(UtilNumber.getBigDecimalScale("order.decimals"), UtilNumber.getBigDecimalRoundingMode("order.rounding"));
}
@@ -890,7 +894,7 @@ public class ShoppingCartHelper {
}
} catch (NumberFormatException nfe) {
Debug.logWarning(nfe, UtilProperties.getMessage(resource_error, "OrderCaughtNumberFormatExceptionOnCartUpdate", cart.getLocale()));
- } catch (Exception e) {
+ } catch (GeneralException e) {
Debug.logWarning(e, UtilProperties.getMessage(resource_error, "OrderCaughtExceptionOnCartUpdate", cart.getLocale()));
}
} // else not a parameter we need
@@ -898,8 +902,7 @@ public class ShoppingCartHelper {
// get a list of the items to delete
if (removeSelected) {
- for (int si = 0; si < selectedItems.length; si++) {
- String indexStr = selectedItems[si];
+ for (String indexStr : selectedItems) {
ShoppingCartItem item = null;
try {
int index = Integer.parseInt(indexStr);
@@ -916,8 +919,9 @@ public class ShoppingCartHelper {
for (ShoppingCartItem item : deleteList) {
int itemIndex = this.cart.getItemIndex(item);
- if (Debug.infoOn())
+ if (Debug.infoOn()) {
Debug.logInfo("Removing item index: " + itemIndex, module);
+ }
try {
this.cart.removeCartItem(itemIndex, dispatcher);
cart.setShipmentMethodTypeId(itemIndex, null);
Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java?rev=1818329&r1=1818328&r2=1818329&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartItem.java Fri Dec 15 20:33:56 2017
@@ -141,18 +141,18 @@ public class ShoppingCartItem implements
private Timestamp estimatedShipDate = null;
private Timestamp cancelBackOrderDate = null;
- private Map<String, String> contactMechIdsMap = new HashMap<String, String>();
+ private Map<String, String> contactMechIdsMap = new HashMap<>();
private List<GenericValue> orderItemPriceInfos = null;
- private List<GenericValue> itemAdjustments = new LinkedList<GenericValue>();
+ private List<GenericValue> itemAdjustments = new LinkedList<>();
private boolean isPromo = false;
private BigDecimal promoQuantityUsed = BigDecimal.ZERO;
- private Map<GenericPK, BigDecimal> quantityUsedPerPromoCandidate = new HashMap<GenericPK, BigDecimal>();
- private Map<GenericPK, BigDecimal> quantityUsedPerPromoFailed = new HashMap<GenericPK, BigDecimal>();
- private Map<GenericPK, BigDecimal> quantityUsedPerPromoActual = new HashMap<GenericPK, BigDecimal>();
- private Map<String, GenericValue> additionalProductFeatureAndAppls = new HashMap<String, GenericValue>();
+ private Map<GenericPK, BigDecimal> quantityUsedPerPromoCandidate = new HashMap<>();
+ private Map<GenericPK, BigDecimal> quantityUsedPerPromoFailed = new HashMap<>();
+ private Map<GenericPK, BigDecimal> quantityUsedPerPromoActual = new HashMap<>();
+ private Map<String, GenericValue> additionalProductFeatureAndAppls = new HashMap<>();
private List<String> alternativeOptionProductIds = null;
private ProductConfigWrapper configWrapper = null;
- private List<GenericValue> featuresForSupplier = new LinkedList<GenericValue>();
+ private List<GenericValue> featuresForSupplier = new LinkedList<>();
/**
* Makes a ShoppingCartItem for a purchase order item and adds it to the cart.
@@ -385,7 +385,7 @@ public class ShoppingCartItem implements
ShoppingCart cart, Boolean triggerExternalOpsBool, Boolean triggerPriceRulesBool, GenericValue parentProduct, Boolean skipInventoryChecks, Boolean skipProductChecks) throws CartItemModifyException {
ShoppingCartItem newItem = new ShoppingCartItem(product, additionalProductFeatureAndAppls, attributes, prodCatalogId, configWrapper, cart.getLocale(), itemType, itemGroup, parentProduct);
-
+
selectedAmount = selectedAmount == null ? BigDecimal.ZERO : selectedAmount;
unitPrice = unitPrice == null ? BigDecimal.ZERO : unitPrice;
reservLength = reservLength == null ? BigDecimal.ZERO : reservLength;
@@ -440,11 +440,13 @@ public class ShoppingCartItem implements
}
newItem.setReservPersons(reservPersons);
- if (product.get("reserv2ndPPPerc") != null)
- newItem.setReserv2ndPPPerc(product.getBigDecimal("reserv2ndPPPerc"));
+ if (product.get("reserv2ndPPPerc") != null) {
+ newItem.setReserv2ndPPPerc(product.getBigDecimal("reserv2ndPPPerc"));
+ }
- if (product.get("reservNthPPPerc") != null)
- newItem.setReservNthPPPerc(product.getBigDecimal("reservNthPPPerc"));
+ if (product.get("reservNthPPPerc") != null) {
+ newItem.setReservNthPPPerc(product.getBigDecimal("reservNthPPPerc"));
+ }
if ((accommodationMapId != null) && (accommodationSpotId != null)) {
newItem.setAccommodationId(accommodationMapId,accommodationSpotId);
@@ -495,7 +497,8 @@ public class ShoppingCartItem implements
return newItem;
}
- public static GenericValue findProduct(Delegator delegator, boolean skipProductChecks, String prodCatalogId, String productId, Locale locale) throws CartItemModifyException, ItemNotFoundException {
+ public static GenericValue findProduct(Delegator delegator, boolean skipProductChecks, String prodCatalogId,
+ String productId, Locale locale) throws ItemNotFoundException {
GenericValue product;
try {
@@ -658,28 +661,28 @@ public class ShoppingCartItem implements
this.orderItemAssocTypeId = item.getOrderItemAssocTypeId();
this.setStatusId(item.getStatusId());
if (UtilValidate.isEmpty(item.getOrderItemAttributes())) {
- this.orderItemAttributes = new HashMap<String, String>();
+ this.orderItemAttributes = new HashMap<>();
this.orderItemAttributes.putAll(item.getOrderItemAttributes());
}
- this.attributes = item.getAttributes() == null ? new HashMap<String, Object>() : new HashMap<String, Object>(item.getAttributes());
+ this.attributes = item.getAttributes() == null ? new HashMap<>() : new HashMap<>(item.getAttributes());
this.setOrderItemSeqId(item.getOrderItemSeqId());
this.locale = item.locale;
this.setShipBeforeDate(item.getShipBeforeDate());
this.setShipAfterDate(item.getShipAfterDate());
this.setEstimatedShipDate(item.getEstimatedShipDate());
this.setCancelBackOrderDate(item.getCancelBackOrderDate());
- this.contactMechIdsMap = item.getOrderItemContactMechIds() == null ? null : new HashMap<String, String>(item.getOrderItemContactMechIds());
- this.orderItemPriceInfos = item.getOrderItemPriceInfos() == null ? null : new LinkedList<GenericValue>(item.getOrderItemPriceInfos());
+ this.contactMechIdsMap = item.getOrderItemContactMechIds() == null ? null : new HashMap<>(item.getOrderItemContactMechIds());
+ this.orderItemPriceInfos = item.getOrderItemPriceInfos() == null ? null : new LinkedList<>(item.getOrderItemPriceInfos());
this.itemAdjustments.addAll(item.getAdjustments());
this.isPromo = item.getIsPromo();
this.promoQuantityUsed = item.promoQuantityUsed;
- this.quantityUsedPerPromoCandidate = new HashMap<GenericPK, BigDecimal>(item.quantityUsedPerPromoCandidate);
- this.quantityUsedPerPromoFailed = new HashMap<GenericPK, BigDecimal>(item.quantityUsedPerPromoFailed);
- this.quantityUsedPerPromoActual = new HashMap<GenericPK, BigDecimal>(item.quantityUsedPerPromoActual);
+ this.quantityUsedPerPromoCandidate = new HashMap<>(item.quantityUsedPerPromoCandidate);
+ this.quantityUsedPerPromoFailed = new HashMap<>(item.quantityUsedPerPromoFailed);
+ this.quantityUsedPerPromoActual = new HashMap<>(item.quantityUsedPerPromoActual);
this.additionalProductFeatureAndAppls = item.getAdditionalProductFeatureAndAppls() == null ?
- null : new HashMap<String, GenericValue>(item.getAdditionalProductFeatureAndAppls());
+ null : new HashMap<>(item.getAdditionalProductFeatureAndAppls());
if (item.getAlternativeOptionProductIds() != null) {
- List<String> tempAlternativeOptionProductIds = new LinkedList<String>();
+ List<String> tempAlternativeOptionProductIds = new LinkedList<>();
tempAlternativeOptionProductIds.addAll(item.getAlternativeOptionProductIds());
this.setAlternativeOptionProductIds(tempAlternativeOptionProductIds);
}
@@ -692,15 +695,16 @@ public class ShoppingCartItem implements
/** Cannot create shopping cart item with no parameters */
protected ShoppingCartItem() {}
- /** Creates new ShoppingCartItem object.
+ /** Creates new ShoppingCartItem object.
* @deprecated Use {@link #ShoppingCartItem(GenericValue, Map, Map, String, Locale, String, ShoppingCartItemGroup, LocalDispatcher)} instead*/
+ @Deprecated
protected ShoppingCartItem(GenericValue product, Map<String, GenericValue> additionalProductFeatureAndAppls, Map<String, Object> attributes, String prodCatalogId, Locale locale, String itemType, ShoppingCart.ShoppingCartItemGroup itemGroup) {
this(product, additionalProductFeatureAndAppls, attributes, prodCatalogId, locale, itemType, itemGroup, null);
}
- /** Creates new ShoppingCartItem object.
+ /** Creates new ShoppingCartItem object.
* @param dispatcher TODO*/
- protected ShoppingCartItem(GenericValue product, Map<String, GenericValue> additionalProductFeatureAndAppls, Map<String, Object> attributes, String prodCatalogId, Locale locale,
+ protected ShoppingCartItem(GenericValue product, Map<String, GenericValue> additionalProductFeatureAndAppls, Map<String, Object> attributes, String prodCatalogId, Locale locale,
String itemType, ShoppingCart.ShoppingCartItemGroup itemGroup, LocalDispatcher dispatcher) {
this(product, additionalProductFeatureAndAppls, attributes, prodCatalogId, null, locale, itemType, itemGroup, null);
String productName = ProductContentWrapper.getProductContentAsText(product, "PRODUCT_NAME", this.locale, dispatcher, "html");
@@ -724,8 +728,9 @@ public class ShoppingCartItem implements
this._product = product;
this.productId = _product.getString("productId");
this._parentProduct = parentProduct;
- if (parentProduct != null)
+ if (parentProduct != null) {
this.parentProductId = _parentProduct.getString("productId");
+ }
if (UtilValidate.isEmpty(itemType)) {
if (UtilValidate.isNotEmpty(_product.getString("productTypeId"))) {
if ("ASSET_USAGE".equals(_product.getString("productTypeId"))) {
@@ -744,7 +749,7 @@ public class ShoppingCartItem implements
}
this.itemGroup = itemGroup;
this.prodCatalogId = prodCatalogId;
- this.attributes = (attributes == null ? new HashMap<String, Object>() : attributes);
+ this.attributes = (attributes == null ? new HashMap<>() : attributes);
this.delegator = _product.getDelegator();
this.delegatorName = _product.getDelegator().getDelegatorName();
this.addAllProductFeatureAndAppls(additionalProductFeatureAndAppls);
@@ -768,7 +773,7 @@ public class ShoppingCartItem implements
this.setBasePrice(basePrice);
this.setDisplayPrice(basePrice);
}
- this.attributes = (attributes == null ? new HashMap<String, Object>() : attributes);
+ this.attributes = (attributes == null ? new HashMap<>() : attributes);
this.prodCatalogId = prodCatalogId;
this.delegatorName = delegator.getDelegatorName();
this.locale = locale;
@@ -916,12 +921,11 @@ public class ShoppingCartItem implements
if (fixedAsset.getBigDecimal("productionCapacity").compareTo(quantity) >= 0) {
String msg = UtilProperties.getMessage(resource_error, "item.availableOk", cart.getLocale());
return msg;
- } else {
- Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("quantityReq", quantity,
- "quantityAvail", fixedAsset.getString("productionCapacity"));
- String msg = UtilProperties.getMessage(resource_error, "item.availableQnt", messageMap , cart.getLocale());
- return msg;
}
+ Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("quantityReq", quantity,
+ "quantityAvail", fixedAsset.getString("productionCapacity"));
+ String msg = UtilProperties.getMessage(resource_error, "item.availableQnt", messageMap, cart.getLocale());
+ return msg;
}
// now find all the dates and check the availabilty for each date
// please note that calendarId is the same for (TechData)Calendar, CalendarExcDay and CalendarExWeek
@@ -937,21 +941,25 @@ public class ShoppingCartItem implements
Debug.logWarning(e, module);
}
if (techDataCalendarExcDay == null) {
- if (fixedAsset.get("productionCapacity") != null && fixedAsset.getBigDecimal("productionCapacity").compareTo(quantity) < 0)
+ if (fixedAsset.get("productionCapacity") != null && fixedAsset.getBigDecimal("productionCapacity").compareTo(quantity) < 0) {
resultMessage = resultMessage.concat(exceptionDateStartTime.toString().substring(0, 10) + ", ");
+ }
} else {
// see if we can get the number of assets available
// first try techDataCalendarExcDay(exceptionCapacity) and then FixedAsset(productionCapacity)
// if still zero, do not check availability
BigDecimal exceptionCapacity = BigDecimal.ZERO;
- if (techDataCalendarExcDay.get("exceptionCapacity") != null)
+ if (techDataCalendarExcDay.get("exceptionCapacity") != null) {
exceptionCapacity = techDataCalendarExcDay.getBigDecimal("exceptionCapacity");
- if (exceptionCapacity.compareTo(BigDecimal.ZERO) == 0 && fixedAsset.get("productionCapacity") != null)
+ }
+ if (exceptionCapacity.compareTo(BigDecimal.ZERO) == 0 && fixedAsset.get("productionCapacity") != null) {
exceptionCapacity = fixedAsset.getBigDecimal("productionCapacity");
+ }
if (exceptionCapacity.compareTo(BigDecimal.ZERO) != 0) {
BigDecimal usedCapacity = BigDecimal.ZERO;
- if (techDataCalendarExcDay.get("usedCapacity") != null)
+ if (techDataCalendarExcDay.get("usedCapacity") != null) {
usedCapacity = techDataCalendarExcDay.getBigDecimal("usedCapacity");
+ }
if (exceptionCapacity.compareTo(quantity.add(usedCapacity)) < 0) {
resultMessage = resultMessage.concat(exceptionDateStartTime.toString().substring(0, 10) + ", ");
Debug.logInfo("No rental fixed Asset available: " + exceptionCapacity +
@@ -965,11 +973,9 @@ public class ShoppingCartItem implements
String msg = UtilProperties.getMessage(resource_error, "item.availableOk", cart.getLocale());
return msg;
}
- else {
- Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("resultMessage", resultMessage);
- String msg = UtilProperties.getMessage(resource_error, "item.notAvailable", messageMap, cart.getLocale());
- return msg;
- }
+ Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("resultMessage", resultMessage);
+ String msg = UtilProperties.getMessage(resource_error, "item.notAvailable", messageMap, cart.getLocale());
+ return msg;
}
protected boolean isInventoryAvailableOrNotRequired(BigDecimal quantity, String productStoreId, LocalDispatcher dispatcher) throws CartItemModifyException {
@@ -1008,7 +1014,7 @@ public class ShoppingCartItem implements
// check inventory if new quantity is greater than old quantity; don't worry about inventory getting pulled out from under, that will be handled at checkout time
if (_product != null && quantity.compareTo(this.quantity) > 0) {
if (!isInventoryAvailableOrNotRequired(quantity, productStoreId, dispatcher)) {
- Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("requestedQuantity", UtilFormatOut.formatQuantity(quantity.doubleValue()),
+ Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("requestedQuantity", UtilFormatOut.formatQuantity(quantity.doubleValue()),
"productName",this.getName(dispatcher), "productId", productId);
String excMsg = UtilProperties.getMessage(resource, "OrderDoNotHaveEnoughProducts", messageMap , cart.getLocale());
Debug.logWarning(excMsg, module);
@@ -1056,7 +1062,7 @@ public class ShoppingCartItem implements
// set basePrice using the calculateProductPrice service
if (_product != null && isModifiedPrice == false) {
try {
- Map<String, Object> priceContext = new HashMap<String, Object>();
+ Map<String, Object> priceContext = new HashMap<>();
String partyId = cart.getPartyId();
if (partyId != null) {
@@ -1067,16 +1073,18 @@ public class ShoppingCartItem implements
BigDecimal pieces = BigDecimal.ONE;
if(isAlternativePacking && UtilValidate.isNotEmpty(this.getParentProduct())){
GenericValue originalProduct = this.getParentProduct();
- if (originalProduct != null) pieces = new BigDecimal(originalProduct.getLong("piecesIncluded"));
+ if (originalProduct != null) {
+ pieces = new BigDecimal(originalProduct.getLong("piecesIncluded"));
+ }
priceContext.put("product", originalProduct);
this._parentProduct = null;
}else{
priceContext.put("product", this.getProduct());
}
-
+
priceContext.put("quantity", this.getQuantity());
priceContext.put("amount", this.getSelectedAmount());
-
+
if ("PURCHASE_ORDER".equals(cart.getOrderType())) {
priceContext.put("currencyUomId", cart.getCurrency());
Map<String, Object> priceResult = dispatcher.runSync("calculatePurchasePrice", priceContext);
@@ -1087,13 +1095,13 @@ public class ShoppingCartItem implements
if (!validPriceFound.booleanValue()) {
throw new CartItemModifyException("Could not find a valid price for the product with ID [" + this.getProductId() + "] and supplier with ID [" + partyId + "], not adding to cart.");
}
-
+
if(isAlternativePacking){
this.setBasePrice(((BigDecimal) priceResult.get("price")).divide(pieces, RoundingMode.HALF_UP));
}else{
this.setBasePrice(((BigDecimal) priceResult.get("price")));
}
-
+
this.setDisplayPrice(this.basePrice);
this.orderItemPriceInfos = UtilGenerics.checkList(priceResult.get("orderItemPriceInfos"));
} else {
@@ -1140,7 +1148,7 @@ public class ShoppingCartItem implements
if (Boolean.FALSE.equals(validPriceFound)) {
throw new CartItemModifyException("Could not find a valid price for the product with ID [" + this.getProductId() + "], not adding to cart.");
}
-
+
//set alternative product price
if(isAlternativePacking){
int decimals = 2;
@@ -1171,10 +1179,10 @@ public class ShoppingCartItem implements
if (priceResult.get("price") != null) {
this.setDisplayPrice(((BigDecimal) priceResult.get("price")));
}
-
+
this.setSpecialPromoPrice((BigDecimal) priceResult.get("specialPromoPrice"));
}
-
+
this.orderItemPriceInfos = UtilGenerics.checkList(priceResult.get("orderItemPriceInfos"));
// If product is configurable, the price is taken from the configWrapper.
@@ -1194,7 +1202,7 @@ public class ShoppingCartItem implements
}
// no try to do a recurring price calculation; not all products have recurring prices so may be null
- Map<String, Object> recurringPriceContext = new HashMap<String, Object>();
+ Map<String, Object> recurringPriceContext = new HashMap<>();
recurringPriceContext.putAll(priceContext);
recurringPriceContext.put("productPricePurposeId", "RECURRING_CHARGE");
Map<String, Object> recurringPriceResult = dispatcher.runSync("calculateProductPrice", recurringPriceContext);
@@ -1230,14 +1238,13 @@ public class ShoppingCartItem implements
}
/** Returns the reservation start date with a number of days added. */
public Timestamp getReservStart(BigDecimal addDays) {
- if (addDays.compareTo(BigDecimal.ZERO) == 0)
- return this.reservStart != null ? (Timestamp) this.reservStart.clone() : null;
- else {
- if (this.reservStart != null)
- return new Timestamp((long)(this.reservStart.getTime() + (addDays.doubleValue() * 86400000.0)));
- else
- return null;
+ if (addDays.compareTo(BigDecimal.ZERO) == 0) {
+ return this.reservStart != null ? (Timestamp) this.reservStart.clone() : null;
+ }
+ if (this.reservStart != null) {
+ return new Timestamp((long) (this.reservStart.getTime() + (addDays.doubleValue() * 86400000.0)));
}
+ return null;
}
/** Returns the reservation length. */
public BigDecimal getReservLength() {
@@ -1260,17 +1267,15 @@ public class ShoppingCartItem implements
public synchronized BigDecimal getPromoQuantityUsed() {
if (this.getIsPromo()) {
return this.quantity;
- } else {
- return this.promoQuantityUsed;
}
+ return this.promoQuantityUsed;
}
public synchronized BigDecimal getPromoQuantityAvailable() {
if (this.getIsPromo()) {
return BigDecimal.ZERO;
- } else {
- return this.quantity.subtract(this.promoQuantityUsed);
}
+ return this.quantity.subtract(this.promoQuantityUsed);
}
public Iterator<Map.Entry<GenericPK, BigDecimal>> getQuantityUsedPerPromoActualIter() {
@@ -1286,7 +1291,9 @@ public class ShoppingCartItem implements
}
public synchronized BigDecimal addPromoQuantityCandidateUse(BigDecimal quantityDesired, GenericValue productPromoCondAction, boolean checkAvailableOnly) {
- if (quantityDesired.compareTo(BigDecimal.ZERO) == 0) return BigDecimal.ZERO;
+ if (quantityDesired.compareTo(BigDecimal.ZERO) == 0) {
+ return BigDecimal.ZERO;
+ }
BigDecimal promoQuantityAvailable = this.getPromoQuantityAvailable();
BigDecimal promoQuantityToUse = quantityDesired;
if (promoQuantityAvailable.compareTo(BigDecimal.ZERO) > 0) {
@@ -1308,9 +1315,8 @@ public class ShoppingCartItem implements
}
return promoQuantityToUse;
- } else {
- return BigDecimal.ZERO;
}
+ return BigDecimal.ZERO;
}
public BigDecimal getPromoQuantityCandidateUse(GenericValue productPromoCondAction) {
@@ -1318,9 +1324,8 @@ public class ShoppingCartItem implements
BigDecimal existingValue = this.quantityUsedPerPromoCandidate.get(productPromoCondActionPK);
if (existingValue == null) {
return BigDecimal.ZERO;
- } else {
- return existingValue;
}
+ return existingValue;
}
public BigDecimal getPromoQuantityCandidateUseActionAndAllConds(GenericValue productPromoAction) {
@@ -1503,8 +1508,12 @@ public class ShoppingCartItem implements
}
public boolean isInItemGroup(String groupNumber) {
- if (this.itemGroup == null) return false;
- if (this.itemGroup.getGroupNumber().equals(groupNumber)) return true;
+ if (this.itemGroup == null) {
+ return false;
+ }
+ if (this.itemGroup.getGroupNumber().equals(groupNumber)) {
+ return true;
+ }
return false;
}
@@ -1630,10 +1639,9 @@ public class ShoppingCartItem implements
GenericValue product = getProduct();
if (product != null) {
return ProductWorker.shippingApplies(product);
- } else {
- // we don't ship non-product items
- return false;
}
+ // we don't ship non-product items
+ return false;
}
/** Returns true if tax charges apply to this item. */
@@ -1641,10 +1649,9 @@ public class ShoppingCartItem implements
GenericValue product = getProduct();
if (product != null) {
return ProductWorker.taxApplies(product);
- } else {
- // we do tax non-product items
- return true;
}
+ // we do tax non-product items
+ return true;
}
/** Returns the item's productId. */
@@ -1671,18 +1678,19 @@ public class ShoppingCartItem implements
public void setName(String itemName) {
this.itemDescription = itemName;
}
- /** Returns the item's description.
- * @deprecated use getName(LocalDispatcher dispatcher)
+ /** Returns the item's description.
+ * @deprecated use getName(LocalDispatcher dispatcher)
**/
+ @Deprecated
public String getName() {
return itemDescription;
}
-
+
/** Returns the item's description or PRODUCT_NAME from content. */
public String getName(LocalDispatcher dispatcher) {
if (itemDescription != null) {
return itemDescription;
- } else {
+ }
GenericValue product = getProduct();
if (product != null) {
String productName = ProductContentWrapper.getProductContentAsText(product, "PRODUCT_NAME", this.locale, dispatcher, "html");
@@ -1695,13 +1703,10 @@ public class ShoppingCartItem implements
}
if (productName == null) {
return "";
- } else {
- return productName;
- }
- } else {
- return "";
}
+ return productName;
}
+ return "";
}
/** Returns the item's description. */
@@ -1721,12 +1726,10 @@ public class ShoppingCartItem implements
if (description == null) {
return "";
- } else {
- return description;
}
- } else {
- return null;
+ return description;
}
+ return null;
}
public ProductConfigWrapper getConfigWrapper() {
@@ -1742,18 +1745,18 @@ public class ShoppingCartItem implements
// if the weight is null, see if there is an associated virtual product and get the weight of that product
if (weight == null) {
GenericValue parentProduct = this.getParentProduct();
- if (parentProduct != null) weight = parentProduct.getBigDecimal("productWeight");
+ if (parentProduct != null) {
+ weight = parentProduct.getBigDecimal("productWeight");
+ }
}
if (weight == null) {
return BigDecimal.ZERO;
- } else {
- return weight;
}
- } else {
- // non-product items have 0 weight
- return BigDecimal.ZERO;
+ return weight;
}
+ // non-product items have 0 weight
+ return BigDecimal.ZERO;
}
/** Returns the item's pieces included */
@@ -1765,23 +1768,23 @@ public class ShoppingCartItem implements
// if the piecesIncluded is null, see if there is an associated virtual product and get the piecesIncluded of that product
if (pieces == null) {
GenericValue parentProduct = this.getParentProduct();
- if (parentProduct != null) pieces = parentProduct.getLong("piecesIncluded");
+ if (parentProduct != null) {
+ pieces = parentProduct.getLong("piecesIncluded");
+ }
}
if (pieces == null) {
return 1;
- } else {
- return pieces.longValue();
}
- } else {
- // non-product item assumed 1 piece
- return 1;
+ return pieces.longValue();
}
+ // non-product item assumed 1 piece
+ return 1;
}
/** Returns a Set of the item's features */
public Set<String> getFeatureSet() {
- Set<String> featureSet = new LinkedHashSet<String>();
+ Set<String> featureSet = new LinkedHashSet<>();
GenericValue product = this.getProduct();
if (product != null) {
List<GenericValue> featureAppls = null;
@@ -1853,24 +1856,29 @@ public class ShoppingCartItem implements
}
}
- if (height == null) height = BigDecimal.ZERO;
- if (width == null) width = BigDecimal.ZERO;
- if (depth == null) depth = BigDecimal.ZERO;
+ if (height == null) {
+ height = BigDecimal.ZERO;
+ }
+ if (width == null) {
+ width = BigDecimal.ZERO;
+ }
+ if (depth == null) {
+ depth = BigDecimal.ZERO;
+ }
// determine girth (longest field is length)
BigDecimal[] sizeInfo = { height, width, depth };
Arrays.sort(sizeInfo);
return (sizeInfo[0].add(sizeInfo[0])).add(sizeInfo[1].add(sizeInfo[1])).add(sizeInfo[2]);
- } else {
- // non-product items have 0 size
- return BigDecimal.ZERO;
}
+ // non-product items have 0 size
+ return BigDecimal.ZERO;
}
public Map<String, Object> getItemProductInfo() {
- Map<String, Object> itemInfo = new HashMap<String, Object>();
+ Map<String, Object> itemInfo = new HashMap<>();
itemInfo.put("productId", this.getProductId());
itemInfo.put("weight", this.getWeight());
itemInfo.put("weightUomId", this.getProduct().getString("weightUomId"));
@@ -1919,13 +1927,14 @@ public class ShoppingCartItem implements
}
public BigDecimal getRecurringBasePrice() {
- if (this.recurringBasePrice == null) return null;
+ if (this.recurringBasePrice == null) {
+ return null;
+ }
if (selectedAmount.compareTo(BigDecimal.ZERO) > 0) {
return this.recurringBasePrice.multiply(selectedAmount);
- } else {
- return this.recurringBasePrice;
}
+ return this.recurringBasePrice;
}
public BigDecimal getRecurringDisplayPrice() {
@@ -1935,9 +1944,8 @@ public class ShoppingCartItem implements
if (selectedAmount.compareTo(BigDecimal.ZERO) > 0) {
return this.recurringDisplayPrice.multiply(this.selectedAmount);
- } else {
- return this.recurringDisplayPrice;
}
+ return this.recurringDisplayPrice;
}
/** Returns the list price. */
@@ -2036,20 +2044,26 @@ public class ShoppingCartItem implements
public BigDecimal getDisplayItemRecurringSubTotalNoAdj() {
BigDecimal curRecurringDisplayPrice = this.getRecurringDisplayPrice();
- if (curRecurringDisplayPrice == null) return BigDecimal.ZERO;
+ if (curRecurringDisplayPrice == null) {
+ return BigDecimal.ZERO;
+ }
return curRecurringDisplayPrice.multiply(this.getQuantity());
}
public void addAllProductFeatureAndAppls(Map<String, GenericValue> productFeatureAndApplsToAdd) {
- if (productFeatureAndApplsToAdd == null) return;
+ if (productFeatureAndApplsToAdd == null) {
+ return;
+ }
for (GenericValue additionalProductFeatureAndAppl : productFeatureAndApplsToAdd.values()) {
this.putAdditionalProductFeatureAndAppl(additionalProductFeatureAndAppl);
}
}
public void putAdditionalProductFeatureAndAppl(GenericValue additionalProductFeatureAndAppl) {
- if (additionalProductFeatureAndAppl == null) return;
+ if (additionalProductFeatureAndAppl == null) {
+ return;
+ }
// if one already exists with the given type, remove it with the corresponding adjustment
removeAdditionalProductFeatureAndAppl(additionalProductFeatureAndAppl.getString("productFeatureTypeId"));
@@ -2084,12 +2098,16 @@ public class ShoppingCartItem implements
}
public GenericValue getAdditionalProductFeatureAndAppl(String productFeatureTypeId) {
- if (this.additionalProductFeatureAndAppls == null) return null;
+ if (this.additionalProductFeatureAndAppls == null) {
+ return null;
+ }
return this.additionalProductFeatureAndAppls.get(productFeatureTypeId);
}
public GenericValue removeAdditionalProductFeatureAndAppl(String productFeatureTypeId) {
- if (this.additionalProductFeatureAndAppls == null) return null;
+ if (this.additionalProductFeatureAndAppls == null) {
+ return null;
+ }
GenericValue oldAdditionalProductFeatureAndAppl = this.additionalProductFeatureAndAppls.remove(productFeatureTypeId);
@@ -2105,7 +2123,7 @@ public class ShoppingCartItem implements
}
public Map<String, BigDecimal> getFeatureIdQtyMap(BigDecimal quantity) {
- Map<String, BigDecimal> featureMap = new HashMap<String, BigDecimal>();
+ Map<String, BigDecimal> featureMap = new HashMap<>();
GenericValue product = this.getProduct();
if (product != null) {
List<GenericValue> featureAppls = null;
@@ -2171,18 +2189,22 @@ public class ShoppingCartItem implements
/** Creates an OrderItemAttribute entry. */
public void setOrderItemAttribute(String name, String value) {
- if (orderItemAttributes == null) orderItemAttributes = new HashMap<String, String>();
+ if (orderItemAttributes == null) {
+ orderItemAttributes = new HashMap<>();
+ }
this.orderItemAttributes.put(name, value);
}
/** Return an OrderItemAttribute. */
public String getOrderItemAttribute(String name) {
- if (orderItemAttributes == null) return null;
+ if (orderItemAttributes == null) {
+ return null;
+ }
return this.orderItemAttributes.get(name);
}
public Map<String, String> getOrderItemAttributes() {
- Map<String, String> attrs = new HashMap<String, String>();
+ Map<String, String> attrs = new HashMap<>();
if (orderItemAttributes != null) {
attrs.putAll(orderItemAttributes);
}
@@ -2208,7 +2230,9 @@ public class ShoppingCartItem implements
}
public void removeFeatureAdjustment(String productFeatureId) {
- if (productFeatureId == null) return;
+ if (productFeatureId == null) {
+ return;
+ }
Iterator<GenericValue> itemAdjustmentsIter = itemAdjustments.iterator();
while (itemAdjustmentsIter.hasNext()) {
@@ -2226,7 +2250,9 @@ public class ShoppingCartItem implements
/** Add a contact mech to this purpose; the contactMechPurposeTypeId is required */
public void addContactMech(String contactMechPurposeTypeId, String contactMechId) {
- if (contactMechPurposeTypeId == null) throw new IllegalArgumentException("You must specify a contactMechPurposeTypeId to add a ContactMech");
+ if (contactMechPurposeTypeId == null) {
+ throw new IllegalArgumentException("You must specify a contactMechPurposeTypeId to add a ContactMech");
+ }
contactMechIdsMap.put(contactMechPurposeTypeId, contactMechId);
}
@@ -2260,14 +2286,18 @@ public class ShoppingCartItem implements
}
public boolean equals(ShoppingCartItem item) {
- if (item == null) return false;
+ if (item == null) {
+ return false;
+ }
return this.equals(item.getProductId(), item.additionalProductFeatureAndAppls, item.attributes, item.prodCatalogId, item.selectedAmount, item.getItemType(), item.getItemGroup(), item.getIsPromo());
}
+ @Override
public boolean equals(Object obj) {
return super.equals(obj);
}
+ @Override
public int hashCode() {
return super.hashCode();
}
@@ -2423,18 +2453,16 @@ public class ShoppingCartItem implements
GenericValue parentProduct = this.getParentProduct();
if (parentProduct != null) {
return parentProduct.getString("productId");
- } else {
- return null;
}
+ return null;
}
public Map<String, List<GenericValue>> getOptionalProductFeatures() {
if (_product != null) {
return ProductWorker.getOptionalProductFeatures(getDelegator(), this.productId);
- } else {
- // non-product items do not have features
- return new HashMap<String, List<GenericValue>>();
}
+ // non-product items do not have features
+ return new HashMap<>();
}
public Delegator getDelegator() {
@@ -2449,7 +2477,7 @@ public class ShoppingCartItem implements
public List<ShoppingCartItem> explodeItem(ShoppingCart cart, LocalDispatcher dispatcher) throws CartItemModifyException {
BigDecimal baseQuantity = this.getQuantity();
- List<ShoppingCartItem> newItems = new ArrayList<ShoppingCartItem>();
+ List<ShoppingCartItem> newItems = new ArrayList<>();
if (baseQuantity.compareTo(BigDecimal.ONE) > 0) {
for (int i = 1; i < baseQuantity.intValue(); i++) {
@@ -2470,8 +2498,9 @@ public class ShoppingCartItem implements
BigDecimal adjAmount = newAdjustment.getBigDecimal("amount");
// we use != because adjustments can be +/-
- if (adjAmount != null && adjAmount.compareTo(BigDecimal.ZERO) != 0)
+ if (adjAmount != null && adjAmount.compareTo(BigDecimal.ZERO) != 0) {
newAdjustment.set("amount", adjAmount.divide(baseQuantity, generalRounding));
+ }
Debug.logInfo("Cloned adj: " + newAdjustment, module);
item.addAdjustment(newAdjustment);
} else {
@@ -2499,8 +2528,9 @@ public class ShoppingCartItem implements
BigDecimal adjAmount = newAdjustment.getBigDecimal("amount");
// we use != becuase adjustments can be +/-
- if (adjAmount != null && adjAmount.compareTo(BigDecimal.ZERO) != 0)
+ if (adjAmount != null && adjAmount.compareTo(BigDecimal.ZERO) != 0) {
newAdjustment.set("amount", adjAmount.divide(baseQuantity, generalRounding));
+ }
Debug.logInfo("Updated adj: " + newAdjustment, module);
this.addAdjustment(newAdjustment);
}
Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartServices.java?rev=1818329&r1=1818328&r2=1818329&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartServices.java Fri Dec 15 20:33:56 2017
@@ -373,12 +373,14 @@ public class ShoppingCartServices {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
- if ("ITEM_REJECTED".equals(item.getString("statusId")) || "ITEM_CANCELLED".equals(item.getString("statusId"))) continue;
+ if ("ITEM_REJECTED".equals(item.getString("statusId")) || "ITEM_CANCELLED".equals(item.getString("statusId"))) {
+ continue;
+ }
try {
product = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne();
if ("DIGITAL_GOOD".equals(product.getString("productTypeId"))) {
- Map<String, Object> surveyResponseMap = new HashMap<String, Object>();
- Map<String, Object> answers = new HashMap<String, Object>();
+ Map<String, Object> surveyResponseMap = new HashMap<>();
+ Map<String, Object> answers = new HashMap<>();
List<GenericValue> surveyResponseAndAnswers = EntityQuery.use(delegator).from("SurveyResponseAndAnswer").where("orderId", orderId, "orderItemSeqId", orderItemSeqId).queryList();
if (UtilValidate.isNotEmpty(surveyResponseAndAnswers)) {
String surveyId = EntityUtil.getFirst(surveyResponseAndAnswers).getString("surveyId");
@@ -390,12 +392,9 @@ public class ShoppingCartServices {
surveyResponseResult = dispatcher.runSync("createSurveyResponse", surveyResponseMap);
}
}
- } catch (GenericEntityException e) {
+ } catch (GenericEntityException | GenericServiceException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
- } catch (GenericServiceException e) {
- Debug.logError(e.toString(), module);
- return ServiceUtil.returnError(e.toString());
}
// do not include PROMO items
@@ -489,10 +488,7 @@ public class ShoppingCartServices {
}
try {
itemIndex = cart.addItemToEnd(productId, amount, quantity, unitPrice, reservStart, reservLength, reservPersons,accommodationMapId,accommodationSpotId, null, null, prodCatalogId, configWrapper, item.getString("orderItemTypeId"), dispatcher, null, unitPrice == null ? null : false, skipInventoryChecks, skipProductChecks);
- } catch (ItemNotFoundException e) {
- Debug.logError(e, module);
- return ServiceUtil.returnError(e.getMessage());
- } catch (CartItemModifyException e) {
+ } catch (ItemNotFoundException | CartItemModifyException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
@@ -568,7 +564,9 @@ public class ShoppingCartServices {
List<GenericValue> itemAdjustments = orh.getOrderItemAdjustments(item);
if (itemAdjustments != null) {
for (GenericValue itemAdjustment : itemAdjustments) {
- if (!isTaxAdjustment(itemAdjustment)) cartItem.addAdjustment(itemAdjustment);
+ if (!isTaxAdjustment(itemAdjustment)) {
+ cartItem.addAdjustment(itemAdjustment);
+ }
}
}
}
@@ -578,7 +576,9 @@ public class ShoppingCartServices {
int itemIndex = 0;
for (GenericValue item : orderItems) {
// if rejected or cancelled ignore, just like above otherwise all indexes will be off by one!
- if ("ITEM_REJECTED".equals(item.getString("statusId")) || "ITEM_CANCELLED".equals(item.getString("statusId"))) continue;
+ if ("ITEM_REJECTED".equals(item.getString("statusId")) || "ITEM_CANCELLED".equals(item.getString("statusId"))) {
+ continue;
+ }
List<GenericValue> orderItemAdjustments = orh.getOrderItemAdjustments(item);
// set the item's ship group info
@@ -628,7 +628,9 @@ public class ShoppingCartServices {
} else {
List<GenericValue> itemTaxAdj = cartShipItemInfo.itemTaxAdj;
for (GenericValue shipGroupItemAdjustment : shipGroupItemAdjustments) {
- if (isTaxAdjustment(shipGroupItemAdjustment)) itemTaxAdj.add(shipGroupItemAdjustment);
+ if (isTaxAdjustment(shipGroupItemAdjustment)) {
+ itemTaxAdj.add(shipGroupItemAdjustment);
+ }
}
}
}
@@ -774,11 +776,11 @@ public class ShoppingCartServices {
// Convert the quote adjustment to order header adjustments and
// put them in a map: the key/values pairs are quoteItemSeqId/List of adjs
- Map<String, List<GenericValue>> orderAdjsMap = new HashMap<String, List<GenericValue>>() ;
+ Map<String, List<GenericValue>> orderAdjsMap = new HashMap<>() ;
for (GenericValue quoteAdj : quoteAdjs) {
List<GenericValue> orderAdjs = orderAdjsMap.get(UtilValidate.isNotEmpty(quoteAdj.getString("quoteItemSeqId")) ? quoteAdj.getString("quoteItemSeqId") : quoteId);
if (orderAdjs == null) {
- orderAdjs = new LinkedList<GenericValue>();
+ orderAdjs = new LinkedList<>();
orderAdjsMap.put(UtilValidate.isNotEmpty(quoteAdj.getString("quoteItemSeqId")) ? quoteAdj.getString("quoteItemSeqId") : quoteId, orderAdjs);
}
// convert quote adjustments to order adjustments
@@ -878,10 +880,7 @@ public class ShoppingCartServices {
try {
itemIndex = cart.addItemToEnd(productId, amount, quantity, quoteUnitPrice, reservStart, reservLength, reservPersons,null,null, null, null, null, configWrapper, null, dispatcher, Boolean.valueOf(!applyQuoteAdjustments), Boolean.valueOf(quoteUnitPrice.compareTo(BigDecimal.ZERO) == 0), Boolean.FALSE, Boolean.FALSE);
- } catch (ItemNotFoundException e) {
- Debug.logError(e, module);
- return ServiceUtil.returnError(e.getMessage());
- } catch (CartItemModifyException e) {
+ } catch (ItemNotFoundException | CartItemModifyException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
@@ -915,8 +914,11 @@ public class ShoppingCartServices {
if (adjs != null) {
for (GenericValue adj : adjs) {
- if (isTaxAdjustment( adj )) shipInfo.shipTaxAdj.add(adj);
- else cartAdjs.add(adj);
+ if (isTaxAdjustment( adj )) {
+ shipInfo.shipTaxAdj.add(adj);
+ } else {
+ cartAdjs.add(adj);
+ }
}
}
@@ -934,10 +936,14 @@ public class ShoppingCartServices {
if (isTaxAdjustment( adj )) {
CartShipItemInfo csii = shipInfo.getShipItemInfo(item);
- if (csii.itemTaxAdj == null) shipInfo.setItemInfo(item, UtilMisc.toList(adj));
- else csii.itemTaxAdj.add(adj);
+ if (csii.itemTaxAdj == null) {
+ shipInfo.setItemInfo(item, UtilMisc.toList(adj));
+ } else {
+ csii.itemTaxAdj.add(adj);
+ }
+ } else {
+ item.addAdjustment(adj);
}
- else item.addAdjustment(adj);
}
}
}
@@ -1060,10 +1066,7 @@ public class ShoppingCartServices {
}
try {
itemIndex = cart.addItemToEnd(productId, null, quantity, null, null, null, null, null, configWrapper, dispatcher, Boolean.TRUE, Boolean.TRUE);
- } catch (ItemNotFoundException e) {
- Debug.logError(e, module);
- return ServiceUtil.returnError(e.getMessage());
- } catch (CartItemModifyException e) {
+ } catch (ItemNotFoundException | CartItemModifyException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
@@ -1120,7 +1123,7 @@ public class ShoppingCartServices {
result.put("displayGrandTotalCurrencyFormatted",org.apache.ofbiz.base.util.UtilFormatOut.formatCurrency(shoppingCart.getDisplayGrandTotal(), isoCode, locale));
BigDecimal orderAdjustmentsTotal = OrderReadHelper.calcOrderAdjustments(OrderReadHelper.getOrderHeaderAdjustments(shoppingCart.getAdjustments(), null), shoppingCart.getSubTotal(), true, true, true);
result.put("displayOrderAdjustmentsTotalCurrencyFormatted", org.apache.ofbiz.base.util.UtilFormatOut.formatCurrency(orderAdjustmentsTotal, isoCode, locale));
- Map<String, Object> cartItemData = new HashMap<String, Object>();
+ Map<String, Object> cartItemData = new HashMap<>();
for (ShoppingCartItem cartLine : shoppingCart) {
int cartLineIndex = shoppingCart.getItemIndex(cartLine);
cartItemData.put("displayItemQty_" + cartLineIndex, cartLine.getQuantity());
@@ -1173,7 +1176,7 @@ public class ShoppingCartServices {
Debug.logError(e.toString(), module);
return ServiceUtil.returnError(e.toString());
}
- Map<String, Object> vendorMap = new HashMap<String, Object>();
+ Map<String, Object> vendorMap = new HashMap<>();
for (ShoppingCartItem item : cart) {
GenericValue vendorProduct = null;
String productId = item.getParentProductId();