@Test public void testDetermineDeliveryAvailableTimeRangeNamedNoFfExclusionsSkipMiddle() throws Exception { final CarrierSlaService carrierSlaService = this.context.mock(CarrierSlaService.class, "carrierSlaService"); final MutableShoppingCart shoppingCart = this.context.mock(MutableShoppingCart.class, "shoppingCart"); final MutableOrderInfo orderInfo = this.context.mock(MutableOrderInfo.class, "orderInfo"); final CarrierSlaEntity sla = new CarrierSlaEntity(); sla.setExcludeDates("2017-02-08,2017-02-10:2017-02-15,2017-02-17"); sla.setExcludeWeekDays("1"); sla.setNamedDay(true); sla.setGuaranteed(true); sla.setMinDays(1); sla.setMaxDays(15); final LocalDate calendar = DateUtils.ldParseSDT("2017-02-07"); final DeliveryTimeEstimationVisitorDefaultImpl visitor = new DeliveryTimeEstimationVisitorDefaultImpl(null, carrierSlaService) { @Override protected LocalDate now() { return calendar; } }; context.checking(new Expectations() {{ allowing(carrierSlaService).findById(123L); will(returnValue(sla)); allowing(shoppingCart).getOrderInfo(); will(returnValue(orderInfo)); allowing(orderInfo).getDetailByKey("deliveryDate0"); will(returnValue(null)); oneOf(orderInfo).putDetail("deliveryDate0", null); oneOf(orderInfo).putDetail("deliveryDateMin0", null); oneOf(orderInfo).putDetail("deliveryDateMax0", null); oneOf(orderInfo).putDetail("deliveryDateDExcl0", null); oneOf(orderInfo).putDetail("deliveryDateWExcl0", null); oneOf(orderInfo).putDetail("deliveryDate0", time("2017-02-09")); oneOf(orderInfo).putDetail("deliveryDateMin0", time("2017-02-09")); oneOf(orderInfo).putDetail("deliveryDateMax0", time("2017-02-22")); oneOf(orderInfo).putDetail("deliveryDateDExcl0", time("2017-02-10","2017-02-11","2017-02-12","2017-02-13","2017-02-14","2017-02-15","2017-02-17","2017-02-19")); oneOf(orderInfo).putDetail("deliveryDateWExcl0", "1"); }}); visitor.determineDeliveryAvailableTimeRange(shoppingCart, 123L, null); this.context.assertIsSatisfied(); }
protected void determineDeliveryAvailableTimeRange(final MutableShoppingCart shoppingCart, final Long carrierSlaId, final Warehouse ff) { if (carrierSlaId == null) { return; } final CarrierSla sla = carrierSlaService.findById(carrierSlaId); if (sla == null) { return; } final String suffix = sla.getCarrierslaId() + (ff != null ? ff.getCode() : ""); final String requestedDateKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + suffix; final String minKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "Min" + suffix; final String maxKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "Max" + suffix; final String excludedDatesKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "DExcl" + suffix; final String excludedWeekdaysKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "WExcl" + suffix; LocalDate requestedDate = DateUtils.ldFrom(NumberUtils.toLong(shoppingCart.getOrderInfo().getDetailByKey(requestedDateKey))); shoppingCart.getOrderInfo().putDetail(requestedDateKey, null); shoppingCart.getOrderInfo().putDetail(minKey, null); shoppingCart.getOrderInfo().putDetail(maxKey, null); shoppingCart.getOrderInfo().putDetail(excludedDatesKey, null); shoppingCart.getOrderInfo().putDetail(excludedWeekdaysKey, null); if (!sla.isNamedDay()) { return; } LocalDate minDeliveryTime = now(); if (ff != null) { final Set<String> checkedGroups = new HashSet<>(); LocalDate longestMinDeliveryTime = minDeliveryTime; for (final Map.Entry<DeliveryBucket, List<CartItem>> bucketAndItems : shoppingCart.getCartItemMap().entrySet()) { final DeliveryBucket bucket = bucketAndItems.getKey(); if (ff.getCode().equals(bucket.getSupplier())) { final String dgroup = bucket.getGroup(); if (!CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP.equals(dgroup) && !checkedGroups.contains(dgroup)) { final LocalDate deliveryTime = skipInventoryLeadTime(dgroup, ff, shoppingCart, bucketAndItems.getValue(), minDeliveryTime); if (deliveryTime.isAfter(longestMinDeliveryTime)) { longestMinDeliveryTime = deliveryTime; } checkedGroups.add(dgroup); } } } minDeliveryTime = longestMinDeliveryTime; } final Map<LocalDate, LocalDate> slaExcludedDates = getCarrierSlaExcludedDates(sla); final int minDays = sla.getMinDays() != null ? sla.getMinDays() : 0; final int maxDays = sla.getMaxDays() != null ? sla.getMaxDays() : MAX_NAMED_DAY_IF_NOT_SET; if (minDays > 0) { minDeliveryTime = minDeliveryTime.plusDays(minDays); } LocalDate maxDeliveryTime = minDeliveryTime; minDeliveryTime = skipWeekdayExclusions(sla, minDeliveryTime); minDeliveryTime = skipDatesExclusions(sla, minDeliveryTime, slaExcludedDates); LocalDate min = minDeliveryTime; if (requestedDate.isBefore(minDeliveryTime)) { requestedDate = minDeliveryTime; } if (maxDays > minDays) { maxDeliveryTime = maxDeliveryTime.plusDays(maxDays - minDays); } else { maxDeliveryTime = maxDeliveryTime.plusDays(1); } LocalDate max = maxDeliveryTime; final Map<LocalDate, LocalDate> exclusions = sla.getExcludeDatesAsMap(); if (!exclusions.isEmpty() || !sla.getExcludeWeekDaysAsList().isEmpty()) { final StringBuilder exclusionsInMinMax = new StringBuilder(); LocalDate nextDay = min; LocalDate lastValidDate = min; while (nextDay.isBefore(max)) { nextDay = nextDay.plusDays(1); LocalDate expectedNextDay = nextDay; nextDay = skipWeekdayExclusions(sla, nextDay); nextDay = skipDatesExclusions(sla, nextDay, exclusions); if (!expectedNextDay.isEqual(nextDay)) { LocalDate excluded = expectedNextDay; if (!requestedDate.isBefore(expectedNextDay) && requestedDate.isBefore(nextDay)) { requestedDate = nextDay; } do { if (exclusionsInMinMax.length() > 0) { exclusionsInMinMax.append(','); } exclusionsInMinMax.append(DateUtils.millis(excluded)); excluded = excluded.plusDays(1); } while (excluded.isBefore(nextDay)); } else { lastValidDate = expectedNextDay; } } if (exclusionsInMinMax.length() > 0) { shoppingCart.getOrderInfo().putDetail(excludedDatesKey, exclusionsInMinMax.toString()); } if (StringUtils.isNotBlank(sla.getExcludeWeekDays())) { shoppingCart.getOrderInfo().putDetail(excludedWeekdaysKey, sla.getExcludeWeekDays()); } if (lastValidDate.isBefore(max)) { max = lastValidDate; } if (requestedDate.isAfter(lastValidDate)) { requestedDate = lastValidDate; } } if (requestedDate.isAfter(max)) { requestedDate = max; } shoppingCart.getOrderInfo().putDetail(requestedDateKey, String.valueOf(DateUtils.millis(requestedDate))); shoppingCart.getOrderInfo().putDetail(minKey, String.valueOf(DateUtils.millis(min))); shoppingCart.getOrderInfo().putDetail(maxKey, String.valueOf(DateUtils.millis(max))); }
DeliveryTimeEstimationVisitorDefaultImpl implements DeliveryTimeEstimationVisitor, Configuration { protected void determineDeliveryAvailableTimeRange(final MutableShoppingCart shoppingCart, final Long carrierSlaId, final Warehouse ff) { if (carrierSlaId == null) { return; } final CarrierSla sla = carrierSlaService.findById(carrierSlaId); if (sla == null) { return; } final String suffix = sla.getCarrierslaId() + (ff != null ? ff.getCode() : ""); final String requestedDateKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + suffix; final String minKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "Min" + suffix; final String maxKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "Max" + suffix; final String excludedDatesKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "DExcl" + suffix; final String excludedWeekdaysKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "WExcl" + suffix; LocalDate requestedDate = DateUtils.ldFrom(NumberUtils.toLong(shoppingCart.getOrderInfo().getDetailByKey(requestedDateKey))); shoppingCart.getOrderInfo().putDetail(requestedDateKey, null); shoppingCart.getOrderInfo().putDetail(minKey, null); shoppingCart.getOrderInfo().putDetail(maxKey, null); shoppingCart.getOrderInfo().putDetail(excludedDatesKey, null); shoppingCart.getOrderInfo().putDetail(excludedWeekdaysKey, null); if (!sla.isNamedDay()) { return; } LocalDate minDeliveryTime = now(); if (ff != null) { final Set<String> checkedGroups = new HashSet<>(); LocalDate longestMinDeliveryTime = minDeliveryTime; for (final Map.Entry<DeliveryBucket, List<CartItem>> bucketAndItems : shoppingCart.getCartItemMap().entrySet()) { final DeliveryBucket bucket = bucketAndItems.getKey(); if (ff.getCode().equals(bucket.getSupplier())) { final String dgroup = bucket.getGroup(); if (!CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP.equals(dgroup) && !checkedGroups.contains(dgroup)) { final LocalDate deliveryTime = skipInventoryLeadTime(dgroup, ff, shoppingCart, bucketAndItems.getValue(), minDeliveryTime); if (deliveryTime.isAfter(longestMinDeliveryTime)) { longestMinDeliveryTime = deliveryTime; } checkedGroups.add(dgroup); } } } minDeliveryTime = longestMinDeliveryTime; } final Map<LocalDate, LocalDate> slaExcludedDates = getCarrierSlaExcludedDates(sla); final int minDays = sla.getMinDays() != null ? sla.getMinDays() : 0; final int maxDays = sla.getMaxDays() != null ? sla.getMaxDays() : MAX_NAMED_DAY_IF_NOT_SET; if (minDays > 0) { minDeliveryTime = minDeliveryTime.plusDays(minDays); } LocalDate maxDeliveryTime = minDeliveryTime; minDeliveryTime = skipWeekdayExclusions(sla, minDeliveryTime); minDeliveryTime = skipDatesExclusions(sla, minDeliveryTime, slaExcludedDates); LocalDate min = minDeliveryTime; if (requestedDate.isBefore(minDeliveryTime)) { requestedDate = minDeliveryTime; } if (maxDays > minDays) { maxDeliveryTime = maxDeliveryTime.plusDays(maxDays - minDays); } else { maxDeliveryTime = maxDeliveryTime.plusDays(1); } LocalDate max = maxDeliveryTime; final Map<LocalDate, LocalDate> exclusions = sla.getExcludeDatesAsMap(); if (!exclusions.isEmpty() || !sla.getExcludeWeekDaysAsList().isEmpty()) { final StringBuilder exclusionsInMinMax = new StringBuilder(); LocalDate nextDay = min; LocalDate lastValidDate = min; while (nextDay.isBefore(max)) { nextDay = nextDay.plusDays(1); LocalDate expectedNextDay = nextDay; nextDay = skipWeekdayExclusions(sla, nextDay); nextDay = skipDatesExclusions(sla, nextDay, exclusions); if (!expectedNextDay.isEqual(nextDay)) { LocalDate excluded = expectedNextDay; if (!requestedDate.isBefore(expectedNextDay) && requestedDate.isBefore(nextDay)) { requestedDate = nextDay; } do { if (exclusionsInMinMax.length() > 0) { exclusionsInMinMax.append(','); } exclusionsInMinMax.append(DateUtils.millis(excluded)); excluded = excluded.plusDays(1); } while (excluded.isBefore(nextDay)); } else { lastValidDate = expectedNextDay; } } if (exclusionsInMinMax.length() > 0) { shoppingCart.getOrderInfo().putDetail(excludedDatesKey, exclusionsInMinMax.toString()); } if (StringUtils.isNotBlank(sla.getExcludeWeekDays())) { shoppingCart.getOrderInfo().putDetail(excludedWeekdaysKey, sla.getExcludeWeekDays()); } if (lastValidDate.isBefore(max)) { max = lastValidDate; } if (requestedDate.isAfter(lastValidDate)) { requestedDate = lastValidDate; } } if (requestedDate.isAfter(max)) { requestedDate = max; } shoppingCart.getOrderInfo().putDetail(requestedDateKey, String.valueOf(DateUtils.millis(requestedDate))); shoppingCart.getOrderInfo().putDetail(minKey, String.valueOf(DateUtils.millis(min))); shoppingCart.getOrderInfo().putDetail(maxKey, String.valueOf(DateUtils.millis(max))); } }
DeliveryTimeEstimationVisitorDefaultImpl implements DeliveryTimeEstimationVisitor, Configuration { protected void determineDeliveryAvailableTimeRange(final MutableShoppingCart shoppingCart, final Long carrierSlaId, final Warehouse ff) { if (carrierSlaId == null) { return; } final CarrierSla sla = carrierSlaService.findById(carrierSlaId); if (sla == null) { return; } final String suffix = sla.getCarrierslaId() + (ff != null ? ff.getCode() : ""); final String requestedDateKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + suffix; final String minKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "Min" + suffix; final String maxKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "Max" + suffix; final String excludedDatesKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "DExcl" + suffix; final String excludedWeekdaysKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "WExcl" + suffix; LocalDate requestedDate = DateUtils.ldFrom(NumberUtils.toLong(shoppingCart.getOrderInfo().getDetailByKey(requestedDateKey))); shoppingCart.getOrderInfo().putDetail(requestedDateKey, null); shoppingCart.getOrderInfo().putDetail(minKey, null); shoppingCart.getOrderInfo().putDetail(maxKey, null); shoppingCart.getOrderInfo().putDetail(excludedDatesKey, null); shoppingCart.getOrderInfo().putDetail(excludedWeekdaysKey, null); if (!sla.isNamedDay()) { return; } LocalDate minDeliveryTime = now(); if (ff != null) { final Set<String> checkedGroups = new HashSet<>(); LocalDate longestMinDeliveryTime = minDeliveryTime; for (final Map.Entry<DeliveryBucket, List<CartItem>> bucketAndItems : shoppingCart.getCartItemMap().entrySet()) { final DeliveryBucket bucket = bucketAndItems.getKey(); if (ff.getCode().equals(bucket.getSupplier())) { final String dgroup = bucket.getGroup(); if (!CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP.equals(dgroup) && !checkedGroups.contains(dgroup)) { final LocalDate deliveryTime = skipInventoryLeadTime(dgroup, ff, shoppingCart, bucketAndItems.getValue(), minDeliveryTime); if (deliveryTime.isAfter(longestMinDeliveryTime)) { longestMinDeliveryTime = deliveryTime; } checkedGroups.add(dgroup); } } } minDeliveryTime = longestMinDeliveryTime; } final Map<LocalDate, LocalDate> slaExcludedDates = getCarrierSlaExcludedDates(sla); final int minDays = sla.getMinDays() != null ? sla.getMinDays() : 0; final int maxDays = sla.getMaxDays() != null ? sla.getMaxDays() : MAX_NAMED_DAY_IF_NOT_SET; if (minDays > 0) { minDeliveryTime = minDeliveryTime.plusDays(minDays); } LocalDate maxDeliveryTime = minDeliveryTime; minDeliveryTime = skipWeekdayExclusions(sla, minDeliveryTime); minDeliveryTime = skipDatesExclusions(sla, minDeliveryTime, slaExcludedDates); LocalDate min = minDeliveryTime; if (requestedDate.isBefore(minDeliveryTime)) { requestedDate = minDeliveryTime; } if (maxDays > minDays) { maxDeliveryTime = maxDeliveryTime.plusDays(maxDays - minDays); } else { maxDeliveryTime = maxDeliveryTime.plusDays(1); } LocalDate max = maxDeliveryTime; final Map<LocalDate, LocalDate> exclusions = sla.getExcludeDatesAsMap(); if (!exclusions.isEmpty() || !sla.getExcludeWeekDaysAsList().isEmpty()) { final StringBuilder exclusionsInMinMax = new StringBuilder(); LocalDate nextDay = min; LocalDate lastValidDate = min; while (nextDay.isBefore(max)) { nextDay = nextDay.plusDays(1); LocalDate expectedNextDay = nextDay; nextDay = skipWeekdayExclusions(sla, nextDay); nextDay = skipDatesExclusions(sla, nextDay, exclusions); if (!expectedNextDay.isEqual(nextDay)) { LocalDate excluded = expectedNextDay; if (!requestedDate.isBefore(expectedNextDay) && requestedDate.isBefore(nextDay)) { requestedDate = nextDay; } do { if (exclusionsInMinMax.length() > 0) { exclusionsInMinMax.append(','); } exclusionsInMinMax.append(DateUtils.millis(excluded)); excluded = excluded.plusDays(1); } while (excluded.isBefore(nextDay)); } else { lastValidDate = expectedNextDay; } } if (exclusionsInMinMax.length() > 0) { shoppingCart.getOrderInfo().putDetail(excludedDatesKey, exclusionsInMinMax.toString()); } if (StringUtils.isNotBlank(sla.getExcludeWeekDays())) { shoppingCart.getOrderInfo().putDetail(excludedWeekdaysKey, sla.getExcludeWeekDays()); } if (lastValidDate.isBefore(max)) { max = lastValidDate; } if (requestedDate.isAfter(lastValidDate)) { requestedDate = lastValidDate; } } if (requestedDate.isAfter(max)) { requestedDate = max; } shoppingCart.getOrderInfo().putDetail(requestedDateKey, String.valueOf(DateUtils.millis(requestedDate))); shoppingCart.getOrderInfo().putDetail(minKey, String.valueOf(DateUtils.millis(min))); shoppingCart.getOrderInfo().putDetail(maxKey, String.valueOf(DateUtils.millis(max))); } DeliveryTimeEstimationVisitorDefaultImpl(final WarehouseService warehouseService,
                                                    final CarrierSlaService carrierSlaService); }
DeliveryTimeEstimationVisitorDefaultImpl implements DeliveryTimeEstimationVisitor, Configuration { protected void determineDeliveryAvailableTimeRange(final MutableShoppingCart shoppingCart, final Long carrierSlaId, final Warehouse ff) { if (carrierSlaId == null) { return; } final CarrierSla sla = carrierSlaService.findById(carrierSlaId); if (sla == null) { return; } final String suffix = sla.getCarrierslaId() + (ff != null ? ff.getCode() : ""); final String requestedDateKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + suffix; final String minKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "Min" + suffix; final String maxKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "Max" + suffix; final String excludedDatesKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "DExcl" + suffix; final String excludedWeekdaysKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "WExcl" + suffix; LocalDate requestedDate = DateUtils.ldFrom(NumberUtils.toLong(shoppingCart.getOrderInfo().getDetailByKey(requestedDateKey))); shoppingCart.getOrderInfo().putDetail(requestedDateKey, null); shoppingCart.getOrderInfo().putDetail(minKey, null); shoppingCart.getOrderInfo().putDetail(maxKey, null); shoppingCart.getOrderInfo().putDetail(excludedDatesKey, null); shoppingCart.getOrderInfo().putDetail(excludedWeekdaysKey, null); if (!sla.isNamedDay()) { return; } LocalDate minDeliveryTime = now(); if (ff != null) { final Set<String> checkedGroups = new HashSet<>(); LocalDate longestMinDeliveryTime = minDeliveryTime; for (final Map.Entry<DeliveryBucket, List<CartItem>> bucketAndItems : shoppingCart.getCartItemMap().entrySet()) { final DeliveryBucket bucket = bucketAndItems.getKey(); if (ff.getCode().equals(bucket.getSupplier())) { final String dgroup = bucket.getGroup(); if (!CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP.equals(dgroup) && !checkedGroups.contains(dgroup)) { final LocalDate deliveryTime = skipInventoryLeadTime(dgroup, ff, shoppingCart, bucketAndItems.getValue(), minDeliveryTime); if (deliveryTime.isAfter(longestMinDeliveryTime)) { longestMinDeliveryTime = deliveryTime; } checkedGroups.add(dgroup); } } } minDeliveryTime = longestMinDeliveryTime; } final Map<LocalDate, LocalDate> slaExcludedDates = getCarrierSlaExcludedDates(sla); final int minDays = sla.getMinDays() != null ? sla.getMinDays() : 0; final int maxDays = sla.getMaxDays() != null ? sla.getMaxDays() : MAX_NAMED_DAY_IF_NOT_SET; if (minDays > 0) { minDeliveryTime = minDeliveryTime.plusDays(minDays); } LocalDate maxDeliveryTime = minDeliveryTime; minDeliveryTime = skipWeekdayExclusions(sla, minDeliveryTime); minDeliveryTime = skipDatesExclusions(sla, minDeliveryTime, slaExcludedDates); LocalDate min = minDeliveryTime; if (requestedDate.isBefore(minDeliveryTime)) { requestedDate = minDeliveryTime; } if (maxDays > minDays) { maxDeliveryTime = maxDeliveryTime.plusDays(maxDays - minDays); } else { maxDeliveryTime = maxDeliveryTime.plusDays(1); } LocalDate max = maxDeliveryTime; final Map<LocalDate, LocalDate> exclusions = sla.getExcludeDatesAsMap(); if (!exclusions.isEmpty() || !sla.getExcludeWeekDaysAsList().isEmpty()) { final StringBuilder exclusionsInMinMax = new StringBuilder(); LocalDate nextDay = min; LocalDate lastValidDate = min; while (nextDay.isBefore(max)) { nextDay = nextDay.plusDays(1); LocalDate expectedNextDay = nextDay; nextDay = skipWeekdayExclusions(sla, nextDay); nextDay = skipDatesExclusions(sla, nextDay, exclusions); if (!expectedNextDay.isEqual(nextDay)) { LocalDate excluded = expectedNextDay; if (!requestedDate.isBefore(expectedNextDay) && requestedDate.isBefore(nextDay)) { requestedDate = nextDay; } do { if (exclusionsInMinMax.length() > 0) { exclusionsInMinMax.append(','); } exclusionsInMinMax.append(DateUtils.millis(excluded)); excluded = excluded.plusDays(1); } while (excluded.isBefore(nextDay)); } else { lastValidDate = expectedNextDay; } } if (exclusionsInMinMax.length() > 0) { shoppingCart.getOrderInfo().putDetail(excludedDatesKey, exclusionsInMinMax.toString()); } if (StringUtils.isNotBlank(sla.getExcludeWeekDays())) { shoppingCart.getOrderInfo().putDetail(excludedWeekdaysKey, sla.getExcludeWeekDays()); } if (lastValidDate.isBefore(max)) { max = lastValidDate; } if (requestedDate.isAfter(lastValidDate)) { requestedDate = lastValidDate; } } if (requestedDate.isAfter(max)) { requestedDate = max; } shoppingCart.getOrderInfo().putDetail(requestedDateKey, String.valueOf(DateUtils.millis(requestedDate))); shoppingCart.getOrderInfo().putDetail(minKey, String.valueOf(DateUtils.millis(min))); shoppingCart.getOrderInfo().putDetail(maxKey, String.valueOf(DateUtils.millis(max))); } DeliveryTimeEstimationVisitorDefaultImpl(final WarehouseService warehouseService,
                                                    final CarrierSlaService carrierSlaService); @Override void visit(final CustomerOrder order); @Override void visit(final CustomerOrderDelivery delivery); @Override void visit(final MutableShoppingCart shoppingCart); @Override ConfigurationContext getCfgContext(); void setCfgContext(final ConfigurationContext cfgContext); }
DeliveryTimeEstimationVisitorDefaultImpl implements DeliveryTimeEstimationVisitor, Configuration { protected void determineDeliveryAvailableTimeRange(final MutableShoppingCart shoppingCart, final Long carrierSlaId, final Warehouse ff) { if (carrierSlaId == null) { return; } final CarrierSla sla = carrierSlaService.findById(carrierSlaId); if (sla == null) { return; } final String suffix = sla.getCarrierslaId() + (ff != null ? ff.getCode() : ""); final String requestedDateKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + suffix; final String minKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "Min" + suffix; final String maxKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "Max" + suffix; final String excludedDatesKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "DExcl" + suffix; final String excludedWeekdaysKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + "WExcl" + suffix; LocalDate requestedDate = DateUtils.ldFrom(NumberUtils.toLong(shoppingCart.getOrderInfo().getDetailByKey(requestedDateKey))); shoppingCart.getOrderInfo().putDetail(requestedDateKey, null); shoppingCart.getOrderInfo().putDetail(minKey, null); shoppingCart.getOrderInfo().putDetail(maxKey, null); shoppingCart.getOrderInfo().putDetail(excludedDatesKey, null); shoppingCart.getOrderInfo().putDetail(excludedWeekdaysKey, null); if (!sla.isNamedDay()) { return; } LocalDate minDeliveryTime = now(); if (ff != null) { final Set<String> checkedGroups = new HashSet<>(); LocalDate longestMinDeliveryTime = minDeliveryTime; for (final Map.Entry<DeliveryBucket, List<CartItem>> bucketAndItems : shoppingCart.getCartItemMap().entrySet()) { final DeliveryBucket bucket = bucketAndItems.getKey(); if (ff.getCode().equals(bucket.getSupplier())) { final String dgroup = bucket.getGroup(); if (!CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP.equals(dgroup) && !checkedGroups.contains(dgroup)) { final LocalDate deliveryTime = skipInventoryLeadTime(dgroup, ff, shoppingCart, bucketAndItems.getValue(), minDeliveryTime); if (deliveryTime.isAfter(longestMinDeliveryTime)) { longestMinDeliveryTime = deliveryTime; } checkedGroups.add(dgroup); } } } minDeliveryTime = longestMinDeliveryTime; } final Map<LocalDate, LocalDate> slaExcludedDates = getCarrierSlaExcludedDates(sla); final int minDays = sla.getMinDays() != null ? sla.getMinDays() : 0; final int maxDays = sla.getMaxDays() != null ? sla.getMaxDays() : MAX_NAMED_DAY_IF_NOT_SET; if (minDays > 0) { minDeliveryTime = minDeliveryTime.plusDays(minDays); } LocalDate maxDeliveryTime = minDeliveryTime; minDeliveryTime = skipWeekdayExclusions(sla, minDeliveryTime); minDeliveryTime = skipDatesExclusions(sla, minDeliveryTime, slaExcludedDates); LocalDate min = minDeliveryTime; if (requestedDate.isBefore(minDeliveryTime)) { requestedDate = minDeliveryTime; } if (maxDays > minDays) { maxDeliveryTime = maxDeliveryTime.plusDays(maxDays - minDays); } else { maxDeliveryTime = maxDeliveryTime.plusDays(1); } LocalDate max = maxDeliveryTime; final Map<LocalDate, LocalDate> exclusions = sla.getExcludeDatesAsMap(); if (!exclusions.isEmpty() || !sla.getExcludeWeekDaysAsList().isEmpty()) { final StringBuilder exclusionsInMinMax = new StringBuilder(); LocalDate nextDay = min; LocalDate lastValidDate = min; while (nextDay.isBefore(max)) { nextDay = nextDay.plusDays(1); LocalDate expectedNextDay = nextDay; nextDay = skipWeekdayExclusions(sla, nextDay); nextDay = skipDatesExclusions(sla, nextDay, exclusions); if (!expectedNextDay.isEqual(nextDay)) { LocalDate excluded = expectedNextDay; if (!requestedDate.isBefore(expectedNextDay) && requestedDate.isBefore(nextDay)) { requestedDate = nextDay; } do { if (exclusionsInMinMax.length() > 0) { exclusionsInMinMax.append(','); } exclusionsInMinMax.append(DateUtils.millis(excluded)); excluded = excluded.plusDays(1); } while (excluded.isBefore(nextDay)); } else { lastValidDate = expectedNextDay; } } if (exclusionsInMinMax.length() > 0) { shoppingCart.getOrderInfo().putDetail(excludedDatesKey, exclusionsInMinMax.toString()); } if (StringUtils.isNotBlank(sla.getExcludeWeekDays())) { shoppingCart.getOrderInfo().putDetail(excludedWeekdaysKey, sla.getExcludeWeekDays()); } if (lastValidDate.isBefore(max)) { max = lastValidDate; } if (requestedDate.isAfter(lastValidDate)) { requestedDate = lastValidDate; } } if (requestedDate.isAfter(max)) { requestedDate = max; } shoppingCart.getOrderInfo().putDetail(requestedDateKey, String.valueOf(DateUtils.millis(requestedDate))); shoppingCart.getOrderInfo().putDetail(minKey, String.valueOf(DateUtils.millis(min))); shoppingCart.getOrderInfo().putDetail(maxKey, String.valueOf(DateUtils.millis(max))); } DeliveryTimeEstimationVisitorDefaultImpl(final WarehouseService warehouseService,
                                                    final CarrierSlaService carrierSlaService); @Override void visit(final CustomerOrder order); @Override void visit(final CustomerOrderDelivery delivery); @Override void visit(final MutableShoppingCart shoppingCart); @Override ConfigurationContext getCfgContext(); void setCfgContext(final ConfigurationContext cfgContext);  }