Merge pull request #528 from mifoscontributer/mifosx-611
Add data validations for bulkloanreassignment
This commit is contained in:
+26
@@ -263,4 +263,30 @@ public final class LoanEventApiJsonValidator {
|
|||||||
|
|
||||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void validateForBulkLoanReassignment(final String json) {
|
||||||
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
|
|
||||||
|
final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("assignmentDate", "fromLoanOfficerId",
|
||||||
|
"toLoanOfficerId", "loans", "locale", "dateFormat"));
|
||||||
|
|
||||||
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
|
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||||
|
|
||||||
|
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loanOfficer");
|
||||||
|
|
||||||
|
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
||||||
|
|
||||||
|
final LocalDate assignmentDate = this.fromApiJsonHelper.extractLocalDateNamed("assignmentDate", element);
|
||||||
|
baseDataValidator.reset().parameter("assignmentDate").value(assignmentDate).notNull();
|
||||||
|
final Long fromLoanOfficerId = this.fromApiJsonHelper.extractLongNamed("fromLoanOfficerId", element);
|
||||||
|
baseDataValidator.reset().parameter("fromLoanOfficerId").value(fromLoanOfficerId).notNull().longGreaterThanZero();
|
||||||
|
final Long toLoanOfficerId = this.fromApiJsonHelper.extractLongNamed("toLoanOfficerId", element);
|
||||||
|
baseDataValidator.reset().parameter("toLoanOfficerId").value(toLoanOfficerId).notNull().longGreaterThanZero();
|
||||||
|
final String[] loans = this.fromApiJsonHelper.extractArrayNamed("loans", element);
|
||||||
|
baseDataValidator.reset().parameter("loans").value(loans).arrayNotEmpty();
|
||||||
|
|
||||||
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+6
-4
@@ -16,6 +16,8 @@ import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext
|
|||||||
import org.mifosplatform.organisation.staff.data.StaffAccountSummaryCollectionData;
|
import org.mifosplatform.organisation.staff.data.StaffAccountSummaryCollectionData;
|
||||||
import org.mifosplatform.portfolio.accountdetails.data.LoanAccountSummaryData;
|
import org.mifosplatform.portfolio.accountdetails.data.LoanAccountSummaryData;
|
||||||
import org.mifosplatform.portfolio.accountdetails.service.AccountDetailsReadPlatformService;
|
import org.mifosplatform.portfolio.accountdetails.service.AccountDetailsReadPlatformService;
|
||||||
|
import org.mifosplatform.portfolio.client.domain.ClientStatus;
|
||||||
|
import org.mifosplatform.portfolio.group.domain.GroupingTypeStatus;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
@@ -42,13 +44,13 @@ public class BulkLoansReadPlatformServiceImpl implements BulkLoansReadPlatformSe
|
|||||||
context.authenticatedUser();
|
context.authenticatedUser();
|
||||||
|
|
||||||
final StaffClientMapper staffClientMapper = new StaffClientMapper();
|
final StaffClientMapper staffClientMapper = new StaffClientMapper();
|
||||||
final String clientSql = "select distinct " + staffClientMapper.schema();
|
final String clientSql = "select distinct " + staffClientMapper.schema() +" and c.status_enum=?";
|
||||||
|
|
||||||
final StaffGroupMapper staffGroupMapper = new StaffGroupMapper();
|
final StaffGroupMapper staffGroupMapper = new StaffGroupMapper();
|
||||||
final String groupSql = "select distinct " + staffGroupMapper.schema();
|
final String groupSql = "select distinct " + staffGroupMapper.schema() +" and g.status_enum=?";
|
||||||
|
|
||||||
final List<StaffAccountSummaryCollectionData.LoanAccountSummary> clientSummaryList = this.jdbcTemplate.query(clientSql,
|
final List<StaffAccountSummaryCollectionData.LoanAccountSummary> clientSummaryList = this.jdbcTemplate.query(clientSql,
|
||||||
staffClientMapper, new Object[] { loanOfficerId });
|
staffClientMapper, new Object[] { loanOfficerId, ClientStatus.ACTIVE.getValue()});
|
||||||
|
|
||||||
for (StaffAccountSummaryCollectionData.LoanAccountSummary clientSummary : clientSummaryList) {
|
for (StaffAccountSummaryCollectionData.LoanAccountSummary clientSummary : clientSummaryList) {
|
||||||
|
|
||||||
@@ -59,7 +61,7 @@ public class BulkLoansReadPlatformServiceImpl implements BulkLoansReadPlatformSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
final List<StaffAccountSummaryCollectionData.LoanAccountSummary> groupSummaryList = this.jdbcTemplate.query(groupSql, staffGroupMapper,
|
final List<StaffAccountSummaryCollectionData.LoanAccountSummary> groupSummaryList = this.jdbcTemplate.query(groupSql, staffGroupMapper,
|
||||||
new Object[] { loanOfficerId });
|
new Object[] { loanOfficerId, GroupingTypeStatus.ACTIVE.getValue()});
|
||||||
|
|
||||||
for (StaffAccountSummaryCollectionData.LoanAccountSummary groupSummary : groupSummaryList) {
|
for (StaffAccountSummaryCollectionData.LoanAccountSummary groupSummary : groupSummaryList) {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -930,6 +930,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
public CommandProcessingResult bulkLoanReassignment(final JsonCommand command) {
|
public CommandProcessingResult bulkLoanReassignment(final JsonCommand command) {
|
||||||
|
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
this.loanEventApiJsonValidator.validateForBulkLoanReassignment(command.json());
|
||||||
|
|
||||||
final Long fromLoanOfficerId = command.longValueOfParameterNamed("fromLoanOfficerId");
|
final Long fromLoanOfficerId = command.longValueOfParameterNamed("fromLoanOfficerId");
|
||||||
final Long toLoanOfficerId = command.longValueOfParameterNamed("toLoanOfficerId");
|
final Long toLoanOfficerId = command.longValueOfParameterNamed("toLoanOfficerId");
|
||||||
@@ -950,7 +951,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
loan.reassignLoanOfficer(toLoanOfficer, dateOfLoanOfficerAssignment);
|
loan.reassignLoanOfficer(toLoanOfficer, dateOfLoanOfficerAssignment);
|
||||||
this.loanRepository.save(loan);
|
this.loanRepository.save(loan);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loanRepository.flush();
|
this.loanRepository.flush();
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
|
|||||||
Reference in New Issue
Block a user