Skip to content

Commit

Permalink
Improve SAP error logs FIST-897 #resolve (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis-Cruz authored Nov 11, 2020
1 parent b0b257c commit 894178b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
import java.math.BigDecimal;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class EventProcessor {

public static void calculate(final Supplier<Event> supplier) {
final ErrorLogConsumer errorLog = (oid, user, name, amount, cycleType, error, args, type, countryOfVatNumber,
vatNumber, address, locality, postCode, countryOfAddress, paymentMethod, documentNumber, actionType) -> {};
final EventLogger elogger = (msg, args) -> {};
final ErrorLogConsumer errorLog = (oid, user, name, amount, cycleType, error, args, type, countryOfVatNumber,
vatNumber, address, locality, postCode, countryOfAddress, paymentMethod, documentNumber, actionType) -> {
};
final EventLogger elogger = (msg, args) -> {
};
registerEventSapRequests(errorLog, elogger, supplier.get(), true);
}

Expand Down Expand Up @@ -63,9 +66,11 @@ private static void syncToSap(final ErrorLogConsumer errorLog, final EventLogger
}

public static void sync(final Supplier<Event> supplier) {
final ErrorLogConsumer errorLog = (oid, user, name, amount, cycleType, error, args, type, countryOfVatNumber,
vatNumber, address, locality, postCode, countryOfAddress, paymentMethod, documentNumber, actionType) -> {};
final EventLogger elogger = (msg, args) -> {};
final ErrorLogConsumer errorLog = (oid, user, name, amount, cycleType, error, args, type, countryOfVatNumber,
vatNumber, address, locality, postCode, countryOfAddress, paymentMethod, documentNumber, actionType) -> {
};
final EventLogger elogger = (msg, args) -> {
};
syncEventWithSap(errorLog, elogger, supplier.get());
}

Expand Down Expand Up @@ -126,7 +131,7 @@ private static void processSap(final ErrorLogConsumer errorLog, final EventLogge
return;
}

if(Strings.isNullOrEmpty(payment.getRefundId())) {
if (Strings.isNullOrEmpty(payment.getRefundId())) {
sapEvent.registerPayment((CreditEntry) accountingEntry);
} else {
sapEvent.registerAdvancementInPayment(payment);
Expand Down Expand Up @@ -160,7 +165,7 @@ private static void processSap(final ErrorLogConsumer errorLog, final EventLogge
//processing payments of past events
DebtInterestCalculator calculator = event.getDebtInterestCalculator(new DateTime());
calculator.getPayments().filter(p -> !sapEvent.hasPayment(p.getId()) && !sapEvent.hasCredit(p.getId())
&& p.getCreated().isAfter(EventWrapper.SAP_TRANSACTIONS_THRESHOLD))
&& p.getCreated().isAfter(EventWrapper.SAP_TRANSACTIONS_THRESHOLD))
.filter(p -> !offsetPayments || p.getCreated().plusDays(15).isBeforeNow())
.forEach(p -> sapEvent.registerPastPayment(p));
}
Expand Down Expand Up @@ -235,8 +240,15 @@ private static void logError(final ErrorLogConsumer errorLog, final EventLogger
.filter(sr -> !sr.getIntegrated())
.map(sr -> sr.getDocumentNumber())
.collect(Collectors.joining(", "));
final String errorMessageExtraInfo = Stream.concat(Stream.of(errorMessage),
event.getSapRequestSet().stream()
.filter(sr -> sr.getSent())
.filter(sr -> !sr.getIntegrated())
.flatMap(sr -> sr.getErrorMessages().stream()))
.filter(m -> m != null)
.collect(Collectors.joining(", "));
errorLog.accept(event.getExternalId(), Utils.getUserIdentifier(event.getParty()), event.getParty().getName(),
amount == null ? "" : amount.toPlainString(), cycleType == null ? "" : cycleType.getDescription(), errorMessage,
amount == null ? "" : amount.toPlainString(), cycleType == null ? "" : cycleType.getDescription(), errorMessageExtraInfo,
"", "", "", "", "", "", "", "", "", documentNumbers, "");
elogger.log("%s: %s%n", event.getExternalId(), errorMessage);
elogger.log(
Expand All @@ -261,8 +273,15 @@ private static void logError(Event event, ErrorLogConsumer errorLog, EventLogger
.filter(sr -> !sr.getIntegrated())
.map(sr -> sr.getDocumentNumber())
.collect(Collectors.joining(", "));
final String errorMessageExtraInfo = Stream.concat(Stream.of(errorMessage),
event.getSapRequestSet().stream()
.filter(sr -> sr.getSent())
.filter(sr -> !sr.getIntegrated())
.flatMap(sr -> sr.getErrorMessages().stream()))
.filter(m -> m != null)
.collect(Collectors.joining(", "));
errorLog.accept(event.getExternalId(), Utils.getUserIdentifier(event.getParty()), event.getParty().getName(),
amount == null ? "" : amount.toPlainString(), cycleType == null ? "" : cycleType.getDescription(), errorMessage,
amount == null ? "" : amount.toPlainString(), cycleType == null ? "" : cycleType.getDescription(), errorMessageExtraInfo,
"", "", "", "", "", "", "", "", "", documentNumbers, "");
elogger.log("%s: %s %s %s %n", event.getExternalId(), errorMessage, "", "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Utils {

Expand Down Expand Up @@ -297,13 +298,20 @@ private static void logError(final ErrorLogConsumer consumer, final String error
.filter(sr -> !sr.getIntegrated())
.map(sr -> sr.getDocumentNumber())
.collect(Collectors.joining(", "));
final String errorMessageExtraInfo = Stream.concat(Stream.of(error),
event.getSapRequestSet().stream()
.filter(sr -> sr.getSent())
.filter(sr -> !sr.getIntegrated())
.flatMap(sr -> sr.getErrorMessages().stream()))
.filter(m -> m != null)
.collect(Collectors.joining(", "));
consumer.accept(
event.getExternalId(),
user,
party == null ? "" : party.getName(),
amount == null ? "" : amount.toPlainString(),
cycleType == null ? "" : cycleType.getDescription(),
error,
errorMessageExtraInfo,
vat,
"",
country == null ? "" : country.getCode(),
Expand Down

0 comments on commit 894178b

Please sign in to comment.