update javadoc around multi tenant aware infrastructure classes. begin start of delete client support.

This commit is contained in:
Keith Woodlock
2012-07-24 14:50:18 +01:00
parent 3c7ffb3822
commit 2527563841
9 changed files with 62 additions and 6 deletions
@@ -7,6 +7,7 @@ import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
@@ -197,6 +198,17 @@ public class ClientsApiResource {
return Response.ok().entity(identifier).build();
}
@DELETE
@Path("{clientId}")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public Response deleteClient(@PathParam("clientId") final Long clientId) {
this.clientWritePlatformService.deleteClient(clientId);
return Response.ok(new EntityIdentifier(clientId)).build();
}
@GET
@Path("{clientId}/loans")
@@ -8,4 +8,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface NoteRepository extends JpaRepository<Note, Long>, JpaSpecificationExecutor<Note> {
List<Note> findByLoanId(Long id);
List<Note> findByClientId(Long id);
}
@@ -18,4 +18,7 @@ public interface ClientWritePlatformService {
@PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE')")
EntityIdentifier updateNote(NoteCommand command);
@PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE', 'CAN_DELETE_CLIENT_ROLE')")
void deleteClient(Long clientId);
}
@@ -1,5 +1,7 @@
package org.mifosng.platform.client.service;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.api.commands.NoteCommand;
@@ -35,6 +37,16 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
this.noteRepository = noteRepository;
}
@Transactional
@Override
public void deleteClient(final Long clientId) {
List<Note> relatedNotes = this.noteRepository.findByClientId(clientId);
this.noteRepository.deleteInBatch(relatedNotes);
this.clientRepository.delete(clientId);
}
@Transactional
@Override
public Long enrollClient(final ClientCommand command) {
@@ -12,6 +12,9 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
/**
* A JDBC implementation of {@link TenantDetailsService} for loading a tenants details by a <code>tenantIdentifier</code>.
*/
@Service
public class JdbcTenantDetailsService implements TenantDetailsService {
@@ -16,7 +16,19 @@ import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
/**
*
* A customised version of spring security's {@link BasicAuthenticationFilter}.
*
* This filter is responsible for extracting multi-tenant and basic auth
* credentials from the request and checking that the details provided are
* valid.
*
* If multi-tenant and basic auth credentials are valid, the details of the
* tenant are stored in {@link MifosPlatformTenant} and stored in a
* {@link ThreadLocal} variable for this request using
* {@link ThreadLocalContextUtil}.
*
* If multi-tenant and basic auth credentials are invalid, a http error response
* is returned.
*/
public class TenantAwareBasicAuthenticationFilter extends BasicAuthenticationFilter {
@@ -39,7 +51,7 @@ public class TenantAwareBasicAuthenticationFilter extends BasicAuthenticationFil
try {
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
// ignore to allow 'preflight' requests from AJAX applications in different domain
// ignore to allow 'preflight' requests from AJAX applications in different origin (domain name)
} else {
String tenantId = request.getHeader(tenantRequestHeader);
@@ -7,10 +7,18 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.AbstractDataSource;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
import org.springframework.stereotype.Service;
/**
*
* Based on springs {@link AbstractRoutingDataSource} idea, this is a
* {@link DataSource} that routes or delegates to another data source depending
* on the tenant details passed in the request.
*
* The tenant details are process earlier and stored in a {@link ThreadLocal}.
*
* The {@link DataSourcePerTenantService} is responsible for returning the
* appropriate {@link DataSource} for the tenant of this request.
*/
@Service(value="tenantAwareDataSource")
public class TenantAwareRoutingDataSource extends AbstractDataSource {
@@ -28,7 +36,7 @@ public class TenantAwareRoutingDataSource extends AbstractDataSource {
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
public Connection getConnection(final String username, final String password) throws SQLException {
return determineTargetDataSource().getConnection(username, password);
}
}
@@ -12,7 +12,11 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
/**
*
* Implementation that returns a new or existing tomcat 7 jdbc connection pool
* datasource based on the tenant details stored in a {@link ThreadLocal}
* variable for this request.
*
* {@link ThreadLocalContextUtil} is used to retrieve the {@link MifosPlatformTenant} for the request.
*/
@Service
public class TomcatJdbcDataSourcePerTenantService implements DataSourcePerTenantService {
@@ -162,7 +162,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
@Transactional
@Override
public void deleteUser(Long userId) {
public void deleteUser(final Long userId) {
try {
this.appUserRepository.delete(userId);
} catch (InvalidDataAccessApiUsageException exception) {