Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- @CronTarget(jobName = JobName.ADD_ACCRUAL_ENTRIES)
- public void addAccrualAccounting() throws JobExecutionException {
- //retrieves a list of updated accuruls info for loans
- Collection<LoanScheduleAccrualData> loanScheduleAccrualDatas = this.loanReadPlatformService.retriveScheduleAccrualData();
- StringBuilder sb = new StringBuilder();
- //map containing accuruals for loan_ids
- Map<Long, Collection<LoanScheduleAccrualData>> loanDataMap = new HashMap<>();
- //Iterate through the list of accruals to get the matching loan_id
- //if found loan_id on map, update new accuruals for that loan
- //else add a new entry on the map with updated accurals for that loan
- for (final LoanScheduleAccrualData accrualData : loanScheduleAccrualDatas) {
- if (loanDataMap.containsKey(accrualData.getLoanId())) {
- loanDataMap.get(accrualData.getLoanId()).add(accrualData);
- } else {
- Collection<LoanScheduleAccrualData> accrualDatas = new ArrayList<>();
- accrualDatas.add(accrualData);
- loanDataMap.put(accrualData.getLoanId(), accrualDatas);
- }
- }
- // add accurual transactions for each loan until due date of the job run
- for (Map.Entry<Long, Collection<LoanScheduleAccrualData>> mapEntry : loanDataMap.entrySet()) {
- try {
- this.loanAccrualWritePlatformService.addAccrualAccounting(mapEntry.getKey(), mapEntry.getValue());
- } catch (Exception e) {
- Throwable realCause = e;
- if (e.getCause() != null) {
- realCause = e.getCause();
- }
- sb.append("failed to add accural transaction for loan " + mapEntry.getKey() + " with message " + realCause.getMessage());
- }
- }
- if (sb.length() > 0) { throw new JobExecutionException(sb.toString()); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement