use of net.javacrumbs.shedlock.core.SchedulerLock in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDueStandingOrderTask method payDueStandingOrders.
@Scheduled(fixedRate = 60 * 1000)
@SchedulerLock(name = "payDueStandingOrders")
public void payDueStandingOrders() {
log.info("Standing order payment task waking up. The time is now {}.", format.print(DateTime.now()));
final DateTime now = DateTime.now();
for (FRStandingOrder frStandingOrder : standingOrderService.getActiveStandingOrders()) {
FRStandingOrderData obStandingOrder = frStandingOrder.getStandingOrder();
// Check the OB status code has an ACTIVE status (because standing orders could be imported on /data endpoint with INACTIVE status).
if (FRStandingOrderData.FRStandingOrderStatus.ACTIVE != obStandingOrder.getStandingOrderStatusCode()) {
log.warn("Standing Order: '{}' has been given an OBExternalStandingOrderStatus1Code of {} and will not be processed.", frStandingOrder, obStandingOrder.getStandingOrderStatusCode());
continue;
}
log.info("Processing standing order {}", obStandingOrder);
try {
boolean isFirstPaymentDue = obStandingOrder.getFirstPaymentDateTime().isBefore(now);
boolean isFinalPaymentDue = obStandingOrder.getFinalPaymentDateTime().isBefore(now);
boolean isNextRecurringPaymentDue = obStandingOrder.getNextPaymentDateTime().isBefore(now);
boolean isBeforeFinalPayment = obStandingOrder.getNextPaymentDateTime().isBefore(obStandingOrder.getFinalPaymentDateTime());
log.debug("Standing order '{}', status: '{}', isFirstPaymentDue {} , isFinalPaymentDue {} , isNextPaymentDue: {}, isBeforeFinalPayment: {}", frStandingOrder.getId(), frStandingOrder.getStatus(), isFirstPaymentDue, isFinalPaymentDue, isNextRecurringPaymentDue, isBeforeFinalPayment);
if (StandingOrderStatus.ACTIVE == frStandingOrder.getStatus() && isNextRecurringPaymentDue && isBeforeFinalPayment) {
log.info("Active standing order '{}' has passed recurring payment date but not reached final payment date - make payment and calculate next recurring payment", frStandingOrder.getId());
doCreditAndDebitPayment(frStandingOrder, obStandingOrder.getNextPaymentAmount());
frStandingOrder.getStandingOrder().setNextPaymentDateTime(frequencyService.getNextDateTime(obStandingOrder.getNextPaymentDateTime(), obStandingOrder.getFrequency()));
} else if (StandingOrderStatus.ACTIVE == frStandingOrder.getStatus() && isFinalPaymentDue) {
log.info("Active standing order '{}' has passed final payment date - make final payment and set to COMPLETE", frStandingOrder.getId());
doCreditAndDebitPayment(frStandingOrder, obStandingOrder.getFinalPaymentAmount());
frStandingOrder.setStatus(StandingOrderStatus.COMPLETED);
} else if (StandingOrderStatus.PENDING == frStandingOrder.getStatus() && isFirstPaymentDue) {
log.info("Pending standing order '{}' has passed start payment date - make first payment and set to active", frStandingOrder.getId());
doCreditAndDebitPayment(frStandingOrder, obStandingOrder.getFirstPaymentAmount());
frStandingOrder.setStatus(StandingOrderStatus.ACTIVE);
} else {
log.debug("Active standing order '{}' is not due for payment", frStandingOrder.getId());
}
} catch (CurrencyConverterException e) {
log.error("Can't convert amount in the right currency", e);
log.error("Update payment status to rejected");
frStandingOrder.setRejectionReason("Can't convert amount in the right currency: " + e.getMessage());
frStandingOrder.setStatus(StandingOrderStatus.REJECTED);
log.info("Rejected payment {}", obStandingOrder);
} catch (Exception e) {
log.error("Couldn't pay standing order payment.", e);
log.error("Update payment status to rejected");
frStandingOrder.setRejectionReason("Failed to execute payment: " + e.getMessage());
frStandingOrder.setStatus(StandingOrderStatus.REJECTED);
log.info("Rejected payment {}", obStandingOrder);
} finally {
standingOrderService.updateStandingOrder(frStandingOrder);
paymentNotificationService.paymentStatusChanged(frStandingOrder);
}
}
log.info("All due standing order payments are now completed. The time is now {}.", format.print(DateTime.now()));
}
use of net.javacrumbs.shedlock.core.SchedulerLock in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptInternationalPaymentTask method autoAcceptPayment.
@Scheduled(fixedRate = 60 * 1000)
@SchedulerLock(name = "internationalPayment")
public void autoAcceptPayment() {
log.info("Auto-accept payment task waking up. The time is now {}.", format.print(DateTime.now()));
Collection<FRInternationalConsent> allPaymentsInProcess = internationalPaymentService.getAllPaymentsInProcess();
for (FRInternationalConsent payment : allPaymentsInProcess) {
log.info("Processing payment {}", payment);
try {
String identificationTo = moveDebitPayment(payment);
Optional<Account> isAccountToFromOurs = accountStoreService.findAccountByIdentification(identificationTo);
if (isAccountToFromOurs.isPresent()) {
moveCreditPayment(payment, identificationTo, isAccountToFromOurs.get());
} else {
log.info("Account '{}' not ours", identificationTo);
}
log.info("Update payment status to completed");
payment.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED);
log.info("Payment {}", payment);
} catch (CurrencyConverterException e) {
log.info("Can't convert amount in the right currency", e);
log.info("Update payment status to rejected");
payment.setStatus(ConsentStatusCode.REJECTED);
log.info("Payment {}", payment);
} catch (Exception e) {
log.error("Couldn't auto-pay payment.", e);
log.info("Update payment status to rejected");
payment.setStatus(ConsentStatusCode.REJECTED);
log.info("Payment {}", payment);
} finally {
internationalPaymentService.updatePayment(payment);
paymentNotificationService.paymentStatusChanged(payment);
}
}
log.info("All payments in process are now accepted. See you in 1 minute! The time is now {}.", format.print(DateTime.now()));
}
use of net.javacrumbs.shedlock.core.SchedulerLock in project so by onap.
the class ArchiveInfraRequestsScheduler method infraRequestsScheduledTask.
/**
* Runs the scheduler nightly [Seconds] [Minutes] [Hours] [Day of month] [Month] [Day of week] [Year]
*
* @throws ScheduledTaskException
*/
@ScheduledLogging
@Scheduled(cron = "0 0 1 * * ?")
@SchedulerLock(name = "archiveInfraRequestsScheduler")
public void infraRequestsScheduledTask() throws ScheduledTaskException {
logger.debug("Start of archiveInfraRequestsScheduler");
Date currentDate = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(currentDate);
calendar.add(Calendar.DATE, -archivedPeriod);
Date archivingDate = calendar.getTime();
logger.debug("Date before 6 months: " + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DATE) + "-" + calendar.get(Calendar.YEAR));
List<InfraActiveRequests> requestsByEndTime = new ArrayList<>();
// Could use sorting here
PageRequest pageRequest = PageRequest.of(0, 100);
do {
requestsByEndTime = infraActiveRepo.findByEndTimeLessThan(archivingDate, pageRequest);
logger.debug("{} requests to be archived based on End Time", requestsByEndTime.size());
archiveInfraRequests(requestsByEndTime);
} while (!requestsByEndTime.isEmpty());
List<InfraActiveRequests> requestsByStartTime = new ArrayList<>();
do {
requestsByStartTime = infraActiveRepo.findByStartTimeLessThanAndEndTime(archivingDate, null, pageRequest);
logger.debug("{} requests to be archived based on Start Time", requestsByEndTime.size());
archiveInfraRequests(requestsByStartTime);
} while (!requestsByStartTime.isEmpty());
logger.debug("End of archiveInfraRequestsScheduler");
}
use of net.javacrumbs.shedlock.core.SchedulerLock in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticPaymentTask method autoAcceptPayment.
@Scheduled(fixedRate = 60 * 1000)
@SchedulerLock(name = "domesticPayment")
public void autoAcceptPayment() {
log.info("Auto-accept payment task waking up. The time is now {}.", format.print(DateTime.now()));
Collection<FRDomesticConsent> allPaymentsInProcess = domesticPaymentsService.getAllPaymentsInProcess();
for (FRDomesticConsent payment : allPaymentsInProcess) {
log.info("Processing payment {}", payment);
try {
String identificationTo = moveDebitPayment(payment);
Optional<Account> isAccountToFromOurs = accountStoreService.findAccountByIdentification(identificationTo);
if (isAccountToFromOurs.isPresent()) {
moveCreditPayment(payment, identificationTo, isAccountToFromOurs.get());
} else {
log.info("Account '{}' not ours", identificationTo);
}
log.info("Update payment status to completed");
payment.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED);
log.info("Payment {}", payment);
} catch (CurrencyConverterException e) {
log.info("Can't convert amount in the right currency", e);
log.info("Update payment status to rejected");
payment.setStatus(ConsentStatusCode.REJECTED);
log.info("Payment {}", payment);
} catch (Exception e) {
log.error("Couldn't auto-pay payment.", e);
log.info("Update payment status to rejected");
payment.setStatus(ConsentStatusCode.REJECTED);
log.info("Payment {}", payment);
} finally {
domesticPaymentsService.updatePayment(payment);
paymentNotificationService.paymentStatusChanged(payment);
}
}
log.info("All payments in process are now accepted. See you in 1 minute! The time is now {}.", format.print(DateTime.now()));
}
use of net.javacrumbs.shedlock.core.SchedulerLock in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDueScheduledPaymentTask method payDueScheduledPayments.
@Scheduled(fixedRate = 60 * 1000)
@SchedulerLock(name = "payDueScheduledPayments")
public void payDueScheduledPayments() {
log.info("Scheduled payments payment task waking up. The time is now {}.", format.print(DateTime.now()));
for (FRScheduledPayment scheduledPayment : scheduledPaymentService.getPendingAndDueScheduledPayments()) {
FRScheduledPaymentData payment = scheduledPayment.getScheduledPayment();
if (!payment.getScheduledPaymentDateTime().isBefore(DateTime.now())) {
log.warn("Scheduled payment: {} with scheduledPaymentDateTime: {} is not due yet and should not have been loaded", scheduledPayment.getId(), payment.getScheduledPaymentDateTime());
continue;
}
log.info("Processing scheduled payment {}", payment);
try {
String identificationFrom = moveDebitPayment(scheduledPayment);
Optional<Account> isAccountFromOurs = accountStoreService.findAccountByIdentification(identificationFrom);
if (isAccountFromOurs.isPresent()) {
moveCreditPayment(scheduledPayment, identificationFrom, isAccountFromOurs.get());
} else {
log.info("Account '{}' not ours", identificationFrom);
}
log.info("Update payment status to completed");
scheduledPayment.setStatus(ScheduledPaymentStatus.COMPLETED);
log.debug("Payment {}", payment);
} catch (CurrencyConverterException e) {
log.info("Can't convert amount in the right currency", e);
log.info("Update payment status to rejected");
scheduledPayment.setRejectionReason("Can't convert amount in the right currency: " + e.getMessage());
scheduledPayment.setStatus(ScheduledPaymentStatus.REJECTED);
log.info("Payment {}", payment);
} catch (Exception e) {
log.error("Couldn't pay scheduled payment.", e);
log.info("Update payment status to rejected");
scheduledPayment.setRejectionReason("Failed to execute payment: " + e.getMessage());
scheduledPayment.setStatus(ScheduledPaymentStatus.REJECTED);
log.info("Payment {}", payment);
} finally {
scheduledPaymentService.updateSchedulePayment(scheduledPayment);
paymentNotificationService.paymentStatusChanged(scheduledPayment);
}
}
log.info("All due scheduled payments are now completed. The time is now {}.", format.print(DateTime.now()));
}
Aggregations