Advertisement
KumaranathFernando

Untitled

Jun 26th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1.     @Override
  2.     @CronTarget(jobName = JobName.ADD_ACCRUAL_ENTRIES)
  3.     public void addAccrualAccounting() throws JobExecutionException {
  4.         //retrieves a list of updated accuruls info for loans
  5.         Collection<LoanScheduleAccrualData> loanScheduleAccrualDatas = this.loanReadPlatformService.retriveScheduleAccrualData();
  6.  
  7.         StringBuilder sb = new StringBuilder();
  8.  
  9.         //map containing accuruals for loan_ids
  10.         Map<Long, Collection<LoanScheduleAccrualData>> loanDataMap = new HashMap<>();
  11.  
  12.         //Iterate through the list of accruals to get the matching loan_id
  13.         //if found loan_id on map, update new accuruals for that loan
  14.         //else add a new entry on the map with updated accurals for that loan
  15.         for (final LoanScheduleAccrualData accrualData : loanScheduleAccrualDatas) {
  16.             if (loanDataMap.containsKey(accrualData.getLoanId())) {
  17.                 loanDataMap.get(accrualData.getLoanId()).add(accrualData);
  18.             } else {
  19.                 Collection<LoanScheduleAccrualData> accrualDatas = new ArrayList<>();
  20.                 accrualDatas.add(accrualData);
  21.                 loanDataMap.put(accrualData.getLoanId(), accrualDatas);
  22.             }
  23.         }
  24.  
  25.         // add accurual transactions for each loan until due date of the job run
  26.         for (Map.Entry<Long, Collection<LoanScheduleAccrualData>> mapEntry : loanDataMap.entrySet()) {
  27.             try {
  28.                 this.loanAccrualWritePlatformService.addAccrualAccounting(mapEntry.getKey(), mapEntry.getValue());
  29.             } catch (Exception e) {
  30.                 Throwable realCause = e;
  31.                 if (e.getCause() != null) {
  32.                     realCause = e.getCause();
  33.                 }
  34.                 sb.append("failed to add accural transaction for loan " + mapEntry.getKey() + " with message " + realCause.getMessage());
  35.             }
  36.         }
  37.  
  38.         if (sb.length() > 0) { throw new JobExecutionException(sb.toString()); }
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement