diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index dcdceb92e..d8581ce96 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -261,7 +261,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Override public CommandProcessingResult disburseLoan(final Long loanId, final JsonCommand command, Boolean isAccountTransfer) { - final AppUser currentUser = this.context.authenticatedUser(); + final AppUser currentUser = getAppUserIfPresent(); this.loanEventApiJsonValidator.validateDisbursement(command.json(), isAccountTransfer); @@ -516,7 +516,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Override public Map bulkLoanDisbursal(final JsonCommand command, final CollectionSheetBulkDisbursalCommand bulkDisbursalCommand, Boolean isAccountTransfer) { - final AppUser currentUser = this.context.authenticatedUser(); + final AppUser currentUser = getAppUserIfPresent(); final SingleDisbursalCommand[] disbursalCommand = bulkDisbursalCommand.getDisburseTransactions(); final Map changes = new LinkedHashMap<>(); @@ -643,7 +643,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Override public CommandProcessingResult undoLoanDisbursal(final Long loanId, final JsonCommand command) { - final AppUser currentUser = this.context.authenticatedUser(); + final AppUser currentUser = getAppUserIfPresent(); final Loan loan = this.loanAssembler.assembleFrom(loanId); checkClientOrGroupActive(loan); @@ -768,10 +768,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Override public CommandProcessingResult adjustLoanTransaction(final Long loanId, final Long transactionId, final JsonCommand command) { - AppUser currentUser = null; - if (this.context != null) { - currentUser = this.context.authenticatedUser(); - } + AppUser currentUser = getAppUserIfPresent(); this.loanEventApiJsonValidator.validateTransaction(command.json()); @@ -918,7 +915,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Override public CommandProcessingResult waiveInterestOnLoan(final Long loanId, final JsonCommand command) { - AppUser currentUser = this.context.authenticatedUser(); + AppUser currentUser = getAppUserIfPresent(); this.loanEventApiJsonValidator.validateTransaction(command.json()); @@ -1025,7 +1022,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Transactional @Override public CommandProcessingResult writeOff(final Long loanId, final JsonCommand command) { - final AppUser currentUser = this.context.authenticatedUser(); + final AppUser currentUser = getAppUserIfPresent(); this.loanEventApiJsonValidator.validateTransactionWithNoAmount(command.json()); @@ -1101,7 +1098,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Override public CommandProcessingResult closeLoan(final Long loanId, final JsonCommand command) { - AppUser currentUser = this.context.authenticatedUser(); + AppUser currentUser = getAppUserIfPresent(); this.loanEventApiJsonValidator.validateTransactionWithNoAmount(command.json()); @@ -1197,7 +1194,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Transactional @Override public CommandProcessingResult closeAsRescheduled(final Long loanId, final JsonCommand command) { - this.context.authenticatedUser(); this.loanEventApiJsonValidator.validateTransactionWithNoAmount(command.json()); @@ -1236,8 +1232,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Override public CommandProcessingResult addLoanCharge(final Long loanId, final JsonCommand command) { - this.context.authenticatedUser(); - this.loanEventApiJsonValidator.validateAddLoanCharge(command.json()); final Loan loan = this.loanAssembler.assembleFrom(loanId); @@ -1305,10 +1299,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf } public void runScheduleRecalculation(Loan loan) { - AppUser currentUser = null; - if (this.context != null) { - currentUser = this.context.authenticatedUser(); - } + AppUser currentUser = getAppUserIfPresent(); if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled()) { CalendarInstance restCalendarInstance = calendarInstanceRepository.findCalendarInstaneByEntityId( loan.loanInterestRecalculationDetailId(), CalendarEntityType.LOAN_RECALCULATION_DETAIL.getValue()); @@ -1433,8 +1424,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Override public CommandProcessingResult updateLoanCharge(final Long loanId, final Long loanChargeId, final JsonCommand command) { - this.context.authenticatedUser(); - this.loanEventApiJsonValidator.validateUpdateOfLoanCharge(command.json()); final Loan loan = this.loanAssembler.assembleFrom(loanId); @@ -1465,7 +1454,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Override public CommandProcessingResult waiveLoanCharge(final Long loanId, final Long loanChargeId, final JsonCommand command) { - AppUser currentUser = this.context.authenticatedUser(); + AppUser currentUser = getAppUserIfPresent(); final Loan loan = this.loanAssembler.assembleFrom(loanId); checkClientOrGroupActive(loan); @@ -1572,8 +1561,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Override public CommandProcessingResult deleteLoanCharge(final Long loanId, final Long loanChargeId, final JsonCommand command) { - this.context.authenticatedUser(); - final Loan loan = this.loanAssembler.assembleFrom(loanId); checkClientOrGroupActive(loan); final LoanCharge loanCharge = retrieveLoanChargeBy(loanId, loanChargeId); @@ -1860,8 +1847,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Override public CommandProcessingResult loanReassignment(final Long loanId, final JsonCommand command) { - this.context.authenticatedUser(); - this.loanEventApiJsonValidator.validateUpdateOfLoanOfficer(command.json()); final Long fromLoanOfficerId = command.longValueOfParameterNamed("fromLoanOfficerId"); @@ -1894,7 +1879,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Override public CommandProcessingResult bulkLoanReassignment(final JsonCommand command) { - this.context.authenticatedUser(); this.loanEventApiJsonValidator.validateForBulkLoanReassignment(command.json()); final Long fromLoanOfficerId = command.longValueOfParameterNamed("fromLoanOfficerId"); @@ -1927,8 +1911,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Override public CommandProcessingResult removeLoanOfficer(final Long loanId, final JsonCommand command) { - this.context.authenticatedUser(); - final LoanUpdateCommand loanUpdateCommand = this.loanUpdateCommandFromApiJsonDeserializer.commandFromApiJson(command.json()); loanUpdateCommand.validate(); @@ -2442,7 +2424,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Transactional public CommandProcessingResult updateDisbursementDateForTranche(final Long loanId, final Long disbursementId, final JsonCommand command) { - AppUser currentUser = this.context.authenticatedUser(); + AppUser currentUser = getAppUserIfPresent(); final Loan loan = this.loanAssembler.assembleFrom(loanId); checkClientOrGroupActive(loan);