minor cleanups

This commit is contained in:
Vishwas Babu A J
2014-06-10 23:16:10 -07:00
parent 6cc6d03785
commit c89699c9df
8 changed files with 42 additions and 59 deletions
@@ -44,10 +44,8 @@ public class CurrencyWritePlatformServiceJpaRepositoryImpl implements CurrencyWr
public CurrencyWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, public CurrencyWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
final CurrencyCommandFromApiJsonDeserializer fromApiJsonDeserializer, final CurrencyCommandFromApiJsonDeserializer fromApiJsonDeserializer,
final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository, final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository,
final OrganisationCurrencyRepository organisationCurrencyRepository, final OrganisationCurrencyRepository organisationCurrencyRepository, final LoanProductReadPlatformService loanProductService,
final LoanProductReadPlatformService loanProductService, final SavingsProductReadPlatformService savingsProductService, final ChargeReadPlatformService chargeService) {
final SavingsProductReadPlatformService savingsProductService,
final ChargeReadPlatformService chargeService) {
this.context = context; this.context = context;
this.fromApiJsonDeserializer = fromApiJsonDeserializer; this.fromApiJsonDeserializer = fromApiJsonDeserializer;
this.applicationCurrencyRepository = applicationCurrencyRepository; this.applicationCurrencyRepository = applicationCurrencyRepository;
@@ -81,16 +79,15 @@ public class CurrencyWritePlatformServiceJpaRepositoryImpl implements CurrencyWr
} }
for (OrganisationCurrency priorCurrency : this.organisationCurrencyRepository.findAll()) { for (OrganisationCurrency priorCurrency : this.organisationCurrencyRepository.findAll()) {
if (!allowedCurrencyCodes.contains(priorCurrency.getCode())) { if (!allowedCurrencyCodes.contains(priorCurrency.getCode())) {
// Check if it's safe to remove this currency. // Check if it's safe to remove this currency.
if (!loanProductService.retrieveAllLoanProductsForCurrency(priorCurrency).isEmpty() || if (!loanProductService.retrieveAllLoanProductsForCurrency(priorCurrency.getCode()).isEmpty()
!savingsProductService.retrieveAllForCurrency(priorCurrency).isEmpty() || || !savingsProductService.retrieveAllForCurrency(priorCurrency.getCode()).isEmpty()
!chargeService.retrieveAllChargesForCurrency(priorCurrency).isEmpty()) { || !chargeService.retrieveAllChargesForCurrency(priorCurrency.getCode()).isEmpty()) { throw new CurrencyInUseException(
throw new CurrencyInUseException(priorCurrency.getCode()); priorCurrency.getCode()); }
} }
}
} }
changes.put("currencies", allowedCurrencyCodes.toArray(new String[allowedCurrencyCodes.size()])); changes.put("currencies", allowedCurrencyCodes.toArray(new String[allowedCurrencyCodes.size()]));
this.organisationCurrencyRepository.deleteAll(); this.organisationCurrencyRepository.deleteAll();
@@ -7,14 +7,13 @@ package org.mifosplatform.portfolio.charge.service;
import java.util.Collection; import java.util.Collection;
import org.mifosplatform.organisation.office.domain.OrganisationCurrency;
import org.mifosplatform.portfolio.charge.data.ChargeData; import org.mifosplatform.portfolio.charge.data.ChargeData;
public interface ChargeReadPlatformService { public interface ChargeReadPlatformService {
Collection<ChargeData> retrieveAllCharges(); Collection<ChargeData> retrieveAllCharges();
Collection<ChargeData> retrieveAllChargesForCurrency(OrganisationCurrency currency); Collection<ChargeData> retrieveAllChargesForCurrency(String currencyCode);
ChargeData retrieveCharge(Long chargeId); ChargeData retrieveCharge(Long chargeId);
@@ -18,7 +18,6 @@ import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.organisation.monetary.data.CurrencyData;
import org.mifosplatform.organisation.monetary.service.CurrencyReadPlatformService; import org.mifosplatform.organisation.monetary.service.CurrencyReadPlatformService;
import org.mifosplatform.organisation.office.domain.OrganisationCurrency;
import org.mifosplatform.portfolio.charge.data.ChargeData; import org.mifosplatform.portfolio.charge.data.ChargeData;
import org.mifosplatform.portfolio.charge.domain.ChargeAppliesTo; import org.mifosplatform.portfolio.charge.domain.ChargeAppliesTo;
import org.mifosplatform.portfolio.charge.exception.ChargeNotFoundException; import org.mifosplatform.portfolio.charge.exception.ChargeNotFoundException;
@@ -64,20 +63,17 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
return this.jdbcTemplate.query(sql, rm, new Object[] {}); return this.jdbcTemplate.query(sql, rm, new Object[] {});
} }
@Override @Override
@Cacheable(value = "charges", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('ch')") public Collection<ChargeData> retrieveAllChargesForCurrency(String currencyCode) {
public Collection<ChargeData> retrieveAllChargesForCurrency( this.context.authenticatedUser();
OrganisationCurrency currency) {
this.context.authenticatedUser();
final ChargeMapper rm = new ChargeMapper(); final ChargeMapper rm = new ChargeMapper();
final String sql = "select " + rm.chargeSchema() final String sql = "select " + rm.chargeSchema() + " where c.is_deleted=0 and c.currency_code='" + currencyCode
+ " where c.is_deleted=0 and c.currency_code='" + currency.getCode() + "' order by c.name ";
+ "' order by c.name ";
return this.jdbcTemplate.query(sql, rm, new Object[] {}); return this.jdbcTemplate.query(sql, rm, new Object[] {});
} }
@Override @Override
public ChargeData retrieveCharge(final Long chargeId) { public ChargeData retrieveCharge(final Long chargeId) {
@@ -7,7 +7,6 @@ package org.mifosplatform.portfolio.loanproduct.service;
import java.util.Collection; import java.util.Collection;
import org.mifosplatform.organisation.office.domain.OrganisationCurrency;
import org.mifosplatform.portfolio.loanproduct.data.LoanProductBorrowerCycleVariationData; import org.mifosplatform.portfolio.loanproduct.data.LoanProductBorrowerCycleVariationData;
import org.mifosplatform.portfolio.loanproduct.data.LoanProductData; import org.mifosplatform.portfolio.loanproduct.data.LoanProductData;
@@ -20,8 +19,8 @@ public interface LoanProductReadPlatformService {
LoanProductData retrieveLoanProduct(Long productId); LoanProductData retrieveLoanProduct(Long productId);
LoanProductData retrieveNewLoanProductDetails(); LoanProductData retrieveNewLoanProductDetails();
Collection<LoanProductData> retrieveAllLoanProductsForCurrency(OrganisationCurrency currency); Collection<LoanProductData> retrieveAllLoanProductsForCurrency(String currencyCode);
Collection<LoanProductData> retrieveAvailableLoanProductsForMix(); Collection<LoanProductData> retrieveAvailableLoanProductsForMix();
@@ -19,7 +19,6 @@ import org.mifosplatform.infrastructure.core.service.DateUtils;
import org.mifosplatform.infrastructure.core.service.RoutingDataSource; import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.organisation.monetary.data.CurrencyData;
import org.mifosplatform.organisation.office.domain.OrganisationCurrency;
import org.mifosplatform.portfolio.charge.data.ChargeData; import org.mifosplatform.portfolio.charge.data.ChargeData;
import org.mifosplatform.portfolio.charge.service.ChargeReadPlatformService; import org.mifosplatform.portfolio.charge.service.ChargeReadPlatformService;
import org.mifosplatform.portfolio.loanproduct.data.LoanProductBorrowerCycleVariationData; import org.mifosplatform.portfolio.loanproduct.data.LoanProductBorrowerCycleVariationData;
@@ -291,19 +290,17 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
} }
} }
@Override
public Collection<LoanProductData> retrieveAllLoanProductsForCurrency(
OrganisationCurrency currency) {
this.context.authenticatedUser();
final LoanProductMapper rm = new LoanProductMapper(null, null); @Override
public Collection<LoanProductData> retrieveAllLoanProductsForCurrency(String currencyCode) {
this.context.authenticatedUser();
final String sql = "select " + rm.loanProductSchema() final LoanProductMapper rm = new LoanProductMapper(null, null);
+ " where lp.currency_code='" + currency.getCode() + "'";
return this.jdbcTemplate.query(sql, rm, new Object[] {}); final String sql = "select " + rm.loanProductSchema() + " where lp.currency_code='" + currencyCode + "'";
}
return this.jdbcTemplate.query(sql, rm, new Object[] {});
}
@Override @Override
public Collection<LoanProductData> retrieveAvailableLoanProductsForMix() { public Collection<LoanProductData> retrieveAvailableLoanProductsForMix() {
@@ -13,7 +13,6 @@ import org.springframework.data.jpa.domain.AbstractPersistable;
@Table(name = "m_savings_interest_incentives") @Table(name = "m_savings_interest_incentives")
public class DepositAccountInterestIncentives extends AbstractPersistable<Long> { public class DepositAccountInterestIncentives extends AbstractPersistable<Long> {
@SuppressWarnings("unused")
@ManyToOne @ManyToOne
@JoinColumn(name = "deposit_account_interest_rate_slab_id", nullable = false) @JoinColumn(name = "deposit_account_interest_rate_slab_id", nullable = false)
private DepositAccountInterestRateChartSlabs depositAccountInterestRateChartSlabs; private DepositAccountInterestRateChartSlabs depositAccountInterestRateChartSlabs;
@@ -7,7 +7,6 @@ package org.mifosplatform.portfolio.savings.service;
import java.util.Collection; import java.util.Collection;
import org.mifosplatform.organisation.office.domain.OrganisationCurrency;
import org.mifosplatform.portfolio.savings.data.SavingsProductData; import org.mifosplatform.portfolio.savings.data.SavingsProductData;
public interface SavingsProductReadPlatformService { public interface SavingsProductReadPlatformService {
@@ -18,7 +17,7 @@ public interface SavingsProductReadPlatformService {
Collection<SavingsProductData> retrieveAllForLookupByType(Boolean isOverdraftType); Collection<SavingsProductData> retrieveAllForLookupByType(Boolean isOverdraftType);
Collection<SavingsProductData> retrieveAllForCurrency(OrganisationCurrency currency); Collection<SavingsProductData> retrieveAllForCurrency(String currencyCode);
SavingsProductData retrieveOne(Long productId); SavingsProductData retrieveOne(Long productId);
@@ -16,7 +16,6 @@ import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.service.RoutingDataSource; import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.organisation.monetary.data.CurrencyData;
import org.mifosplatform.organisation.office.domain.OrganisationCurrency;
import org.mifosplatform.portfolio.savings.DepositAccountType; import org.mifosplatform.portfolio.savings.DepositAccountType;
import org.mifosplatform.portfolio.savings.data.SavingsProductData; import org.mifosplatform.portfolio.savings.data.SavingsProductData;
import org.mifosplatform.portfolio.savings.exception.SavingsProductNotFoundException; import org.mifosplatform.portfolio.savings.exception.SavingsProductNotFoundException;
@@ -179,25 +178,23 @@ public class SavingsProductReadPlatformServiceImpl implements SavingsProductRead
@Override @Override
public Collection<SavingsProductData> retrieveAllForLookupByType(Boolean isOverdraftType) { public Collection<SavingsProductData> retrieveAllForLookupByType(Boolean isOverdraftType) {
String sql = "select " + this.savingsProductLookupsRowMapper.schema(); String sql = "select " + this.savingsProductLookupsRowMapper.schema();
if(isOverdraftType != null){ if (isOverdraftType != null) {
sql += " where sp.allow_overdraft=?"; sql += " where sp.allow_overdraft=?";
return this.jdbcTemplate.query(sql, this.savingsProductLookupsRowMapper, isOverdraftType); return this.jdbcTemplate.query(sql, this.savingsProductLookupsRowMapper, isOverdraftType);
} }
return this.jdbcTemplate.query(sql, this.savingsProductLookupsRowMapper); return this.jdbcTemplate.query(sql, this.savingsProductLookupsRowMapper);
} }
@Override
public Collection<SavingsProductData> retrieveAllForCurrency(
OrganisationCurrency currency) {
this.context.authenticatedUser();
final String sql = "select " + this.savingsProductRowMapper.schema() @Override
+ " where sp.currency_code='" + currency.getCode() + "'"; public Collection<SavingsProductData> retrieveAllForCurrency(String currencyCode) {
this.context.authenticatedUser();
final String sql = "select " + this.savingsProductRowMapper.schema() + " where sp.currency_code='" + currencyCode + "'";
return this.jdbcTemplate.query(sql, this.savingsProductRowMapper, new Object[] { DepositAccountType.SAVINGS_DEPOSIT.getValue() }); return this.jdbcTemplate.query(sql, this.savingsProductRowMapper, new Object[] { DepositAccountType.SAVINGS_DEPOSIT.getValue() });
} }
} }