From 822eea631f7b09d7a377c6d6b6a966ab3b32f348 Mon Sep 17 00:00:00 2001 From: Anuruddha Premalal Date: Mon, 9 Sep 2013 22:43:43 +0530 Subject: [PATCH] Update cache zone namings, Remove roles from being cached, added caching to loadOfficeById, added caching to loadTenantById(not cached though), made basicAuthenticationProcessingFilter bean to be depend on cachemanager bean --- .../service/JdbcTenantDetailsService.java | 2 ++ ...antAwareJpaPlatformUserDetailsService.java | 2 +- .../OfficeReadPlatformServiceImpl.java | 3 ++- ...WritePlatformServiceJpaRepositoryImpl.java | 5 +++-- .../AppUserReadPlatformServiceImpl.java | 6 +++++ ...WritePlatformServiceJpaRepositoryImpl.java | 6 ++--- .../service/RoleReadPlatformServiceImpl.java | 3 --- ...WritePlatformServiceJpaRepositoryImpl.java | 4 ---- .../resources/META-INF/spring/ehcache.xml | 22 +++++++++---------- .../META-INF/spring/securityContext.xml | 2 +- 10 files changed, 28 insertions(+), 27 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/JdbcTenantDetailsService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/JdbcTenantDetailsService.java index 8f04bd37b..f7d947b2b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/JdbcTenantDetailsService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/JdbcTenantDetailsService.java @@ -15,6 +15,7 @@ import org.mifosplatform.infrastructure.core.domain.MifosPlatformTenant; import org.mifosplatform.infrastructure.security.exception.InvalidTenantIdentiferException; 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; import org.springframework.jdbc.core.RowMapper; @@ -65,6 +66,7 @@ public class JdbcTenantDetailsService implements TenantDetailsService { } @Override + @Cacheable(value = "tenantsById", key = "#tenantIdentifier") public MifosPlatformTenant loadTenantById(final String tenantIdentifier) { try { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/TenantAwareJpaPlatformUserDetailsService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/TenantAwareJpaPlatformUserDetailsService.java index ba8a2a273..49343456e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/TenantAwareJpaPlatformUserDetailsService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/security/service/TenantAwareJpaPlatformUserDetailsService.java @@ -25,7 +25,7 @@ public class TenantAwareJpaPlatformUserDetailsService implements PlatformUserDet private PlatformUserRepository platformUserRepository; @Override - @Cacheable(value = "users", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#username+'un')") + @Cacheable(value = "usersByUsername", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#username+'ubu')") public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException, DataAccessException { final PlatformUser appUser = this.platformUserRepository.findByUsername(username); 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 b73d016e0..8067690c9 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 @@ -142,7 +142,7 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService } @Override - @Cacheable(value = "office_template", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'oft')") + @Cacheable(value = "officesForDropdown", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'ofd')") public Collection retrieveAllOfficesForDropdown() { final AppUser currentUser = context.authenticatedUser(); @@ -156,6 +156,7 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService } @Override + @Cacheable(value = "officesById", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#officeId)") public OfficeData retrieveOffice(final Long officeId) { try { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java index e54a3455f..9de32df83 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java @@ -64,7 +64,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP @Override @Caching(evict = { @CacheEvict(value = "offices", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'of')"), - @CacheEvict(value = "office_template", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'oft')") }) + @CacheEvict(value = "officesForDropdown", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'ofd')") }) public CommandProcessingResult createOffice(final JsonCommand command) { try { @@ -102,7 +102,8 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP @Override @Caching(evict = { @CacheEvict(value = "offices", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'of')"), - @CacheEvict(value = "office_template", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'oft')") }) + @CacheEvict(value = "officesForDropdown", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'ofd')"), + @CacheEvict(value = "officesById", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#officeId)")}) public CommandProcessingResult updateOffice(final Long officeId, final JsonCommand command) { try { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserReadPlatformServiceImpl.java index 1f0f952f6..c0a9dd881 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserReadPlatformServiceImpl.java @@ -23,6 +23,7 @@ import org.mifosplatform.useradministration.domain.AppUserRepository; import org.mifosplatform.useradministration.domain.Role; import org.mifosplatform.useradministration.exception.UserNotFoundException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Service; @@ -48,6 +49,7 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic } @Override + @Cacheable(value = "users", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy())") public Collection retrieveAllUsers() { AppUser currentUser = context.authenticatedUser(); @@ -143,4 +145,8 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic + " join m_office o on o.id = u.office_id where o.hierarchy like ? and u.is_deleted=0 order by u.username"; } } + + public PlatformSecurityContext getContext() { + return this.context; + } } \ 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 81c185fce..393958914 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 @@ -67,7 +67,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit @Transactional @Override - @CacheEvict(value = "users", allEntries = true) + @CacheEvict(value = "usersByUsername", allEntries = true) public CommandProcessingResult createUser(final JsonCommand command) { try { @@ -111,7 +111,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit @Transactional @Override - @CacheEvict(value = "users", allEntries = true) + @CacheEvict(value = "usersByUsername", allEntries = true) public CommandProcessingResult updateUser(final Long userId, final JsonCommand command) { try { @@ -172,7 +172,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit @Transactional @Override - @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/java/org/mifosplatform/useradministration/service/RoleReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleReadPlatformServiceImpl.java index a7ad83c1f..71e1769d2 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleReadPlatformServiceImpl.java @@ -14,8 +14,6 @@ import org.mifosplatform.infrastructure.core.service.RoutingDataSource; import org.mifosplatform.useradministration.data.RoleData; import org.mifosplatform.useradministration.exception.RoleNotFoundException; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.cache.annotation.Cacheable; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; @@ -34,7 +32,6 @@ public class RoleReadPlatformServiceImpl implements RoleReadPlatformService { } @Override - @Cacheable(value = "roles", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('rl')") public Collection retrieveAll() { final String sql = "select " + roleRowMapper.schema() + " order by r.id"; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java index 94fd83320..39dc3a3e7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java @@ -25,7 +25,6 @@ import org.mifosplatform.useradministration.serialization.PermissionsCommandFrom import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.CacheEvict; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -53,7 +52,6 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf @Transactional @Override - @CacheEvict(value = "roles", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('rl')") public CommandProcessingResult createRole(final JsonCommand command) { try { @@ -99,7 +97,6 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf @Transactional @Override - @CacheEvict(value = "roles", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('rl')") public CommandProcessingResult updateRole(final Long roleId, final JsonCommand command) { try { context.authenticatedUser(); @@ -129,7 +126,6 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf @Transactional @Override - @CacheEvict(value = "roles", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('rl')") public CommandProcessingResult updateRolePermissions(final Long roleId, final JsonCommand command) { context.authenticatedUser(); 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 14883e6e1..5b02dcb18 100644 --- a/mifosng-provider/src/main/resources/META-INF/spring/ehcache.xml +++ b/mifosng-provider/src/main/resources/META-INF/spring/ehcache.xml @@ -1,21 +1,21 @@ - + - + + - + - \ No newline at end of file diff --git a/mifosng-provider/src/main/resources/META-INF/spring/securityContext.xml b/mifosng-provider/src/main/resources/META-INF/spring/securityContext.xml index b9648e1e7..0cb43ea5d 100644 --- a/mifosng-provider/src/main/resources/META-INF/spring/securityContext.xml +++ b/mifosng-provider/src/main/resources/META-INF/spring/securityContext.xml @@ -29,7 +29,7 @@ - +