ensure retrieval of head office returns no allowedParents.

This commit is contained in:
Keith Woodlock
2012-08-22 13:15:51 +01:00
parent 9a3ab88996
commit 1aafc0b09d
2 changed files with 20 additions and 10 deletions
@@ -1,5 +1,6 @@
package org.mifosng.platform.api;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
@@ -81,6 +82,9 @@ public class OfficesApiResource {
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
OfficeData office = this.readPlatformService.retrieveNewOfficeTemplate();
List<OfficeLookup> allowedParents = new ArrayList<OfficeLookup>(this.readPlatformService.retrieveAllOfficesForLookup());
office = OfficeData.appendedTemplate(office, allowedParents);
typicalResponseParameters.add("allowedParents");
return this.apiJsonSerializerService.serializeOfficeDataToJson(prettyPrint, typicalResponseParameters, office);
}
@@ -141,24 +141,26 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
context.authenticatedUser();
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(
retrieveAllOfficesForLookup());
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>();
return OfficeData.template(parentLookups, new LocalDate());
}
@Override
public List<OfficeLookup> retrieveAllowedParents(Long officeId) {
public List<OfficeLookup> retrieveAllowedParents(final Long officeId) {
context.authenticatedUser();
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(retrieveAllOfficesForLookup());
List<OfficeLookup> filterParentLookups = new ArrayList<OfficeLookup>();
for (OfficeLookup office : parentLookups) {
if (!office.getId().equals(officeId)) {
filterParentLookups.add(office);
if (isNotHeadOffice(officeId)) {
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(retrieveAllOfficesForLookup());
for (OfficeLookup office : parentLookups) {
if (!office.getId().equals(officeId)) {
filterParentLookups.add(office);
}
}
}
@@ -166,6 +168,10 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
}
private boolean isNotHeadOffice(final Long officeId) {
return !Long.valueOf(1).equals(officeId);
}
@Override
public OfficeTransactionData retrieveNewOfficeTransactionDetails() {
context.authenticatedUser();