diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/StaffApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/StaffApiResource.java index 0e88ef988..c78914498 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/StaffApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/StaffApiResource.java @@ -164,22 +164,22 @@ public class StaffApiResource { .extractFieldsForResponseIfProvided(uriInfo .getQueryParameters()); - final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo - .getQueryParameters()); + final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); - Collection offices = this.officeReadPlatformService.retrieveAllOfficesForLookup(); + final Collection offices = this.officeReadPlatformService.retrieveAllOfficesForLookup(); Collection loanOfficers = null; StaffAccountSummaryCollectionData staffAccountSummaryCollectionData = null; - if (officeId != null){ + if (officeId != null) { loanOfficers = this.readPlatformService.retrieveAllLoanOfficersByOffice(officeId); } - if (loanOfficerId != null){ + + if (loanOfficerId != null) { staffAccountSummaryCollectionData = this.readPlatformService.retrieveLoanOfficerAccountSummary(loanOfficerId); } - LoanReassignmentData loanReassignmentData = new LoanReassignmentData(officeId, loanOfficerId, offices, + final LoanReassignmentData loanReassignmentData = new LoanReassignmentData(officeId, loanOfficerId, offices, loanOfficers, staffAccountSummaryCollectionData); return this.apiJsonSerializerService.serializeLoanReassignmentDataToJson(prettyPrint, responseParameters, loanReassignmentData); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/BulkLoanReassignmentCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/BulkLoanReassignmentCommand.java index 8e22cf59d..359c44556 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/BulkLoanReassignmentCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/BulkLoanReassignmentCommand.java @@ -1,35 +1,31 @@ package org.mifosng.platform.api.commands; - -import java.util.Set; - +/** + * Immutable data object for reassigning loan officers on loans in bulk. + */ public class BulkLoanReassignmentCommand { - private final Long fromLoanOfficerId; - private final Long toLoanOfficerId; + private final Long fromLoanOfficerId; + private final Long toLoanOfficerId; - private final String[] loans; + private final String[] loans; - private final Set modifiedParameters; + public BulkLoanReassignmentCommand(Long fromLoanOfficerId, + Long toLoanOfficerId, String[] loans) { + this.fromLoanOfficerId = fromLoanOfficerId; + this.toLoanOfficerId = toLoanOfficerId; + this.loans = loans; + } - public BulkLoanReassignmentCommand(Set modifiedParameters, Long fromLoanOfficerId, - Long toLoanOfficerId, String[] loans) { - this.fromLoanOfficerId = fromLoanOfficerId; - this.toLoanOfficerId = toLoanOfficerId; - this.loans = loans; - this.modifiedParameters = modifiedParameters; - } + public Long getFromLoanOfficerId() { + return fromLoanOfficerId; + } - public Long getFromLoanOfficerId() { - return fromLoanOfficerId; - } + public Long getToLoanOfficerId() { + return toLoanOfficerId; + } - public Long getToLoanOfficerId() { - return toLoanOfficerId; - } - - public String[] getLoans() { - return loans; - } - -} + public String[] getLoans() { + return loans; + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanReassignmentData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanReassignmentData.java index efd883ec3..e59618bfb 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanReassignmentData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/LoanReassignmentData.java @@ -2,45 +2,34 @@ package org.mifosng.platform.api.data; import java.util.Collection; +/** + * Immutable data object returned for loan-officer reassignment screens. + */ public class LoanReassignmentData { - private final Long officeId; + @SuppressWarnings("unused") + private final Long officeId; + @SuppressWarnings("unused") private final Long fromLoanOfficerId; //template + @SuppressWarnings("unused") private final Collection officeOptions; - + @SuppressWarnings("unused") private final Collection loanOfficerOptions; - + @SuppressWarnings("unused") private final StaffAccountSummaryCollectionData accountSummaryCollection; - public LoanReassignmentData(Long officeId, Long fromLoanOfficerId, - Collection officeOptions, Collection loanOfficerOptions, - StaffAccountSummaryCollectionData accountSummaryCollection) { + public LoanReassignmentData( + final Long officeId, + final Long fromLoanOfficerId, + final Collection officeOptions, + final Collection loanOfficerOptions, + final StaffAccountSummaryCollectionData accountSummaryCollection) { this.officeId = officeId; this.fromLoanOfficerId = fromLoanOfficerId; this.officeOptions = officeOptions; this.loanOfficerOptions = loanOfficerOptions; this.accountSummaryCollection = accountSummaryCollection; } - - public Long getOfficeId() { - return officeId; - } - - public Long getFromLoanOfficerId() { - return fromLoanOfficerId; - } - - public Collection getOfficeOptions() { - return officeOptions; - } - - public Collection getLoanOfficerOptions() { - return loanOfficerOptions; - } - - public StaffAccountSummaryCollectionData getAccountSummaryCollection() { - return accountSummaryCollection; - } -} +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/StaffAccountSummaryCollectionData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/StaffAccountSummaryCollectionData.java index 1195210bb..70ee4a4f3 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/StaffAccountSummaryCollectionData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/StaffAccountSummaryCollectionData.java @@ -1,83 +1,78 @@ package org.mifosng.platform.api.data; - import java.util.Collection; import java.util.List; +/** + * + */ public class StaffAccountSummaryCollectionData { - private final List clients; + @SuppressWarnings("unused") + private final List clients; + @SuppressWarnings("unused") + private final List groups; - private final List groups; + public StaffAccountSummaryCollectionData(final List clients, final List groups) { + this.clients = clients; + this.groups = groups; + } - public StaffAccountSummaryCollectionData(List clients, List groups) { - this.clients = clients; - this.groups = groups; - } + public static final class ClientSummary { - public List getClients() { - return clients; - } + private final Long id; + private final String displayName; - public List getGroups() { - return groups; - } + private Collection loans; - public static final class ClientSummary { + public ClientSummary(Long id, String displayName) { + this.id = id; + this.displayName = displayName; + } - private final Long id; - private final String displayName; + public Long getId() { + return id; + } - private Collection loans; + public String getDisplayName() { + return displayName; + } - public ClientSummary(Long id, String displayName) { - this.id = id; - this.displayName = displayName; - } + public Collection getLoans() { + return loans; + } - public Long getId() { - return id; - } + public void setLoans(Collection loans) { + this.loans = loans; + } + } - public String getDisplayName() { - return displayName; - } + public static final class GroupSummary { - public Collection getLoans() { - return loans; - } + private final Long id; + private final String name; - public void setLoans(Collection loans) { - this.loans = loans; - } - } + private Collection loans; - public static final class GroupSummary { + public GroupSummary(Long id, String name) { + this.id = id; + this.name = name; + } - private final Long id; - private final String name; + public Long getId() { + return id; + } - private Collection loans; + public String getName() { + return name; + } - public GroupSummary(Long id, String name) { - this.id = id; - this.name = name; - } + public Collection getLoans() { + return loans; + } - public Long getId() { - return id; - } - - public String getName() { - return name; - } - - public Collection getLoans() { - return loans; - } - - public void setLoans(Collection loans) { - this.loans = loans; - } - } -} + public void setLoans(Collection loans) { + this.loans = loans; + } + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java index d862fc817..456ccc217 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java @@ -155,7 +155,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService { } @Override - public BulkLoanReassignmentCommand convertJsonToBulkLoanReassignmentCommand(String json) { + public BulkLoanReassignmentCommand convertJsonToBulkLoanReassignmentCommand(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); @@ -193,7 +193,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService { } // - return new BulkLoanReassignmentCommand(modifiedParameters, fromLoanOfficerId, toLoanOfficerId, loans); + return new BulkLoanReassignmentCommand(fromLoanOfficerId, toLoanOfficerId, loans); } @Override diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/domain/Loan.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/domain/Loan.java index 7f8434622..0481abedf 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/domain/Loan.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/domain/Loan.java @@ -296,14 +296,6 @@ public class Loan extends AbstractAuditableCustom { return this.loanProduct; } - public Staff getLoanofficer() { - return loanofficer; - } - - public void setLoanofficer(Staff loanofficer) { - this.loanofficer = loanofficer; - } - public LoanProductRelatedDetail repaymentScheduleDetail() { return this.loanRepaymentScheduleDetail; } @@ -1374,6 +1366,18 @@ public class Loan extends AbstractAuditableCustom { public boolean hasIdentifyOf(final Long loanId) { return loanId.equals(this.getId()); } + + public boolean hasLoanOfficer(final Staff fromLoanOfficer) { + + boolean matchesCurrentLoanOfficer = false; + if (this.loanofficer != null) { + matchesCurrentLoanOfficer = this.loanofficer.identifiedBy(fromLoanOfficer); + } else { + matchesCurrentLoanOfficer = fromLoanOfficer == null; + } + + return matchesCurrentLoanOfficer; + } public LocalDate getInterestChargedFromDate() { LocalDate interestChargedFrom = null; @@ -1420,4 +1424,8 @@ public class Loan extends AbstractAuditableCustom { private MonetaryCurrency getCurrency() { return this.loanRepaymentScheduleDetail.getCurrency(); } + + public void updateLoanofficer(final Staff newLoanOfficer) { + this.loanofficer = newLoanOfficer; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformServiceJpaRepositoryImpl.java index 39e051824..88f1789c4 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -728,8 +728,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf return new EntityIdentifier(loanCharge.getId()); } + @Transactional @Override - public EntityIdentifier bulkLoanReassignment(BulkLoanReassignmentCommand command) { + public EntityIdentifier bulkLoanReassignment(final BulkLoanReassignmentCommand command) { this.context.authenticatedUser(); @@ -746,11 +747,12 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf if (loan == null) { throw new LoanNotFoundException(loanId); } - if (!loan.getLoanofficer().equals(fromLoanOfficer)){ + + if (!loan.hasLoanOfficer(fromLoanOfficer)){ throw new LoanOfficerAssignmentException(loan.getId(), fromLoanOfficer.getId()); } - loan.setLoanofficer(toLoanOfficer); + loan.updateLoanofficer(toLoanOfficer); this.loanRepository.save(loan); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/staff/domain/Staff.java b/mifosng-provider/src/main/java/org/mifosng/platform/staff/domain/Staff.java index 24c1930a7..75390e144 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/staff/domain/Staff.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/staff/domain/Staff.java @@ -90,5 +90,8 @@ public class Staff extends AbstractAuditableCustom { public Boolean getLoanOfficerFlag() { return loanOfficerFlag; } - + + public boolean identifiedBy(Staff staff) { + return getId().equals(staff.getId()); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/staff/service/StaffReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/staff/service/StaffReadPlatformService.java index 1ab4adf64..b2dbfc692 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/staff/service/StaffReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/staff/service/StaffReadPlatformService.java @@ -11,7 +11,7 @@ public interface StaffReadPlatformService { Collection retrieveAllStaff(final String extraCriteria); - Collection retrieveAllLoanOfficersByOffice(final long officeId); + Collection retrieveAllLoanOfficersByOffice(final Long officeId); - StaffAccountSummaryCollectionData retrieveLoanOfficerAccountSummary(final long loanOfficerId); + StaffAccountSummaryCollectionData retrieveLoanOfficerAccountSummary(final Long loanOfficerId); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/staff/service/StaffReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/staff/service/StaffReadPlatformServiceImpl.java index d36f4e9dd..2aa2c8904 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/staff/service/StaffReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/staff/service/StaffReadPlatformServiceImpl.java @@ -82,10 +82,8 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService { } @Override - public Collection retrieveAllLoanOfficersByOffice(long officeId) { - return retrieveAllStaff(" office_id = " + officeId - + " and is_loan_officer = 1"); - + public Collection retrieveAllLoanOfficersByOffice(final Long officeId) { + return retrieveAllStaff(" office_id=" + officeId + " and is_loan_officer=1"); } @Override @@ -106,73 +104,74 @@ public class StaffReadPlatformServiceImpl implements StaffReadPlatformService { } } - @Override - public StaffAccountSummaryCollectionData retrieveLoanOfficerAccountSummary(long loanOfficerId) { + @Override + public StaffAccountSummaryCollectionData retrieveLoanOfficerAccountSummary(final Long loanOfficerId) { - context.authenticatedUser(); + context.authenticatedUser(); - StaffClientMapper staffClientMapper = new StaffClientMapper(); - String clientSql = "select distinct " + staffClientMapper.schema(); + StaffClientMapper staffClientMapper = new StaffClientMapper(); + String clientSql = "select distinct " + staffClientMapper.schema(); - StaffGroupMapper staffGroupMapper = new StaffGroupMapper(); - String groupSql = "select distinct " + staffGroupMapper.schema(); + StaffGroupMapper staffGroupMapper = new StaffGroupMapper(); + String groupSql = "select distinct " + staffGroupMapper.schema(); - List clientSummaryList = - this.jdbcTemplate.query(clientSql, staffClientMapper, new Object[]{loanOfficerId}); + List clientSummaryList = this.jdbcTemplate + .query(clientSql, staffClientMapper, + new Object[] { loanOfficerId }); - for (StaffAccountSummaryCollectionData.ClientSummary clientSummary : clientSummaryList){ + for (StaffAccountSummaryCollectionData.ClientSummary clientSummary : clientSummaryList) { - Collection clientLoanAccounts = - this.clientReadPlatformService.retrieveClientLoanAccountsByLoanOfficerId(clientSummary.getId(), loanOfficerId); + Collection clientLoanAccounts = this.clientReadPlatformService + .retrieveClientLoanAccountsByLoanOfficerId( + clientSummary.getId(), loanOfficerId); - clientSummary.setLoans(clientLoanAccounts); - } + clientSummary.setLoans(clientLoanAccounts); + } - List groupSummaryList = - this.jdbcTemplate.query(groupSql, staffGroupMapper, new Object[]{loanOfficerId}); + List groupSummaryList = this.jdbcTemplate + .query(groupSql, staffGroupMapper, new Object[] { loanOfficerId }); - for (StaffAccountSummaryCollectionData.GroupSummary groupSummary : groupSummaryList){ + for (StaffAccountSummaryCollectionData.GroupSummary groupSummary : groupSummaryList) { - Collection groupLoanAccounts = - this.groupReadPlatformService.retrieveGroupLoanAccountsByLoanOfficerId(groupSummary.getId(), loanOfficerId); + Collection groupLoanAccounts = this.groupReadPlatformService + .retrieveGroupLoanAccountsByLoanOfficerId( + groupSummary.getId(), loanOfficerId); - groupSummary.setLoans(groupLoanAccounts); - } + groupSummary.setLoans(groupLoanAccounts); + } - return new StaffAccountSummaryCollectionData(clientSummaryList, groupSummaryList); - } + return new StaffAccountSummaryCollectionData(clientSummaryList, groupSummaryList); + } private static final class StaffClientMapper implements RowMapper { - public String schema(){ + public String schema() { return " c.id as id, c.display_name as displayName from m_client c " + " join m_loan l on c.id = l.client_id where l.loan_officer_id = ? "; } @Override - public StaffAccountSummaryCollectionData.ClientSummary mapRow(ResultSet rs, int rowNum) throws SQLException { - Long id = JdbcSupport.getLong(rs, "id"); - String displayName = rs.getString("displayName"); + public StaffAccountSummaryCollectionData.ClientSummary mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + final Long id = JdbcSupport.getLong(rs, "id"); + final String displayName = rs.getString("displayName"); return new StaffAccountSummaryCollectionData.ClientSummary(id, displayName); } - } private static final class StaffGroupMapper implements RowMapper { - public String schema(){ + public String schema() { return " g.id as id, g.name as name from m_group g" + " join m_loan l on g.id = l.group_id where l.loan_officer_id = ? "; } @Override - public StaffAccountSummaryCollectionData.GroupSummary mapRow(ResultSet rs, int rowNum) throws SQLException { - Long id = JdbcSupport.getLong(rs, "id"); - String name = rs.getString("name"); + public StaffAccountSummaryCollectionData.GroupSummary mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + final Long id = JdbcSupport.getLong(rs, "id"); + final String name = rs.getString("name"); return new StaffAccountSummaryCollectionData.GroupSummary(id, name); } - } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java index 33eda9039..f5151c910 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java @@ -48,8 +48,7 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffCommandValidator validator = new StaffCommandValidator(command); validator.validateForCreate(); - Office staffOffice = this.officeRepository.findOne(command - .getOfficeId()); + Office staffOffice = this.officeRepository.findOne(command.getOfficeId()); if (staffOffice == null) { throw new OfficeNotFoundException(command.getOfficeId()); }