From 0393ed5017dbd4425c00ccb7382aafeb0c55343f Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Thu, 13 Jun 2013 14:29:21 +0100 Subject: [PATCH] MIFOSX-445: support ability to use staff from branches higher in hierarchy on groups. --- api-docs/apiLive.htm | 40 +++++++++++++++++-- .../service/StaffReadPlatformService.java | 4 +- .../service/StaffReadPlatformServiceImpl.java | 23 +++++------ .../group/api/GroupsApiResource.java | 40 +++++++++++-------- .../service/GroupReadPlatformService.java | 2 +- .../service/GroupReadPlatformServiceImpl.java | 13 +++++- .../loanaccount/api/LoansApiResource.java | 7 ++-- 7 files changed, 88 insertions(+), 41 deletions(-) diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 27b0588df..9d2994592 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -1372,6 +1372,10 @@ clients/template Retrieve Client Template + + groups/template + Retrieve Group Template + loanproducts/template Retrieve Loan Product Template @@ -3353,6 +3357,33 @@ GET https://DomainName/mifosng-provider/api/v1/centers

Retrieve Group Template

+

This is a convenience resource. It can be useful when + building maintenance user interface screens for client + applications. The template data returned consists of any or all + of: +

    +
  • Field Defaults
  • +
  • Allowed Value Lists
  • +
+

+
Arguments
+
+
officeId
+
+ Integer optional +
+
centerId
+
+ Integer optional +
+
staffInSelectedOfficeOnly
+
+ Boolean optional +
+
Defaults to false if not provided. If staffInSelectedOfficeOnly=true only staff + who are associated with the selected branch are returned.
+
+

Example Requests:

groups/template

@@ -3360,7 +3391,8 @@ GET https://DomainName/mifosng-provider/api/v1/centers
groups/template?centerId=1

- +
groups/template?centerId=1&staffInSelectedOfficeOnly=true
+

Template to create a standard group

@@ -4076,12 +4108,12 @@ GET https://DomainName/mifosng-provider/api/v1/groups
If entered, productId, productName and selectedProduct fields are returned.
-
loanOfficersInSelectedOfficeOnly
+
staffInSelectedOfficeOnly
Boolean optional
-
Defaults to false if not provided. If loanOfficersInSelectedOfficeOnly=true only loan officers - who are associated with the select branch are returned.
+
Defaults to false if not provided. If staffInSelectedOfficeOnly=true only loan officers + who are associated with the selected branch are returned.

Example Requests:

loans/template?templateType=individual&clientId=1
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformService.java index 3d5e42ef0..7dde36477 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformService.java @@ -18,10 +18,10 @@ public interface StaffReadPlatformService { Collection retrieveAllLoanOfficersInOfficeById(final Long officeId); /** - * returns all loan officers in offices that are above the provided + * returns all staff in offices that are above the provided * officeId. */ - Collection retrieveAllLoanOfficersInOfficeAndItsParentOfficeHierarchy(Long officeId); + Collection retrieveAllStaffInOfficeAndItsParentOfficeHierarchy(Long officeId, boolean loanOfficersOnly); Collection retrieveAllStaff(String sqlSearch, Long officeId); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformServiceImpl.java index 677e46cd1..5e71696e6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformServiceImpl.java @@ -59,24 +59,23 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService { private static final class StaffInOfficeHierarchyMapper implements RowMapper { - final String schema; + public String schema(final boolean loanOfficersOnly) { - public StaffInOfficeHierarchyMapper() { - StringBuilder sqlBuilder = new StringBuilder(200); sqlBuilder.append("s.id as id, s.office_id as officeId, o.name as officeName,"); sqlBuilder.append("s.firstname as firstname, s.lastname as lastname,"); sqlBuilder.append("s.display_name as displayName, s.is_loan_officer as isLoanOfficer "); sqlBuilder.append("from m_office o "); sqlBuilder.append("join m_office ohierarchy on o.hierarchy like concat(ohierarchy.hierarchy, '%') "); - sqlBuilder.append("join m_staff s on s.office_id = ohierarchy.id and s.is_loan_officer is true "); - sqlBuilder.append("where o.id = ? "); - - this.schema = sqlBuilder.toString(); - } + sqlBuilder.append("join m_staff s on s.office_id = ohierarchy.id "); - public String schema() { - return this.schema; + if (loanOfficersOnly) { + sqlBuilder.append("and s.is_loan_officer is true "); + } + + sqlBuilder.append("where o.id = ? "); + + return sqlBuilder.toString(); } @Override @@ -195,9 +194,9 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService { } @Override - public Collection retrieveAllLoanOfficersInOfficeAndItsParentOfficeHierarchy(final Long officeId) { + public Collection retrieveAllStaffInOfficeAndItsParentOfficeHierarchy(final Long officeId, final boolean loanOfficersOnly) { - String sql = "select " + this.staffInOfficeHierarchyMapper.schema(); + String sql = "select " + this.staffInOfficeHierarchyMapper.schema(loanOfficersOnly); sql = sql + " order by s.lastname"; return this.jdbcTemplate.query(sql, this.staffInOfficeHierarchyMapper, new Object[] { officeId }); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java index 30e0d037b..7b2507582 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java @@ -12,6 +12,7 @@ import java.util.Set; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; @@ -97,8 +98,8 @@ public class GroupsApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String retrieveTemplate(@Context final UriInfo uriInfo, @QueryParam("officeId") final Long officeId, - @QueryParam("center") final boolean isCenterGroup, - @QueryParam("centerId") final Long centerId) { + @QueryParam("center") final boolean isCenterGroup, @QueryParam("centerId") final Long centerId, + @DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly) { this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.GROUP_RESOURCE_NAME); @@ -109,7 +110,8 @@ public class GroupsApiResource { GroupingTypesApiConstants.CENTER_GROUP_RESPONSE_DATA_PARAMETERS); } - final GroupGeneralData groupTemplate = this.groupReadPlatformService.retrieveTemplate(officeId, isCenterGroup); + final GroupGeneralData groupTemplate = this.groupReadPlatformService.retrieveTemplate(officeId, isCenterGroup, + staffInSelectedOfficeOnly); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.groupGeneralApiJsonSerializer.serialize(settings, groupTemplate, GroupingTypesApiConstants.GROUP_RESPONSE_DATA_PARAMETERS); @@ -138,13 +140,14 @@ public class GroupsApiResource { @Path("{groupId}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public String retrieveOne(@Context final UriInfo uriInfo, @PathParam("groupId") final Long groupId) { + public String retrieveOne(@Context final UriInfo uriInfo, @PathParam("groupId") final Long groupId, + @DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly) { this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.GROUP_RESOURCE_NAME); final Set associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters()); GroupGeneralData group = this.groupReadPlatformService.retrieveOne(groupId); - + // associations Collection membersOfGroup = null; if (!associationParameters.isEmpty()) { @@ -155,10 +158,11 @@ public class GroupsApiResource { } } } - + final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); if (template) { - final GroupGeneralData templateGroup = this.groupReadPlatformService.retrieveTemplate(group.officeId(), false); + final GroupGeneralData templateGroup = this.groupReadPlatformService.retrieveTemplate(group.officeId(), false, + staffInSelectedOfficeOnly); group = GroupGeneralData.withTemplateAndAssociations(templateGroup, group, membersOfGroup); } else { group = GroupGeneralData.withAssocations(group, membersOfGroup); @@ -227,8 +231,8 @@ public class GroupsApiResource { @Path("{groupId}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public String activateOrGenerateCollectionSheet(@PathParam("groupId") final Long groupId, @QueryParam("command") final String commandParam, - final String apiRequestBodyAsJson, @Context final UriInfo uriInfo) { + public String activateOrGenerateCollectionSheet(@PathParam("groupId") final Long groupId, + @QueryParam("command") final String commandParam, final String apiRequestBodyAsJson, @Context final UriInfo uriInfo) { final CommandWrapperBuilder builder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson); @@ -237,32 +241,34 @@ public class GroupsApiResource { final CommandWrapper commandRequest = builder.activateGroup(groupId).build(); result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); - }else if (is(commandParam, "associateClients")) { + } else if (is(commandParam, "associateClients")) { final CommandWrapper commandRequest = builder.associateClientsToGroup(groupId).build(); result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); - }else if (is(commandParam, "disassociateClients")) { + } else if (is(commandParam, "disassociateClients")) { final CommandWrapper commandRequest = builder.disassociateClientsFromGroup(groupId).build(); result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); - }else if (is(commandParam, "generateCollectionSheet")) { + } else if (is(commandParam, "generateCollectionSheet")) { final JsonElement parsedQuery = this.fromJsonHelper.parse(apiRequestBodyAsJson); final JsonQuery query = JsonQuery.from(apiRequestBodyAsJson, parsedQuery, this.fromJsonHelper); - final JLGCollectionSheetData collectionSheet = this.collectionSheetReadPlatformService.generateGroupCollectionSheet(groupId, query); + final JLGCollectionSheetData collectionSheet = this.collectionSheetReadPlatformService.generateGroupCollectionSheet(groupId, + query); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.toApiJsonSerializer.serialize(settings, collectionSheet, GroupingTypesApiConstants.COLLECTIONSHEET_DATA_PARAMETERS); - }else if (is(commandParam, "saveCollectionSheet")) { + } else if (is(commandParam, "saveCollectionSheet")) { final CommandWrapper commandRequest = builder.saveGroupCollectionSheet(groupId).build(); result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); - }else if (is(commandParam, "unassignStaff")) { + } else if (is(commandParam, "unassignStaff")) { final CommandWrapper commandRequest = builder.unassignGroupStaff(groupId).build(); result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } else { - throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "generateCollectionSheet", "saveCollectionSheet", "unassignStaff" }); + throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "generateCollectionSheet", + "saveCollectionSheet", "unassignStaff" }); } - + } private boolean is(final String commandParam, final String commandValue) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformService.java index 1e232cb3a..9a38c6aed 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformService.java @@ -14,7 +14,7 @@ import org.mifosplatform.portfolio.group.data.GroupGeneralData; public interface GroupReadPlatformService { - GroupGeneralData retrieveTemplate(Long officeId, boolean isCenterGroup); + GroupGeneralData retrieveTemplate(Long officeId, boolean isCenterGroup, boolean staffInSelectedOfficeOnly); Page retrieveAll(SearchParameters searchParameters); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java index bf7baad6a..53207d039 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java @@ -65,7 +65,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { } @Override - public GroupGeneralData retrieveTemplate(final Long officeId, final boolean isCenterGroup) { + public GroupGeneralData retrieveTemplate(final Long officeId, final boolean isCenterGroup, final boolean staffInSelectedOfficeOnly) { final Long defaultOfficeId = defaultToUsersOfficeIfNull(officeId); @@ -75,7 +75,16 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { } final Collection officeOptions = this.officeReadPlatformService.retrieveAllOfficesForDropdown(); - Collection staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(defaultOfficeId); + + final boolean loanOfficersOnly = false; + Collection staffOptions = null; + if (staffInSelectedOfficeOnly) { + staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(defaultOfficeId); + } else { + staffOptions = this.staffReadPlatformService.retrieveAllStaffInOfficeAndItsParentOfficeHierarchy(defaultOfficeId, + loanOfficersOnly); + } + if (CollectionUtils.isEmpty(staffOptions)) { staffOptions = null; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java index 19536882e..c96d99fa4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java @@ -164,7 +164,7 @@ public class LoansApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String template(@QueryParam("clientId") final Long clientId, @QueryParam("groupId") final Long groupId, @QueryParam("productId") final Long productId, @QueryParam("templateType") final String templateType, - @DefaultValue("false") @QueryParam("loanOfficersInSelectedOfficeOnly") final boolean loanOfficersInSelectedOfficeOnly, + @DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly, @Context final UriInfo uriInfo) { context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions); @@ -227,7 +227,7 @@ public class LoansApiResource { } if (officeId != null) { - if (loanOfficersInSelectedOfficeOnly) { + if (staffInSelectedOfficeOnly) { // only bring back loan officers in selected branch/office Collection loanOfficersInBranch = this.staffReadPlatformService .retrieveAllLoanOfficersInOfficeById(officeId); @@ -239,8 +239,9 @@ public class LoansApiResource { // by default bring back all loan officers in selected // branch/office as well as loan officers in officer above // this office + final boolean restrictToLoanOfficersOnly = true; Collection loanOfficersInHierarchy = this.staffReadPlatformService - .retrieveAllLoanOfficersInOfficeAndItsParentOfficeHierarchy(officeId); + .retrieveAllStaffInOfficeAndItsParentOfficeHierarchy(officeId, restrictToLoanOfficersOnly); if (!CollectionUtils.isEmpty(loanOfficersInHierarchy)) { allowedLoanOfficers = new ArrayList(loanOfficersInHierarchy);