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,9 +10,10 @@ 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";
// general public final static String ENTITY_NAME = "RESCHEDULELOAN";
// general
public static final String localeParamName = "locale"; public static final String localeParamName = "locale";
public static final String dateFormatParamName = "dateFormat"; public static final String dateFormatParamName = "dateFormat";
@@ -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));
} }
@@ -43,108 +43,102 @@ import org.springframework.stereotype.Component;
@Scope("singleton") @Scope("singleton")
public class RescheduleLoansApiResource { public class RescheduleLoansApiResource {
private final DefaultToApiJsonSerializer<LoanRescheduleRequestData> loanRescheduleRequestToApiJsonSerializer; private final DefaultToApiJsonSerializer<LoanRescheduleRequestData> loanRescheduleRequestToApiJsonSerializer;
private final DefaultToApiJsonSerializer<LoanScheduleData> loanRescheduleToApiJsonSerializer; private final DefaultToApiJsonSerializer<LoanScheduleData> loanRescheduleToApiJsonSerializer;
private final PlatformSecurityContext platformSecurityContext; private final PlatformSecurityContext platformSecurityContext;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final LoanRescheduleRequestReadPlatformService loanRescheduleRequestReadPlatformService; private final LoanRescheduleRequestReadPlatformService loanRescheduleRequestReadPlatformService;
private final LoanReschedulePreviewPlatformService loanReschedulePreviewPlatformService; private final LoanReschedulePreviewPlatformService loanReschedulePreviewPlatformService;
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, final ApiRequestParameterHelper apiRequestParameterHelper,
final ApiRequestParameterHelper apiRequestParameterHelper, final DefaultToApiJsonSerializer<LoanScheduleData> loanRescheduleToApiJsonSerializer,
final DefaultToApiJsonSerializer<LoanScheduleData> loanRescheduleToApiJsonSerializer, final LoanReschedulePreviewPlatformService loanReschedulePreviewPlatformService) {
final LoanReschedulePreviewPlatformService loanReschedulePreviewPlatformService) { this.loanRescheduleRequestToApiJsonSerializer = loanRescheduleRequestToApiJsonSerializer;
this.loanRescheduleRequestToApiJsonSerializer = loanRescheduleRequestToApiJsonSerializer; this.platformSecurityContext = platformSecurityContext;
this.platformSecurityContext = platformSecurityContext; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.loanRescheduleRequestReadPlatformService = loanRescheduleRequestReadPlatformService;
this.loanRescheduleRequestReadPlatformService = loanRescheduleRequestReadPlatformService; this.apiRequestParameterHelper = apiRequestParameterHelper;
this.apiRequestParameterHelper = apiRequestParameterHelper; this.loanRescheduleToApiJsonSerializer = loanRescheduleToApiJsonSerializer;
this.loanRescheduleToApiJsonSerializer = loanRescheduleToApiJsonSerializer; this.loanReschedulePreviewPlatformService = loanReschedulePreviewPlatformService;
this.loanReschedulePreviewPlatformService = loanReschedulePreviewPlatformService; }
}
@GET @GET
@Path("{requestId}") @Path("{requestId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String readLoanRescheduleRequest(@Context final UriInfo uriInfo, @PathParam("requestId") final Long requestId,
@QueryParam("command") final String command) {
this.platformSecurityContext.authenticatedUser().validateHasReadPermission(RescheduleLoansApiConstants.ENTITY_NAME);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper
.process(uriInfo.getQueryParameters());
if(compareIgnoreCase(command, "previewLoanReschedule")) {
final LoanRescheduleModel loanRescheduleModel = this.loanReschedulePreviewPlatformService.previewLoanReschedule(requestId);
return this.loanRescheduleToApiJsonSerializer.serialize(settings, loanRescheduleModel.toData(), new HashSet<String>());
}
final LoanRescheduleRequestData loanRescheduleRequestData = this.loanRescheduleRequestReadPlatformService
.readLoanRescheduleRequest(requestId);
return this.loanRescheduleRequestToApiJsonSerializer.serialize(settings, loanRescheduleRequestData);
}
@POST
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String createLoanRescheduleRequest(final String apiRequestBodyAsJson) { public String readLoanRescheduleRequest(@Context final UriInfo uriInfo, @PathParam("requestId") final Long requestId,
final CommandWrapper commandWrapper = new CommandWrapperBuilder() @QueryParam("command") final String command) {
.createLoanRescheduleRequest(RescheduleLoansApiConstants.ENTITY_NAME) this.platformSecurityContext.authenticatedUser().validateHasReadPermission(RescheduleLoansApiConstants.ENTITY_NAME);
.withJson(apiRequestBodyAsJson)
.build();
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
if (compareIgnoreCase(command, "previewLoanReschedule")) {
final LoanRescheduleModel loanRescheduleModel = this.loanReschedulePreviewPlatformService.previewLoanReschedule(requestId);
return this.loanRescheduleToApiJsonSerializer.serialize(settings, loanRescheduleModel.toData(), new HashSet<String>());
}
final LoanRescheduleRequestData loanRescheduleRequestData = this.loanRescheduleRequestReadPlatformService
.readLoanRescheduleRequest(requestId);
return this.loanRescheduleRequestToApiJsonSerializer.serialize(settings, loanRescheduleRequestData);
}
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String createLoanRescheduleRequest(final String apiRequestBodyAsJson) {
final CommandWrapper commandWrapper = new CommandWrapperBuilder()
.createLoanRescheduleRequest(RescheduleLoansApiConstants.ENTITY_NAME).withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
return this.loanRescheduleRequestToApiJsonSerializer.serialize(commandProcessingResult); return this.loanRescheduleRequestToApiJsonSerializer.serialize(commandProcessingResult);
} }
@POST @POST
@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 {
throw new UnrecognizedQueryParamException("command", command, new Object[] { "approve", "reject" }); throw new UnrecognizedQueryParamException("command", command, new Object[] { "approve", "reject" });
} }
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper); final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
return this.loanRescheduleRequestToApiJsonSerializer.serialize(commandProcessingResult); return this.loanRescheduleRequestToApiJsonSerializer.serialize(commandProcessingResult);
} }
/** /**
* 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
* @return true if the two strings are equal, else false * @param secondString
**/ * the second string
private boolean compareIgnoreCase(String firstString, String secondString) { * @return true if the two strings are equal, else false
return StringUtils.isNotBlank(firstString) && firstString.trim().equalsIgnoreCase(secondString); **/
} private boolean compareIgnoreCase(String firstString, String secondString) {
return StringUtils.isNotBlank(firstString) && firstString.trim().equalsIgnoreCase(secondString);
}
} }
@@ -33,344 +33,288 @@ import com.google.gson.reflect.TypeToken;
@Component @Component
public class LoanRescheduleRequestDataValidator { public class LoanRescheduleRequestDataValidator {
private final FromJsonHelper fromJsonHelper; private final FromJsonHelper fromJsonHelper;
private final LoanRescheduleRequestReadPlatformService loanRescheduleRequestReadPlatformService; private final LoanRescheduleRequestReadPlatformService loanRescheduleRequestReadPlatformService;
@Autowired @Autowired
public LoanRescheduleRequestDataValidator(FromJsonHelper fromJsonHelper, public LoanRescheduleRequestDataValidator(FromJsonHelper fromJsonHelper,
LoanRescheduleRequestReadPlatformService loanRescheduleRequestReadPlatformService) { LoanRescheduleRequestReadPlatformService loanRescheduleRequestReadPlatformService) {
this.fromJsonHelper = fromJsonHelper; this.fromJsonHelper = fromJsonHelper;
this.loanRescheduleRequestReadPlatformService = loanRescheduleRequestReadPlatformService; this.loanRescheduleRequestReadPlatformService = loanRescheduleRequestReadPlatformService;
} }
/** /**
* 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
* @return void * the JSON command object (instance of the JsonCommand class)
**/ * @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) dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.submittedOnDateParamName).value(submittedOnDate).notNull();
.value(submittedOnDate).notNull();
if(submittedOnDate != null && loan.getDisbursementDate().isAfter(submittedOnDate)) { if (submittedOnDate != null && loan.getDisbursementDate().isAfter(submittedOnDate)) {
dataValidatorBuilder dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.submittedOnDateParamName)
.reset() .failWithCode("before.loan.disbursement.date", "Submission date cannot be before the loan disbursement date");
.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)
.failWithCode("adjustedDueDate.before.rescheduleFromDate", .failWithCode("adjustedDueDate.before.rescheduleFromDate",
"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
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.graceOnInterestParamName, jsonElement) if (!this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.graceOnPrincipalParamName, jsonElement)
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.extraTermsParamName, jsonElement) && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.graceOnInterestParamName, jsonElement)
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.newInterestRateParamName, jsonElement) && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.extraTermsParamName, jsonElement)
&& !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.adjustedDueDateParamName, jsonElement)) { && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.newInterestRateParamName, jsonElement)
dataValidatorBuilder && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.adjustedDueDateParamName, jsonElement)) {
.reset() dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.graceOnPrincipalParamName).notNull();
.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() "The loan can only be rescheduled once.");
.failWithCodeNoParameterAddedToErrorCode("loan.already.rescheduled",
"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
* @return void * the JSON command object (instance of the JsonCommand class)
**/ * @return void
public void validateForApproveAction(final JsonCommand jsonCommand, LoanRescheduleRequest loanRescheduleRequest) { **/
final String jsonString = jsonCommand.json(); public void validateForApproveAction(final JsonCommand jsonCommand, LoanRescheduleRequest loanRescheduleRequest) {
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() "request.is.not.in.submitted.and.pending.state",
.failWithCodeNoParameterAddedToErrorCode( "Loan reschedule request approval is not allowed. "
"request.is.not.in.submitted.and.pending.state", + "Loan reschedule request is not in submitted and pending approval state.");
"Loan reschedule request approval is not allowed. "
+ "Loan reschedule request is not in submitted and pending approval state.");
} }
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() "The loan can only be rescheduled once.");
.failWithCodeNoParameterAddedToErrorCode("loan.already.rescheduled",
"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
* @return void * the JSON command object (instance of the JsonCommand class)
**/ * @return void
public void validateForRejectAction(final JsonCommand jsonCommand, LoanRescheduleRequest loanRescheduleRequest) { **/
final String jsonString = jsonCommand.json(); public void validateForRejectAction(final JsonCommand jsonCommand, LoanRescheduleRequest loanRescheduleRequest) {
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() "request.is.not.in.submitted.and.pending.state",
.failWithCodeNoParameterAddedToErrorCode( "Loan reschedule request rejection is not allowed. "
"request.is.not.in.submitted.and.pending.state", + "Loan reschedule request is not in submitted and pending approval state.");
"Loan reschedule request rejection is not allowed. "
+ "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,9 +10,9 @@ 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;
private final boolean pendingApproval; private final boolean pendingApproval;
@@ -25,7 +25,7 @@ public class LoanRescheduleRequestStatusEnumData {
* Note: Same status types/states for loan accounts are used in here * Note: Same status types/states for loan accounts are used in here
**/ **/
public LoanRescheduleRequestStatusEnumData(Long id, String code, String value) { public LoanRescheduleRequestStatusEnumData(Long id, String code, String value) {
this.id = id; this.id = id;
this.code = code; this.code = code;
this.value = value; this.value = value;
this.pendingApproval = Long.valueOf(LoanStatus.SUBMITTED_AND_PENDING_APPROVAL.getValue()).equals(this.id); this.pendingApproval = Long.valueOf(LoanStatus.SUBMITTED_AND_PENDING_APPROVAL.getValue()).equals(this.id);
@@ -46,14 +46,14 @@ public class LoanRescheduleRequestStatusEnumData {
} }
public boolean isPendingApproval() { public boolean isPendingApproval() {
return this.pendingApproval; return this.pendingApproval;
} }
public boolean isApproved() { public boolean isApproved() {
return this.approved; return this.approved;
} }
public boolean isRejected() { public boolean isRejected() {
return this.rejected; return this.rejected;
} }
} }
@@ -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.");
}
} }