From 4f5db16722483417e787879afc2b2b7c5afd7537 Mon Sep 17 00:00:00 2001 From: ashok-conflux Date: Wed, 13 Nov 2013 15:56:54 +0530 Subject: [PATCH] display parent offices staff for creating a center --- .../portfolio/group/api/CentersApiResource.java | 11 +++++++---- .../group/service/CenterReadPlatformService.java | 2 +- .../group/service/CenterReadPlatformServiceImpl.java | 12 ++++++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java index ea52302cd..58798399a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.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; @@ -98,7 +99,8 @@ public class CentersApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String retrieveTemplate(@Context final UriInfo uriInfo, @QueryParam("command") final String commandParam, - @QueryParam("officeId") final Long officeId) { + @QueryParam("officeId") final Long officeId, + @DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly) { this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.CENTER_RESOURCE_NAME); @@ -109,7 +111,7 @@ public class CentersApiResource { GroupingTypesApiConstants.CENTER_RESPONSE_DATA_PARAMETERS); } - final CenterData template = this.centerReadPlatformService.retrieveTemplate(officeId); + final CenterData template = this.centerReadPlatformService.retrieveTemplate(officeId, staffInSelectedOfficeOnly); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.centerApiJsonSerializer.serialize(settings, template, GroupingTypesApiConstants.CENTER_RESPONSE_DATA_PARAMETERS); @@ -138,7 +140,8 @@ public class CentersApiResource { @Path("{centerId}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public String retrieveOne(@Context final UriInfo uriInfo, @PathParam("centerId") final Long centerId) { + public String retrieveOne(@Context final UriInfo uriInfo, @PathParam("centerId") final Long centerId, + @DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly) { this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.CENTER_RESOURCE_NAME); final Set associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters()); @@ -148,7 +151,7 @@ public class CentersApiResource { final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); if (template) { - final CenterData templateCenter = this.centerReadPlatformService.retrieveTemplate(center.officeId()); + final CenterData templateCenter = this.centerReadPlatformService.retrieveTemplate(center.officeId(), staffInSelectedOfficeOnly); center = CenterData.withTemplate(templateCenter, center); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformService.java index 4fa01bd13..240c9879b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformService.java @@ -13,7 +13,7 @@ import org.mifosplatform.portfolio.group.data.GroupGeneralData; public interface CenterReadPlatformService { - CenterData retrieveTemplate(Long officeId); + CenterData retrieveTemplate(Long officeId, boolean staffInSelectedOfficeOnly); CenterData retrieveOne(Long centerId); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformServiceImpl.java index 7175c324b..5453c9e6a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformServiceImpl.java @@ -239,13 +239,21 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService } @Override - public CenterData retrieveTemplate(final Long officeId) { + public CenterData retrieveTemplate(final Long officeId, final boolean staffInSelectedOfficeOnly) { final Long officeIdDefaulted = defaultToUsersOfficeIfNull(officeId); final Collection officeOptions = this.officeReadPlatformService.retrieveAllOfficesForDropdown(); + + final boolean loanOfficersOnly = false; + Collection staffOptions = null; + if (staffInSelectedOfficeOnly) { + staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(officeIdDefaulted); + } else { + staffOptions = this.staffReadPlatformService.retrieveAllStaffInOfficeAndItsParentOfficeHierarchy(officeIdDefaulted, + loanOfficersOnly); + } - Collection staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(officeIdDefaulted); if (CollectionUtils.isEmpty(staffOptions)) { staffOptions = null; }