Merge pull request #665 from ashok-conflux/MIFOSX-783

display parent offices staff for creating a center
This commit is contained in:
Keith Woodlock
2013-11-14 04:43:08 -08:00
3 changed files with 18 additions and 7 deletions
@@ -12,6 +12,7 @@ import java.util.Set;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.PUT; import javax.ws.rs.PUT;
@@ -98,7 +99,8 @@ public class CentersApiResource {
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String retrieveTemplate(@Context final UriInfo uriInfo, @QueryParam("command") final String commandParam, 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); this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.CENTER_RESOURCE_NAME);
@@ -109,7 +111,7 @@ public class CentersApiResource {
GroupingTypesApiConstants.CENTER_RESPONSE_DATA_PARAMETERS); 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()); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.centerApiJsonSerializer.serialize(settings, template, GroupingTypesApiConstants.CENTER_RESPONSE_DATA_PARAMETERS); return this.centerApiJsonSerializer.serialize(settings, template, GroupingTypesApiConstants.CENTER_RESPONSE_DATA_PARAMETERS);
@@ -138,7 +140,8 @@ public class CentersApiResource {
@Path("{centerId}") @Path("{centerId}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ 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); this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.CENTER_RESOURCE_NAME);
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters()); final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
@@ -148,7 +151,7 @@ public class CentersApiResource {
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
if (template) { if (template) {
final CenterData templateCenter = this.centerReadPlatformService.retrieveTemplate(center.officeId()); final CenterData templateCenter = this.centerReadPlatformService.retrieveTemplate(center.officeId(), staffInSelectedOfficeOnly);
center = CenterData.withTemplate(templateCenter, center); center = CenterData.withTemplate(templateCenter, center);
} }
@@ -13,7 +13,7 @@ import org.mifosplatform.portfolio.group.data.GroupGeneralData;
public interface CenterReadPlatformService { public interface CenterReadPlatformService {
CenterData retrieveTemplate(Long officeId); CenterData retrieveTemplate(Long officeId, boolean staffInSelectedOfficeOnly);
CenterData retrieveOne(Long centerId); CenterData retrieveOne(Long centerId);
@@ -239,13 +239,21 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
} }
@Override @Override
public CenterData retrieveTemplate(final Long officeId) { public CenterData retrieveTemplate(final Long officeId, final boolean staffInSelectedOfficeOnly) {
final Long officeIdDefaulted = defaultToUsersOfficeIfNull(officeId); final Long officeIdDefaulted = defaultToUsersOfficeIfNull(officeId);
final Collection<OfficeData> officeOptions = this.officeReadPlatformService.retrieveAllOfficesForDropdown(); final Collection<OfficeData> officeOptions = this.officeReadPlatformService.retrieveAllOfficesForDropdown();
final boolean loanOfficersOnly = false;
Collection<StaffData> staffOptions = null;
if (staffInSelectedOfficeOnly) {
staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(officeIdDefaulted);
} else {
staffOptions = this.staffReadPlatformService.retrieveAllStaffInOfficeAndItsParentOfficeHierarchy(officeIdDefaulted,
loanOfficersOnly);
}
Collection<StaffData> staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(officeIdDefaulted);
if (CollectionUtils.isEmpty(staffOptions)) { if (CollectionUtils.isEmpty(staffOptions)) {
staffOptions = null; staffOptions = null;
} }