diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeReadPlatformService.java index 51144ddc0..c59b34f95 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeReadPlatformService.java @@ -7,14 +7,11 @@ package org.mifosplatform.organisation.office.service; import java.util.Collection; -import org.mifosplatform.infrastructure.core.domain.MifosPlatformTenant; import org.mifosplatform.organisation.office.data.OfficeData; import org.mifosplatform.organisation.office.data.OfficeTransactionData; public interface OfficeReadPlatformService { - MifosPlatformTenant loadTenantById(String tenantIdentifier); - Collection retrieveAllOffices(boolean includeAllOffices); Collection retrieveAllOfficesForDropdown(); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeReadPlatformServiceImpl.java index ef6864819..29c5c67af 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeReadPlatformServiceImpl.java @@ -11,13 +11,9 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; -import javax.sql.DataSource; - import org.joda.time.LocalDate; import org.mifosplatform.infrastructure.core.domain.JdbcSupport; -import org.mifosplatform.infrastructure.core.domain.MifosPlatformTenant; import org.mifosplatform.infrastructure.core.service.RoutingDataSource; -import org.mifosplatform.infrastructure.security.exception.InvalidTenantIdentiferException; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.organisation.monetary.service.CurrencyReadPlatformService; @@ -26,7 +22,6 @@ import org.mifosplatform.organisation.office.data.OfficeTransactionData; import org.mifosplatform.organisation.office.exception.OfficeNotFoundException; import org.mifosplatform.useradministration.domain.AppUser; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.cache.annotation.Cacheable; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; @@ -37,19 +32,16 @@ import org.springframework.stereotype.Service; public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService { private final JdbcTemplate jdbcTemplate; - private final JdbcTemplate tenantsJdbcTemplate; private final PlatformSecurityContext context; private final CurrencyReadPlatformService currencyReadPlatformService; private final static String nameDecoratedBaseOnHierarchy = "concat(substring('........................................', 1, ((LENGTH(o.hierarchy) - LENGTH(REPLACE(o.hierarchy, '.', '')) - 1) * 4)), o.name)"; @Autowired public OfficeReadPlatformServiceImpl(final PlatformSecurityContext context, - final CurrencyReadPlatformService currencyReadPlatformService, final RoutingDataSource dataSource, - @Qualifier("tenantDataSourceJndi") final DataSource tenantsJndiDataSource) { + final CurrencyReadPlatformService currencyReadPlatformService, final RoutingDataSource dataSource) { this.context = context; this.currencyReadPlatformService = currencyReadPlatformService; this.jdbcTemplate = new JdbcTemplate(dataSource); - this.tenantsJdbcTemplate = new JdbcTemplate(tenantsJndiDataSource); } private static final class OfficeMapper implements RowMapper { @@ -134,7 +126,6 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService } } - /** TODO: Vishwas This change breaks caching, need to have a relook **/ @Override @Cacheable(value = "offices", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'of')") public Collection retrieveAllOffices(final boolean includeAllOffices) { @@ -243,48 +234,4 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService public PlatformSecurityContext getContext() { return this.context; } - - @Override - @Cacheable(value = "tenantsById", key = "#tenantIdentifier") - public MifosPlatformTenant loadTenantById(final String tenantIdentifier) { - - try { - final TenantMapper rm = new TenantMapper(); - final String sql = "select " + rm.schema() + " where t.identifier like ?"; - - return this.tenantsJdbcTemplate.queryForObject(sql, rm, new Object[] { tenantIdentifier }); - } catch (final EmptyResultDataAccessException e) { - throw new InvalidTenantIdentiferException("The tenant identifier: " + tenantIdentifier + " is not valid."); - } - } - - private static final class TenantMapper implements RowMapper { - - private final StringBuilder sqlBuilder = new StringBuilder( - "id, name,identifier, schema_name as schemaName, schema_server as schemaServer, schema_server_port as schemaServerPort, auto_update as autoUpdate, ")// - .append(" schema_username as schemaUsername, schema_password as schemaPassword , timezone_id as timezoneId ")// - .append(" from tenants t");// - - public String schema() { - return this.sqlBuilder.toString(); - } - - @Override - public MifosPlatformTenant mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { - - final Long id = rs.getLong("id"); - final String tenantIdentifier = rs.getString("identifier"); - final String name = rs.getString("name"); - final String schemaName = rs.getString("schemaName"); - final String schemaServer = rs.getString("schemaServer"); - final String schemaServerPort = rs.getString("schemaServerPort"); - final String schemaUsername = rs.getString("schemaUsername"); - final String schemaPassword = rs.getString("schemaPassword"); - final String timezoneId = rs.getString("timezoneId"); - final boolean autoUpdateEnabled = rs.getBoolean("autoUpdate"); - - return new MifosPlatformTenant(id, tenantIdentifier, name, schemaName, schemaServer, schemaServerPort, schemaUsername, - schemaPassword, timezoneId, autoUpdateEnabled); - } - } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java index b1802c506..23ef92d42 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java @@ -34,6 +34,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Caching; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -67,7 +68,9 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit @Transactional @Override - @CacheEvict(value = "usersByUsername", allEntries = true) + @Caching(evict = { + @CacheEvict(value = "users", allEntries = true), + @CacheEvict(value = "usersByUsername", allEntries = true)}) public CommandProcessingResult createUser(final JsonCommand command) { try { @@ -111,7 +114,9 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit @Transactional @Override - @CacheEvict(value = "usersByUsername", allEntries = true) + @Caching(evict = { + @CacheEvict(value = "users", allEntries = true), + @CacheEvict(value = "usersByUsername", allEntries = true)}) public CommandProcessingResult updateUser(final Long userId, final JsonCommand command) { try { @@ -172,7 +177,9 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit @Transactional @Override - @CacheEvict(value = "usersByUsername", allEntries = true) + @Caching(evict = { + @CacheEvict(value = "users", allEntries = true), + @CacheEvict(value = "usersByUsername", allEntries = true)}) public CommandProcessingResult deleteUser(final Long userId) { final AppUser user = this.appUserRepository.findOne(userId); diff --git a/mifosng-provider/src/main/resources/META-INF/spring/ehcache.xml b/mifosng-provider/src/main/resources/META-INF/spring/ehcache.xml index 5b02dcb18..7a63ad5c8 100644 --- a/mifosng-provider/src/main/resources/META-INF/spring/ehcache.xml +++ b/mifosng-provider/src/main/resources/META-INF/spring/ehcache.xml @@ -6,6 +6,9 @@ xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"> + +