use of com.axelor.apps.bankpayment.service.PaymentScheduleLineBankPaymentService in project axelor-open-suite by axelor.
the class PaymentScheduleLineController method reject.
public void reject(ActionRequest request, ActionResponse response) {
try {
@SuppressWarnings("unchecked") List<? extends Number> idList = MoreObjects.firstNonNull((List<? extends Number>) request.getContext().get("idList"), Collections.emptyList());
boolean represent = (boolean) request.getContext().get("represent");
// TODO: one rejection reason per payment schedule line
InterbankCodeLine interbankCodeLine;
@SuppressWarnings("unchecked") Map<String, Object> interbankCodeLineMap = (Map<String, Object>) request.getContext().get("interbankCodeLine");
if (interbankCodeLineMap != null) {
interbankCodeLine = Beans.get(InterbankCodeLineRepository.class).find(((Number) interbankCodeLineMap.get("id")).longValue());
} else {
interbankCodeLine = null;
}
Map<Long, InterbankCodeLine> idMap = new LinkedHashMap<>();
idList.stream().map(Number::longValue).forEach(id -> idMap.put(id, interbankCodeLine));
PaymentScheduleLineBankPaymentService paymentScheduleLineBankPaymentService = Beans.get(PaymentScheduleLineBankPaymentService.class);
if (idMap.size() == 1) {
Entry<Long, InterbankCodeLine> entry = idMap.entrySet().iterator().next();
long id = entry.getKey();
InterbankCodeLine rejectionReason = entry.getValue();
paymentScheduleLineBankPaymentService.reject(id, rejectionReason, represent);
} else {
int errorCount = paymentScheduleLineBankPaymentService.rejectFromIdMap(idMap, represent);
if (errorCount != 0) {
response.setError(String.format(I18n.get("%d errors occurred. Please check tracebacks for details."), errorCount));
return;
}
}
response.setFlash(String.format(I18n.get("%d line successfully rejected", "%d lines successfully rejected", idMap.size()), idMap.size()));
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations