MIFOSX-108 minor issues fixes.

This commit is contained in:
Michal Dudzinski
2012-10-22 13:53:45 +02:00
parent dd95e0ad49
commit 6dfdc458ae
6 changed files with 33 additions and 16 deletions
@@ -33,6 +33,7 @@ import org.mifosng.platform.client.service.ClientReadPlatformService;
import org.mifosng.platform.group.service.GroupReadPlatformService;
import org.mifosng.platform.group.service.GroupWritePlatformService;
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
import org.mifosng.platform.security.PlatformSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -64,6 +65,9 @@ public class GroupsApiResource {
@Autowired
private ApiJsonSerializerService apiJsonSerializerService;
@Autowired
private PlatformSecurityContext context;
private static final Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("id", "officeId", "name", "externalId", "clientMembers")
);
@@ -120,14 +124,12 @@ public class GroupsApiResource {
responseParameters.add("allowedClients");
responseParameters.add("allowedOffices");
final String extraCriteria;
if (officeId != null){
extraCriteria = getGroupExtraCriteria(null, officeId, null, null, null);
availableClients = this.clientReadPlatformService.retrieveAllIndividualClientsForLookupByOfficeId(officeId);
} else {
extraCriteria = getGroupExtraCriteria(null, group.getOfficeId(), null, null, null);
availableClients = this.clientReadPlatformService.retrieveAllIndividualClientsForLookupByOfficeId(group.getOfficeId());
}
availableClients = this.clientReadPlatformService.retrieveAllIndividualClientsForLookup(extraCriteria);
availableClients.removeAll(group.clientMembers());
allowedOffices = officeReadPlatformService.retrieveAllOfficesForLookup();
@@ -151,11 +153,14 @@ public class GroupsApiResource {
}
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
responseParameters.addAll(Arrays.asList("allowedClients", "allowedOffices"));
responseParameters.addAll(Arrays.asList("officeId", "allowedClients", "allowedOffices"));
final String extraCriteria = getGroupExtraCriteria(null, officeId, null, null, null);
GroupData groupData = this.groupReadPlatformService.retrieveNewGroupDetails(extraCriteria);
GroupData groupData;
if (officeId != null){
groupData = this.groupReadPlatformService.retrieveNewGroupDetails(officeId);
} else {
groupData = this.groupReadPlatformService.retrieveNewGroupDetails(context.authenticatedUser().getOffice().getId());
}
return this.apiJsonSerializerService.serializeGroupDataToJson(prettyPrint, responseParameters, groupData);
}
@@ -49,9 +49,9 @@ public class GroupData {
this.allowedOffices = allowedOffices;
}
public GroupData(final Collection<ClientLookup> allowedClients, final Collection<OfficeLookup> allowedOffices) {
public GroupData(final Long officeId, final Collection<ClientLookup> allowedClients, final Collection<OfficeLookup> allowedOffices) {
this.id = null;
this.officeId = null;
this.officeId = officeId;
this.officeName = null;
this.name = null;
this.externalId = null;
@@ -18,6 +18,8 @@ public interface ClientReadPlatformService {
Collection<ClientLookup> retrieveAllIndividualClientsForLookup(String extraCriteria);
Collection<ClientLookup> retrieveAllIndividualClientsForLookupByOfficeId(Long officeId);
ClientAccountSummaryCollectionData retrieveClientAccountDetails(Long clientId);
Collection<NoteData> retrieveAllClientNotes(Long clientId);
@@ -114,6 +114,17 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
return this.jdbcTemplate.query(sql, rm, new Object[] {});
}
@Override
public Collection<ClientLookup> retrieveAllIndividualClientsForLookupByOfficeId(Long officeId) {
this.context.authenticatedUser();
ClientLookupMapper rm = new ClientLookupMapper();
String sql = "select " + rm.clientLookupSchema() + " and c.office_id = " + officeId;
return this.jdbcTemplate.query(sql, rm, new Object[] {});
}
@Override
public ClientData retrieveNewClientDetails() {
@@ -12,7 +12,7 @@ public interface GroupReadPlatformService {
GroupData retrieveGroup(Long groupId);
GroupData retrieveNewGroupDetails(String extraCriteria);
GroupData retrieveNewGroupDetails(Long officeId);
Collection<ClientLookup> retrieveClientMembers(Long groupId);
@@ -19,6 +19,7 @@ import org.mifosng.platform.infrastructure.JdbcSupport;
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
import org.mifosng.platform.security.PlatformSecurityContext;
import org.mifosng.platform.user.domain.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -76,16 +77,14 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
}
@Override
public GroupData retrieveNewGroupDetails(String extraCriteria) {
this.context.authenticatedUser();
public GroupData retrieveNewGroupDetails(final Long officeId) {
List<ClientLookup> allowedClients = new ArrayList<ClientLookup>(
this.clientReadPlatformService.retrieveAllIndividualClientsForLookup(extraCriteria));
this.clientReadPlatformService.retrieveAllIndividualClientsForLookupByOfficeId(officeId));
List<OfficeLookup> allowedOffices = new ArrayList<OfficeLookup>(officeReadPlatformService.retrieveAllOfficesForLookup());
return new GroupData(allowedClients, allowedOffices);
return new GroupData(officeId, allowedClients, allowedOffices);
}
private static final class GroupMapper implements RowMapper<GroupData> {