@Override public String value(WrappedBooking input) { return Attribute.normalize(input.getReferenceName()); } },
@Override public void modify(WrappedBooking booking) { if (StringUtils.startsWithIgnoreCase(booking.getReferenceName(), "PayPal") && booking.getPurpose() != null) { Matcher matcher = PAYPAL_PURPOSE_PATTERN.matcher(booking.getPurpose()); if (matcher.matches() && matcher.groupCount() == 4) { booking.setOtherAccount("PayPal Zahlung an " + matcher.group(3)); } } }
@Override public boolean match(WrappedBooking wrappedBooking) { switch (rule.getSimilarityMatchType()) { case IBAN: return StringUtils.equalsIgnoreCase(rule.getExpression(), wrappedBooking.getBankConnection()); case REFERENCE_NAME: if (wrappedBooking.getReferenceName() != null) { Double result = JARO_WINKLER.apply(rule.getExpression(), wrappedBooking.getReferenceName().toLowerCase()); if (result >= MIN_DISTANCE) { log.debug("similarity expression {} compared with {} resulted in score {}", rule.getExpression(), wrappedBooking.getReferenceName().toLowerCase(), result); } return result >= MIN_DISTANCE; } return false; case PURPOSE: Double result = JARO_WINKLER.apply(rule.getExpression(), normalize(wrappedBooking.getPurpose())); if (result >= MIN_DISTANCE) { log.debug("similarity expression {} compared with {} resulted in score {}", rule.getExpression(), normalize(wrappedBooking.getPurpose()), result); } return result >= MIN_DISTANCE; } throw new IllegalArgumentException("missing match type"); }
private boolean evalRecurrentGroup(BookingGroup bookingGroup, List<WrappedBooking> bookings, List<Matcher> contractBlackList) { if (bookings.size() == 0) { return false; } BigDecimal amount = AmountCalculator.calcAmount(bookings); if (amount.compareTo(BigDecimal.ZERO) == 0) { return false; } bookingGroup.setCycle(CycleCalculator.fromDates(bookings.stream() .map(WrappedBooking::getExecutionDate) .collect(Collectors.toList()))); bookingGroup.setContract(ContractValidator.isContract(bookingGroup, bookings, contractBlackList)); bookingGroup.setCancelled(!bookingGroup.isEffective(LocalDate.now(), bookings)); bookingGroup.setMainCategory(bookings.get(0).getMainCategory()); bookingGroup.setSubCategory(bookings.get(0).getSubCategory()); bookingGroup.setSpecification(bookings.get(0).getSpecification()); bookingGroup.setHomepage(bookings.get(0).getHomepage()); bookingGroup.setHotline(bookings.get(0).getHotline()); bookingGroup.setEmail(bookings.get(0).getEmail()); bookingGroup.setLogo(bookings.get(0).getLogo()); bookingGroup.setMandatreference(bookings.get(0).getMandateReference()); if (StringUtils.isNotBlank(bookings.get(0).getOtherAccount())) { bookingGroup.setOtherAccount(bookings.get(0).getOtherAccount()); } else { bookingGroup.setOtherAccount(bookings.get(0).getReferenceName()); } bookingGroup.setAmount(amount); return true; }
/** * Assert if the given booking is a recurrent income booking. * * @param booking the booking to be asserted * @return true if the booking is a recurrent income booking otherwise false. */ public static boolean isRecurrent(WrappedBooking booking) { // should only have positive amount if (booking.getAmount() == null || booking.getAmount().compareTo(BigDecimal.ZERO) < 0) { return false; } // should have a purpose if (booking.getPurpose() == null) { return false; } // should not have a valid bank connection return booking.getIban() != null || (booking.getBankCode() != null && booking.getAccountNumber() != null) || booking.getReferenceName() != null; }
@Override public BookingGroup createGroup(WrappedBooking booking) { BookingGroup bookingGroup; if (booking.getCreditorId() != null && booking.getMandateReference() != null) { log.trace("interpreted as standing order booking with kref & mref"); bookingGroup = new BookingGroup(booking.getCreditorId(), booking.getMandateReference(), getGroupName(), getGroupType()); } else if (booking.getIban() != null) { log.trace("interpreted as standing order booking with iban"); bookingGroup = new BookingGroup(booking.getIban(), booking.getAmount().toPlainString(), getGroupName(), getGroupType()); } else { log.trace("interpreted as non sepa booking with amount"); bookingGroup = new BookingGroup(booking.getReferenceName(), booking.getAmount().toPlainString(), getGroupName(), getGroupType()); } return bookingGroup; }