Merge pull request #395 from vishwasbabu/develop-old

updating client apis to allow linking with staff from parent offices
This commit is contained in:
Vishwas Babu A J
2013-06-24 07:26:01 -07:00
5 changed files with 50 additions and 27 deletions
+13
View File
@@ -1827,6 +1827,19 @@ function executeAjaxRequest(url, verbType, jsonData, basicAuthKey, successFuncti
<li class=normalli>Allowed Value Lists</li>
</ul>
</p>
<h5>Arguments</h5>
<dl class="argument-list">
<dt>officeId</dt>
<dd>
Integer <span>optional</span>
</dd>
<dt>staffInSelectedOfficeOnly</dt>
<dd>
Boolean <span>optional</span>
</dd>
<dd>Defaults to false if not provided. If <strong>staffInSelectedOfficeOnly=true</strong> only staff
who are associated with the selected branch are returned.</dd>
</dl>
<p>Example Request:</p>
<div class=apiClick>clients/template</div>
</div>
@@ -14,6 +14,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;
@@ -68,7 +69,7 @@ public class ClientsApiResource {
final OfficeReadPlatformService officeReadPlatformService, final ToApiJsonSerializer<ClientData> toApiJsonSerializer,
final ToApiJsonSerializer<ClientAccountSummaryCollectionData> clientAccountSummaryToApiJsonSerializer,
final ApiRequestParameterHelper apiRequestParameterHelper,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final StaffReadPlatformService staffReadPlatformService) {
this.context = context;
this.clientReadPlatformService = readPlatformService;
@@ -85,16 +86,17 @@ public class ClientsApiResource {
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveTemplate(@Context final UriInfo uriInfo, @QueryParam("officeId") final Long officeId,
@QueryParam("commandParam") final String commandParam) {
@QueryParam("commandParam") final String commandParam,
@DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly) {
context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_RESOURCE_NAME);
ClientData clientData = null;
context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_RESOURCE_NAME);
if (is(commandParam, "close")) {
clientData = this.clientReadPlatformService.retrieveAllClosureReasons(ClientApiConstants.CLIENT_CLOSURE_REASON);
}else{
clientData = this.clientReadPlatformService.retrieveTemplate(officeId);
clientData = this.clientReadPlatformService.retrieveAllClosureReasons(ClientApiConstants.CLIENT_CLOSURE_REASON);
} else {
clientData = this.clientReadPlatformService.retrieveTemplate(officeId, staffInSelectedOfficeOnly);
}
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
@@ -119,7 +121,7 @@ public class ClientsApiResource {
final Page<ClientData> clientData = this.clientReadPlatformService.retrieveAll(searchParameters);
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, clientData , ClientApiConstants.CLIENT_RESPONSE_DATA_PARAMETERS);
return this.toApiJsonSerializer.serialize(settings, clientData, ClientApiConstants.CLIENT_RESPONSE_DATA_PARAMETERS);
}
@GET
@@ -213,14 +215,13 @@ public class ClientsApiResource {
commandRequest = builder.unassignClientStaff(clientId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
} else if(is(commandParam, "close")) {
} else if (is(commandParam, "close")) {
commandRequest = builder.closeClient(clientId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
if (result == null) {
throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "unassignStaff", "assignStaff" });
}
if (result == null) { throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate",
"unassignStaff", "assignStaff" }); }
return this.toApiJsonSerializer.serialize(result);
}
@@ -5,7 +5,6 @@
*/
package org.mifosplatform.portfolio.client.service;
import java.util.Collection;
import org.mifosplatform.infrastructure.core.service.Page;
@@ -16,7 +15,7 @@ import org.mifosplatform.portfolio.group.service.SearchParameters;
public interface ClientReadPlatformService {
ClientData retrieveTemplate(Long officeId);
ClientData retrieveTemplate(Long officeId, boolean staffInSelectedOfficeOnly);
Page<ClientData> retrieveAll(SearchParameters searchParameters);
@@ -33,6 +32,6 @@ public interface ClientReadPlatformService {
ClientData retrieveClientByIdentifier(Long identifierTypeId, String identifierKey);
Collection<ClientData> retrieveClientMembersOfGroup(Long groupId);
ClientData retrieveAllClosureReasons(String clientClosureReason);
ClientData retrieveAllClosureReasons(String clientClosureReason);
}
@@ -73,19 +73,26 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
}
@Override
public ClientData retrieveTemplate(final Long officeId) {
public ClientData retrieveTemplate(final Long officeId, final boolean staffInSelectedOfficeOnly) {
this.context.authenticatedUser();
final Long defaultOfficeId = defaultToUsersOfficeIfNull(officeId);
final Collection<OfficeData> offices = officeReadPlatformService.retrieveAllOfficesForDropdown();
Collection<StaffData> staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(defaultOfficeId);
final boolean loanOfficersOnly = false;
if (staffInSelectedOfficeOnly) {
staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(defaultOfficeId);
} else {
staffOptions = this.staffReadPlatformService.retrieveAllStaffInOfficeAndItsParentOfficeHierarchy(defaultOfficeId,
loanOfficersOnly);
}
if (CollectionUtils.isEmpty(staffOptions)) {
staffOptions = null;
}
return ClientData.template(defaultOfficeId, new LocalDate(), offices, staffOptions, null);
}
@@ -582,7 +589,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
officeName);
}
}
private Long defaultToUsersOfficeIfNull(final Long officeId) {
Long defaultOfficeId = officeId;
if (defaultOfficeId == null) {
@@ -593,7 +600,8 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
@Override
public ClientData retrieveAllClosureReasons(String clientClosureReason) {
final List<CodeValueData> closureReasons = new ArrayList<CodeValueData>(codeValueReadPlatformService.retrieveCodeValuesByCode(clientClosureReason));
final List<CodeValueData> closureReasons = new ArrayList<CodeValueData>(
codeValueReadPlatformService.retrieveCodeValuesByCode(clientClosureReason));
return ClientData.template(null, null, null, null, closureReasons);
}
@@ -71,8 +71,9 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
public ClientWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
final ClientRepositoryWrapper clientRepository, final OfficeRepository officeRepository, final NoteRepository noteRepository,
final ClientDataValidator fromApiJsonDeserializer, final AccountNumberGeneratorFactory accountIdentifierGeneratorFactory,
final GroupRepository groupRepository, final StaffRepositoryWrapper staffRepository, final CodeValueRepositoryWrapper codeValueRepository,
final LoanRepository loanRepository, final SavingsAccountRepository savingsRepository) {
final GroupRepository groupRepository, final StaffRepositoryWrapper staffRepository,
final CodeValueRepositoryWrapper codeValueRepository, final LoanRepository loanRepository,
final SavingsAccountRepository savingsRepository) {
this.context = context;
this.clientRepository = clientRepository;
this.officeRepository = officeRepository;
@@ -154,7 +155,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
Staff staff = null;
final Long staffId = command.longValueOfParameterNamed(ClientApiConstants.staffIdParamName);
if (staffId != null) {
staff = this.staffRepository.findByOfficeWithNotFoundDetection(staffId, officeId);
staff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(staffId, clientOffice.getHierarchy());
}
final Client newClient = Client.createNew(clientOffice, clientParentGroup, staff, command);
@@ -192,7 +193,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
final Client clientForUpdate = this.clientRepository.findOneWithNotFoundDetection(clientId);
final String clientHierarchy = clientForUpdate.getOffice().getHierarchy();
this.context.validateAccessRights(clientHierarchy);
final Map<String, Object> changes = clientForUpdate.update(command);
@@ -202,7 +203,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
final Long newValue = command.longValueOfParameterNamed(ClientApiConstants.staffIdParamName);
Staff newStaff = null;
if (newValue != null) {
newStaff = this.staffRepository.findByOfficeWithNotFoundDetection(newValue, clientForUpdate.officeId());
newStaff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(newValue, clientForUpdate.getOffice()
.getHierarchy());
}
clientForUpdate.updateStaff(newStaff);
}
@@ -303,7 +305,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
Staff staff = null;
final Long staffId = command.longValueOfParameterNamed(ClientApiConstants.staffIdParamName);
if (staffId != null) {
staff = this.staffRepository.findByOfficeWithNotFoundDetection(staffId, clientForUpdate.officeId());
staff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(staffId, clientForUpdate.getOffice().getHierarchy());
clientForUpdate.assignStaff(staff);
}
@@ -319,7 +321,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
.with(actualChanges) //
.build();
}
@Transactional
@Override
public CommandProcessingResult closeClient(final Long clientId, final JsonCommand command) {