Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.service.ExternalIdFactory;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.account.PortfolioAccountType;
import org.apache.fineract.portfolio.account.data.AccountTransferDTO;
import org.apache.fineract.portfolio.account.data.AccountTransfersDataValidator;
Expand Down Expand Up @@ -93,6 +94,7 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer
private final ExternalIdFactory externalIdFactory;
private final FineractProperties fineractProperties;
private final LoanAdjustmentService loanAdjustmentService;
private final PlatformSecurityContext context;

@Transactional
@Override
Expand Down Expand Up @@ -127,6 +129,7 @@ public CommandProcessingResult create(final JsonCommand command) {
fromSavingsAccountId = command.longValueOfParameterNamed(fromAccountIdParamName);
final SavingsAccount fromSavingsAccount = this.savingsAccountAssembler.assembleFrom(fromSavingsAccountId,
backdatedTxnsAllowedTill);
this.context.validateAccessRights(fromSavingsAccount.office().getHierarchy());

final SavingsTransactionBooleanValues transactionBooleanValues = new SavingsTransactionBooleanValues(isAccountTransfer,
isRegularTransaction, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer(), isInterestTransfer, isWithdrawBalance);
Expand All @@ -135,6 +138,7 @@ public CommandProcessingResult create(final JsonCommand command) {

final Long toSavingsId = command.longValueOfParameterNamed(toAccountIdParamName);
final SavingsAccount toSavingsAccount = this.savingsAccountAssembler.assembleFrom(toSavingsId, backdatedTxnsAllowedTill);
this.context.validateAccessRights(toSavingsAccount.office().getHierarchy());

final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, transactionDate,
transactionAmount, paymentDetail, isAccountTransfer, isRegularTransaction, backdatedTxnsAllowedTill);
Expand All @@ -154,6 +158,7 @@ public CommandProcessingResult create(final JsonCommand command) {
fromSavingsAccountId = command.longValueOfParameterNamed(fromAccountIdParamName);
final SavingsAccount fromSavingsAccount = this.savingsAccountAssembler.assembleFrom(fromSavingsAccountId,
backdatedTxnsAllowedTill);
this.context.validateAccessRights(fromSavingsAccount.office().getHierarchy());

final SavingsTransactionBooleanValues transactionBooleanValues = new SavingsTransactionBooleanValues(isAccountTransfer,
isRegularTransaction, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer(), isInterestTransfer, isWithdrawBalance);
Expand All @@ -162,6 +167,7 @@ public CommandProcessingResult create(final JsonCommand command) {

final Long toLoanAccountId = command.longValueOfParameterNamed(toAccountIdParamName);
Loan toLoanAccount = this.loanAccountAssembler.assembleFrom(toLoanAccountId);
this.context.validateAccessRights(toLoanAccount.getOffice().getHierarchy());

final Boolean isHolidayValidationDone = false;
final HolidayDetailDTO holidayDetailDto = null;
Expand All @@ -184,12 +190,14 @@ public CommandProcessingResult create(final JsonCommand command) {

fromLoanAccountId = command.longValueOfParameterNamed(fromAccountIdParamName);
final Loan fromLoanAccount = this.loanAccountAssembler.assembleFrom(fromLoanAccountId);
this.context.validateAccessRights(fromLoanAccount.getOffice().getHierarchy());
ExternalId externalId = externalIdFactory.create();
final LoanTransaction loanRefundTransaction = this.loanAccountDomainService.makeRefund(fromLoanAccountId,
new CommandProcessingResultBuilder(), transactionDate, transactionAmount, paymentDetail, null, externalId);

final Long toSavingsAccountId = command.longValueOfParameterNamed(toAccountIdParamName);
final SavingsAccount toSavingsAccount = this.savingsAccountAssembler.assembleFrom(toSavingsAccountId, backdatedTxnsAllowedTill);
this.context.validateAccessRights(toSavingsAccount.office().getHierarchy());

final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, transactionDate,
transactionAmount, paymentDetail, isAccountTransfer, isRegularTransaction, backdatedTxnsAllowedTill);
Expand Down Expand Up @@ -307,6 +315,8 @@ public Long transferFunds(final AccountTransferDTO accountTransferDTO) {
this.savingsAccountAssembler.setHelpers(fromSavingsAccount);
toLoanAccount = accountTransferDetails.toLoanAccount();
}
this.context.validateAccessRights(fromSavingsAccount.office().getHierarchy());
this.context.validateAccessRights(toLoanAccount.getOffice().getHierarchy());

final SavingsTransactionBooleanValues transactionBooleanValues = new SavingsTransactionBooleanValues(isAccountTransfer,
isRegularTransaction, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer(),
Expand Down Expand Up @@ -379,6 +389,8 @@ public Long transferFunds(final AccountTransferDTO accountTransferDTO) {
toSavingsAccount = accountTransferDetails.toSavingsAccount();
this.savingsAccountAssembler.setHelpers(toSavingsAccount);
}
this.context.validateAccessRights(fromSavingsAccount.office().getHierarchy());
this.context.validateAccessRights(toSavingsAccount.office().getHierarchy());

final SavingsTransactionBooleanValues transactionBooleanValues = new SavingsTransactionBooleanValues(isAccountTransfer,
isRegularTransaction, fromSavingsAccount.isWithdrawalFeeApplicableForTransfer(),
Expand Down Expand Up @@ -421,6 +433,9 @@ public Long transferFunds(final AccountTransferDTO accountTransferDTO) {
toSavingsAccount = accountTransferDetails.toSavingsAccount();
this.savingsAccountAssembler.setHelpers(toSavingsAccount);
}
this.context.validateAccessRights(fromLoanAccount.getOffice().getHierarchy());
this.context.validateAccessRights(toSavingsAccount.office().getHierarchy());

LoanTransaction loanTransaction = null;

ExternalId txnExternalId = accountTransferDTO.getTxnExternalId();
Expand Down Expand Up @@ -471,12 +486,16 @@ public AccountTransferDetails repayLoanWithTopup(AccountTransferDTO accountTrans
} else {
fromLoanAccount = accountTransferDTO.getFromLoan();
}
this.context.validateAccessRights(fromLoanAccount.getOffice().getHierarchy());

Loan toLoanAccount = null;
if (accountTransferDTO.getToLoan() == null) {
toLoanAccount = this.loanAccountAssembler.assembleFrom(accountTransferDTO.getToAccountId());
} else {
toLoanAccount = accountTransferDTO.getToLoan();
}
this.context.validateAccessRights(fromLoanAccount.getOffice().getHierarchy());
this.context.validateAccessRights(toLoanAccount.getOffice().getHierarchy());

ExternalId externalIdForDisbursement = accountTransferDTO.getTxnExternalId();

Expand Down Expand Up @@ -581,6 +600,7 @@ public CommandProcessingResult refundByTransfer(JsonCommand command) {

final Long fromLoanAccountId = command.longValueOfParameterNamed(fromAccountIdParamName);
final Loan fromLoanAccount = this.loanAccountAssembler.assembleFrom(fromLoanAccountId);
this.context.validateAccessRights(fromLoanAccount.getOffice().getHierarchy());

BigDecimal overpaid = this.loanReadPlatformService.retrieveTotalPaidInAdvance(fromLoanAccountId).getPaidInAdvance();
final boolean backdatedTxnsAllowedTill = false;
Expand All @@ -599,6 +619,7 @@ public CommandProcessingResult refundByTransfer(JsonCommand command) {

final Long toSavingsAccountId = command.longValueOfParameterNamed(toAccountIdParamName);
final SavingsAccount toSavingsAccount = this.savingsAccountAssembler.assembleFrom(toSavingsAccountId, backdatedTxnsAllowedTill);
this.context.validateAccessRights(toSavingsAccount.office().getHierarchy());

final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, transactionDate,
transactionAmount, paymentDetail, true, true, backdatedTxnsAllowedTill);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.fineract.infrastructure.core.service.ExternalIdFactory;
import org.apache.fineract.infrastructure.core.service.PaginationHelper;
import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.infrastructure.security.service.SqlValidator;
import org.apache.fineract.infrastructure.security.utils.ColumnValidator;
import org.apache.fineract.organisation.office.service.OfficeReadPlatformService;
Expand Down Expand Up @@ -92,11 +93,12 @@ public AccountTransfersWritePlatformService accountTransfersWritePlatformService
LoanAccountDomainService loanAccountDomainService, SavingsAccountWritePlatformService savingsAccountWritePlatformService,
AccountTransferDetailRepository accountTransferDetailRepository, LoanReadPlatformService loanReadPlatformService,
GSIMRepositoy gsimRepository, ConfigurationDomainService configurationDomainService, ExternalIdFactory externalIdFactory,
FineractProperties fineractProperties, LoanAdjustmentService loanAdjustmentService) {
FineractProperties fineractProperties, LoanAdjustmentService loanAdjustmentService, PlatformSecurityContext context) {

return new AccountTransfersWritePlatformServiceImpl(accountTransfersDataValidator, accountTransferAssembler,
accountTransferRepository, savingsAccountAssembler, savingsAccountDomainService, loanAccountAssembler,
loanAccountDomainService, savingsAccountWritePlatformService, accountTransferDetailRepository, loanReadPlatformService,
gsimRepository, configurationDomainService, externalIdFactory, fineractProperties, loanAdjustmentService);
gsimRepository, configurationDomainService, externalIdFactory, fineractProperties, loanAdjustmentService, context);
}

@Bean
Expand Down
Loading
Loading