Merge pull request #395 from vishwasbabu/develop-old
updating client apis to allow linking with staff from parent offices
This commit is contained in:
@@ -1827,6 +1827,19 @@ function executeAjaxRequest(url, verbType, jsonData, basicAuthKey, successFuncti
|
|||||||
<li class=normalli>Allowed Value Lists</li>
|
<li class=normalli>Allowed Value Lists</li>
|
||||||
</ul>
|
</ul>
|
||||||
</p>
|
</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>
|
<p>Example Request:</p>
|
||||||
<div class=apiClick>clients/template</div>
|
<div class=apiClick>clients/template</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+11
-10
@@ -14,6 +14,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;
|
||||||
@@ -68,7 +69,7 @@ public class ClientsApiResource {
|
|||||||
final OfficeReadPlatformService officeReadPlatformService, final ToApiJsonSerializer<ClientData> toApiJsonSerializer,
|
final OfficeReadPlatformService officeReadPlatformService, final ToApiJsonSerializer<ClientData> toApiJsonSerializer,
|
||||||
final ToApiJsonSerializer<ClientAccountSummaryCollectionData> clientAccountSummaryToApiJsonSerializer,
|
final ToApiJsonSerializer<ClientAccountSummaryCollectionData> clientAccountSummaryToApiJsonSerializer,
|
||||||
final ApiRequestParameterHelper apiRequestParameterHelper,
|
final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
|
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
|
||||||
final StaffReadPlatformService staffReadPlatformService) {
|
final StaffReadPlatformService staffReadPlatformService) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.clientReadPlatformService = readPlatformService;
|
this.clientReadPlatformService = readPlatformService;
|
||||||
@@ -85,16 +86,17 @@ public class ClientsApiResource {
|
|||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveTemplate(@Context final UriInfo uriInfo, @QueryParam("officeId") final Long officeId,
|
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);
|
context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_RESOURCE_NAME);
|
||||||
|
|
||||||
ClientData clientData = null;
|
ClientData clientData = null;
|
||||||
context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_RESOURCE_NAME);
|
context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_RESOURCE_NAME);
|
||||||
if (is(commandParam, "close")) {
|
if (is(commandParam, "close")) {
|
||||||
clientData = this.clientReadPlatformService.retrieveAllClosureReasons(ClientApiConstants.CLIENT_CLOSURE_REASON);
|
clientData = this.clientReadPlatformService.retrieveAllClosureReasons(ClientApiConstants.CLIENT_CLOSURE_REASON);
|
||||||
}else{
|
} else {
|
||||||
clientData = this.clientReadPlatformService.retrieveTemplate(officeId);
|
clientData = this.clientReadPlatformService.retrieveTemplate(officeId, staffInSelectedOfficeOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
@@ -119,7 +121,7 @@ public class ClientsApiResource {
|
|||||||
final Page<ClientData> clientData = this.clientReadPlatformService.retrieveAll(searchParameters);
|
final Page<ClientData> clientData = this.clientReadPlatformService.retrieveAll(searchParameters);
|
||||||
|
|
||||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
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
|
@GET
|
||||||
@@ -213,14 +215,13 @@ public class ClientsApiResource {
|
|||||||
commandRequest = builder.unassignClientStaff(clientId).build();
|
commandRequest = builder.unassignClientStaff(clientId).build();
|
||||||
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
return this.toApiJsonSerializer.serialize(result);
|
return this.toApiJsonSerializer.serialize(result);
|
||||||
} else if(is(commandParam, "close")) {
|
} else if (is(commandParam, "close")) {
|
||||||
commandRequest = builder.closeClient(clientId).build();
|
commandRequest = builder.closeClient(clientId).build();
|
||||||
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) { throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate",
|
||||||
throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "unassignStaff", "assignStaff" });
|
"unassignStaff", "assignStaff" }); }
|
||||||
}
|
|
||||||
|
|
||||||
return this.toApiJsonSerializer.serialize(result);
|
return this.toApiJsonSerializer.serialize(result);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.portfolio.client.service;
|
package org.mifosplatform.portfolio.client.service;
|
||||||
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.service.Page;
|
import org.mifosplatform.infrastructure.core.service.Page;
|
||||||
@@ -16,7 +15,7 @@ import org.mifosplatform.portfolio.group.service.SearchParameters;
|
|||||||
|
|
||||||
public interface ClientReadPlatformService {
|
public interface ClientReadPlatformService {
|
||||||
|
|
||||||
ClientData retrieveTemplate(Long officeId);
|
ClientData retrieveTemplate(Long officeId, boolean staffInSelectedOfficeOnly);
|
||||||
|
|
||||||
Page<ClientData> retrieveAll(SearchParameters searchParameters);
|
Page<ClientData> retrieveAll(SearchParameters searchParameters);
|
||||||
|
|
||||||
@@ -33,6 +32,6 @@ public interface ClientReadPlatformService {
|
|||||||
ClientData retrieveClientByIdentifier(Long identifierTypeId, String identifierKey);
|
ClientData retrieveClientByIdentifier(Long identifierTypeId, String identifierKey);
|
||||||
|
|
||||||
Collection<ClientData> retrieveClientMembersOfGroup(Long groupId);
|
Collection<ClientData> retrieveClientMembersOfGroup(Long groupId);
|
||||||
|
|
||||||
ClientData retrieveAllClosureReasons(String clientClosureReason);
|
ClientData retrieveAllClosureReasons(String clientClosureReason);
|
||||||
}
|
}
|
||||||
+14
-6
@@ -73,19 +73,26 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientData retrieveTemplate(final Long officeId) {
|
public ClientData retrieveTemplate(final Long officeId, final boolean staffInSelectedOfficeOnly) {
|
||||||
|
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
final Long defaultOfficeId = defaultToUsersOfficeIfNull(officeId);
|
final Long defaultOfficeId = defaultToUsersOfficeIfNull(officeId);
|
||||||
|
|
||||||
final Collection<OfficeData> offices = officeReadPlatformService.retrieveAllOfficesForDropdown();
|
final Collection<OfficeData> offices = officeReadPlatformService.retrieveAllOfficesForDropdown();
|
||||||
|
|
||||||
Collection<StaffData> staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(defaultOfficeId);
|
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)) {
|
if (CollectionUtils.isEmpty(staffOptions)) {
|
||||||
staffOptions = null;
|
staffOptions = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ClientData.template(defaultOfficeId, new LocalDate(), offices, staffOptions, null);
|
return ClientData.template(defaultOfficeId, new LocalDate(), offices, staffOptions, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,7 +589,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
|||||||
officeName);
|
officeName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Long defaultToUsersOfficeIfNull(final Long officeId) {
|
private Long defaultToUsersOfficeIfNull(final Long officeId) {
|
||||||
Long defaultOfficeId = officeId;
|
Long defaultOfficeId = officeId;
|
||||||
if (defaultOfficeId == null) {
|
if (defaultOfficeId == null) {
|
||||||
@@ -593,7 +600,8 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientData retrieveAllClosureReasons(String clientClosureReason) {
|
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);
|
return ClientData.template(null, null, null, null, closureReasons);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-7
@@ -71,8 +71,9 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
|||||||
public ClientWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
public ClientWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
||||||
final ClientRepositoryWrapper clientRepository, final OfficeRepository officeRepository, final NoteRepository noteRepository,
|
final ClientRepositoryWrapper clientRepository, final OfficeRepository officeRepository, final NoteRepository noteRepository,
|
||||||
final ClientDataValidator fromApiJsonDeserializer, final AccountNumberGeneratorFactory accountIdentifierGeneratorFactory,
|
final ClientDataValidator fromApiJsonDeserializer, final AccountNumberGeneratorFactory accountIdentifierGeneratorFactory,
|
||||||
final GroupRepository groupRepository, final StaffRepositoryWrapper staffRepository, final CodeValueRepositoryWrapper codeValueRepository,
|
final GroupRepository groupRepository, final StaffRepositoryWrapper staffRepository,
|
||||||
final LoanRepository loanRepository, final SavingsAccountRepository savingsRepository) {
|
final CodeValueRepositoryWrapper codeValueRepository, final LoanRepository loanRepository,
|
||||||
|
final SavingsAccountRepository savingsRepository) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.clientRepository = clientRepository;
|
this.clientRepository = clientRepository;
|
||||||
this.officeRepository = officeRepository;
|
this.officeRepository = officeRepository;
|
||||||
@@ -154,7 +155,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
|||||||
Staff staff = null;
|
Staff staff = null;
|
||||||
final Long staffId = command.longValueOfParameterNamed(ClientApiConstants.staffIdParamName);
|
final Long staffId = command.longValueOfParameterNamed(ClientApiConstants.staffIdParamName);
|
||||||
if (staffId != null) {
|
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);
|
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 Client clientForUpdate = this.clientRepository.findOneWithNotFoundDetection(clientId);
|
||||||
final String clientHierarchy = clientForUpdate.getOffice().getHierarchy();
|
final String clientHierarchy = clientForUpdate.getOffice().getHierarchy();
|
||||||
|
|
||||||
this.context.validateAccessRights(clientHierarchy);
|
this.context.validateAccessRights(clientHierarchy);
|
||||||
|
|
||||||
final Map<String, Object> changes = clientForUpdate.update(command);
|
final Map<String, Object> changes = clientForUpdate.update(command);
|
||||||
@@ -202,7 +203,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
|||||||
final Long newValue = command.longValueOfParameterNamed(ClientApiConstants.staffIdParamName);
|
final Long newValue = command.longValueOfParameterNamed(ClientApiConstants.staffIdParamName);
|
||||||
Staff newStaff = null;
|
Staff newStaff = null;
|
||||||
if (newValue != null) {
|
if (newValue != null) {
|
||||||
newStaff = this.staffRepository.findByOfficeWithNotFoundDetection(newValue, clientForUpdate.officeId());
|
newStaff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(newValue, clientForUpdate.getOffice()
|
||||||
|
.getHierarchy());
|
||||||
}
|
}
|
||||||
clientForUpdate.updateStaff(newStaff);
|
clientForUpdate.updateStaff(newStaff);
|
||||||
}
|
}
|
||||||
@@ -303,7 +305,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
|||||||
Staff staff = null;
|
Staff staff = null;
|
||||||
final Long staffId = command.longValueOfParameterNamed(ClientApiConstants.staffIdParamName);
|
final Long staffId = command.longValueOfParameterNamed(ClientApiConstants.staffIdParamName);
|
||||||
if (staffId != null) {
|
if (staffId != null) {
|
||||||
staff = this.staffRepository.findByOfficeWithNotFoundDetection(staffId, clientForUpdate.officeId());
|
staff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(staffId, clientForUpdate.getOffice().getHierarchy());
|
||||||
clientForUpdate.assignStaff(staff);
|
clientForUpdate.assignStaff(staff);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +321,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
|||||||
.with(actualChanges) //
|
.with(actualChanges) //
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult closeClient(final Long clientId, final JsonCommand command) {
|
public CommandProcessingResult closeClient(final Long clientId, final JsonCommand command) {
|
||||||
|
|||||||
Reference in New Issue
Block a user