removing eclipse warnings

This commit is contained in:
Vishwas Babu A J
2014-10-28 02:31:26 -07:00
parent b3424921d5
commit 8a9c05e212
5 changed files with 394 additions and 492 deletions
@@ -10,6 +10,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
public class RescheduleLoansApiConstants { public class RescheduleLoansApiConstants {
public final static String ENTITY_NAME = "RESCHEDULELOAN"; public final static String ENTITY_NAME = "RESCHEDULELOAN";
// general // general
@@ -29,20 +30,20 @@ public class RescheduleLoansApiConstants {
public static final String submittedOnDateParamName = "submittedOnDate"; public static final String submittedOnDateParamName = "submittedOnDate";
public static final String adjustedDueDateParamName = "adjustedDueDate"; public static final String adjustedDueDateParamName = "adjustedDueDate";
public static final Set<String> CREATE_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(localeParamName, public static final Set<String> CREATE_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName, dateFormatParamName,
dateFormatParamName, graceOnPrincipalParamName, graceOnInterestParamName, extraTermsParamName, graceOnPrincipalParamName, graceOnInterestParamName, extraTermsParamName, rescheduleFromDateParamName,
rescheduleFromDateParamName, newInterestRateParamName, rescheduleReasonIdParamName, rescheduleReasonCommentParamName, newInterestRateParamName, rescheduleReasonIdParamName, rescheduleReasonCommentParamName, submittedOnDateParamName,
submittedOnDateParamName, loanIdParamName, adjustedDueDateParamName, recalculateInterestParamName)); loanIdParamName, adjustedDueDateParamName, recalculateInterestParamName));
// reject action request parameters // reject action request parameters
public static final String rejectedOnDateParam = "rejectedOnDate"; public static final String rejectedOnDateParam = "rejectedOnDate";
public static final Set<String> REJECT_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(localeParamName, public static final Set<String> REJECT_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName, dateFormatParamName,
dateFormatParamName, rejectedOnDateParam)); rejectedOnDateParam));
// approve action request parameters // approve action request parameters
public static final String approvedOnDateParam = "approvedOnDate"; public static final String approvedOnDateParam = "approvedOnDate";
public static final Set<String> APPROVE_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(localeParamName, public static final Set<String> APPROVE_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName, dateFormatParamName,
dateFormatParamName, approvedOnDateParam)); approvedOnDateParam));
} }
@@ -52,8 +52,7 @@ public class RescheduleLoansApiResource {
private final ApiRequestParameterHelper apiRequestParameterHelper; private final ApiRequestParameterHelper apiRequestParameterHelper;
@Autowired @Autowired
public RescheduleLoansApiResource( public RescheduleLoansApiResource(final DefaultToApiJsonSerializer<LoanRescheduleRequestData> loanRescheduleRequestToApiJsonSerializer,
final DefaultToApiJsonSerializer<LoanRescheduleRequestData> loanRescheduleRequestToApiJsonSerializer,
final PlatformSecurityContext platformSecurityContext, final PlatformSecurityContext platformSecurityContext,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final LoanRescheduleRequestReadPlatformService loanRescheduleRequestReadPlatformService, final LoanRescheduleRequestReadPlatformService loanRescheduleRequestReadPlatformService,
@@ -77,10 +76,9 @@ public class RescheduleLoansApiResource {
@QueryParam("command") final String command) { @QueryParam("command") final String command) {
this.platformSecurityContext.authenticatedUser().validateHasReadPermission(RescheduleLoansApiConstants.ENTITY_NAME); this.platformSecurityContext.authenticatedUser().validateHasReadPermission(RescheduleLoansApiConstants.ENTITY_NAME);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
.process(uriInfo.getQueryParameters());
if(compareIgnoreCase(command, "previewLoanReschedule")) { if (compareIgnoreCase(command, "previewLoanReschedule")) {
final LoanRescheduleModel loanRescheduleModel = this.loanReschedulePreviewPlatformService.previewLoanReschedule(requestId); final LoanRescheduleModel loanRescheduleModel = this.loanReschedulePreviewPlatformService.previewLoanReschedule(requestId);
return this.loanRescheduleToApiJsonSerializer.serialize(settings, loanRescheduleModel.toData(), new HashSet<String>()); return this.loanRescheduleToApiJsonSerializer.serialize(settings, loanRescheduleModel.toData(), new HashSet<String>());
@@ -97,9 +95,7 @@ public class RescheduleLoansApiResource {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String createLoanRescheduleRequest(final String apiRequestBodyAsJson) { public String createLoanRescheduleRequest(final String apiRequestBodyAsJson) {
final CommandWrapper commandWrapper = new CommandWrapperBuilder() final CommandWrapper commandWrapper = new CommandWrapperBuilder()
.createLoanRescheduleRequest(RescheduleLoansApiConstants.ENTITY_NAME) .createLoanRescheduleRequest(RescheduleLoansApiConstants.ENTITY_NAME).withJson(apiRequestBodyAsJson).build();
.withJson(apiRequestBodyAsJson)
.build();
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper); final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
@@ -110,22 +106,18 @@ public class RescheduleLoansApiResource {
@Path("{requestId}") @Path("{requestId}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String updateLoanRescheduleRequest(@PathParam("requestId") final Long requestId, public String updateLoanRescheduleRequest(@PathParam("requestId") final Long requestId, @QueryParam("command") final String command,
@QueryParam("command") final String command, final String apiRequestBodyAsJson) { final String apiRequestBodyAsJson) {
CommandWrapper commandWrapper = null; CommandWrapper commandWrapper = null;
if(compareIgnoreCase(command, "approve")) { if (compareIgnoreCase(command, "approve")) {
commandWrapper = new CommandWrapperBuilder() commandWrapper = new CommandWrapperBuilder().approveLoanRescheduleRequest(RescheduleLoansApiConstants.ENTITY_NAME, requestId)
.approveLoanRescheduleRequest(RescheduleLoansApiConstants.ENTITY_NAME, requestId) .withJson(apiRequestBodyAsJson).build();
.withJson(apiRequestBodyAsJson)
.build();
} }
else if(compareIgnoreCase(command, "reject")) { else if (compareIgnoreCase(command, "reject")) {
commandWrapper = new CommandWrapperBuilder() commandWrapper = new CommandWrapperBuilder().rejectLoanRescheduleRequest(RescheduleLoansApiConstants.ENTITY_NAME, requestId)
.rejectLoanRescheduleRequest(RescheduleLoansApiConstants.ENTITY_NAME, requestId) .withJson(apiRequestBodyAsJson).build();
.withJson(apiRequestBodyAsJson)
.build();
} }
else { else {
@@ -140,8 +132,10 @@ public class RescheduleLoansApiResource {
/** /**
* Compares two strings, ignoring differences in case * Compares two strings, ignoring differences in case
* *
* @param firstString the first string * @param firstString
* @param secondString the second string * the first string
* @param secondString
* the second string
* @return true if the two strings are equal, else false * @return true if the two strings are equal, else false
**/ **/
private boolean compareIgnoreCase(String firstString, String secondString) { private boolean compareIgnoreCase(String firstString, String secondString) {
@@ -46,86 +46,76 @@ public class LoanRescheduleRequestDataValidator {
/** /**
* Validates the request to create a new loan reschedule entry * Validates the request to create a new loan reschedule entry
* *
* @param jsonCommand the JSON command object (instance of the JsonCommand class) * @param jsonCommand
* the JSON command object (instance of the JsonCommand class)
* @return void * @return void
**/ **/
public void validateForCreateAction(final JsonCommand jsonCommand, final Loan loan) { public void validateForCreateAction(final JsonCommand jsonCommand, final Loan loan) {
final String jsonString = jsonCommand.json(); final String jsonString = jsonCommand.json();
if (StringUtils.isBlank(jsonString)) { if (StringUtils.isBlank(jsonString)) { throw new InvalidJsonException(); }
throw new InvalidJsonException();
}
final Type typeToken = new TypeToken<Map<String, Object>>() {}.getType(); final Type typeToken = new TypeToken<Map<String, Object>>() {}.getType();
this.fromJsonHelper.checkForUnsupportedParameters(typeToken, jsonString, this.fromJsonHelper
RescheduleLoansApiConstants.CREATE_REQUEST_DATA_PARAMETERS); .checkForUnsupportedParameters(typeToken, jsonString, RescheduleLoansApiConstants.CREATE_REQUEST_DATA_PARAMETERS);
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors) final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors).resource(StringUtils
.resource(StringUtils.lowerCase(RescheduleLoansApiConstants.ENTITY_NAME)); .lowerCase(RescheduleLoansApiConstants.ENTITY_NAME));
final JsonElement jsonElement = jsonCommand.parsedJson(); final JsonElement jsonElement = jsonCommand.parsedJson();
if(!loan.status().isActive()) { if (!loan.status().isActive()) {
dataValidatorBuilder dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode("loan.is.not.active", "Loan is not active");
.reset()
.failWithCodeNoParameterAddedToErrorCode("loan.is.not.active",
"Loan is not active");
} }
final Long loanId = this.fromJsonHelper.extractLongNamed( final Long loanId = this.fromJsonHelper.extractLongNamed(RescheduleLoansApiConstants.loanIdParamName, jsonElement);
RescheduleLoansApiConstants.loanIdParamName, jsonElement); dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.loanIdParamName).value(loanId).notNull()
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.loanIdParamName) .integerGreaterThanZero();
.value(loanId).notNull().integerGreaterThanZero();
final LocalDate submittedOnDate = this.fromJsonHelper.extractLocalDateNamed( final LocalDate submittedOnDate = this.fromJsonHelper.extractLocalDateNamed(RescheduleLoansApiConstants.submittedOnDateParamName,
RescheduleLoansApiConstants.submittedOnDateParamName, jsonElement); jsonElement);
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.submittedOnDateParamName).value(submittedOnDate).notNull();
if (submittedOnDate != null && loan.getDisbursementDate().isAfter(submittedOnDate)) {
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.submittedOnDateParamName) dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.submittedOnDateParamName)
.value(submittedOnDate).notNull(); .failWithCode("before.loan.disbursement.date", "Submission date cannot be before the loan disbursement date");
if(submittedOnDate != null && loan.getDisbursementDate().isAfter(submittedOnDate)) {
dataValidatorBuilder
.reset()
.parameter(RescheduleLoansApiConstants.submittedOnDateParamName)
.failWithCode("before.loan.disbursement.date",
"Submission date cannot be before the loan disbursement date");
} }
final LocalDate rescheduleFromDate = this.fromJsonHelper.extractLocalDateNamed( final LocalDate rescheduleFromDate = this.fromJsonHelper.extractLocalDateNamed(
RescheduleLoansApiConstants.rescheduleFromDateParamName, jsonElement); RescheduleLoansApiConstants.rescheduleFromDateParamName, jsonElement);
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName) dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName).value(rescheduleFromDate).notNull();
.value(rescheduleFromDate).notNull();
final Integer graceOnPrincipal = this.fromJsonHelper.extractIntegerWithLocaleNamed( final Integer graceOnPrincipal = this.fromJsonHelper.extractIntegerWithLocaleNamed(
RescheduleLoansApiConstants.graceOnPrincipalParamName, jsonElement); RescheduleLoansApiConstants.graceOnPrincipalParamName, jsonElement);
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.graceOnPrincipalParamName) dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.graceOnPrincipalParamName).value(graceOnPrincipal)
.value(graceOnPrincipal).ignoreIfNull().integerGreaterThanZero(); .ignoreIfNull().integerGreaterThanZero();
final Integer graceOnInterest = this.fromJsonHelper.extractIntegerWithLocaleNamed( final Integer graceOnInterest = this.fromJsonHelper.extractIntegerWithLocaleNamed(
RescheduleLoansApiConstants.graceOnInterestParamName, jsonElement); RescheduleLoansApiConstants.graceOnInterestParamName, jsonElement);
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.graceOnInterestParamName) dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.graceOnInterestParamName).value(graceOnInterest).ignoreIfNull()
.value(graceOnInterest).ignoreIfNull().integerGreaterThanZero(); .integerGreaterThanZero();
final Integer extraTerms = this.fromJsonHelper.extractIntegerWithLocaleNamed( final Integer extraTerms = this.fromJsonHelper.extractIntegerWithLocaleNamed(RescheduleLoansApiConstants.extraTermsParamName,
RescheduleLoansApiConstants.extraTermsParamName, jsonElement); jsonElement);
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.extraTermsParamName) dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.extraTermsParamName).value(extraTerms).ignoreIfNull()
.value(extraTerms).ignoreIfNull().integerGreaterThanZero(); .integerGreaterThanZero();
final Long rescheduleReasonId = this.fromJsonHelper.extractLongNamed( final Long rescheduleReasonId = this.fromJsonHelper.extractLongNamed(RescheduleLoansApiConstants.rescheduleReasonIdParamName,
RescheduleLoansApiConstants.rescheduleReasonIdParamName, jsonElement); jsonElement);
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleReasonIdParamName) dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleReasonIdParamName).value(rescheduleReasonId).notNull()
.value(rescheduleReasonId).notNull().integerGreaterThanZero(); .integerGreaterThanZero();
final String rescheduleReasonComment = this.fromJsonHelper.extractStringNamed( final String rescheduleReasonComment = this.fromJsonHelper.extractStringNamed(
RescheduleLoansApiConstants.rescheduleReasonCommentParamName, jsonElement); RescheduleLoansApiConstants.rescheduleReasonCommentParamName, jsonElement);
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleReasonCommentParamName) dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleReasonCommentParamName).value(rescheduleReasonComment)
.value(rescheduleReasonComment).ignoreIfNull().notExceedingLengthOf(500); .ignoreIfNull().notExceedingLengthOf(500);
final LocalDate adjustedDueDate = this.fromJsonHelper.extractLocalDateNamed( final LocalDate adjustedDueDate = this.fromJsonHelper.extractLocalDateNamed(RescheduleLoansApiConstants.adjustedDueDateParamName,
RescheduleLoansApiConstants.adjustedDueDateParamName, jsonElement); jsonElement);
if(adjustedDueDate != null && rescheduleFromDate != null && adjustedDueDate.isBefore(rescheduleFromDate)) { if (adjustedDueDate != null && rescheduleFromDate != null && adjustedDueDate.isBefore(rescheduleFromDate)) {
dataValidatorBuilder dataValidatorBuilder
.reset() .reset()
.parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName) .parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName)
@@ -133,123 +123,99 @@ public class LoanRescheduleRequestDataValidator {
"Adjusted due date cannot be before the reschedule from date"); "Adjusted due date cannot be before the reschedule from date");
} }
// at least one of the following must be provided => graceOnPrincipal, graceOnInterest, extraTerms, newInterestRate // at least one of the following must be provided => graceOnPrincipal,
if(!this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.graceOnPrincipalParamName, jsonElement) // graceOnInterest, extraTerms, newInterestRate
if (!this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.graceOnPrincipalParamName, jsonElement)
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.graceOnInterestParamName, jsonElement) && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.graceOnInterestParamName, jsonElement)
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.extraTermsParamName, jsonElement) && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.extraTermsParamName, jsonElement)
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.newInterestRateParamName, jsonElement) && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.newInterestRateParamName, jsonElement)
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.adjustedDueDateParamName, jsonElement)) { && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.adjustedDueDateParamName, jsonElement)) {
dataValidatorBuilder dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.graceOnPrincipalParamName).notNull();
.reset()
.parameter(RescheduleLoansApiConstants.graceOnPrincipalParamName)
.notNull();
} }
if(rescheduleFromDate != null) { if (rescheduleFromDate != null) {
LoanRepaymentScheduleInstallment installment = loan.getRepaymentScheduleInstallment(rescheduleFromDate); LoanRepaymentScheduleInstallment installment = loan.getRepaymentScheduleInstallment(rescheduleFromDate);
if(installment == null) { if (installment == null) {
dataValidatorBuilder dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName)
.reset() .failWithCode("repayment.schedule.installment.does.not.exist", "Repayment schedule installment does not exist");
.parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName)
.failWithCode("repayment.schedule.installment.does.not.exist",
"Repayment schedule installment does not exist");
} }
if(installment != null && installment.isObligationsMet()) { if (installment != null && installment.isObligationsMet()) {
dataValidatorBuilder dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName)
.reset() .failWithCode("repayment.schedule.installment.obligation.met", "Repayment schedule installment obligation met");
.parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName)
.failWithCode("repayment.schedule.installment.obligation.met",
"Repayment schedule installment obligation met");
} }
if(installment != null && installment.isPartlyPaid()) { if (installment != null && installment.isPartlyPaid()) {
dataValidatorBuilder dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName)
.reset() .failWithCode("repayment.schedule.installment.partly.paid", "Repayment schedule installment is partly paid");
.parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName)
.failWithCode("repayment.schedule.installment.partly.paid",
"Repayment schedule installment is partly paid");
} }
if(installment != null) { if (installment != null) {
if(installment.getPenaltyChargesOutstanding(loan.getCurrency()).isGreaterThanZero()) { if (installment.getPenaltyChargesOutstanding(loan.getCurrency()).isGreaterThanZero()) {
dataValidatorBuilder dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode(
.reset() "repayment.schedule.installment.has.an.outstanding.penalty.charge",
.failWithCodeNoParameterAddedToErrorCode("repayment.schedule.installment.has.an.outstanding.penalty.charge",
"Repayment schedule installment has an outsatnding penalty charge."); "Repayment schedule installment has an outsatnding penalty charge.");
} }
if(installment.getFeeChargesOutstanding(loan.getCurrency()).isGreaterThanZero()) { if (installment.getFeeChargesOutstanding(loan.getCurrency()).isGreaterThanZero()) {
dataValidatorBuilder dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode(
.reset() "repayment.schedule.installment.has.an.outstanding.fee.charge",
.failWithCodeNoParameterAddedToErrorCode("repayment.schedule.installment.has.an.outstanding.fee.charge",
"Repayment schedule installment has an outsatnding fee charge."); "Repayment schedule installment has an outsatnding fee charge.");
} }
} }
} }
if(loanId != null) { if (loanId != null) {
List<LoanRescheduleRequestData> loanRescheduleRequestData = this.loanRescheduleRequestReadPlatformService List<LoanRescheduleRequestData> loanRescheduleRequestData = this.loanRescheduleRequestReadPlatformService
.readLoanRescheduleRequests(loanId, LoanStatus.APPROVED.getValue()); .readLoanRescheduleRequests(loanId, LoanStatus.APPROVED.getValue());
if(loanRescheduleRequestData.size() > 0) { if (loanRescheduleRequestData.size() > 0) {
dataValidatorBuilder dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode("loan.already.rescheduled",
.reset()
.failWithCodeNoParameterAddedToErrorCode("loan.already.rescheduled",
"The loan can only be rescheduled once."); "The loan can only be rescheduled once.");
} }
} }
if(!dataValidationErrors.isEmpty()) { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
throw new PlatformApiDataValidationException(dataValidationErrors);
}
} }
/** /**
* Validates a user request to approve a loan reschedule request * Validates a user request to approve a loan reschedule request
* *
* @param jsonCommand the JSON command object (instance of the JsonCommand class) * @param jsonCommand
* the JSON command object (instance of the JsonCommand class)
* @return void * @return void
**/ **/
public void validateForApproveAction(final JsonCommand jsonCommand, LoanRescheduleRequest loanRescheduleRequest) { public void validateForApproveAction(final JsonCommand jsonCommand, LoanRescheduleRequest loanRescheduleRequest) {
final String jsonString = jsonCommand.json(); final String jsonString = jsonCommand.json();
if (StringUtils.isBlank(jsonString)) { if (StringUtils.isBlank(jsonString)) { throw new InvalidJsonException(); }
throw new InvalidJsonException();
}
final Type typeToken = new TypeToken<Map<String, Object>>() {}.getType(); final Type typeToken = new TypeToken<Map<String, Object>>() {}.getType();
this.fromJsonHelper.checkForUnsupportedParameters(typeToken, jsonString, this.fromJsonHelper.checkForUnsupportedParameters(typeToken, jsonString,
RescheduleLoansApiConstants.APPROVE_REQUEST_DATA_PARAMETERS); RescheduleLoansApiConstants.APPROVE_REQUEST_DATA_PARAMETERS);
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors) final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors).resource(StringUtils
.resource(StringUtils.lowerCase(RescheduleLoansApiConstants.ENTITY_NAME)); .lowerCase(RescheduleLoansApiConstants.ENTITY_NAME));
final JsonElement jsonElement = jsonCommand.parsedJson(); final JsonElement jsonElement = jsonCommand.parsedJson();
final LocalDate approvedOnDate = this.fromJsonHelper.extractLocalDateNamed( final LocalDate approvedOnDate = this.fromJsonHelper.extractLocalDateNamed(RescheduleLoansApiConstants.approvedOnDateParam,
RescheduleLoansApiConstants.approvedOnDateParam, jsonElement); jsonElement);
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.approvedOnDateParam) dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.approvedOnDateParam).value(approvedOnDate).notNull();
.value(approvedOnDate).notNull();
if(approvedOnDate != null && loanRescheduleRequest.getSubmittedOnDate().isAfter(approvedOnDate)) { if (approvedOnDate != null && loanRescheduleRequest.getSubmittedOnDate().isAfter(approvedOnDate)) {
dataValidatorBuilder dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.approvedOnDateParam)
.reset() .failWithCode("before.submission.date", "Approval date cannot be before the request submission date.");
.parameter(RescheduleLoansApiConstants.approvedOnDateParam)
.failWithCode("before.submission.date",
"Approval date cannot be before the request submission date.");
} }
LoanRescheduleRequestStatusEnumData loanRescheduleRequestStatusEnumData = LoanRescheduleRequestEnumerations LoanRescheduleRequestStatusEnumData loanRescheduleRequestStatusEnumData = LoanRescheduleRequestEnumerations
.status(loanRescheduleRequest.getStatusEnum()); .status(loanRescheduleRequest.getStatusEnum());
if(!loanRescheduleRequestStatusEnumData.isPendingApproval()) { if (!loanRescheduleRequestStatusEnumData.isPendingApproval()) {
dataValidatorBuilder dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode(
.reset()
.failWithCodeNoParameterAddedToErrorCode(
"request.is.not.in.submitted.and.pending.state", "request.is.not.in.submitted.and.pending.state",
"Loan reschedule request approval is not allowed. " "Loan reschedule request approval is not allowed. "
+ "Loan reschedule request is not in submitted and pending approval state."); + "Loan reschedule request is not in submitted and pending approval state.");
@@ -258,119 +224,97 @@ public class LoanRescheduleRequestDataValidator {
LocalDate rescheduleFromDate = loanRescheduleRequest.getRescheduleFromDate(); LocalDate rescheduleFromDate = loanRescheduleRequest.getRescheduleFromDate();
final Loan loan = loanRescheduleRequest.getLoan(); final Loan loan = loanRescheduleRequest.getLoan();
if(loan != null) { if (loan != null) {
Long loanId = loan.getId(); Long loanId = loan.getId();
if(!loan.status().isActive()) { if (!loan.status().isActive()) {
dataValidatorBuilder dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode("loan.is.not.active", "Loan is not active");
.reset()
.failWithCodeNoParameterAddedToErrorCode("loan.is.not.active",
"Loan is not active");
} }
if(rescheduleFromDate != null) { if (rescheduleFromDate != null) {
LoanRepaymentScheduleInstallment installment = loan.getRepaymentScheduleInstallment(rescheduleFromDate); LoanRepaymentScheduleInstallment installment = loan.getRepaymentScheduleInstallment(rescheduleFromDate);
if(installment == null) { if (installment == null) {
dataValidatorBuilder dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode(
.reset() "loan.repayment.schedule.installment.does.not.exist", "Repayment schedule installment does not exist");
.failWithCodeNoParameterAddedToErrorCode("loan.repayment.schedule.installment.does.not.exist",
"Repayment schedule installment does not exist");
} }
if(installment != null && installment.isObligationsMet()) { if (installment != null && installment.isObligationsMet()) {
dataValidatorBuilder dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode(
.reset() "loan.repayment.schedule.installment." + "obligation.met", "Repayment schedule installment obligation met");
.failWithCodeNoParameterAddedToErrorCode("loan.repayment.schedule.installment."
+ "obligation.met", "Repayment schedule installment obligation met");
} }
if(installment != null) { if (installment != null) {
if(installment.getPenaltyChargesOutstanding(loan.getCurrency()).isGreaterThanZero()) { if (installment.getPenaltyChargesOutstanding(loan.getCurrency()).isGreaterThanZero()) {
dataValidatorBuilder dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode(
.reset() "repayment.schedule.installment.has.an.outstanding.penalty.charge",
.failWithCodeNoParameterAddedToErrorCode("repayment.schedule.installment.has.an.outstanding.penalty.charge",
"Repayment schedule installment has an outsatnding penalty charge."); "Repayment schedule installment has an outsatnding penalty charge.");
} }
if(installment.getFeeChargesOutstanding(loan.getCurrency()).isGreaterThanZero()) { if (installment.getFeeChargesOutstanding(loan.getCurrency()).isGreaterThanZero()) {
dataValidatorBuilder dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode(
.reset() "repayment.schedule.installment.has.an.outstanding.fee.charge",
.failWithCodeNoParameterAddedToErrorCode("repayment.schedule.installment.has.an.outstanding.fee.charge",
"Repayment schedule installment has an outsatnding fee charge."); "Repayment schedule installment has an outsatnding fee charge.");
} }
} }
} }
if(loanId != null) { if (loanId != null) {
List<LoanRescheduleRequestData> loanRescheduleRequestData = this.loanRescheduleRequestReadPlatformService List<LoanRescheduleRequestData> loanRescheduleRequestData = this.loanRescheduleRequestReadPlatformService
.readLoanRescheduleRequests(loanId, LoanStatus.APPROVED.getValue()); .readLoanRescheduleRequests(loanId, LoanStatus.APPROVED.getValue());
if(loanRescheduleRequestData.size() > 0) { if (loanRescheduleRequestData.size() > 0) {
dataValidatorBuilder dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode("loan.already.rescheduled",
.reset()
.failWithCodeNoParameterAddedToErrorCode("loan.already.rescheduled",
"The loan can only be rescheduled once."); "The loan can only be rescheduled once.");
} }
} }
} }
if(!dataValidationErrors.isEmpty()) { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
throw new PlatformApiDataValidationException(dataValidationErrors);
}
} }
/** /**
* Validates a user request to reject a loan reschedule request * Validates a user request to reject a loan reschedule request
* *
* @param jsonCommand the JSON command object (instance of the JsonCommand class) * @param jsonCommand
* the JSON command object (instance of the JsonCommand class)
* @return void * @return void
**/ **/
public void validateForRejectAction(final JsonCommand jsonCommand, LoanRescheduleRequest loanRescheduleRequest) { public void validateForRejectAction(final JsonCommand jsonCommand, LoanRescheduleRequest loanRescheduleRequest) {
final String jsonString = jsonCommand.json(); final String jsonString = jsonCommand.json();
if (StringUtils.isBlank(jsonString)) { if (StringUtils.isBlank(jsonString)) { throw new InvalidJsonException(); }
throw new InvalidJsonException();
}
final Type typeToken = new TypeToken<Map<String, Object>>() {}.getType(); final Type typeToken = new TypeToken<Map<String, Object>>() {}.getType();
this.fromJsonHelper.checkForUnsupportedParameters(typeToken, jsonString, this.fromJsonHelper
RescheduleLoansApiConstants.REJECT_REQUEST_DATA_PARAMETERS); .checkForUnsupportedParameters(typeToken, jsonString, RescheduleLoansApiConstants.REJECT_REQUEST_DATA_PARAMETERS);
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors) final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors).resource(StringUtils
.resource(StringUtils.lowerCase(RescheduleLoansApiConstants.ENTITY_NAME)); .lowerCase(RescheduleLoansApiConstants.ENTITY_NAME));
final JsonElement jsonElement = jsonCommand.parsedJson(); final JsonElement jsonElement = jsonCommand.parsedJson();
final LocalDate rejectedOnDate = this.fromJsonHelper.extractLocalDateNamed( final LocalDate rejectedOnDate = this.fromJsonHelper.extractLocalDateNamed(RescheduleLoansApiConstants.rejectedOnDateParam,
RescheduleLoansApiConstants.rejectedOnDateParam, jsonElement); jsonElement);
dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rejectedOnDateParam) dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rejectedOnDateParam).value(rejectedOnDate).notNull();
.value(rejectedOnDate).notNull();
if(rejectedOnDate != null && loanRescheduleRequest.getSubmittedOnDate().isAfter(rejectedOnDate)) { if (rejectedOnDate != null && loanRescheduleRequest.getSubmittedOnDate().isAfter(rejectedOnDate)) {
dataValidatorBuilder dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rejectedOnDateParam)
.reset() .failWithCode("before.submission.date", "Rejection date cannot be before the request submission date.");
.parameter(RescheduleLoansApiConstants.rejectedOnDateParam)
.failWithCode("before.submission.date",
"Rejection date cannot be before the request submission date.");
} }
LoanRescheduleRequestStatusEnumData loanRescheduleRequestStatusEnumData = LoanRescheduleRequestEnumerations LoanRescheduleRequestStatusEnumData loanRescheduleRequestStatusEnumData = LoanRescheduleRequestEnumerations
.status(loanRescheduleRequest.getStatusEnum()); .status(loanRescheduleRequest.getStatusEnum());
if(!loanRescheduleRequestStatusEnumData.isPendingApproval()) { if (!loanRescheduleRequestStatusEnumData.isPendingApproval()) {
dataValidatorBuilder dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode(
.reset()
.failWithCodeNoParameterAddedToErrorCode(
"request.is.not.in.submitted.and.pending.state", "request.is.not.in.submitted.and.pending.state",
"Loan reschedule request rejection is not allowed. " "Loan reschedule request rejection is not allowed. "
+ "Loan reschedule request is not in submitted and pending approval state."); + "Loan reschedule request is not in submitted and pending approval state.");
} }
if(!dataValidationErrors.isEmpty()) { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
throw new PlatformApiDataValidationException(dataValidationErrors);
}
} }
} }
@@ -10,8 +10,8 @@ import org.mifosplatform.portfolio.loanaccount.domain.LoanStatus;
/** /**
* Immutable data object represent loan reschedule request status enumerations. * Immutable data object represent loan reschedule request status enumerations.
**/ **/
@SuppressWarnings("unused")
public class LoanRescheduleRequestStatusEnumData { public class LoanRescheduleRequestStatusEnumData {
private final Long id; private final Long id;
private final String code; private final String code;
private final String value; private final String value;
@@ -227,7 +227,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
catch (final DataIntegrityViolationException dve) { catch (final DataIntegrityViolationException dve) {
// handle the data integrity violation // handle the data integrity violation
handleCreateActionDataIntegrityViolation(jsonCommand, dve); handleDataIntegrityViolation(jsonCommand, dve);
// return an empty command processing result object // return an empty command processing result object
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
@@ -350,7 +350,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
catch (final DataIntegrityViolationException dve) { catch (final DataIntegrityViolationException dve) {
// handle the data integrity violation // handle the data integrity violation
handleApproveActionDataIntegrityViolation(jsonCommand, dve); handleDataIntegrityViolation(jsonCommand, dve);
// return an empty command processing result object // return an empty command processing result object
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
@@ -373,7 +373,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
this.loanRescheduleRequestDataValidator.validateForRejectAction(jsonCommand, loanRescheduleRequest); this.loanRescheduleRequestDataValidator.validateForRejectAction(jsonCommand, loanRescheduleRequest);
final AppUser appUser = this.platformSecurityContext.authenticatedUser(); final AppUser appUser = this.platformSecurityContext.authenticatedUser();
final Map<String, Object> changes = new LinkedHashMap<String, Object>(); final Map<String, Object> changes = new LinkedHashMap<>();
LocalDate rejectedOnDate = jsonCommand.localDateValueOfParameterNamed("rejectedOnDate"); LocalDate rejectedOnDate = jsonCommand.localDateValueOfParameterNamed("rejectedOnDate");
final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(jsonCommand.dateFormat()).withLocale( final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(jsonCommand.dateFormat()).withLocale(
@@ -394,7 +394,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
catch (final DataIntegrityViolationException dve) { catch (final DataIntegrityViolationException dve) {
// handle the data integrity violation // handle the data integrity violation
handleRejectActionDataIntegrityViolation(jsonCommand, dve); handleDataIntegrityViolation(jsonCommand, dve);
// return an empty command processing result object // return an empty command processing result object
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
@@ -402,8 +402,8 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
} }
/** /**
* handles the data integrity violation exception caught in the create * handles the data integrity violation exception for loan reschedule write
* method * services
* *
* @param jsonCommand * @param jsonCommand
* JSON command object * JSON command object
@@ -412,49 +412,12 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche
* @return void * @return void
**/ **/
@SuppressWarnings("unused") @SuppressWarnings("unused")
private void handleCreateActionDataIntegrityViolation(final JsonCommand jsonCommand, final DataIntegrityViolationException dve) { private void handleDataIntegrityViolation(final JsonCommand jsonCommand, final DataIntegrityViolationException dve) {
logger.error(dve.getMessage(), dve); logger.error(dve.getMessage(), dve);
throw new PlatformDataIntegrityException("error.msg.group.unknown.data.integrity.issue", throw new PlatformDataIntegrityException("error.msg.loan.reschedule.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource.");
} }
/**
* handles the data integrity violation exception caught in the reject
* method
*
* @param jsonCommand
* JSON command object
* @param dve
* data integrity violation exception
* @return void
**/
@SuppressWarnings("unused")
private void handleRejectActionDataIntegrityViolation(final JsonCommand jsonCommand, final DataIntegrityViolationException dve) {
logger.error(dve.getMessage(), dve);
throw new PlatformDataIntegrityException("error.msg.group.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.");
}
/**
* handles the data integrity violation exception caught in the approve
* method
*
* @param jsonCommand
* JSON command object
* @param dve
* data integrity violation exception
* @return void
**/
@SuppressWarnings("unused")
private void handleApproveActionDataIntegrityViolation(final JsonCommand jsonCommand, final DataIntegrityViolationException dve) {
logger.error(dve.getMessage(), dve);
throw new PlatformDataIntegrityException("error.msg.group.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.");
}
} }