ilscipio/scipio-erp

View on GitHub
applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java

Summary

Maintainability
F
5 days
Test Coverage

ProductPromoWorker has 43 methods (exceeds 20 allowed). Consider refactoring.
Open

public final class ProductPromoWorker {

    private static final Debug.OfbizLogger module = Debug.getOfbizLogger(java.lang.invoke.MethodHandles.lookup().lookupClass());
    public static final String resource = "OrderUiLabels";
    public static final String resource_error = "OrderErrorUiLabels";

    Consider simplifying this complex logical expression.
    Open

                            if (passedItemConds && !cartItem.getIsPromo() &&
                                    (productIds.contains(cartItem.getProductId()) || (parentProductId != null && productIds.contains(parentProductId))) &&
                                    (product == null || !"N".equals(product.getString("includeInPromotions"))) &&
                                    (UtilValidate.isEmpty(promoRuleActionProductIds) ||
                                            (UtilValidate.isNotEmpty(promoRuleActionProductIds) && promoRuleActionProductIds.contains(cartItem.getProductId())))) {

      Consider simplifying this complex logical expression.
      Open

                              if (passedItemConds && !cartItem.getIsPromo() &&
                                      (productIds.contains(cartItem.getProductId()) || (parentProductId != null && productIds.contains(parentProductId))) &&
                                      (product == null || !"N".equals(product.getString("includeInPromotions"))) &&
                                      (UtilValidate.isEmpty(promoRuleActionProductIds) ||
                                          (UtilValidate.isNotEmpty(promoRuleActionProductIds) && promoRuleActionProductIds.contains(cartItem.getProductId())))) {

        Method runProductPromoRules has 11 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            protected static boolean runProductPromoRules(ShoppingCart cart, Long useLimit, boolean requireCode, String productPromoCodeId, Long codeUseLimit, long maxUseLimit,
                GenericValue productPromo, List<GenericValue> productPromoRules, LocalDispatcher dispatcher, Delegator delegator, Timestamp nowTimestamp) throws GenericEntityException, UseLimitException {

          Consider simplifying this complex logical expression.
          Open

                          if (passedItemConds && !cartItem.getIsPromo() &&
                                  (productIds.contains(cartItem.getProductId()) || (parentProductId != null && productIds.contains(parentProductId))) &&
                                  (product == null || !"N".equals(product.getString("includeInPromotions")))) {
                              // reduce quantity still needed to qualify for promo (quantityNeeded)
                              quantityNeeded = quantityNeeded.subtract(cartItem.addPromoQuantityCandidateUse(quantityNeeded, productPromoCond, false));

            Consider simplifying this complex logical expression.
            Open

                            if (passedItemConds && !cartItem.getIsPromo() && (productIds.contains(cartItem.getProductId()) || (parentProductId != null && productIds.contains(parentProductId))) &&
                                    (product == null || !"N".equals(product.getString("includeInPromotions")))) {
                                // reduce quantity still needed to qualify for promo (quantityNeeded)
                                BigDecimal quantityUsed = cartItem.addPromoQuantityCandidateUse(quantityDesired, productPromoAction, false);
                                if (quantityUsed.compareTo(BigDecimal.ZERO) > 0) {

              Consider simplifying this complex logical expression.
              Open

                                  if (passedItemConds && !cartItem.getIsPromo() &&
                                          (productIds.contains(cartItem.getProductId()) || (parentProductId != null && productIds.contains(parentProductId))) &&
                                          (product == null || !"N".equals(product.getString("includeInPromotions")))) {
              
                                      // just count the entire sub-total of the item

                Consider simplifying this complex logical expression.
                Open

                                        if (passedItemConds && !cartItem.getIsPromo() &&
                                                (productIds.contains(cartItem.getProductId()) || (parentProductId != null && productIds.contains(parentProductId))) &&
                                                (product == null || !"N".equals(product.getString("includeInPromotions")))) {
                
                                            // just count the entire sub-total of the item

                  Consider simplifying this complex logical expression.
                  Open

                                  if (passedItemConds && !cartItem.getIsPromo() &&
                                          (productIds.contains(cartItem.getProductId()) || (parentProductId != null && productIds.contains(parentProductId))) &&
                                          (product == null || !"N".equals(product.getString("includeInPromotions")))) {
                  
                                      BigDecimal basePrice = cartItem.getBasePrice();

                    Consider simplifying this complex logical expression.
                    Open

                                    if (passedItemConds && !cartItem.getIsPromo() &&
                                            (productIds.contains(cartItem.getProductId()) || (parentProductId != null && productIds.contains(parentProductId))) &&
                                            (product == null || !"N".equals(product.getString("includeInPromotions")))) {
                                        // reduce quantity still needed to qualify for promo (quantityNeeded)
                                        BigDecimal quantityUsed = cartItem.addPromoQuantityCandidateUse(quantityDesired, productPromoAction, false);

                      Consider simplifying this complex logical expression.
                      Open

                                      if (passedItemConds && !cartItem.getIsPromo() &&
                                              (productIds.contains(cartItem.getProductId()) || (parentProductId != null && productIds.contains(parentProductId))) &&
                                              (product == null || !"N".equals(product.getString("includeInPromotions")))) {
                                          // reduce quantity still needed to qualify for promo (quantityNeeded)
                                          BigDecimal quantityUsed = cartItem.addPromoQuantityCandidateUse(quantityDesired, productPromoAction, false);

                        Method runProductPromos has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            protected static void runProductPromos(List<GenericValue> productPromoList, ShoppingCart cart, Delegator delegator, LocalDispatcher dispatcher, Timestamp nowTimestamp, boolean isolatedTestRun) throws GeneralException {

                          Method performAction has 6 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              public static void performAction(ActionResultInfo actionResultInfo, GenericValue productPromoAction, ShoppingCart cart, Delegator delegator, LocalDispatcher dispatcher, Timestamp nowTimestamp) throws GenericEntityException, CartItemModifyException {

                            Avoid deeply nested control flow statements.
                            Open

                                                        if (cart.getOrderId() != null) {
                                                            List<GenericValue> orderproductPromoCodes =  EntityQuery.use(delegator).from("OrderProductPromoCode").where("orderId", cart.getOrderId()).queryList();
                                                            Iterator<GenericValue> orderproductPromoCodesItr = UtilMisc.toIterator(orderproductPromoCodes);
                                                            while (orderproductPromoCodesItr != null && orderproductPromoCodesItr.hasNext()) {
                                                                GenericValue orderproductPromoCode = orderproductPromoCodesItr.next();

                              Avoid deeply nested control flow statements.
                              Open

                                                          if (discount.negate().compareTo(cartItem.getBasePrice().multiply(cartItem.getRentalAdjustment())) > 0) {
                                                              discount = cartItem.getBasePrice().multiply(cartItem.getRentalAdjustment()).negate();
                                                          }

                                Method checkConditionsForItem has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                    public static boolean checkConditionsForItem(GenericValue productPromoActionOrCond, ShoppingCart cart, ShoppingCartItem cartItem, Delegator delegator, LocalDispatcher dispatcher, Timestamp nowTimestamp) throws GenericEntityException {

                                  Avoid deeply nested control flow statements.
                                  Open

                                                              if (enteredCodes.size() > 0) {
                                                                  // get all promo codes entered, do a query with an IN condition to see if any of those are related
                                                                  EntityCondition codeCondition = EntityCondition.makeCondition(EntityCondition.makeCondition("productPromoId", EntityOperator.EQUALS, productPromoId), EntityOperator.AND, EntityCondition.makeCondition("productPromoCodeId", EntityOperator.IN, enteredCodes));
                                                                  // may want to sort by something else to decide which code to use if there is more than one candidate
                                                                  List<GenericValue> productPromoCodeList = EntityQuery.use(delegator).from("ProductPromoCode").where(codeCondition).orderBy("productPromoCodeId").queryList();

                                    Avoid deeply nested control flow statements.
                                    Open

                                                                if ("PPIP_PARTY_ID".equals(productPromoCond.getString("inputParamEnumId"))) {
                                                                    condResult = checkCondition(productPromoCond, cart, delegator, dispatcher, nowTimestamp);
                                                                } else if ("PPIP_PARTY_GRP_MEM".equals(productPromoCond.getString("inputParamEnumId"))) {
                                                                    condResult = checkCondition(productPromoCond, cart, delegator, dispatcher, nowTimestamp);
                                                                } else if ("PPIP_PARTY_CLASS".equals(productPromoCond.getString("inputParamEnumId"))) {

                                      Avoid deeply nested control flow statements.
                                      Open

                                                                  if (quantityUsed.compareTo(BigDecimal.ZERO) > 0) {
                                                                      quantityDesired = quantityDesired.subtract(quantityUsed);
                                      
                                                                      // create an adjustment and add it to the cartItem that implements the promotion action
                                                                      BigDecimal percentModifier = productPromoAction.get("amount") == null ? BigDecimal.ZERO : productPromoAction.getBigDecimal("amount").movePointLeft(2);

                                        Method checkConditionForItem has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                        Open

                                            public static boolean checkConditionForItem(GenericValue productPromoCond, ShoppingCart cart, ShoppingCartItem cartItem, Delegator delegator, LocalDispatcher dispatcher, Timestamp nowTimestamp) throws GenericEntityException {

                                          Avoid deeply nested control flow statements.
                                          Open

                                                                      if (actionChangedCart) {
                                                                          promoUsed = true;
                                                                          cartChanged = true;
                                                                      }

                                            Method makeProductPromoCondActionIdSets has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                            Open

                                                public static void makeProductPromoCondActionIdSets(String productPromoId, Set<String> productIdsCond, Set<String> productIdsAction, Delegator delegator, Timestamp nowTimestamp, boolean filterOldProducts) throws GenericEntityException {

                                              Method makeProductPromoIdSet has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                              Open

                                                  public static void makeProductPromoIdSet(Set<String> productIds, List<GenericValue> productPromoCategories, List<GenericValue> productPromoProducts, Delegator delegator, Timestamp nowTimestamp, boolean filterOldProducts) throws GenericEntityException {

                                                Method checkCanUsePromoCode has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                Open

                                                    public static String checkCanUsePromoCode(String productPromoCodeId, String partyId, Delegator delegator, ShoppingCart cart, Locale locale) {

                                                  Method doOrderPromoAction has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                  Open

                                                      public static void doOrderPromoAction(GenericValue productPromoAction, ShoppingCart cart, BigDecimal amount, String amountField, Delegator delegator) {

                                                    Method makeProductPromoCondActionIdSets has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                    Open

                                                        public static void makeProductPromoCondActionIdSets(String productPromoId, Set<String> productIdsCond, Set<String> productIdsAction, Delegator delegator, Timestamp nowTimestamp) throws GenericEntityException {

                                                      Method doOrderItemPromoAction has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                      Open

                                                          public static void doOrderItemPromoAction(GenericValue productPromoAction, ShoppingCartItem cartItem, BigDecimal amount, String amountField, Delegator delegator) {

                                                        Method distributeDiscountAmount has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                        Open

                                                            public static void distributeDiscountAmount(BigDecimal discountAmountTotal, BigDecimal totalAmount, List<ShoppingCartItem> cartItemsUsed, GenericValue productPromoAction, Delegator delegator) {

                                                          Method performAction has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                          Open

                                                              protected static ActionResultInfo performAction(GenericValue productPromoAction, ShoppingCart cart, Delegator delegator, LocalDispatcher dispatcher, Timestamp nowTimestamp) throws GenericEntityException, CartItemModifyException {

                                                            Method checkCondition has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                            Open

                                                                public static boolean checkCondition(GenericValue productPromoCond, ShoppingCart cart, Delegator delegator, LocalDispatcher dispatcher, Timestamp nowTimestamp) throws GenericEntityException {

                                                              Method handleProductPromoCategories has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                              Open

                                                                  protected static void handleProductPromoCategories(Set<String> productIds, List<GenericValue> productPromoCategories, String productPromoApplEnumId, Delegator delegator, Timestamp nowTimestamp) throws GenericEntityException {

                                                                Method getAllProductIds has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                Open

                                                                    protected static void getAllProductIds(Set<String> productCategoryIdSet, Set<String> productIdSet, Delegator delegator, Timestamp nowTimestamp, boolean include) throws GenericEntityException {

                                                                  Avoid too many return statements within this method.
                                                                  Open

                                                                                      return UtilProperties.getMessage(resource_error, "productpromoworker.promotion_code_no_account_or_email", UtilMisc.toMap("productPromoCodeId", productPromoCodeId), locale);

                                                                    Avoid too many return statements within this method.
                                                                    Open

                                                                                            return false;

                                                                      Avoid too many return statements within this method.
                                                                      Open

                                                                                          return false;

                                                                        Avoid too many return statements within this method.
                                                                        Open

                                                                                        return false;

                                                                          Avoid too many return statements within this method.
                                                                          Open

                                                                                          if (compare > 0) return true;

                                                                            Avoid too many return statements within this method.
                                                                            Open

                                                                                                    return false;

                                                                              Avoid too many return statements within this method.
                                                                              Open

                                                                                          return null;

                                                                                Avoid too many return statements within this method.
                                                                                Open

                                                                                                return UtilProperties.getMessage(resource_error, "productpromoworker.promotion_code_maximum_limit", UtilMisc.toMap("productPromoCodeId", productPromoCodeId), locale);

                                                                                  Avoid too many return statements within this method.
                                                                                  Open

                                                                                                  return false;

                                                                                    Avoid too many return statements within this method.
                                                                                    Open

                                                                                                        return false;

                                                                                      Avoid too many return statements within this method.
                                                                                      Open

                                                                                                      return false;

                                                                                        Avoid too many return statements within this method.
                                                                                        Open

                                                                                                        if (compare >= 0) return true;

                                                                                          Avoid too many return statements within this method.
                                                                                          Open

                                                                                                      return UtilProperties.getMessage(resource_error, "productpromoworker.promotion_code_error_lookup", UtilMisc.toMap("productPromoCodeId", productPromoCodeId, "errorMsg", e.toString()), locale);

                                                                                            Avoid too many return statements within this method.
                                                                                            Open

                                                                                                                return false;

                                                                                              Avoid too many return statements within this method.
                                                                                              Open

                                                                                                                  return false;

                                                                                                Avoid too many return statements within this method.
                                                                                                Open

                                                                                                                return false;

                                                                                                  Avoid too many return statements within this method.
                                                                                                  Open

                                                                                                                  return directResult.booleanValue();

                                                                                                    Avoid too many return statements within this method.
                                                                                                    Open

                                                                                                                            return false;

                                                                                                      Avoid too many return statements within this method.
                                                                                                      Open

                                                                                                                      if (compare <= 0) return true;

                                                                                                        Avoid too many return statements within this method.
                                                                                                        Open

                                                                                                                            return true;

                                                                                                          Avoid too many return statements within this method.
                                                                                                          Open

                                                                                                                              return true;

                                                                                                            Avoid too many return statements within this method.
                                                                                                            Open

                                                                                                                            if (compare == 0) return true;

                                                                                                              Avoid too many return statements within this method.
                                                                                                              Open

                                                                                                                                  return true;

                                                                                                                Avoid too many return statements within this method.
                                                                                                                Open

                                                                                                                                    return true;

                                                                                                                  Avoid too many return statements within this method.
                                                                                                                  Open

                                                                                                                          return true;

                                                                                                                    Avoid too many return statements within this method.
                                                                                                                    Open

                                                                                                                            return false;

                                                                                                                      Avoid too many return statements within this method.
                                                                                                                      Open

                                                                                                                                      if (compare < 0) return true;

                                                                                                                        Avoid too many return statements within this method.
                                                                                                                        Open

                                                                                                                                            return true;

                                                                                                                          Avoid too many return statements within this method.
                                                                                                                          Open

                                                                                                                                          if (compare != 0) return true;

                                                                                                                            Avoid too many return statements within this method.
                                                                                                                            Open

                                                                                                                                        return false;

                                                                                                                              There are no issues that match your filters.

                                                                                                                              Category
                                                                                                                              Status