public static Cycle fromDates(List<LocalDate> daten) { if (daten.size() == 1) { return YEARLY; } List<LocalDate> sortierteDaten = daten.stream() .sorted(Comparator.naturalOrder()) // nur die letzten 13 Umsätze berücksichtigen .skip(Math.max(0, daten.size() - MAX_ANZAHL_RELEVANTE_DATEN)) .collect(Collectors.toList()); List<Long> abstaende = new ArrayList<>(); for (int i = 0; i < sortierteDaten.size() - 1; i++) { abstaende.add(ChronoUnit.DAYS.between(sortierteDaten.get(i), sortierteDaten.get(i + 1))); } for (Cycle ausfuehrungsintervall : Cycle.values()) { if (ausfuehrungsintervall == WEEKLY && daten.size() < MIND_ANZAHL_UMSAETZE_FUER_WOECHENTLICHES_INTERVALL) { continue; } if (genuegendAbstaendeMitPassenderLaenge(ausfuehrungsintervall.getMinDays(), ausfuehrungsintervall.getMaxDays(), abstaende)) { return ausfuehrungsintervall; } // ZKB-3068 if (ausfuehrungsintervall == MONTHLY) { long abstandMittelwert = Math.round(abstaende.stream().mapToLong(l -> l).sum() / (float) abstaende.size()); if (genuegendAbstaendeMitPassenderLaenge(ausfuehrungsintervall.getMinDays(), ausfuehrungsintervall.getMaxDays(), abstandMittelwert)) { return ausfuehrungsintervall; } } } return null; }
private static void filterInactiveBookings(List<LocalDate> result, BookingGroup bookingGroup, List<WrappedBooking> bookings, LocalDate executionDate) { if (result.isEmpty()) { return; } List<LocalDate> bookingDates = bookings.stream() .map(WrappedBooking::getExecutionDate) .collect(Collectors.toList()); LocalDate lastBookingDate = LocalDate.ofEpochDay(0); for (WrappedBooking booking : bookings) { if (booking.getExecutionDate().isAfter(lastBookingDate)) { lastBookingDate = booking.getExecutionDate(); } } if (!bookingGroup.getCycle().isValid(lastBookingDate, executionDate)) { for (Iterator<LocalDate> it = result.iterator(); it.hasNext(); ) { LocalDate nextBookingDate = it.next(); if (nextBookingDate.isAfter(lastBookingDate)) { it.remove(); } } } result.removeIf(plandatum -> !bookingGroup.getCycle().isReferenceDateBeforeBookingDateWithTolerance(plandatum, executionDate) && !bookingGroup.getCycle().isOneValidWithinTolerance(plandatum, bookingDates)); }
private static List<LocalDate> bankDaysNextCycle(LocalDate datum, Cycle intervall) { LocalDate nextBookingDate = intervall.nextBookingDate(datum); return nextBookingDate == null ? Collections.emptyList() : BankCalendar.bankDaysInMonth(nextBookingDate); }
static BookingCategory mapToBookingcategory(WrappedBooking wrappedBooking) { BookingCategory bookingCategory = new BookingCategory(); bookingCategory.setReceiver(wrappedBooking.getOtherAccount()); bookingCategory.setMainCategory(wrappedBooking.getMainCategory()); bookingCategory.setSubCategory(wrappedBooking.getSubCategory()); bookingCategory.setSpecification(wrappedBooking.getSpecification()); bookingCategory.setCustom(wrappedBooking.getCustom()); bookingCategory.setEmail(wrappedBooking.getEmail()); bookingCategory.setHomepage(wrappedBooking.getHomepage()); bookingCategory.setHotline(wrappedBooking.getHotline()); bookingCategory.setLogo(wrappedBooking.getLogo()); if (wrappedBooking.getCycle() != null) { bookingCategory.setInterval(Cycle.valueOf(wrappedBooking.getCycle().toString())); } bookingCategory.setRules(wrappedBooking.getRuleIds()); return bookingCategory; }
static de.adorsys.multibanking.domain.BookingGroup toBookingGroup(BookingGroup bookingsGroup) { de.adorsys.multibanking.domain.BookingGroup bookingGroup = de.adorsys.multibanking.domain.BookingGroup.builder() .amount(bookingsGroup.getAmount()) .mainCategory(bookingsGroup.getMainCategory()) .subCategory(bookingsGroup.getSubCategory()) .specification(bookingsGroup.getSpecification()) .bookingPeriods(mapBookingPeriods(bookingsGroup.getBookingPeriods())) .type(de.adorsys.multibanking.domain.BookingGroup.Type.valueOf(bookingsGroup.getGroupType().toString())) .contract(Contract.builder() .email(bookingsGroup.getEmail()) .homepage(bookingsGroup.getHomepage()) .logo(bookingsGroup.getLogo()) .mandateReference(bookingsGroup.getMandatreference()) .hotline(bookingsGroup.getHotline()) .email(bookingsGroup.getEmail()) .interval(bookingsGroup.getCycle() != null ? Cycle.valueOf(bookingsGroup.getCycle().name()) : null) .build() ) .build(); if (bookingsGroup.getGroupType() == Group.Type.CUSTOM || bookingsGroup.getGroupType() == Group.Type.OTHER_INCOME || bookingsGroup.getGroupType() == Group.Type.OTHER_EXPENSES) { bookingGroup.setOtherAccount(""); } else { bookingGroup.setOtherAccount(bookingsGroup.getOtherAccount()); } return bookingGroup; }
static BookingCategory mapToBookingcategory(WrappedBooking wrappedBooking) { BookingCategory bookingCategory = new BookingCategory(); bookingCategory.setReceiver(wrappedBooking.getOtherAccount()); bookingCategory.setMainCategory(wrappedBooking.getMainCategory()); bookingCategory.setSubCategory(wrappedBooking.getSubCategory()); bookingCategory.setSpecification(wrappedBooking.getSpecification()); bookingCategory.setCustom(wrappedBooking.getCustom()); bookingCategory.setEmail(wrappedBooking.getEmail()); bookingCategory.setHomepage(wrappedBooking.getHomepage()); bookingCategory.setHotline(wrappedBooking.getHotline()); bookingCategory.setLogo(wrappedBooking.getLogo()); if (wrappedBooking.getCycle() != null) { bookingCategory.setInterval(Cycle.valueOf(wrappedBooking.getCycle().toString())); } bookingCategory.setRules(wrappedBooking.getRuleIds()); return bookingCategory; }
static de.adorsys.multibanking.domain.BookingGroup toBookingGroup(BookingGroup bookingsGroup) { de.adorsys.multibanking.domain.BookingGroup bookingGroup = de.adorsys.multibanking.domain.BookingGroup.builder() .amount(bookingsGroup.getAmount()) .mainCategory(bookingsGroup.getMainCategory()) .subCategory(bookingsGroup.getSubCategory()) .specification(bookingsGroup.getSpecification()) .bookingPeriods(mapBookingPeriods(bookingsGroup.getBookingPeriods())) .type(de.adorsys.multibanking.domain.BookingGroup.Type.valueOf(bookingsGroup.getGroupType().toString())) .contract(Contract.builder() .email(bookingsGroup.getEmail()) .homepage(bookingsGroup.getHomepage()) .logo(bookingsGroup.getLogo()) .mandateReference(bookingsGroup.getMandatreference()) .hotline(bookingsGroup.getHotline()) .email(bookingsGroup.getEmail()) .interval(bookingsGroup.getCycle() != null ? Cycle.valueOf(bookingsGroup.getCycle().name()) : null) .build() ) .build(); if (bookingsGroup.getGroupType() == Group.Type.CUSTOM || bookingsGroup.getGroupType() == Group.Type.OTHER_INCOME || bookingsGroup.getGroupType() == Group.Type.OTHER_EXPENSES) { bookingGroup.setOtherAccount(""); } else { bookingGroup.setOtherAccount(bookingsGroup.getOtherAccount()); } return bookingGroup; }
static ContractEntity toContract(String userId, String accountId, BookingGroup bookingGroup) { ContractEntity contractEntity = new ContractEntity(); contractEntity.setAmount(bookingGroup.getAmount()); contractEntity.setInterval(Cycle.valueOf(bookingGroup.getCycle().toString())); contractEntity.setUserId(userId); contractEntity.setAccountId(accountId); contractEntity.setEmail(bookingGroup.getEmail()); contractEntity.setHomepage(bookingGroup.getHomepage()); contractEntity.setHotline(bookingGroup.getHotline()); contractEntity.setLogo(bookingGroup.getLogo()); contractEntity.setMainCategory(bookingGroup.getMainCategory()); contractEntity.setSubCategory(bookingGroup.getSubCategory()); contractEntity.setSpecification(bookingGroup.getSpecification()); contractEntity.setProvider(bookingGroup.getOtherAccount()); contractEntity.setMandateReference(bookingGroup.getMandatreference()); return contractEntity; }
public static LocalDate calcNextBookingDate(List<WrappedBooking> bookings, boolean income, Cycle cycle) { if (cycle == null) { return null; } List<LocalDate> lastBookingDates = getLastBookingDates(bookings); LocalDate lastBookingDate = lastBookingDates.get(lastBookingDates.size() - 1); List<Integer> indizes = createIndizes(lastBookingDates.size()); if (lastBookingDates.size() == 1) { return correctNextBookingDate(cycle.nextBookingDate(lastBookingDate), income); } int[] bankDays = lastBookingDates.stream().mapToInt(datum -> BankCalendar.bankDaysInMonth(datum).size()).toArray(); int[] bankDaysLeft = lastBookingDates.stream().mapToInt(datum -> BankCalendar.bankDaysLeft(datum).size()).toArray(); return calcNextBookingDate(income, lastBookingDates, cycle, lastBookingDate, indizes, bankDays, bankDaysLeft, false); }
static ContractEntity toContract(String userId, String accountId, BookingGroup bookingGroup) { ContractEntity contractEntity = new ContractEntity(); contractEntity.setAmount(bookingGroup.getAmount()); contractEntity.setInterval(Cycle.valueOf(bookingGroup.getCycle().toString())); contractEntity.setUserId(userId); contractEntity.setAccountId(accountId); contractEntity.setEmail(bookingGroup.getEmail()); contractEntity.setHomepage(bookingGroup.getHomepage()); contractEntity.setHotline(bookingGroup.getHotline()); contractEntity.setLogo(bookingGroup.getLogo()); contractEntity.setMainCategory(bookingGroup.getMainCategory()); contractEntity.setSubCategory(bookingGroup.getSubCategory()); contractEntity.setSpecification(bookingGroup.getSpecification()); contractEntity.setProvider(bookingGroup.getOtherAccount()); contractEntity.setMandateReference(bookingGroup.getMandatreference()); return contractEntity; }
private static LocalDate nextBookingDateWithHolidays(List<LocalDate> bookingDates, Cycle cycle, LocalDate lastBookingDaate, boolean income) { LocalDate nexBookingDate; if (cycle == Cycle.MONTHLY) { nexBookingDate = calcNextDateMonthCycle(bookingDates, lastBookingDaate); } else { nexBookingDate = cycle.nextBookingDate(lastBookingDaate); } if (nexBookingDate == null) { return null; } if (nexBookingDate.isBefore(LocalDate.now())) { nexBookingDate = LocalDate.now(); } if (BankCalendar.isBankDay(nexBookingDate)) { return nexBookingDate; } return correctNextBookingDate(nexBookingDate, income); }