Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Component
- @Scope("prototype")
- public class AccrualPoster implements Runnable {
- private final static Logger logger = LoggerFactory.getLogger("accrual");
- private List<LoanScheduleAccrualData> loanScheduleAccrualDatas;
- private ConfigurationDomainService configurationDomainService;
- private LoanAccrualWritePlatformService loanAccrualWritePlatformService;
- private LocalDate tillDate;
- private MifosPlatformTenant tenant;
- public void setAccrualPoster(final List<LoanScheduleAccrualData> loanScheduleAccrualDatas) {
- this.loanScheduleAccrualDatas = loanScheduleAccrualDatas;
- }
- public void setConfigurationDomainService(final ConfigurationDomainService configurationDomainService) {
- this.configurationDomainService = configurationDomainService;
- }
- public void setLoanAccrualWritePlatformService(final LoanAccrualWritePlatformService loanAccrualWritePlatformService) {
- this.loanAccrualWritePlatformService = loanAccrualWritePlatformService;
- }
- public void setLocalDate(final LocalDate tillDate) {
- this.tillDate = tillDate;
- }
- public void setTenant(final MifosPlatformTenant tenant) {
- this.tenant = tenant;
- }
- @Override
- public void run() {
- //set the tenant id
- ThreadLocalContextUtil.setTenant(tenant);
- StringBuilder sb = new StringBuilder();
- Map<Long, Collection<LoanScheduleAccrualData>> loanDataMap = new HashMap<>();
- // if invoked updated list of loan schedule is not empty
- if(loanScheduleAccrualDatas.size() > 0)
- logger.info("Inside Thread - Pre Parse - " + loanScheduleAccrualDatas.size());
- //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())) {
- Collection<LoanScheduleAccrualData> accrualDatas = loanDataMap.get(accrualData.getLoanId());
- accrualDatas.add(accrualData);
- loanDataMap.put(accrualData.getLoanId(), accrualDatas);
- } else {
- Collection<LoanScheduleAccrualData> accrualDatas = new ArrayList<>();
- accrualDatas.add(accrualData);
- loanDataMap.put(accrualData.getLoanId(), accrualDatas);
- }
- }
- // why tax component? what for ?
- Map<String, BigDecimal> taxComponents = this.configurationDomainService.retriveTaxComponents();
- logger.info("Inside Thread - Post Parse - " + loanDataMap.size());
- // if current date time is supplied calculate accuruls until current date for each loan
- //else calculate accuruals until due date of job execution
- for (Map.Entry<Long, Collection<LoanScheduleAccrualData>> mapEntry : loanDataMap.entrySet()) {
- if(tillDate != null) {
- try {
- logger.info("loan id - " + mapEntry.getKey());
- this.loanAccrualWritePlatformService.addPeriodicAccruals(tillDate, mapEntry.getKey(), mapEntry.getValue(), taxComponents);
- } catch (PlatformDataIntegrityException e) {
- if(e.getDefaultUserMessage() == null)
- e.printStackTrace();
- sb.append("failed to add accural transaction for loan " + mapEntry.getKey() + " with message " + e.getDefaultUserMessage());
- } catch (AbstractPlatformDomainRuleException e) {
- if(e.getDefaultUserMessage() == null)
- e.printStackTrace();
- sb.append("failed to add accural transaction for loan " + mapEntry.getKey() + " with message " + e.getDefaultUserMessage());
- } catch (AbstractPlatformResourceNotFoundException e) {
- if(e.getDefaultUserMessage() == null)
- e.printStackTrace();
- sb.append("failed to add accural transaction for loan " + mapEntry.getKey() + " with message " + e.getDefaultUserMessage());
- } catch (Exception e) {
- if(e.getMessage() == null)
- e.printStackTrace();
- Throwable realCause = e;
- if (e.getCause() != null) {
- realCause = e.getCause();
- }
- if(realCause.getMessage() == null)
- realCause.printStackTrace();
- sb.append("failed to add accural transaction for loan " + mapEntry.getKey() + " with message " + realCause.getMessage());
- }
- } else {
- try {
- this.loanAccrualWritePlatformService.addAccrualAccounting(mapEntry.getKey(), mapEntry.getValue(), taxComponents);
- } 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)
- logger.info(sb.toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement