From a99997f5dec9b2e8eba5215ddd934b40171be40b Mon Sep 17 00:00:00 2001 From: ashok-conflux Date: Thu, 29 Aug 2013 16:47:30 +0530 Subject: [PATCH] fixed MIFOSX-613 loan office assignment issue --- .../service/StaffReadPlatformServiceImpl.java | 2 +- .../loanaccount/api/LoansApiResource.java | 70 ++----------------- .../LoanEventApiJsonValidator.java | 13 ++-- .../service/LoanReadPlatformService.java | 3 + .../service/LoanReadPlatformServiceImpl.java | 27 ++++++- 5 files changed, 45 insertions(+), 70 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformServiceImpl.java index 52422e9b0..3d7c8808a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffReadPlatformServiceImpl.java @@ -63,7 +63,7 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService { public String schema(final boolean loanOfficersOnly) { StringBuilder sqlBuilder = new StringBuilder(200); - sqlBuilder.append("s.id as id, s.office_id as officeId, o.name as officeName,"); + sqlBuilder.append("s.id as id, s.office_id as officeId, ohierarchy.name as officeName,"); sqlBuilder.append("s.firstname as firstname, s.lastname as lastname,"); sqlBuilder.append("s.display_name as displayName, s.is_loan_officer as isLoanOfficer, s.external_id as externalId "); sqlBuilder.append("from m_office o "); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java index 3dd0ec068..9e60bca46 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java @@ -5,7 +5,6 @@ */ package org.mifosplatform.portfolio.loanaccount.api; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -26,7 +25,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; import org.apache.commons.lang.StringUtils; -import org.joda.time.LocalDate; import org.mifosplatform.commands.domain.CommandWrapper; import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; @@ -43,9 +41,7 @@ import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSeria import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; import org.mifosplatform.infrastructure.core.service.Page; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; -import org.mifosplatform.organisation.staff.data.BulkTransferLoanOfficerData; import org.mifosplatform.organisation.staff.data.StaffData; -import org.mifosplatform.organisation.staff.service.StaffReadPlatformService; import org.mifosplatform.portfolio.calendar.data.CalendarData; import org.mifosplatform.portfolio.calendar.service.CalendarReadPlatformService; import org.mifosplatform.portfolio.charge.data.ChargeData; @@ -113,13 +109,11 @@ public class LoansApiResource { private final LoanChargeReadPlatformService loanChargeReadPlatformService; private final CollateralReadPlatformService loanCollateralReadPlatformService; private final LoanScheduleCalculationPlatformService calculationPlatformService; - private final StaffReadPlatformService staffReadPlatformService; private final GuarantorReadPlatformService guarantorReadPlatformService; private final CodeValueReadPlatformService codeValueReadPlatformService; private final GroupReadPlatformService groupReadPlatformService; private final DefaultToApiJsonSerializer toApiJsonSerializer; private final DefaultToApiJsonSerializer loanScheduleToApiJsonSerializer; - private final DefaultToApiJsonSerializer loanOfficeTransferToApiJsonSerializer; private final ApiRequestParameterHelper apiRequestParameterHelper; private final FromJsonHelper fromJsonHelper; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; @@ -133,11 +127,10 @@ public class LoansApiResource { final ChargeReadPlatformService chargeReadPlatformService, final LoanChargeReadPlatformService loanChargeReadPlatformService, final CollateralReadPlatformService loanCollateralReadPlatformService, final LoanScheduleCalculationPlatformService calculationPlatformService, - final StaffReadPlatformService staffReadPlatformService, final GuarantorReadPlatformService guarantorReadPlatformService, + final GuarantorReadPlatformService guarantorReadPlatformService, final CodeValueReadPlatformService codeValueReadPlatformService, final GroupReadPlatformService groupReadPlatformService, final DefaultToApiJsonSerializer toApiJsonSerializer, final DefaultToApiJsonSerializer loanScheduleToApiJsonSerializer, - final DefaultToApiJsonSerializer loanOfficeTransferToApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper, final FromJsonHelper fromJsonHelper, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final CalendarReadPlatformService calendarReadPlatformService, final NoteReadPlatformServiceImpl noteReadPlatformService) { @@ -150,13 +143,11 @@ public class LoansApiResource { this.loanChargeReadPlatformService = loanChargeReadPlatformService; this.loanCollateralReadPlatformService = loanCollateralReadPlatformService; this.calculationPlatformService = calculationPlatformService; - this.staffReadPlatformService = staffReadPlatformService; this.guarantorReadPlatformService = guarantorReadPlatformService; this.codeValueReadPlatformService = codeValueReadPlatformService; this.groupReadPlatformService = groupReadPlatformService; this.toApiJsonSerializer = toApiJsonSerializer; this.loanScheduleToApiJsonSerializer = loanScheduleToApiJsonSerializer; - this.loanOfficeTransferToApiJsonSerializer = loanOfficeTransferToApiJsonSerializer; this.apiRequestParameterHelper = apiRequestParameterHelper; this.fromJsonHelper = fromJsonHelper; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; @@ -233,28 +224,7 @@ public class LoansApiResource { throw new NotSupportedLoanTemplateTypeException(errorMsg, templateType); } - if (officeId != null) { - if (staffInSelectedOfficeOnly) { - // only bring back loan officers in selected branch/office - Collection loanOfficersInBranch = this.staffReadPlatformService - .retrieveAllLoanOfficersInOfficeById(officeId); - - if (!CollectionUtils.isEmpty(loanOfficersInBranch)) { - allowedLoanOfficers = new ArrayList(loanOfficersInBranch); - } - } else { - // by default bring back all loan officers in selected - // branch/office as well as loan officers in officer above - // this office - final boolean restrictToLoanOfficersOnly = true; - Collection loanOfficersInHierarchy = this.staffReadPlatformService - .retrieveAllStaffInOfficeAndItsParentOfficeHierarchy(officeId, restrictToLoanOfficersOnly); - - if (!CollectionUtils.isEmpty(loanOfficersInHierarchy)) { - allowedLoanOfficers = new ArrayList(loanOfficersInHierarchy); - } - } - } + allowedLoanOfficers = this.loanReadPlatformService.retrieveAllowedLoanOfficers(officeId, staffInSelectedOfficeOnly); // add product options, allowed loan officers and calendar options // (calendar options will be null in individual loan) @@ -268,7 +238,9 @@ public class LoansApiResource { @Path("{loanId}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public String retrieveLoan(@PathParam("loanId") final Long loanId, @Context final UriInfo uriInfo) { + public String retrieveLoan(@PathParam("loanId") final Long loanId, + @DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly, + @Context final UriInfo uriInfo) { context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions); @@ -376,11 +348,7 @@ public class LoansApiResource { chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly); chargeTemplate = this.loanChargeReadPlatformService.retrieveLoanChargeTemplate(); - if (loanBasicDetails.officeId() != null) { - allowedLoanOfficers = this.staffReadPlatformService.retrieveAllLoanOfficersInOfficeById(loanBasicDetails.officeId()); - } else if (loanBasicDetails.groupOfficeId() != null) { - allowedLoanOfficers = this.staffReadPlatformService.retrieveAllLoanOfficersInOfficeById(loanBasicDetails.groupOfficeId()); - } + allowedLoanOfficers = this.loanReadPlatformService.retrieveAllowedLoanOfficers(loanBasicDetails.officeId(), staffInSelectedOfficeOnly); loanPurposeOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode("LoanPurpose"); loanCollateralOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode("LoanCollateral"); @@ -520,30 +488,4 @@ public class LoansApiResource { private boolean is(final String commandParam, final String commandValue) { return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue); } - - @GET - @Path("{loanId}/assign/template") - @Consumes({ MediaType.APPLICATION_JSON }) - @Produces({ MediaType.APPLICATION_JSON }) - public String assignLoanOfficerTemplate(@PathParam("loanId") final Long loanId, @Context final UriInfo uriInfo) { - - // TODO - KW - review if this template method can be put back into - // normal - // template method to avoid 'assign' on api. and avoid needing to query - // for officeId and loanOfficerId in current way! - final LoanAccountData loanBasicDetails = this.loanReadPlatformService.retrieveOne(loanId); - - final Collection allowedLoanOfficers = this.staffReadPlatformService - .retrieveAllLoanOfficersInOfficeById(loanBasicDetails.officeId()); - final Long fromLoanOfficerId = loanBasicDetails.loanOfficerId(); - - final BulkTransferLoanOfficerData loanReassignmentData = BulkTransferLoanOfficerData.template(fromLoanOfficerId, - allowedLoanOfficers, new LocalDate()); - - final Set RESPONSE_DATA_PARAMETERS = new HashSet(Arrays.asList("officeId", "fromLoanOfficerId", "assignmentDate", - "officeOptions", "loanOfficerOptions", "accountSummaryCollection")); - - final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); - return this.loanOfficeTransferToApiJsonSerializer.serialize(settings, loanReassignmentData, RESPONSE_DATA_PARAMETERS); - } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanEventApiJsonValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanEventApiJsonValidator.java index 506a1e9f3..478e1430b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanEventApiJsonValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanEventApiJsonValidator.java @@ -255,12 +255,17 @@ public final class LoanEventApiJsonValidator { final JsonElement element = fromApiJsonHelper.parse(json); - // final Long fromLoanOfficerId = - // fromApiJsonHelper.extractLongNamed("fromLoanOfficerId", element); final Long toLoanOfficerId = fromApiJsonHelper.extractLongNamed("toLoanOfficerId", element); + baseDataValidator.reset().parameter("toLoanOfficerId").value(toLoanOfficerId).notNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("toLoanOfficerId").value(toLoanOfficerId).ignoreIfNull().integerGreaterThanZero(); - + final String assignmentDateStr = this.fromApiJsonHelper.extractStringNamed("assignmentDate", element); + baseDataValidator.reset().parameter("assignmentDate").value(assignmentDateStr).notBlank(); + + if(!StringUtils.isBlank(assignmentDateStr)){ + final LocalDate assignmentDate = this.fromApiJsonHelper.extractLocalDateNamed("assignmentDate", element); + baseDataValidator.reset().parameter("assignmentDate").value(assignmentDate).notNull(); + } + throwExceptionIfValidationWarningsExist(dataValidationErrors); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformService.java index d4f1c55f3..4354bd0ee 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformService.java @@ -8,6 +8,7 @@ package org.mifosplatform.portfolio.loanaccount.service; import java.util.Collection; import org.mifosplatform.infrastructure.core.service.Page; +import org.mifosplatform.organisation.staff.data.StaffData; import org.mifosplatform.portfolio.calendar.data.CalendarData; import org.mifosplatform.portfolio.group.service.SearchParameters; import org.mifosplatform.portfolio.loanaccount.data.LoanAccountData; @@ -50,4 +51,6 @@ public interface LoanReadPlatformService { Collection retrieveCalendars(Long groupId); Page retrieveAll(SearchParameters searchParameters); + + Collection retrieveAllowedLoanOfficers(Long selectedOfficeId, boolean staffInSelectedOfficeOnly); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java index bc95be622..294fc2fbb 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java @@ -29,6 +29,8 @@ import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency; import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepositoryWrapper; import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency; import org.mifosplatform.organisation.monetary.domain.Money; +import org.mifosplatform.organisation.staff.data.StaffData; +import org.mifosplatform.organisation.staff.service.StaffReadPlatformService; import org.mifosplatform.portfolio.accountdetails.service.AccountEnumerations; import org.mifosplatform.portfolio.calendar.data.CalendarData; import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType; @@ -94,6 +96,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { private final ChargeReadPlatformService chargeReadPlatformService; private final CodeValueReadPlatformService codeValueReadPlatformService; private final CalendarReadPlatformService calendarReadPlatformService; + private final StaffReadPlatformService staffReadPlatformService; private final PaginationHelper paginationHelper = new PaginationHelper(); private final LoanMapper loaanLoanMapper = new LoanMapper(); @@ -105,7 +108,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { final GroupReadPlatformService groupReadPlatformService, final LoanDropdownReadPlatformService loanDropdownReadPlatformService, final FundReadPlatformService fundReadPlatformService, final ChargeReadPlatformService chargeReadPlatformService, final CodeValueReadPlatformService codeValueReadPlatformService, final RoutingDataSource dataSource, - final CalendarReadPlatformService calendarReadPlatformService) { + final CalendarReadPlatformService calendarReadPlatformService, final StaffReadPlatformService staffReadPlatformService) { this.context = context; this.loanRepository = loanRepository; this.loanTransactionRepository = loanTransactionRepository; @@ -118,6 +121,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { this.chargeReadPlatformService = chargeReadPlatformService; this.codeValueReadPlatformService = codeValueReadPlatformService; this.calendarReadPlatformService = calendarReadPlatformService; + this.staffReadPlatformService = staffReadPlatformService; this.jdbcTemplate = new JdbcTemplate(dataSource); } @@ -982,4 +986,25 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { return calendarsData; } + @Override + public Collection retrieveAllowedLoanOfficers(Long selectedOfficeId, boolean staffInSelectedOfficeOnly) { + if (selectedOfficeId == null) return null; + + Collection allowedLoanOfficers = null; + + if (staffInSelectedOfficeOnly) { + // only bring back loan officers in selected branch/office + allowedLoanOfficers = this.staffReadPlatformService.retrieveAllLoanOfficersInOfficeById(selectedOfficeId); + } else { + // by default bring back all loan officers in selected + // branch/office as well as loan officers in officer above + // this office + final boolean restrictToLoanOfficersOnly = true; + allowedLoanOfficers = this.staffReadPlatformService.retrieveAllStaffInOfficeAndItsParentOfficeHierarchy(selectedOfficeId, + restrictToLoanOfficersOnly); + } + + return allowedLoanOfficers; + } + } \ No newline at end of file