public static void applyCategories(List<BookingEntity> bookingEntities, AnalyticsResult result) { result.getBookings().forEach(categorizedBooking -> { bookingEntities.stream() .filter(bookingEntity -> categorizedBooking.getBooking().getBookingId().equals(bookingEntity.getExternalId())) .findFirst().ifPresent(bookingEntity -> { if (categorizedBooking.getMainCategory() != null) { bookingEntity.setBookingCategory(mapToBookingcategory(categorizedBooking)); } }); }); }
static List<Booking> convertInput(Collection<BookingEntity> bookings) { List<Booking> interfaceBookings = new ArrayList<>(); for (BookingEntity booking : bookings) { Booking smartanalyticsBooking = new Booking(); smartanalyticsBooking.setBookingId(booking.getExternalId()); smartanalyticsBooking.setCreditorId(booking.getCreditorId()); smartanalyticsBooking.setPurpose(booking.getUsage()); smartanalyticsBooking.setIban(booking.getOtherAccount() != null ? booking.getOtherAccount().getIban() : null); smartanalyticsBooking.setAccountNumber(booking.getOtherAccount() != null ? booking.getOtherAccount().getAccountNumber() : null); smartanalyticsBooking.setBankCode(booking.getOtherAccount() != null ? booking.getOtherAccount().getBlz() : null); smartanalyticsBooking.setAmount(booking.getAmount()); smartanalyticsBooking.setExecutionDate(booking.getValutaDate()); smartanalyticsBooking.setStandingOrder(booking.isStandingOrder()); smartanalyticsBooking.setMandateReference(booking.getMandateReference()); if (booking.getOtherAccount() != null) { if (booking.getOtherAccount().getOwner() != null) { smartanalyticsBooking.setReferenceName(booking.getOtherAccount().getOwner()); } else { smartanalyticsBooking.setReferenceName(booking.getOtherAccount().getName()); } } interfaceBookings.add(smartanalyticsBooking); } return interfaceBookings; }
public static List<BookingPeriod> createGroupPeriods(List<BookingPeriod> bookingPeriods, List<WrappedBooking> bookings) { return bookingPeriods.stream() .map(period -> { List<WrappedBooking> periodBookings = filterPeriodBookings(bookings, period); BigDecimal periodAmount = periodBookings.stream() .map(WrappedBooking::getAmount) .reduce(BigDecimal.ZERO, BigDecimal::add); BookingPeriod groupPeriod = (BookingPeriod) period.clone(); groupPeriod.setAmount(periodAmount); groupPeriod.setBookings(periodBookings .stream() .map(wrappedBooking -> { ExecutedBooking executedBooking = new ExecutedBooking(); executedBooking.setBookingId(wrappedBooking.getBooking().getBookingId()); executedBooking.setExecutionDate(wrappedBooking.getBooking().getExecutionDate()); executedBooking.setExecuted(true); return executedBooking; }) .collect(Collectors.toList())); return groupPeriod; }) .filter(period -> period.getBookings().size() > 0) .collect(Collectors.toList()); }
private static boolean evalBookingPeriod(BookingPeriod period, List<WrappedBooking> bookings, List<LocalDate> bookingDates) { List<WrappedBooking> periodBookings = filterPeriodBookings(bookings, period); //forecast, clone bookings if (periodBookings.size() == 0) { period.setBookings(new ArrayList<>()); bookingDates.stream() .filter(executionDate -> dateInPeriod(executionDate, period)) .forEach(executionDate -> { ExecutedBooking forecastBooking = new ExecutedBooking(); forecastBooking.setBookingId(bookings.get(bookings.size()-1).getBooking().getBookingId()); forecastBooking.setExecuted(false); forecastBooking.setExecutionDate(executionDate); period.getBookings().add(forecastBooking); }); } else { //already executed bookings period.setBookings(periodBookings.stream().map(wrappedBooking -> { ExecutedBooking executedBooking = new ExecutedBooking(); executedBooking.setBookingId(wrappedBooking.getBooking().getBookingId()); executedBooking.setExecuted(true); executedBooking.setExecutionDate(wrappedBooking.getBooking().getExecutionDate()); return executedBooking; }).collect(Collectors.toList())); period.setAmount(periodBookings.stream() .map(WrappedBooking::getAmount) .reduce(BigDecimal.ZERO, BigDecimal::add)); } return period.getBookings().size() > 0 ? true : false; }
static List<Booking> convertInput(Collection<BookingEntity> bookings) { List<Booking> interfaceBookings = new ArrayList<>(); for (BookingEntity booking : bookings) { Booking smartanalyticsBooking = new Booking(); smartanalyticsBooking.setBookingId(booking.getExternalId()); smartanalyticsBooking.setCreditorId(booking.getCreditorId()); smartanalyticsBooking.setPurpose(booking.getUsage()); smartanalyticsBooking.setIban(booking.getOtherAccount() != null ? booking.getOtherAccount().getIban() : null); smartanalyticsBooking.setAccountNumber(booking.getOtherAccount() != null ? booking.getOtherAccount().getAccountNumber() : null); smartanalyticsBooking.setBankCode(booking.getOtherAccount() != null ? booking.getOtherAccount().getBlz() : null); smartanalyticsBooking.setAmount(booking.getAmount()); smartanalyticsBooking.setExecutionDate(booking.getValutaDate()); smartanalyticsBooking.setStandingOrder(booking.isStandingOrder()); smartanalyticsBooking.setMandateReference(booking.getMandateReference()); if (booking.getOtherAccount() != null) { if (booking.getOtherAccount().getOwner() != null) { smartanalyticsBooking.setReferenceName(booking.getOtherAccount().getOwner()); } else { smartanalyticsBooking.setReferenceName(booking.getOtherAccount().getName()); } } interfaceBookings.add(smartanalyticsBooking); } return interfaceBookings; }
public static void applyCategories(List<BookingEntity> bookingEntities, AnalyticsResult result) { result.getBookings().forEach(categorizedBooking -> { bookingEntities.stream() .filter(bookingEntity -> categorizedBooking.getBooking().getBookingId().equals(bookingEntity.getExternalId())) .findFirst().ifPresent(bookingEntity -> { if (categorizedBooking.getMainCategory() != null) { bookingEntity.setBookingCategory(mapToBookingcategory(categorizedBooking)); } }); }); }