MIFOSX-26 group template API returns only clients from specified office.
This commit is contained in:
@@ -13,6 +13,7 @@ import javax.ws.rs.PUT;
|
|||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
@@ -31,6 +32,8 @@ import org.mifosng.platform.client.service.ClientReadPlatformService;
|
|||||||
import org.mifosng.platform.group.service.GroupReadPlatformService;
|
import org.mifosng.platform.group.service.GroupReadPlatformService;
|
||||||
import org.mifosng.platform.group.service.GroupWritePlatformService;
|
import org.mifosng.platform.group.service.GroupWritePlatformService;
|
||||||
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
|
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -40,9 +43,11 @@ import org.springframework.stereotype.Component;
|
|||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class GroupsApiResource {
|
public class GroupsApiResource {
|
||||||
|
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(GroupsApiResource.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private GroupReadPlatformService groupReadPlatformService;
|
private GroupReadPlatformService groupReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private GroupWritePlatformService groupWritePlatformService;
|
private GroupWritePlatformService groupWritePlatformService;
|
||||||
|
|
||||||
@@ -71,19 +76,21 @@ public class GroupsApiResource {
|
|||||||
if (responseParameters.isEmpty()) {
|
if (responseParameters.isEmpty()) {
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
responseParameters.addAll(typicalResponseParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
Collection<GroupData> groups = this.groupReadPlatformService.retrieveAllGroups();
|
Collection<GroupData> groups = this.groupReadPlatformService.retrieveAllGroups();
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeGroupDataToJson(prettyPrint, responseParameters, groups);
|
return this.apiJsonSerializerService.serializeGroupDataToJson(prettyPrint, responseParameters, groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{groupId}")
|
@Path("{groupId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveGroupData(@PathParam("groupId") final Long groupId, @Context final UriInfo uriInfo) {
|
public String retrieveGroupData(@Context final UriInfo uriInfo,
|
||||||
|
@PathParam("groupId") final Long groupId,
|
||||||
|
@QueryParam("officeId") final Long officeId) {
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo
|
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo
|
||||||
.getQueryParameters());
|
.getQueryParameters());
|
||||||
@@ -92,27 +99,34 @@ public class GroupsApiResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
GroupData group = this.groupReadPlatformService.retrieveGroup(groupId);
|
GroupData group = this.groupReadPlatformService.retrieveGroup(groupId);
|
||||||
final Collection<ClientLookup> clientMembers = this.groupReadPlatformService.retrieveClientMembers(groupId);
|
final Collection<ClientLookup> clientMembers = this.groupReadPlatformService.retrieveClientMembers(groupId);
|
||||||
Collection<ClientLookup> availableClients = null;
|
Collection<ClientLookup> availableClients = null;
|
||||||
Collection<OfficeLookup> allowedOffices = null;
|
Collection<OfficeLookup> allowedOffices = null;
|
||||||
|
|
||||||
group = new GroupData(group, clientMembers, availableClients, allowedOffices);
|
group = new GroupData(group, clientMembers, availableClients, allowedOffices);
|
||||||
|
|
||||||
boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
||||||
if (template) {
|
if (template) {
|
||||||
responseParameters.add("allowedClients");
|
responseParameters.add("allowedClients");
|
||||||
responseParameters.add("allowedOffices");
|
responseParameters.add("allowedOffices");
|
||||||
|
|
||||||
availableClients = this.clientReadPlatformService.retrieveAllIndividualClientsForLookup();
|
final String extraCriteria;
|
||||||
|
if (officeId != null){
|
||||||
|
extraCriteria = getGroupExtraCriteria(officeId);
|
||||||
|
} else {
|
||||||
|
extraCriteria = getGroupExtraCriteria(group.getOfficeId());
|
||||||
|
}
|
||||||
|
|
||||||
|
availableClients = this.clientReadPlatformService.retrieveAllIndividualClientsForLookup(extraCriteria);
|
||||||
availableClients.removeAll(group.clientMembers());
|
availableClients.removeAll(group.clientMembers());
|
||||||
|
|
||||||
allowedOffices = officeReadPlatformService.retrieveAllOfficesForLookup();
|
allowedOffices = officeReadPlatformService.retrieveAllOfficesForLookup();
|
||||||
|
|
||||||
group = new GroupData(group, group.clientMembers(), availableClients, allowedOffices);
|
group = new GroupData(group, group.clientMembers(), availableClients, allowedOffices);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeGroupDataToJson(prettyPrint, responseParameters, group);
|
return this.apiJsonSerializerService.serializeGroupDataToJson(prettyPrint, responseParameters, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +134,8 @@ public class GroupsApiResource {
|
|||||||
@Path("template")
|
@Path("template")
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public String newGroupDetails(@Context final UriInfo uriInfo) {
|
public String newGroupDetails(@Context final UriInfo uriInfo,
|
||||||
|
@QueryParam("officeId") final Long officeId) {
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
if (responseParameters.isEmpty()) {
|
if (responseParameters.isEmpty()) {
|
||||||
@@ -130,7 +145,9 @@ public class GroupsApiResource {
|
|||||||
|
|
||||||
responseParameters.addAll(Arrays.asList("allowedClients", "allowedOffices"));
|
responseParameters.addAll(Arrays.asList("allowedClients", "allowedOffices"));
|
||||||
|
|
||||||
GroupData groupData = this.groupReadPlatformService.retrieveNewGroupDetails();
|
final String extraCriteria = getGroupExtraCriteria(officeId);
|
||||||
|
|
||||||
|
GroupData groupData = this.groupReadPlatformService.retrieveNewGroupDetails(extraCriteria);
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeGroupDataToJson(prettyPrint, responseParameters, groupData);
|
return this.apiJsonSerializerService.serializeGroupDataToJson(prettyPrint, responseParameters, groupData);
|
||||||
}
|
}
|
||||||
@@ -194,4 +211,17 @@ public class GroupsApiResource {
|
|||||||
|
|
||||||
return this.apiJsonSerializerService.serializeGroupAccountSummaryCollectionDataToJson(prettyPrint, responseParameters, clientAccount);
|
return this.apiJsonSerializerService.serializeGroupAccountSummaryCollectionDataToJson(prettyPrint, responseParameters, clientAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getGroupExtraCriteria(Long officeId){
|
||||||
|
|
||||||
|
String extraCriteria = "";
|
||||||
|
|
||||||
|
if (officeId != null) {
|
||||||
|
extraCriteria += " office_id = " + officeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("extraCriteria; " + extraCriteria);
|
||||||
|
|
||||||
|
return extraCriteria;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -15,7 +15,7 @@ public interface ClientReadPlatformService {
|
|||||||
|
|
||||||
ClientData retrieveNewClientDetails();
|
ClientData retrieveNewClientDetails();
|
||||||
|
|
||||||
Collection<ClientLookup> retrieveAllIndividualClientsForLookup();
|
Collection<ClientLookup> retrieveAllIndividualClientsForLookup(String extraCriteria);
|
||||||
|
|
||||||
ClientAccountSummaryCollectionData retrieveClientAccountDetails(Long clientId);
|
ClientAccountSummaryCollectionData retrieveClientAccountDetails(Long clientId);
|
||||||
|
|
||||||
|
|||||||
+7
-3
@@ -84,13 +84,17 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ClientLookup> retrieveAllIndividualClientsForLookup() {
|
public Collection<ClientLookup> retrieveAllIndividualClientsForLookup(String extraCriteria) {
|
||||||
|
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
ClientLookupMapper rm = new ClientLookupMapper();
|
ClientLookupMapper rm = new ClientLookupMapper();
|
||||||
|
|
||||||
String sql = "select " + rm.clientLookupSchema() + " where c.is_deleted = 0";
|
String sql = "select " + rm.clientLookupSchema();
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(extraCriteria)){
|
||||||
|
sql += " and (" + extraCriteria + ")";
|
||||||
|
}
|
||||||
|
|
||||||
return this.jdbcTemplate.query(sql, rm, new Object[] {});
|
return this.jdbcTemplate.query(sql, rm, new Object[] {});
|
||||||
}
|
}
|
||||||
@@ -145,7 +149,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
|||||||
public String clientLookupSchema() {
|
public String clientLookupSchema() {
|
||||||
return "c.id as id, c.firstname as firstname, c.lastname as lastname, " +
|
return "c.id as id, c.firstname as firstname, c.lastname as lastname, " +
|
||||||
"c.office_id as officeId, o.name as officeName " +
|
"c.office_id as officeId, o.name as officeName " +
|
||||||
"from m_client c join m_office o on o.id = c.office_id";
|
"from m_client c join m_office o on o.id = c.office_id where c.is_deleted=0 ";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ public interface GroupReadPlatformService {
|
|||||||
|
|
||||||
GroupData retrieveGroup(Long groupId);
|
GroupData retrieveGroup(Long groupId);
|
||||||
|
|
||||||
GroupData retrieveNewGroupDetails();
|
GroupData retrieveNewGroupDetails(String extraCriteria);
|
||||||
|
|
||||||
Collection<ClientLookup> retrieveClientMembers(Long groupId);
|
Collection<ClientLookup> retrieveClientMembers(Long groupId);
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -72,12 +72,12 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupData retrieveNewGroupDetails() {
|
public GroupData retrieveNewGroupDetails(String extraCriteria) {
|
||||||
|
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
List<ClientLookup> allowedClients = new ArrayList<ClientLookup>(
|
List<ClientLookup> allowedClients = new ArrayList<ClientLookup>(
|
||||||
this.clientReadPlatformService.retrieveAllIndividualClientsForLookup());
|
this.clientReadPlatformService.retrieveAllIndividualClientsForLookup(extraCriteria));
|
||||||
|
|
||||||
List<OfficeLookup> allowedOffices = new ArrayList<OfficeLookup>(officeReadPlatformService.retrieveAllOfficesForLookup());
|
List<OfficeLookup> allowedOffices = new ArrayList<OfficeLookup>(officeReadPlatformService.retrieveAllOfficesForLookup());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user