fix merge conflict form cherry pick of 974e45c7875f2b08f4d25a35ac79c25b51a0b1ea

This commit is contained in:
Keith Woodlock
2013-04-10 23:36:47 +01:00
parent b7f72b2943
commit 33c7e9f7d5
8 changed files with 171 additions and 82 deletions
@@ -10,6 +10,7 @@ import javax.persistence.Entity;
import javax.persistence.Table;
import org.mifosplatform.organisation.monetary.data.CurrencyData;
import org.mifosplatform.organisation.office.domain.OrganisationCurrency;
import org.springframework.data.jpa.domain.AbstractPersistable;
@Entity
@@ -39,7 +40,11 @@ public class ApplicationCurrency extends AbstractPersistable<Long> {
this.displaySymbol = null;
}
public ApplicationCurrency(final String code, final String name, final int decimalPlaces, final String nameCode,
public static ApplicationCurrency from(final ApplicationCurrency currency, final int decimalPlaces) {
return new ApplicationCurrency(currency.code, currency.name, decimalPlaces, currency.nameCode, currency.displaySymbol);
}
private ApplicationCurrency(final String code, final String name, final int decimalPlaces, final String nameCode,
final String displaySymbol) {
this.code = code;
this.name = name;
@@ -71,4 +76,8 @@ public class ApplicationCurrency extends AbstractPersistable<Long> {
public CurrencyData toData() {
return new CurrencyData(this.code, this.name, this.decimalPlaces, this.displaySymbol, this.nameCode);
}
public OrganisationCurrency toOrganisationCurrency() {
return new OrganisationCurrency(this.code, this.name, this.decimalPlaces, this.nameCode, this.displaySymbol);
}
}
@@ -8,7 +8,8 @@ package org.mifosplatform.organisation.monetary.domain;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface ApplicationCurrencyRepository extends JpaRepository<ApplicationCurrency, Long>, JpaSpecificationExecutor<ApplicationCurrency> {
public interface ApplicationCurrencyRepository extends JpaRepository<ApplicationCurrency, Long>,
JpaSpecificationExecutor<ApplicationCurrency> {
ApplicationCurrency findOneByCode(String currencyCode);
ApplicationCurrency findOneByCode(String currencyCode);
}
@@ -0,0 +1,55 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.organisation.monetary.domain;
import org.mifosplatform.organisation.monetary.exception.CurrencyNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
* Wrapper for {@link ApplicationCurrencyRepository} that is responsible for
* checking if {@link ApplicationCurrency} is returned when using
* <code>findOne</code> repository method and throwing an appropriate not found
* exception.
* </p>
*
* <p>
* This is to avoid need for checking and throwing in multiple areas of code
* base where {@link ApplicationCurrencyRepository} is required.
* </p>
*/
@Service
public class ApplicationCurrencyRepositoryWrapper {
private final ApplicationCurrencyRepository repository;
@Autowired
public ApplicationCurrencyRepositoryWrapper(final ApplicationCurrencyRepository repository) {
this.repository = repository;
}
public ApplicationCurrency findOneWithNotFoundDetection(final MonetaryCurrency currency) {
final ApplicationCurrency defaultApplicationCurrency = this.repository.findOneByCode(currency.getCode());
if (defaultApplicationCurrency == null) { throw new CurrencyNotFoundException(currency.getCode()); }
final ApplicationCurrency applicationCurrency = ApplicationCurrency.from(defaultApplicationCurrency,
currency.getDigitsAfterDecimal());
return applicationCurrency;
}
/**
* Used when its not needed for {@link ApplicationCurrency} to inherit
* decimal place settings of existing currency.
*/
public ApplicationCurrency findOneWithNotFoundDetection(final String currencyCode) {
final ApplicationCurrency applicationCurrency = this.repository.findOneByCode(currencyCode);
if (applicationCurrency == null) { throw new CurrencyNotFoundException(currencyCode); }
return applicationCurrency;
}
}
@@ -17,8 +17,7 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepository;
import org.mifosplatform.organisation.monetary.exception.CurrencyNotFoundException;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepositoryWrapper;
import org.mifosplatform.organisation.monetary.serialization.CurrencyCommandFromApiJsonDeserializer;
import org.mifosplatform.organisation.office.domain.OrganisationCurrency;
import org.mifosplatform.organisation.office.domain.OrganisationCurrencyRepository;
@@ -30,14 +29,14 @@ import org.springframework.transaction.annotation.Transactional;
public class CurrencyWritePlatformServiceJpaRepositoryImpl implements CurrencyWritePlatformService {
private final PlatformSecurityContext context;
private final ApplicationCurrencyRepository applicationCurrencyRepository;
private final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository;
private final OrganisationCurrencyRepository organisationCurrencyRepository;
private final CurrencyCommandFromApiJsonDeserializer fromApiJsonDeserializer;
@Autowired
public CurrencyWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
final CurrencyCommandFromApiJsonDeserializer fromApiJsonDeserializer,
final ApplicationCurrencyRepository applicationCurrencyRepository,
final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository,
final OrganisationCurrencyRepository organisationCurrencyRepository) {
this.context = context;
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
@@ -60,11 +59,9 @@ public class CurrencyWritePlatformServiceJpaRepositoryImpl implements CurrencyWr
final Set<OrganisationCurrency> allowedCurrencies = new HashSet<OrganisationCurrency>();
for (final String currencyCode : currencies) {
final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode);
if (currency == null) { throw new CurrencyNotFoundException(currencyCode); }
final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneWithNotFoundDetection(currencyCode);
final OrganisationCurrency allowedCurrency = new OrganisationCurrency(currency.getCode(), currency.getName(),
currency.getDecimalPlaces(), currency.getNameCode(), currency.getDisplaySymbol());
final OrganisationCurrency allowedCurrency = currency.toOrganisationCurrency();
allowedCurrencyCodes.add(currencyCode);
allowedCurrencies.add(allowedCurrency);
@@ -14,10 +14,9 @@ import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityExce
import org.mifosplatform.infrastructure.security.exception.NoAuthorizationException;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepository;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepositoryWrapper;
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
import org.mifosplatform.organisation.monetary.domain.Money;
import org.mifosplatform.organisation.monetary.exception.CurrencyNotFoundException;
import org.mifosplatform.organisation.office.domain.Office;
import org.mifosplatform.organisation.office.domain.OfficeRepository;
import org.mifosplatform.organisation.office.domain.OfficeTransaction;
@@ -43,14 +42,14 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
private final OfficeTransactionCommandFromApiJsonDeserializer moneyTransferCommandFromApiJsonDeserializer;
private final OfficeRepository officeRepository;
private final OfficeTransactionRepository officeTransactionRepository;
private final ApplicationCurrencyRepository applicationCurrencyRepository;
private final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository;
@Autowired
public OfficeWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
final OfficeCommandFromApiJsonDeserializer fromApiJsonDeserializer,
final OfficeTransactionCommandFromApiJsonDeserializer moneyTransferCommandFromApiJsonDeserializer,
final OfficeRepository officeRepository, final OfficeTransactionRepository officeMonetaryTransferRepository,
final ApplicationCurrencyRepository applicationCurrencyRepository) {
final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository) {
this.context = context;
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
this.moneyTransferCommandFromApiJsonDeserializer = moneyTransferCommandFromApiJsonDeserializer;
@@ -158,8 +157,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
if (fromOffice == null && toOffice == null) { throw new OfficeNotFoundException(toOfficeId); }
final String currencyCode = command.stringValueOfParameterNamed("currencyCode");
final ApplicationCurrency appCurrency = this.applicationCurrencyRepository.findOneByCode(currencyCode);
if (appCurrency == null) { throw new CurrencyNotFoundException(currencyCode); }
final ApplicationCurrency appCurrency = this.applicationCurrencyRepository.findOneWithNotFoundDetection(currencyCode);
final MonetaryCurrency currency = new MonetaryCurrency(appCurrency.getCode(), appCurrency.getDecimalPlaces());
final Money amount = Money.of(currency, command.bigDecimalValueOfParameterNamed("transactionAmount"));
@@ -177,7 +175,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
@Transactional
@Override
public CommandProcessingResult deleteOfficeTransaction(final Long transactionId, JsonCommand command) {
public CommandProcessingResult deleteOfficeTransaction(final Long transactionId, final JsonCommand command) {
context.authenticatedUser();
@@ -193,7 +191,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
* Guaranteed to throw an exception no matter what the data integrity issue
* is.
*/
private void handleOfficeDataIntegrityIssues(final JsonCommand command, DataIntegrityViolationException dve) {
private void handleOfficeDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) {
Throwable realCause = dve.getMostSpecificCause();
if (realCause.getMessage().contains("externalid_org")) {
@@ -11,7 +11,7 @@ import java.util.Set;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepository;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepositoryWrapper;
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
import org.mifosplatform.portfolio.loanaccount.domain.LoanCharge;
import org.mifosplatform.portfolio.loanaccount.loanschedule.domain.AprCalculator;
@@ -36,15 +36,16 @@ public class LoanScheduleAssembler {
private final FromJsonHelper fromApiJsonHelper;
private final LoanProductRepository loanProductRepository;
private final ApplicationCurrencyRepository applicationCurrencyRepository;
private final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository;
private final LoanChargeAssembler loanChargeAssembler;
private final LoanScheduleGeneratorFactory loanScheduleFactory;
private final AprCalculator aprCalculator;
@Autowired
public LoanScheduleAssembler(final FromJsonHelper fromApiJsonHelper, final LoanProductRepository loanProductRepository,
final ApplicationCurrencyRepository applicationCurrencyRepository, final LoanScheduleGeneratorFactory loanScheduleFactory,
final AprCalculator aprCalculator, final LoanChargeAssembler loanChargeAssembler) {
final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository,
final LoanScheduleGeneratorFactory loanScheduleFactory, final AprCalculator aprCalculator,
final LoanChargeAssembler loanChargeAssembler) {
this.fromApiJsonHelper = fromApiJsonHelper;
this.loanProductRepository = loanProductRepository;
this.applicationCurrencyRepository = applicationCurrencyRepository;
@@ -57,7 +58,7 @@ public class LoanScheduleAssembler {
final JsonElement element = fromApiJsonHelper.parse(json);
return fromJson(element);
}
public LoanSchedule fromJson(final JsonElement element) {
return fromJson(element, null);
}
@@ -69,14 +70,36 @@ public class LoanScheduleAssembler {
if (loanProduct == null) { throw new LoanProductNotFoundException(loanProductId); }
final MonetaryCurrency currency = loanProduct.getCurrency();
final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneByCode(currency.getCode());
final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneWithNotFoundDetection(currency);
final BigDecimal principal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("principal", element);
final BigDecimal minPrincipal = loanProduct.getMinPrincipalAmount().getAmount();//Copy minPrincipal from loan product to loan
final BigDecimal maxPrincipal = loanProduct.getMaxPrincipalAmount().getAmount();//Copy maxPrincipal from loan product to loan
final BigDecimal minPrincipal = loanProduct.getMinPrincipalAmount().getAmount();// Copy
// minPrincipal
// from
// loan
// product
// to
// loan
final BigDecimal maxPrincipal = loanProduct.getMaxPrincipalAmount().getAmount();// Copy
// maxPrincipal
// from
// loan
// product
// to
// loan
final BigDecimal interestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("interestRatePerPeriod", element);
final BigDecimal minInterestRatePerPeriod = loanProduct.getMinNominalInterestRatePerPeriod();//Copy from Loan product to Loan
final BigDecimal maxInterestRatePerPeriod = loanProduct.getMaxNominalInterestRatePerPeriod();//Copy from Loan product to Loan
final BigDecimal minInterestRatePerPeriod = loanProduct.getMinNominalInterestRatePerPeriod();// Copy
// from
// Loan
// product
// to
// Loan
final BigDecimal maxInterestRatePerPeriod = loanProduct.getMaxNominalInterestRatePerPeriod();// Copy
// from
// Loan
// product
// to
// Loan
final Integer interestRateFrequencyType = fromApiJsonHelper.extractIntegerWithLocaleNamed("interestRateFrequencyType", element);
final Integer interestType = fromApiJsonHelper.extractIntegerWithLocaleNamed("interestType", element);
final Integer interestCalculationPeriodType = fromApiJsonHelper.extractIntegerWithLocaleNamed("interestCalculationPeriodType",
@@ -93,8 +116,18 @@ public class LoanScheduleAssembler {
final Integer repaymentEvery = fromApiJsonHelper.extractIntegerWithLocaleNamed("repaymentEvery", element);
final Integer repaymentFrequencyType = fromApiJsonHelper.extractIntegerWithLocaleNamed("repaymentFrequencyType", element);
final Integer numberOfRepayments = fromApiJsonHelper.extractIntegerWithLocaleNamed("numberOfRepayments", element);
final Integer minNumberOfRepayments = loanProduct.getMinNumberOfRepayments();//Copy from Loan product to Loan
final Integer maxNumberOfRepayments = loanProduct.getMaxNumberOfRepayments();//Copy from Loan product to Loan
final Integer minNumberOfRepayments = loanProduct.getMinNumberOfRepayments();// Copy
// from
// Loan
// product
// to
// Loan
final Integer maxNumberOfRepayments = loanProduct.getMaxNumberOfRepayments();// Copy
// from
// Loan
// product
// to
// Loan
final Integer amortizationType = fromApiJsonHelper.extractIntegerWithLocaleNamed("amortizationType", element);
final PeriodFrequencyType repaymentPeriodFrequencyType = PeriodFrequencyType.fromInt(repaymentFrequencyType);
final AmortizationMethod amortizationMethod = AmortizationMethod.fromInt(amortizationType);
@@ -111,9 +144,10 @@ public class LoanScheduleAssembler {
final LoanScheduleGenerator loanScheduleGenerator = this.loanScheduleFactory.create(interestMethod);
return new LoanSchedule(loanScheduleGenerator, applicationCurrency, principal, minPrincipal, maxPrincipal, interestRatePerPeriod, minInterestRatePerPeriod, maxInterestRatePerPeriod,
interestRatePeriodFrequencyType, defaultAnnualNominalInterestRate, interestMethod, interestCalculationPeriodMethod,
repaymentEvery, repaymentPeriodFrequencyType, numberOfRepayments, minNumberOfRepayments, maxNumberOfRepayments, amortizationMethod, loanTermFrequency,
loanTermPeriodFrequencyType, loanCharges, expectedDisbursementDate, repaymentsStartingFromDate, interestChargedFromDate, inArrearsTolerance);
return new LoanSchedule(loanScheduleGenerator, applicationCurrency, principal, minPrincipal, maxPrincipal, interestRatePerPeriod,
minInterestRatePerPeriod, maxInterestRatePerPeriod, interestRatePeriodFrequencyType, defaultAnnualNominalInterestRate,
interestMethod, interestCalculationPeriodMethod, repaymentEvery, repaymentPeriodFrequencyType, numberOfRepayments,
minNumberOfRepayments, maxNumberOfRepayments, amortizationMethod, loanTermFrequency, loanTermPeriodFrequencyType,
loanCharges, expectedDisbursementDate, repaymentsStartingFromDate, interestChargedFromDate, inArrearsTolerance);
}
}
@@ -20,10 +20,9 @@ import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSourc
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.monetary.data.CurrencyData;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepository;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepositoryWrapper;
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
import org.mifosplatform.organisation.monetary.domain.Money;
import org.mifosplatform.organisation.monetary.exception.CurrencyNotFoundException;
import org.mifosplatform.portfolio.client.data.ClientData;
import org.mifosplatform.portfolio.client.service.ClientReadPlatformService;
import org.mifosplatform.portfolio.group.data.GroupData;
@@ -64,7 +63,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
private final JdbcTemplate jdbcTemplate;
private final PlatformSecurityContext context;
private final LoanRepository loanRepository;
private final ApplicationCurrencyRepository applicationCurrencyRepository;
private final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository;
private final LoanProductReadPlatformService loanProductReadPlatformService;
private final ClientReadPlatformService clientReadPlatformService;
private final GroupReadPlatformService groupReadPlatformService;
@@ -72,7 +71,8 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
@Autowired
public LoanReadPlatformServiceImpl(final PlatformSecurityContext context, final LoanRepository loanRepository,
final LoanTransactionRepository loanTransactionRepository, final ApplicationCurrencyRepository applicationCurrencyRepository,
final LoanTransactionRepository loanTransactionRepository,
final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository,
final LoanProductReadPlatformService loanProductReadPlatformService, final ClientReadPlatformService clientReadPlatformService,
final GroupReadPlatformService groupReadPlatformService, final TenantAwareRoutingDataSource dataSource) {
this.context = context;
@@ -162,7 +162,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
context.authenticatedUser();
final GroupData groupAccount = this.groupReadPlatformService.retrieveGroupDetails(groupId , GroupTypes.GROUP.getId() , false);
final GroupData groupAccount = this.groupReadPlatformService.retrieveGroupDetails(groupId, GroupTypes.GROUP.getId(), false);
final LocalDate expectedDisbursementDate = DateUtils.getLocalDateOfTenant();
LoanAccountData loanDetails = LoanAccountData.groupDefaults(groupAccount, expectedDisbursementDate);
@@ -175,11 +175,11 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
}
@Override
public LoanAccountData retrieveTemplateWithCompleteGroupAndProductDetails(Long groupId, Long productId) {
public LoanAccountData retrieveTemplateWithCompleteGroupAndProductDetails(final Long groupId, final Long productId) {
context.authenticatedUser();
final GroupData groupAccount = this.groupReadPlatformService.retrieveGroup(groupId , GroupTypes.GROUP.getId() );
final GroupData groupAccount = this.groupReadPlatformService.retrieveGroup(groupId, GroupTypes.GROUP.getId());
final LocalDate expectedDisbursementDate = DateUtils.getLocalDateOfTenant();
LoanAccountData loanDetails = LoanAccountData.groupDefaults(groupAccount, expectedDisbursementDate);
@@ -201,12 +201,10 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
Loan loan = this.loanRepository.findOne(loanId);
if (loan == null) { throw new LoanNotFoundException(loanId); }
final String currencyCode = loan.repaymentScheduleDetail().getPrincipal().getCurrencyCode();
ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode);
if (currency == null) { throw new CurrencyNotFoundException(currencyCode); }
final MonetaryCurrency currency = loan.getCurrency();
final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneWithNotFoundDetection(currency);
final CurrencyData currencyData = new CurrencyData(currency.getCode(), currency.getName(), currency.getDecimalPlaces(),
currency.getDisplaySymbol(), currency.getNameCode());
final CurrencyData currencyData = applicationCurrency.toData();
final LocalDate earliestUnpaidInstallmentDate = loan.possibleNextRepaymentDate();
@@ -227,19 +225,15 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final Loan loan = this.loanRepository.findOne(loanId);
if (loan == null) { throw new LoanNotFoundException(loanId); }
final String currencyCode = loan.repaymentScheduleDetail().getPrincipal().getCurrencyCode();
final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode);
if (currency == null) { throw new CurrencyNotFoundException(currencyCode); }
final CurrencyData currencyData = new CurrencyData(currency.getCode(), currency.getName(), currency.getDecimalPlaces(),
currency.getDisplaySymbol(), currency.getNameCode());
final MonetaryCurrency currency = loan.getCurrency();
final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneWithNotFoundDetection(currency);
final CurrencyData currencyData = applicationCurrency.toData();
final LoanTransaction waiveOfInterest = loan.deriveDefaultInterestWaiverTransaction();
final LoanTransactionEnumData transactionType = LoanEnumerations.transactionType(LoanTransactionType.WAIVE_INTEREST);
final MonetaryCurrency monetaryCurrency = new MonetaryCurrency(currency.getCode(), currency.getDecimalPlaces());
final BigDecimal amount = waiveOfInterest.getAmount(monetaryCurrency).getAmount();
final BigDecimal amount = waiveOfInterest.getAmount(currency).getAmount();
return new LoanTransactionData(null, transactionType, null, currencyData, waiveOfInterest.getTransactionDate(), amount, null, null,
null, null);
}
@@ -261,18 +255,15 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
final Loan loan = this.loanRepository.findOne(loanId);
if (loan == null) { throw new LoanNotFoundException(loanId); }
final String currencyCode = loan.repaymentScheduleDetail().getPrincipal().getCurrencyCode();
final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode);
if (currency == null) { throw new CurrencyNotFoundException(currencyCode); }
final MonetaryCurrency currency = loan.getCurrency();
final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneWithNotFoundDetection(currency);
final CurrencyData currencyData = applicationCurrency.toData();
final LoanTransaction transaction = this.loanTransactionRepository.findOne(transactionId);
if (transaction == null) { throw new LoanTransactionNotFoundException(transactionId); }
if (transaction.isNotBelongingToLoanOf(loan)) { throw new LoanTransactionNotFoundException(transactionId, loanId); }
final CurrencyData currencyData = new CurrencyData(currency.getCode(), currency.getName(), currency.getDecimalPlaces(),
currency.getDisplaySymbol(), currency.getNameCode());
return transaction.toData(currencyData);
}
@@ -20,7 +20,8 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepository;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepositoryWrapper;
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
import org.mifosplatform.organisation.monetary.domain.Money;
import org.mifosplatform.organisation.staff.domain.Staff;
import org.mifosplatform.portfolio.charge.domain.Charge;
@@ -77,7 +78,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
private final LoanAssembler loanAssembler;
private final ChargeRepositoryWrapper chargeRepository;
private final LoanChargeRepository loanChargeRepository;
private final ApplicationCurrencyRepository applicationCurrencyRepository;
private final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository;
private final JournalEntryWritePlatformService journalEntryWritePlatformService;
private final LoanSummaryWrapper loanSummaryWrapper;
private final LoanRepaymentScheduleTransactionProcessorFactory loanRepaymentScheduleTransactionProcessorFactory;
@@ -89,7 +90,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
final LoanUpdateCommandFromApiJsonDeserializer loanUpdateCommandFromApiJsonDeserializer, final LoanAssembler loanAssembler,
final LoanRepository loanRepository, final LoanTransactionRepository loanTransactionRepository,
final NoteRepository noteRepository, final ChargeRepositoryWrapper chargeRepository,
final LoanChargeRepository loanChargeRepository, final ApplicationCurrencyRepository applicationCurrencyRepository,
final LoanChargeRepository loanChargeRepository, final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository,
final JournalEntryWritePlatformService journalEntryWritePlatformService, final LoanSummaryWrapper loanSummaryWrapper,
final LoanRepaymentScheduleTransactionProcessorFactory loanRepaymentScheduleTransactionProcessorFactory,
final PaymentDetailRepository paymentDetailRepository) {
@@ -123,8 +124,8 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
this.loanEventApiJsonValidator.validateDisbursement(command.json());
final Loan loan = retrieveLoanBy(loanId);
final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(loan.getCurrencyCode());
final MonetaryCurrency currency = loan.getCurrency();
final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneWithNotFoundDetection(currency);
final List<Long> existingTransactionIds = new ArrayList<Long>();
final List<Long> existingReversedTransactionIds = new ArrayList<Long>();
@@ -135,7 +136,8 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
paymentDetailRepository.save(paymentDetail);
}
loan.disburse(currentUser, command, currency, existingTransactionIds, existingReversedTransactionIds, changes, paymentDetail);
loan.disburse(currentUser, command, applicationCurrency, existingTransactionIds, existingReversedTransactionIds, changes,
paymentDetail);
if (!changes.isEmpty()) {
this.loanRepository.save(loan);
@@ -162,7 +164,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
@Transactional
@Override
public Map<String, Object> bulkLoanDisbursal(JsonCommand command, CollectionSheetBulkDisbursalCommand bulkDisbursalCommand) {
public Map<String, Object> bulkLoanDisbursal(final JsonCommand command, final CollectionSheetBulkDisbursalCommand bulkDisbursalCommand) {
final AppUser currentUser = context.authenticatedUser();
/****
@@ -178,8 +180,8 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
SingleDisbursalCommand singleLoanDisbursalCommand = disbursalCommand[i];
final Loan loan = retrieveLoanBy(singleLoanDisbursalCommand.getLoanId());
final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(loan.getCurrencyCode());
final MonetaryCurrency currency = loan.getCurrency();
final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneWithNotFoundDetection(currency);
final List<Long> existingTransactionIds = new ArrayList<Long>();
final List<Long> existingReversedTransactionIds = new ArrayList<Long>();
@@ -189,7 +191,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
paymentDetailRepository.save(paymentDetail);
}
loan.disburse(currentUser, command, currency, existingTransactionIds, existingReversedTransactionIds, changes, paymentDetail);
loan.disburse(currentUser, command, applicationCurrency, existingTransactionIds, existingReversedTransactionIds, changes,
paymentDetail);
if (!changes.isEmpty()) {
this.loanRepository.save(loan);
@@ -224,9 +228,11 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
this.noteRepository.save(note);
}
final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(loan.getCurrencyCode());
final Map<String, Object> accountingBridgeData = loan.deriveAccountingBridgeData(currency.toData(), existingTransactionIds,
existingReversedTransactionIds);
final MonetaryCurrency currency = loan.getCurrency();
final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneWithNotFoundDetection(currency);
final Map<String, Object> accountingBridgeData = loan.deriveAccountingBridgeData(applicationCurrency.toData(),
existingTransactionIds, existingReversedTransactionIds);
journalEntryWritePlatformService.createJournalEntriesForLoan(accountingBridgeData);
}
@@ -898,16 +904,14 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
.build();
}
/**
* @param loan
* @param existingTransactionIds
* @param existingReversedTransactionIds
*/
private void postJournalEntries(final Loan loan, final List<Long> existingTransactionIds,
final List<Long> existingReversedTransactionIds) {
final ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(loan.getCurrencyCode());
final Map<String, Object> accountingBridgeData = loan.deriveAccountingBridgeData(currency.toData(), existingTransactionIds,
existingReversedTransactionIds);
final MonetaryCurrency currency = loan.getCurrency();
final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneWithNotFoundDetection(currency);
final Map<String, Object> accountingBridgeData = loan.deriveAccountingBridgeData(applicationCurrency.toData(),
existingTransactionIds, existingReversedTransactionIds);
journalEntryWritePlatformService.createJournalEntriesForLoan(accountingBridgeData);
}
}