MIFOSX-109: some formatting changes and removal of unused items.
This commit is contained in:
+51
-63
@@ -35,84 +35,72 @@ import org.springframework.stereotype.Component;
|
|||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class GuarantorsApiResource {
|
public class GuarantorsApiResource {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private GuarantorWritePlatformService guarantorWritePlatformService;
|
private GuarantorWritePlatformService guarantorWritePlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private GuarantorReadPlatformService guarantorReadPlatformService;
|
private GuarantorReadPlatformService guarantorReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PortfolioApiDataConversionService apiDataConversionService;
|
private PortfolioApiDataConversionService apiDataConversionService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||||
|
|
||||||
private static final Set<String> typicalResponseParameters = new HashSet<String>(
|
private static final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("externalGuarantor", "existingClientId",
|
||||||
Arrays.asList("externalGuarantor", "existingClientId", "firstname",
|
"firstname", "lastname", "addressLine1", "addressLine2", "city", "state", "zip", "country", "mobileNumber", "housePhoneNumber",
|
||||||
"lastname", "addressLine1", "addressLine2", "city",
|
"comment", "dob"));
|
||||||
"state", "zip", "country", "mobileNumber",
|
|
||||||
"housePhoneNumber", "comment", "dob"));
|
|
||||||
|
|
||||||
private final String SystemEntityType = "m_guarantor_external";
|
private final String SystemEntityType = "m_guarantor_external";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PlatformSecurityContext context;
|
private PlatformSecurityContext context;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveGuarantorDetails(@Context final UriInfo uriInfo,
|
public String retrieveGuarantorDetails(@Context final UriInfo uriInfo, @PathParam("loanId") final Long loanId) {
|
||||||
@PathParam("loanId") final Long loanId) {
|
context.authenticatedUser().validateHasReadPermission(SystemEntityType);
|
||||||
context.authenticatedUser().validateHasReadPermission(SystemEntityType);
|
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
Set<String> responseParameters = ApiParameterHelper
|
if (responseParameters.isEmpty()) {
|
||||||
.extractFieldsForResponseIfProvided(uriInfo
|
responseParameters.addAll(typicalResponseParameters);
|
||||||
.getQueryParameters());
|
}
|
||||||
if (responseParameters.isEmpty()) {
|
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
responseParameters.addAll(typicalResponseParameters);
|
|
||||||
}
|
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo
|
|
||||||
.getQueryParameters());
|
|
||||||
|
|
||||||
GuarantorData guarantorData = guarantorReadPlatformService
|
GuarantorData guarantorData = guarantorReadPlatformService.retrieveGuarantor(loanId);
|
||||||
.retrieveGuarantor(loanId);
|
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeGuarantorDataToJson(
|
return this.apiJsonSerializerService.serializeGuarantorDataToJson(prettyPrint, responseParameters, guarantorData);
|
||||||
prettyPrint, responseParameters, guarantorData);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response createGuarantor(@PathParam("loanId") final Long loanId,
|
public Response createGuarantor(@PathParam("loanId") final Long loanId, final String jsonRequestBody) {
|
||||||
final String jsonRequestBody) {
|
|
||||||
|
|
||||||
final GuarantorCommand command = this.apiDataConversionService
|
final GuarantorCommand command = this.apiDataConversionService.convertJsonToGuarantorCommand(null, loanId, jsonRequestBody);
|
||||||
.convertJsonToGuarantorCommand(null, loanId, jsonRequestBody);
|
|
||||||
|
|
||||||
this.guarantorWritePlatformService.createGuarantor(loanId, command);
|
this.guarantorWritePlatformService.createGuarantor(loanId, command);
|
||||||
|
|
||||||
// returns the loan Identifier for which the guarantor was associated
|
// returns the loan Identifier for which the guarantor was associated
|
||||||
return Response.ok().entity(new EntityIdentifier(loanId)).build();
|
return Response.ok().entity(new EntityIdentifier(loanId)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response updateGuarantor(@PathParam("loanId") final Long loanId,
|
public Response updateGuarantor(@PathParam("loanId") final Long loanId, final String jsonRequestBody) {
|
||||||
final String jsonRequestBody) {
|
final GuarantorCommand command = this.apiDataConversionService.convertJsonToGuarantorCommand(null, loanId, jsonRequestBody);
|
||||||
final GuarantorCommand command = this.apiDataConversionService
|
|
||||||
.convertJsonToGuarantorCommand(null, loanId, jsonRequestBody);
|
|
||||||
|
|
||||||
this.guarantorWritePlatformService.updateGuarantor(loanId, command);
|
this.guarantorWritePlatformService.updateGuarantor(loanId, command);
|
||||||
|
|
||||||
return Response.ok().entity(new EntityIdentifier(loanId)).build();
|
return Response.ok().entity(new EntityIdentifier(loanId)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response deleteGuarantor(@PathParam("loanId") final Long loanId) {
|
public Response deleteGuarantor(@PathParam("loanId") final Long loanId) {
|
||||||
this.guarantorWritePlatformService.removeGuarantor(loanId);
|
this.guarantorWritePlatformService.removeGuarantor(loanId);
|
||||||
return Response.ok(new EntityIdentifier(loanId)).build();
|
return Response.ok(new EntityIdentifier(loanId)).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,442 +70,418 @@ import org.springframework.util.CollectionUtils;
|
|||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class LoansApiResource {
|
public class LoansApiResource {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoanReadPlatformService loanReadPlatformService;
|
private LoanReadPlatformService loanReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoanWritePlatformService loanWritePlatformService;
|
private LoanWritePlatformService loanWritePlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoanProductReadPlatformService loanProductReadPlatformService;
|
private LoanProductReadPlatformService loanProductReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoanDropdownReadPlatformService dropdownReadPlatformService;
|
private LoanDropdownReadPlatformService dropdownReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FundReadPlatformService fundReadPlatformService;
|
private FundReadPlatformService fundReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ChargeReadPlatformService chargeReadPlatformService;
|
private ChargeReadPlatformService chargeReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CalculationPlatformService calculationPlatformService;
|
private CalculationPlatformService calculationPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PortfolioApiDataConversionService apiDataConversionService;
|
private PortfolioApiDataConversionService apiDataConversionService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private StaffReadPlatformService staffReadPlatformService;
|
private StaffReadPlatformService staffReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PlatformSecurityContext context;
|
private PlatformSecurityContext context;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private GuarantorReadPlatformService guarantorReadPlatformService;
|
private GuarantorReadPlatformService guarantorReadPlatformService;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("template")
|
@Path("template")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveDetailsForNewLoanApplicationStepOne(
|
public String retrieveDetailsForNewLoanApplicationStepOne(@QueryParam("clientId") final Long clientId,
|
||||||
@QueryParam("clientId") final Long clientId,
|
@QueryParam("groupId") final Long groupId, @QueryParam("productId") final Long productId, @Context final UriInfo uriInfo) {
|
||||||
@QueryParam("groupId") final Long groupId,
|
|
||||||
@QueryParam("productId") final Long productId,
|
|
||||||
@Context final UriInfo uriInfo) {
|
|
||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission("LOAN");
|
context.authenticatedUser().validateHasReadPermission("LOAN");
|
||||||
|
|
||||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
// tempate related
|
// tempate related
|
||||||
Collection<LoanProductData> productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup();
|
Collection<LoanProductData> productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup();
|
||||||
Collection<EnumOptionData> loanTermFrequencyTypeOptions = dropdownReadPlatformService.retrieveLoanTermFrequencyTypeOptions();
|
Collection<EnumOptionData> loanTermFrequencyTypeOptions = dropdownReadPlatformService.retrieveLoanTermFrequencyTypeOptions();
|
||||||
Collection<EnumOptionData> repaymentFrequencyTypeOptions = dropdownReadPlatformService.retrieveRepaymentFrequencyTypeOptions();
|
Collection<EnumOptionData> repaymentFrequencyTypeOptions = dropdownReadPlatformService.retrieveRepaymentFrequencyTypeOptions();
|
||||||
Collection<EnumOptionData> interestRateFrequencyTypeOptions = dropdownReadPlatformService.retrieveInterestRateFrequencyTypeOptions();
|
Collection<EnumOptionData> interestRateFrequencyTypeOptions = dropdownReadPlatformService
|
||||||
|
.retrieveInterestRateFrequencyTypeOptions();
|
||||||
|
|
||||||
Collection<EnumOptionData> amortizationTypeOptions = dropdownReadPlatformService.retrieveLoanAmortizationTypeOptions();
|
Collection<EnumOptionData> amortizationTypeOptions = dropdownReadPlatformService.retrieveLoanAmortizationTypeOptions();
|
||||||
Collection<EnumOptionData> interestTypeOptions = dropdownReadPlatformService.retrieveLoanInterestTypeOptions();
|
Collection<EnumOptionData> interestTypeOptions = dropdownReadPlatformService.retrieveLoanInterestTypeOptions();
|
||||||
Collection<EnumOptionData> interestCalculationPeriodTypeOptions = dropdownReadPlatformService.retrieveLoanInterestRateCalculatedInPeriodOptions();
|
Collection<EnumOptionData> interestCalculationPeriodTypeOptions = dropdownReadPlatformService
|
||||||
|
.retrieveLoanInterestRateCalculatedInPeriodOptions();
|
||||||
|
|
||||||
Collection<FundData> fundOptions = this.fundReadPlatformService.retrieveAllFunds();
|
Collection<FundData> fundOptions = this.fundReadPlatformService.retrieveAllFunds();
|
||||||
Collection<TransactionProcessingStrategyData> repaymentStrategyOptions = this.dropdownReadPlatformService.retreiveTransactionProcessingStrategies();
|
Collection<TransactionProcessingStrategyData> repaymentStrategyOptions = this.dropdownReadPlatformService
|
||||||
|
.retreiveTransactionProcessingStrategies();
|
||||||
|
|
||||||
final boolean feeChargesOnly = false;
|
final boolean feeChargesOnly = false;
|
||||||
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly);
|
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly);
|
||||||
ChargeData chargeTemplate = this.chargeReadPlatformService.retrieveLoanChargeTemplate();
|
ChargeData chargeTemplate = this.chargeReadPlatformService.retrieveLoanChargeTemplate();
|
||||||
|
|
||||||
LoanBasicDetailsData loanBasicDetails;
|
LoanBasicDetailsData loanBasicDetails;
|
||||||
Long officeId;
|
Long officeId;
|
||||||
|
|
||||||
if ( clientId != null ){
|
if (clientId != null) {
|
||||||
loanBasicDetails = this.loanReadPlatformService.retrieveClientAndProductDetails(clientId, productId);
|
loanBasicDetails = this.loanReadPlatformService.retrieveClientAndProductDetails(clientId, productId);
|
||||||
officeId = loanBasicDetails.getClientOfficeId();
|
officeId = loanBasicDetails.getClientOfficeId();
|
||||||
} else {
|
} else {
|
||||||
loanBasicDetails = this.loanReadPlatformService.retrieveGroupAndProductDetails(groupId, productId);
|
loanBasicDetails = this.loanReadPlatformService.retrieveGroupAndProductDetails(groupId, productId);
|
||||||
officeId = loanBasicDetails.getGroupOfficeId();
|
officeId = loanBasicDetails.getGroupOfficeId();
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean convenienceDataRequired = false;
|
final boolean convenienceDataRequired = false;
|
||||||
Collection<LoanChargeData> charges = loanBasicDetails.getCharges();
|
Collection<LoanChargeData> charges = loanBasicDetails.getCharges();
|
||||||
|
|
||||||
Collection<StaffData> allowedLoanOfficers = this.staffReadPlatformService.retrieveAllLoanOfficersByOffice(officeId);
|
Collection<StaffData> allowedLoanOfficers = this.staffReadPlatformService.retrieveAllLoanOfficersByOffice(officeId);
|
||||||
|
|
||||||
final LoanAccountData newLoanAccount = new LoanAccountData(loanBasicDetails, convenienceDataRequired, null, null, null, charges,
|
final LoanAccountData newLoanAccount = new LoanAccountData(loanBasicDetails, convenienceDataRequired, null, null, null, charges,
|
||||||
productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions,
|
productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions, repaymentStrategyOptions,
|
||||||
repaymentStrategyOptions, interestRateFrequencyTypeOptions,
|
interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions,
|
||||||
amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions, fundOptions, chargeOptions, chargeTemplate, allowedLoanOfficers,null);
|
fundOptions, chargeOptions, chargeTemplate, allowedLoanOfficers, null);
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeLoanAccountDataToJson(prettyPrint, responseParameters, newLoanAccount);
|
return this.apiJsonSerializerService.serializeLoanAccountDataToJson(prettyPrint, responseParameters, newLoanAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{loanId}")
|
@Path("{loanId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveLoanAccountDetails(
|
public String retrieveLoanAccountDetails(@PathParam("loanId") final Long loanId, @Context final UriInfo uriInfo) {
|
||||||
@PathParam("loanId") final Long loanId,
|
|
||||||
@Context final UriInfo uriInfo) {
|
|
||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission("LOAN");
|
context.authenticatedUser().validateHasReadPermission("LOAN");
|
||||||
|
|
||||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
final LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveLoanAccountDetails(loanId);
|
final LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveLoanAccountDetails(loanId);
|
||||||
|
|
||||||
int loanRepaymentsCount = 0;
|
int loanRepaymentsCount = 0;
|
||||||
Collection<LoanTransactionData> loanRepayments = null;
|
Collection<LoanTransactionData> loanRepayments = null;
|
||||||
LoanScheduleData repaymentSchedule = null;
|
LoanScheduleData repaymentSchedule = null;
|
||||||
LoanPermissionData permissions = null;
|
LoanPermissionData permissions = null;
|
||||||
Collection<LoanChargeData> charges = null;
|
Collection<LoanChargeData> charges = null;
|
||||||
GuarantorData guarantorData = null;
|
GuarantorData guarantorData = null;
|
||||||
|
|
||||||
boolean convenienceDataRequired = false;
|
boolean convenienceDataRequired = false;
|
||||||
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
if (!associationParameters.isEmpty()) {
|
if (!associationParameters.isEmpty()) {
|
||||||
|
|
||||||
if (associationParameters.contains("all")) {
|
if (associationParameters.contains("all")) {
|
||||||
associationParameters.addAll(Arrays.asList("repaymentSchedule", "transactions", "permissions", "convenienceData", "charges", "guarantor"));
|
associationParameters.addAll(Arrays.asList("repaymentSchedule", "transactions", "permissions", "convenienceData",
|
||||||
}
|
"charges", "guarantor"));
|
||||||
|
}
|
||||||
|
|
||||||
boolean existsGuarantor = false;
|
boolean existsGuarantor = false;
|
||||||
if (associationParameters.contains("guarantor")) {
|
if (associationParameters.contains("guarantor")) {
|
||||||
if(guarantorReadPlatformService.existsGuarantor(loanId)){
|
if (guarantorReadPlatformService.existsGuarantor(loanId)) {
|
||||||
guarantorData = this.guarantorReadPlatformService.retrieveGuarantor(loanId);
|
guarantorData = this.guarantorReadPlatformService.retrieveGuarantor(loanId);
|
||||||
existsGuarantor = true;
|
existsGuarantor = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (associationParameters.contains("transactions")) {
|
if (associationParameters.contains("transactions")) {
|
||||||
final Collection<LoanTransactionData> currentLoanRepayments = this.loanReadPlatformService.retrieveLoanTransactions(loanId);
|
final Collection<LoanTransactionData> currentLoanRepayments = this.loanReadPlatformService.retrieveLoanTransactions(loanId);
|
||||||
if (!CollectionUtils.isEmpty(currentLoanRepayments)) {
|
if (!CollectionUtils.isEmpty(currentLoanRepayments)) {
|
||||||
loanRepayments = currentLoanRepayments;
|
loanRepayments = currentLoanRepayments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (associationParameters.contains("repaymentSchedule")) {
|
if (associationParameters.contains("repaymentSchedule")) {
|
||||||
|
|
||||||
DisbursementData singleDisbursement = loanBasicDetails.toDisburementData();
|
DisbursementData singleDisbursement = loanBasicDetails.toDisburementData();
|
||||||
repaymentSchedule = this.loanReadPlatformService.retrieveRepaymentSchedule(loanId, loanBasicDetails.getCurrency(),
|
repaymentSchedule = this.loanReadPlatformService.retrieveRepaymentSchedule(loanId, loanBasicDetails.getCurrency(),
|
||||||
singleDisbursement, loanBasicDetails.getTotalDisbursementCharges(), loanBasicDetails.getInArrearsTolerance());
|
singleDisbursement, loanBasicDetails.getTotalDisbursementCharges(), loanBasicDetails.getInArrearsTolerance());
|
||||||
|
|
||||||
// FIXME - KW - Waive feature was changed to waive interest at anytime so this permission checking is probably not needed - look into.
|
// FIXME - KW - Waive feature was changed to waive interest at
|
||||||
final MonetaryCurrency currency = new MonetaryCurrency(loanBasicDetails.getCurrency().getCode(), loanBasicDetails.getCurrency().getDecimalPlaces());
|
// anytime so this permission checking is probably not needed -
|
||||||
final Money tolerance = Money.of(currency, loanBasicDetails.getInArrearsTolerance());
|
// look into.
|
||||||
final Money totalOutstandingMoney = Money.of(currency, repaymentSchedule.totalOutstanding());
|
final MonetaryCurrency currency = new MonetaryCurrency(loanBasicDetails.getCurrency().getCode(), loanBasicDetails
|
||||||
|
.getCurrency().getDecimalPlaces());
|
||||||
|
final Money tolerance = Money.of(currency, loanBasicDetails.getInArrearsTolerance());
|
||||||
|
final Money totalOutstandingMoney = Money.of(currency, repaymentSchedule.totalOutstanding());
|
||||||
|
|
||||||
boolean isWaiveAllowed = totalOutstandingMoney.isGreaterThanZero() && (tolerance.isGreaterThan(totalOutstandingMoney) || tolerance.isEqualTo(totalOutstandingMoney));
|
boolean isWaiveAllowed = totalOutstandingMoney.isGreaterThanZero()
|
||||||
|
&& (tolerance.isGreaterThan(totalOutstandingMoney) || tolerance.isEqualTo(totalOutstandingMoney));
|
||||||
|
|
||||||
if (associationParameters.contains("permissions")) {
|
if (associationParameters.contains("permissions")) {
|
||||||
loanRepaymentsCount = retrieveNonDisbursementTransactions(loanRepayments);
|
loanRepaymentsCount = retrieveNonDisbursementTransactions(loanRepayments);
|
||||||
permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed, loanRepaymentsCount, existsGuarantor);
|
permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed,
|
||||||
}
|
loanRepaymentsCount, existsGuarantor);
|
||||||
convenienceDataRequired = true;
|
}
|
||||||
}
|
convenienceDataRequired = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (associationParameters.contains("charges")) {
|
if (associationParameters.contains("charges")) {
|
||||||
charges = this.chargeReadPlatformService.retrieveLoanCharges(loanId);
|
charges = this.chargeReadPlatformService.retrieveLoanCharges(loanId);
|
||||||
if (CollectionUtils.isEmpty(charges)) {
|
if (CollectionUtils.isEmpty(charges)) {
|
||||||
charges = null; // set back to null so doesnt appear in JSON is no charges exist.
|
charges = null; // set back to null so doesnt appear in JSON
|
||||||
}
|
// is no charges exist.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Collection<LoanProductData> productOptions = null;
|
Collection<LoanProductData> productOptions = null;
|
||||||
Collection<EnumOptionData> loanTermFrequencyTypeOptions = null;
|
Collection<EnumOptionData> loanTermFrequencyTypeOptions = null;
|
||||||
Collection<EnumOptionData> repaymentFrequencyTypeOptions = null;
|
Collection<EnumOptionData> repaymentFrequencyTypeOptions = null;
|
||||||
Collection<TransactionProcessingStrategyData> repaymentStrategyOptions = null;
|
Collection<TransactionProcessingStrategyData> repaymentStrategyOptions = null;
|
||||||
Collection<EnumOptionData> interestRateFrequencyTypeOptions = null;
|
Collection<EnumOptionData> interestRateFrequencyTypeOptions = null;
|
||||||
Collection<EnumOptionData> amortizationTypeOptions = null;
|
Collection<EnumOptionData> amortizationTypeOptions = null;
|
||||||
Collection<EnumOptionData> interestTypeOptions = null;
|
Collection<EnumOptionData> interestTypeOptions = null;
|
||||||
Collection<EnumOptionData> interestCalculationPeriodTypeOptions = null;
|
Collection<EnumOptionData> interestCalculationPeriodTypeOptions = null;
|
||||||
Collection<FundData> fundOptions = null;
|
Collection<FundData> fundOptions = null;
|
||||||
Collection<ChargeData> chargeOptions = null;
|
Collection<ChargeData> chargeOptions = null;
|
||||||
ChargeData chargeTemplate = null;
|
ChargeData chargeTemplate = null;
|
||||||
|
|
||||||
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
||||||
if(template) {
|
if (template) {
|
||||||
productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup();
|
productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup();
|
||||||
loanTermFrequencyTypeOptions = dropdownReadPlatformService.retrieveLoanTermFrequencyTypeOptions();
|
loanTermFrequencyTypeOptions = dropdownReadPlatformService.retrieveLoanTermFrequencyTypeOptions();
|
||||||
repaymentFrequencyTypeOptions = dropdownReadPlatformService.retrieveRepaymentFrequencyTypeOptions();
|
repaymentFrequencyTypeOptions = dropdownReadPlatformService.retrieveRepaymentFrequencyTypeOptions();
|
||||||
interestRateFrequencyTypeOptions = dropdownReadPlatformService.retrieveInterestRateFrequencyTypeOptions();
|
interestRateFrequencyTypeOptions = dropdownReadPlatformService.retrieveInterestRateFrequencyTypeOptions();
|
||||||
|
|
||||||
amortizationTypeOptions = dropdownReadPlatformService.retrieveLoanAmortizationTypeOptions();
|
amortizationTypeOptions = dropdownReadPlatformService.retrieveLoanAmortizationTypeOptions();
|
||||||
interestTypeOptions = dropdownReadPlatformService.retrieveLoanInterestTypeOptions();
|
interestTypeOptions = dropdownReadPlatformService.retrieveLoanInterestTypeOptions();
|
||||||
interestCalculationPeriodTypeOptions = dropdownReadPlatformService.retrieveLoanInterestRateCalculatedInPeriodOptions();
|
interestCalculationPeriodTypeOptions = dropdownReadPlatformService.retrieveLoanInterestRateCalculatedInPeriodOptions();
|
||||||
|
|
||||||
fundOptions = this.fundReadPlatformService.retrieveAllFunds();
|
fundOptions = this.fundReadPlatformService.retrieveAllFunds();
|
||||||
repaymentStrategyOptions = this.dropdownReadPlatformService.retreiveTransactionProcessingStrategies();
|
repaymentStrategyOptions = this.dropdownReadPlatformService.retreiveTransactionProcessingStrategies();
|
||||||
final boolean feeChargesOnly = false;
|
final boolean feeChargesOnly = false;
|
||||||
chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly);
|
chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly);
|
||||||
chargeTemplate = this.chargeReadPlatformService.retrieveLoanChargeTemplate();
|
chargeTemplate = this.chargeReadPlatformService.retrieveLoanChargeTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
final LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, convenienceDataRequired,
|
final LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, convenienceDataRequired, repaymentSchedule,
|
||||||
repaymentSchedule, loanRepayments, permissions, charges,
|
loanRepayments, permissions, charges, productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions,
|
||||||
productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions,
|
repaymentStrategyOptions, interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions,
|
||||||
repaymentStrategyOptions, interestRateFrequencyTypeOptions,
|
interestCalculationPeriodTypeOptions, fundOptions, chargeOptions, chargeTemplate, null, guarantorData);
|
||||||
amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions,
|
|
||||||
fundOptions, chargeOptions, chargeTemplate, null, guarantorData);
|
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeLoanAccountDataToJson(prettyPrint, responseParameters, loanAccount);
|
return this.apiJsonSerializerService.serializeLoanAccountDataToJson(prettyPrint, responseParameters, loanAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int retrieveNonDisbursementTransactions(final Collection<LoanTransactionData> loanRepayments) {
|
private int retrieveNonDisbursementTransactions(final Collection<LoanTransactionData> loanRepayments) {
|
||||||
int loanRepaymentsCount = 0;
|
int loanRepaymentsCount = 0;
|
||||||
if (!CollectionUtils.isEmpty(loanRepayments)) {
|
if (!CollectionUtils.isEmpty(loanRepayments)) {
|
||||||
for (LoanTransactionData transaction : loanRepayments) {
|
for (LoanTransactionData transaction : loanRepayments) {
|
||||||
if (transaction.isNotDisbursement()) {
|
if (transaction.isNotDisbursement()) {
|
||||||
// use this to decide if undo disbural should permission should be set to true.
|
// use this to decide if undo disbural should permission
|
||||||
loanRepaymentsCount++;
|
// should be set to true.
|
||||||
}
|
loanRepaymentsCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return loanRepaymentsCount;
|
}
|
||||||
}
|
return loanRepaymentsCount;
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String calculateLoanScheduleOrSubmitLoanApplication(
|
public String calculateLoanScheduleOrSubmitLoanApplication(@QueryParam("command") final String commandParam,
|
||||||
@QueryParam("command") final String commandParam,
|
@Context final UriInfo uriInfo, final String jsonRequestBody) {
|
||||||
@Context final UriInfo uriInfo,
|
|
||||||
final String jsonRequestBody) {
|
|
||||||
|
|
||||||
final LoanApplicationCommand command = this.apiDataConversionService.convertJsonToLoanApplicationCommand(null, jsonRequestBody);
|
final LoanApplicationCommand command = this.apiDataConversionService.convertJsonToLoanApplicationCommand(null, jsonRequestBody);
|
||||||
|
|
||||||
if (is(commandParam, "calculateLoanSchedule")) {
|
if (is(commandParam, "calculateLoanSchedule")) {
|
||||||
CalculateLoanScheduleCommand calculateLoanScheduleCommand = command.toCalculateLoanScheduleCommand();
|
CalculateLoanScheduleCommand calculateLoanScheduleCommand = command.toCalculateLoanScheduleCommand();
|
||||||
return calculateLoanSchedule(uriInfo, calculateLoanScheduleCommand);
|
return calculateLoanSchedule(uriInfo, calculateLoanScheduleCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
final EntityIdentifier identifier = this.loanWritePlatformService.submitLoanApplication(command);
|
final EntityIdentifier identifier = this.loanWritePlatformService.submitLoanApplication(command);
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeEntityIdentifier(identifier);
|
return this.apiJsonSerializerService.serializeEntityIdentifier(identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String calculateLoanSchedule(final UriInfo uriInfo, final CalculateLoanScheduleCommand command) {
|
private String calculateLoanSchedule(final UriInfo uriInfo, final CalculateLoanScheduleCommand command) {
|
||||||
|
|
||||||
final LoanScheduleData loanSchedule = this.calculationPlatformService.calculateLoanSchedule(command);
|
final LoanScheduleData loanSchedule = this.calculationPlatformService.calculateLoanSchedule(command);
|
||||||
|
|
||||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeLoanScheduleDataToJson(prettyPrint, responseParameters, loanSchedule);
|
return this.apiJsonSerializerService.serializeLoanScheduleDataToJson(prettyPrint, responseParameters, loanSchedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{loanId}")
|
@Path("{loanId}")
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String modifyLoanApplication(
|
public String modifyLoanApplication(@PathParam("loanId") final Long loanId, final String jsonRequestBody) {
|
||||||
@PathParam("loanId") final Long loanId,
|
|
||||||
final String jsonRequestBody) {
|
|
||||||
|
|
||||||
final LoanApplicationCommand command = this.apiDataConversionService.convertJsonToLoanApplicationCommand(loanId, jsonRequestBody);
|
final LoanApplicationCommand command = this.apiDataConversionService.convertJsonToLoanApplicationCommand(loanId, jsonRequestBody);
|
||||||
|
|
||||||
final EntityIdentifier identifier = this.loanWritePlatformService.modifyLoanApplication(command);
|
final EntityIdentifier identifier = this.loanWritePlatformService.modifyLoanApplication(command);
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeEntityIdentifier(identifier);
|
return this.apiJsonSerializerService.serializeEntityIdentifier(identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{loanId}")
|
@Path("{loanId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response deleteLoanApplication(@PathParam("loanId") final Long loanId) {
|
public Response deleteLoanApplication(@PathParam("loanId") final Long loanId) {
|
||||||
|
|
||||||
EntityIdentifier identifier = this.loanWritePlatformService.deleteLoan(loanId);
|
EntityIdentifier identifier = this.loanWritePlatformService.deleteLoan(loanId);
|
||||||
|
|
||||||
return Response.ok().entity(identifier).build();
|
return Response.ok().entity(identifier).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("{loanId}")
|
@Path("{loanId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response stateTransitions(@PathParam("loanId") final Long loanId,
|
public Response stateTransitions(@PathParam("loanId") final Long loanId, @QueryParam("command") final String commandParam,
|
||||||
@QueryParam("command") final String commandParam,
|
final String jsonRequestBody) {
|
||||||
final String jsonRequestBody) {
|
|
||||||
|
|
||||||
LoanStateTransitionCommand command = this.apiDataConversionService.convertJsonToLoanStateTransitionCommand(loanId, jsonRequestBody);
|
LoanStateTransitionCommand command = this.apiDataConversionService.convertJsonToLoanStateTransitionCommand(loanId, jsonRequestBody);
|
||||||
|
|
||||||
Response response = null;
|
Response response = null;
|
||||||
|
|
||||||
if (is(commandParam, "reject")) {
|
if (is(commandParam, "reject")) {
|
||||||
EntityIdentifier identifier = this.loanWritePlatformService
|
EntityIdentifier identifier = this.loanWritePlatformService.rejectLoan(command);
|
||||||
.rejectLoan(command);
|
response = Response.ok().entity(identifier).build();
|
||||||
response = Response.ok().entity(identifier).build();
|
} else if (is(commandParam, "withdrewbyclient")) {
|
||||||
} else if (is(commandParam, "withdrewbyclient")) {
|
EntityIdentifier identifier = this.loanWritePlatformService.withdrawLoan(command);
|
||||||
EntityIdentifier identifier = this.loanWritePlatformService
|
response = Response.ok().entity(identifier).build();
|
||||||
.withdrawLoan(command);
|
} else if (is(commandParam, "approve")) {
|
||||||
response = Response.ok().entity(identifier).build();
|
EntityIdentifier identifier = this.loanWritePlatformService.approveLoanApplication(command);
|
||||||
} else if (is(commandParam, "approve")) {
|
response = Response.ok().entity(identifier).build();
|
||||||
EntityIdentifier identifier = this.loanWritePlatformService
|
} else if (is(commandParam, "disburse")) {
|
||||||
.approveLoanApplication(command);
|
EntityIdentifier identifier = this.loanWritePlatformService.disburseLoan(command);
|
||||||
response = Response.ok().entity(identifier).build();
|
response = Response.ok().entity(identifier).build();
|
||||||
} else if (is(commandParam, "disburse")) {
|
}
|
||||||
EntityIdentifier identifier = this.loanWritePlatformService
|
|
||||||
.disburseLoan(command);
|
|
||||||
response = Response.ok().entity(identifier).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(
|
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(loanId, command.getNote());
|
||||||
loanId, command.getNote());
|
|
||||||
|
|
||||||
if (is(commandParam, "undoapproval")) {
|
if (is(commandParam, "undoapproval")) {
|
||||||
EntityIdentifier identifier = this.loanWritePlatformService
|
EntityIdentifier identifier = this.loanWritePlatformService.undoLoanApproval(undoCommand);
|
||||||
.undoLoanApproval(undoCommand);
|
response = Response.ok().entity(identifier).build();
|
||||||
response = Response.ok().entity(identifier).build();
|
} else if (is(commandParam, "undodisbursal")) {
|
||||||
} else if (is(commandParam, "undodisbursal")) {
|
EntityIdentifier identifier = this.loanWritePlatformService.undoLoanDisbursal(undoCommand);
|
||||||
EntityIdentifier identifier = this.loanWritePlatformService
|
response = Response.ok().entity(identifier).build();
|
||||||
.undoLoanDisbursal(undoCommand);
|
}
|
||||||
response = Response.ok().entity(identifier).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response == null) {
|
if (response == null) { throw new UnrecognizedQueryParamException("command", commandParam); }
|
||||||
throw new UnrecognizedQueryParamException("command", commandParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean is(final String commandParam, final String commandValue) {
|
private boolean is(final String commandParam, final String commandValue) {
|
||||||
return StringUtils.isNotBlank(commandParam)
|
return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue);
|
||||||
&& commandParam.trim().equalsIgnoreCase(commandValue);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("{loanId}/transactions")
|
@Path("{loanId}/transactions")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response executeLoanTransaction(
|
public Response executeLoanTransaction(@PathParam("loanId") final Long loanId, @QueryParam("command") final String commandParam,
|
||||||
@PathParam("loanId") final Long loanId,
|
final String jsonRequestBody) {
|
||||||
@QueryParam("command") final String commandParam,
|
|
||||||
final String jsonRequestBody) {
|
|
||||||
|
|
||||||
final LoanTransactionCommand command = this.apiDataConversionService.convertJsonToLoanTransactionCommand(loanId, jsonRequestBody);
|
final LoanTransactionCommand command = this.apiDataConversionService.convertJsonToLoanTransactionCommand(loanId, jsonRequestBody);
|
||||||
|
|
||||||
EntityIdentifier identifier = null;
|
EntityIdentifier identifier = null;
|
||||||
if (is(commandParam, "repayment")) {
|
if (is(commandParam, "repayment")) {
|
||||||
identifier = this.loanWritePlatformService.makeLoanRepayment(command);
|
identifier = this.loanWritePlatformService.makeLoanRepayment(command);
|
||||||
} else if (is(commandParam, "waiveinterest")) {
|
} else if (is(commandParam, "waiveinterest")) {
|
||||||
identifier = this.loanWritePlatformService.waiveInterestOnLoan(command);
|
identifier = this.loanWritePlatformService.waiveInterestOnLoan(command);
|
||||||
} else if (is(commandParam, "writeoff")) {
|
} else if (is(commandParam, "writeoff")) {
|
||||||
identifier = this.loanWritePlatformService.writeOff(command);
|
identifier = this.loanWritePlatformService.writeOff(command);
|
||||||
} else if (is(commandParam, "close-rescheduled")) {
|
} else if (is(commandParam, "close-rescheduled")) {
|
||||||
identifier = this.loanWritePlatformService.closeAsRescheduled(command);
|
identifier = this.loanWritePlatformService.closeAsRescheduled(command);
|
||||||
} else if (is(commandParam, "close")) {
|
} else if (is(commandParam, "close")) {
|
||||||
identifier = this.loanWritePlatformService.closeLoan(command);
|
identifier = this.loanWritePlatformService.closeLoan(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (identifier == null) {
|
if (identifier == null) { throw new UnrecognizedQueryParamException("command", commandParam); }
|
||||||
throw new UnrecognizedQueryParamException("command", commandParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Response.ok().entity(identifier).build();
|
return Response.ok().entity(identifier).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{loanId}/transactions/template")
|
@Path("{loanId}/transactions/template")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveNewRepaymentDetails(
|
public String retrieveNewRepaymentDetails(@PathParam("loanId") final Long loanId, @QueryParam("command") final String commandParam,
|
||||||
@PathParam("loanId") final Long loanId,
|
@Context final UriInfo uriInfo) {
|
||||||
@QueryParam("command") final String commandParam,
|
|
||||||
@Context final UriInfo uriInfo) {
|
|
||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission("LOAN");
|
context.authenticatedUser().validateHasReadPermission("LOAN");
|
||||||
|
|
||||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
LoanTransactionData transactionData = null;
|
LoanTransactionData transactionData = null;
|
||||||
if (is(commandParam, "repayment")) {
|
if (is(commandParam, "repayment")) {
|
||||||
transactionData = this.loanReadPlatformService.retrieveNewLoanRepaymentDetails(loanId);
|
transactionData = this.loanReadPlatformService.retrieveNewLoanRepaymentDetails(loanId);
|
||||||
} else if (is(commandParam, "waiveinterest")) {
|
} else if (is(commandParam, "waiveinterest")) {
|
||||||
transactionData = this.loanReadPlatformService.retrieveNewLoanWaiveInterestDetails(loanId);
|
transactionData = this.loanReadPlatformService.retrieveNewLoanWaiveInterestDetails(loanId);
|
||||||
} else if (is(commandParam, "writeoff")) {
|
} else if (is(commandParam, "writeoff")) {
|
||||||
transactionData = this.loanReadPlatformService.retrieveNewClosureDetails();
|
transactionData = this.loanReadPlatformService.retrieveNewClosureDetails();
|
||||||
} else if (is(commandParam, "close-rescheduled")) {
|
} else if (is(commandParam, "close-rescheduled")) {
|
||||||
transactionData = this.loanReadPlatformService.retrieveNewClosureDetails();
|
transactionData = this.loanReadPlatformService.retrieveNewClosureDetails();
|
||||||
} else if (is(commandParam, "close")) {
|
} else if (is(commandParam, "close")) {
|
||||||
transactionData = this.loanReadPlatformService.retrieveNewClosureDetails();
|
transactionData = this.loanReadPlatformService.retrieveNewClosureDetails();
|
||||||
} else {
|
} else {
|
||||||
throw new UnrecognizedQueryParamException("command", commandParam);
|
throw new UnrecognizedQueryParamException("command", commandParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, transactionData);
|
return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, transactionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{loanId}/transactions/{transactionId}")
|
@Path("{loanId}/transactions/{transactionId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveTransaction(@PathParam("loanId") final Long loanId,
|
public String retrieveTransaction(@PathParam("loanId") final Long loanId, @PathParam("transactionId") final Long transactionId,
|
||||||
@PathParam("transactionId") final Long transactionId,
|
@Context final UriInfo uriInfo) {
|
||||||
@Context final UriInfo uriInfo) {
|
|
||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission("LOAN");
|
context.authenticatedUser().validateHasReadPermission("LOAN");
|
||||||
|
|
||||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
final LoanTransactionData transactionData = this.loanReadPlatformService.retrieveLoanTransactionDetails(loanId, transactionId);
|
final LoanTransactionData transactionData = this.loanReadPlatformService.retrieveLoanTransactionDetails(loanId, transactionId);
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, transactionData);
|
return this.apiJsonSerializerService.serializeLoanTransactionDataToJson(prettyPrint, responseParameters, transactionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("{loanId}/transactions/{transactionId}")
|
@Path("{loanId}/transactions/{transactionId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response adjustLoanTransaction(
|
public Response adjustLoanTransaction(@PathParam("loanId") final Long loanId, @PathParam("transactionId") final Long transactionId,
|
||||||
@PathParam("loanId") final Long loanId,
|
final String jsonRequestBody) {
|
||||||
@PathParam("transactionId") final Long transactionId,
|
|
||||||
final String jsonRequestBody) {
|
|
||||||
|
|
||||||
final AdjustLoanTransactionCommand command = this.apiDataConversionService
|
final AdjustLoanTransactionCommand command = this.apiDataConversionService.convertJsonToAdjustLoanTransactionCommand(loanId,
|
||||||
.convertJsonToAdjustLoanTransactionCommand(loanId,
|
transactionId, jsonRequestBody);
|
||||||
transactionId, jsonRequestBody);
|
|
||||||
|
|
||||||
EntityIdentifier identifier = this.loanWritePlatformService
|
EntityIdentifier identifier = this.loanWritePlatformService.adjustLoanTransaction(command);
|
||||||
.adjustLoanTransaction(command);
|
|
||||||
|
|
||||||
return Response.ok().entity(identifier).build();
|
return Response.ok().entity(identifier).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("{loanId}/charges")
|
@Path("{loanId}/charges")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response addLoanCharge(
|
public Response addLoanCharge(@PathParam("loanId") final Long loanId, final String jsonRequestBody) {
|
||||||
@PathParam("loanId") final Long loanId,
|
|
||||||
final String jsonRequestBody){
|
|
||||||
|
|
||||||
final LoanChargeCommand command = this.apiDataConversionService.convertJsonToLoanChargeCommand(null, loanId, jsonRequestBody);
|
final LoanChargeCommand command = this.apiDataConversionService.convertJsonToLoanChargeCommand(null, loanId, jsonRequestBody);
|
||||||
|
|
||||||
@@ -516,14 +492,14 @@ public class LoansApiResource {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{loanId}/charges/template")
|
@Path("{loanId}/charges/template")
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveNewLoanChargeDetails(@Context final UriInfo uriInfo) {
|
public String retrieveNewLoanChargeDetails(@Context final UriInfo uriInfo) {
|
||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission("LOAN");
|
context.authenticatedUser().validateHasReadPermission("LOAN");
|
||||||
|
|
||||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
final boolean feeChargesOnly = false;
|
final boolean feeChargesOnly = false;
|
||||||
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly);
|
final Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly);
|
||||||
@@ -534,17 +510,15 @@ public class LoansApiResource {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{loanId}/charges/{chargeId}")
|
@Path("{loanId}/charges/{chargeId}")
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveLoanCharge(
|
public String retrieveLoanCharge(@PathParam("loanId") final Long loanId, @PathParam("chargeId") final Long loanChargeId,
|
||||||
@PathParam("loanId") final Long loanId,
|
@Context final UriInfo uriInfo) {
|
||||||
@PathParam("chargeId") final Long loanChargeId,
|
|
||||||
@Context final UriInfo uriInfo){
|
|
||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission("LOAN");
|
context.authenticatedUser().validateHasReadPermission("LOAN");
|
||||||
|
|
||||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
final LoanChargeData loanCharge = this.chargeReadPlatformService.retrieveLoanChargeDetails(loanChargeId, loanId);
|
final LoanChargeData loanCharge = this.chargeReadPlatformService.retrieveLoanChargeDetails(loanChargeId, loanId);
|
||||||
|
|
||||||
@@ -555,12 +529,11 @@ public class LoansApiResource {
|
|||||||
@Path("{loanId}/charges/{chargeId}")
|
@Path("{loanId}/charges/{chargeId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String updateLoanCharge(
|
public String updateLoanCharge(@PathParam("loanId") final Long loanId, @PathParam("chargeId") final Long loanChargeId,
|
||||||
@PathParam("loanId") final Long loanId,
|
final String jsonRequestBody) {
|
||||||
@PathParam("chargeId") final Long loanChargeId,
|
|
||||||
final String jsonRequestBody){
|
|
||||||
|
|
||||||
final LoanChargeCommand command = this.apiDataConversionService.convertJsonToLoanChargeCommand(loanChargeId, loanId, jsonRequestBody);
|
final LoanChargeCommand command = this.apiDataConversionService.convertJsonToLoanChargeCommand(loanChargeId, loanId,
|
||||||
|
jsonRequestBody);
|
||||||
|
|
||||||
final EntityIdentifier identifier = this.loanWritePlatformService.updateLoanCharge(command);
|
final EntityIdentifier identifier = this.loanWritePlatformService.updateLoanCharge(command);
|
||||||
|
|
||||||
@@ -571,20 +544,18 @@ public class LoansApiResource {
|
|||||||
@Path("{loanId}/charges/{chargeId}")
|
@Path("{loanId}/charges/{chargeId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String waiveLoanCharge(
|
public String waiveLoanCharge(@PathParam("loanId") final Long loanId, @PathParam("chargeId") final Long loanChargeId,
|
||||||
@PathParam("loanId") final Long loanId,
|
@QueryParam("command") final String commandParam) {
|
||||||
@PathParam("chargeId") final Long loanChargeId,
|
|
||||||
@QueryParam("command") final String commandParam){
|
|
||||||
|
|
||||||
final LoanChargeCommand command = LoanChargeCommand.forWaiver(loanChargeId, loanId);
|
final LoanChargeCommand command = LoanChargeCommand.forWaiver(loanChargeId, loanId);
|
||||||
|
|
||||||
String json = "";
|
String json = "";
|
||||||
if (is(commandParam, "waive")) {
|
if (is(commandParam, "waive")) {
|
||||||
final EntityIdentifier identifier = this.loanWritePlatformService.waiveLoanCharge(command);
|
final EntityIdentifier identifier = this.loanWritePlatformService.waiveLoanCharge(command);
|
||||||
json = this.apiJsonSerializerService.serializeEntityIdentifier(identifier);
|
json = this.apiJsonSerializerService.serializeEntityIdentifier(identifier);
|
||||||
} else {
|
} else {
|
||||||
throw new UnrecognizedQueryParamException("command", commandParam);
|
throw new UnrecognizedQueryParamException("command", commandParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
@@ -593,9 +564,7 @@ public class LoansApiResource {
|
|||||||
@Path("{loanId}/charges/{chargeId}")
|
@Path("{loanId}/charges/{chargeId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String deleteLoanCharge(
|
public String deleteLoanCharge(@PathParam("loanId") final Long loanId, @PathParam("chargeId") final Long loanChargeId) {
|
||||||
@PathParam("loanId") final Long loanId,
|
|
||||||
@PathParam("chargeId") final Long loanChargeId){
|
|
||||||
|
|
||||||
final EntityIdentifier identifier = this.loanWritePlatformService.deleteLoanCharge(loanId, loanChargeId);
|
final EntityIdentifier identifier = this.loanWritePlatformService.deleteLoanCharge(loanId, loanChargeId);
|
||||||
return this.apiJsonSerializerService.serializeEntityIdentifier(identifier);
|
return this.apiJsonSerializerService.serializeEntityIdentifier(identifier);
|
||||||
@@ -605,9 +574,7 @@ public class LoansApiResource {
|
|||||||
@Path("{loanId}/assign")
|
@Path("{loanId}/assign")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public Response assignLoanOfficer(
|
public Response assignLoanOfficer(@PathParam("loanId") final Long loanId, final String jsonRequestBody) {
|
||||||
@PathParam("loanId") final Long loanId,
|
|
||||||
final String jsonRequestBody){
|
|
||||||
|
|
||||||
final LoanReassignmentCommand command = this.apiDataConversionService.convertJsonToLoanReassignmentCommand(loanId, jsonRequestBody);
|
final LoanReassignmentCommand command = this.apiDataConversionService.convertJsonToLoanReassignmentCommand(loanId, jsonRequestBody);
|
||||||
|
|
||||||
@@ -620,19 +587,16 @@ public class LoansApiResource {
|
|||||||
@Path("{loanId}/assign/template")
|
@Path("{loanId}/assign/template")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String assignLoanOfficerTemplate(
|
public String assignLoanOfficerTemplate(@PathParam("loanId") final Long loanId, @Context final UriInfo uriInfo) {
|
||||||
@PathParam("loanId") final Long loanId,
|
|
||||||
@Context final UriInfo uriInfo){
|
|
||||||
|
|
||||||
final Set<String> responseParameters = ApiParameterHelper
|
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
.extractFieldsForResponseIfProvided(uriInfo
|
|
||||||
.getQueryParameters());
|
|
||||||
|
|
||||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveLoanAccountDetails(loanId);
|
LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveLoanAccountDetails(loanId);
|
||||||
|
|
||||||
Collection<StaffData> allowedLoanOfficers = this.staffReadPlatformService.retrieveAllLoanOfficersByOffice(loanBasicDetails.getOfficeId());
|
Collection<StaffData> allowedLoanOfficers = this.staffReadPlatformService.retrieveAllLoanOfficersByOffice(loanBasicDetails
|
||||||
|
.getOfficeId());
|
||||||
Long fromLoanOfficerId = loanBasicDetails.getLoanOfficerId();
|
Long fromLoanOfficerId = loanBasicDetails.getLoanOfficerId();
|
||||||
|
|
||||||
LoanReassignmentData loanReassignmentData = LoanReassignmentData.template(fromLoanOfficerId, allowedLoanOfficers, new LocalDate());
|
LoanReassignmentData loanReassignmentData = LoanReassignmentData.template(fromLoanOfficerId, allowedLoanOfficers, new LocalDate());
|
||||||
|
|||||||
+100
-103
@@ -7,135 +7,132 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class GuarantorCommand {
|
public class GuarantorCommand {
|
||||||
|
|
||||||
private final boolean externalGuarantor;
|
private final boolean externalGuarantor;
|
||||||
|
|
||||||
/*** Fields for current customers serving as guarantors **/
|
/*** Fields for current customers serving as guarantors **/
|
||||||
private final Long existingClientId;
|
private final Long existingClientId;
|
||||||
|
|
||||||
/*** Fields for external persons serving as guarantors ***/
|
/*** Fields for external persons serving as guarantors ***/
|
||||||
private final String firstname;
|
// FIXME - kw - what the details for collecting guarantors change? we are using datatable approach but fixing here?
|
||||||
private final String lastname;
|
private final String firstname;
|
||||||
private final String addressLine1;
|
private final String lastname;
|
||||||
private final String addressLine2;
|
private final String addressLine1;
|
||||||
private final String city;
|
private final String addressLine2;
|
||||||
private final String state;
|
private final String city;
|
||||||
private final String zip;
|
private final String state;
|
||||||
private final String country;
|
private final String zip;
|
||||||
private final String mobileNumber;
|
private final String country;
|
||||||
private final String housePhoneNumber;
|
private final String mobileNumber;
|
||||||
private final String comment;
|
private final String housePhoneNumber;
|
||||||
private final String dob;
|
private final String comment;
|
||||||
|
private final String dob;
|
||||||
|
|
||||||
/**Feilds for passing Locale info to generic data service api**/
|
/** Feilds for passing Locale info to generic data service api **/
|
||||||
private String dateFormat;
|
private String dateFormat;
|
||||||
private String locale;
|
private String locale;
|
||||||
|
|
||||||
private final Set<String> modifiedParameters;
|
private final Set<String> modifiedParameters;
|
||||||
|
|
||||||
public GuarantorCommand(final Set<String> modifiedParameters,
|
public GuarantorCommand(final Set<String> modifiedParameters, final Long existingClientId, final String firstname,
|
||||||
final Long existingClientId, final String firstname,
|
final String lastname, final Boolean externalGuarantor, final String addressLine1, final String addressLine2,
|
||||||
final String lastname, final Boolean externalGuarantor,
|
final String city, final String state, final String zip, final String country, final String mobileNumber,
|
||||||
final String addressLine1, final String addressLine2,
|
final String housePhoneNumber, final String comment, final String dob) {
|
||||||
final String city, final String state, final String zip,
|
this.modifiedParameters = modifiedParameters;
|
||||||
final String country, final String mobileNumber,
|
|
||||||
final String housePhoneNumber, final String comment,
|
|
||||||
final String dob) {
|
|
||||||
this.modifiedParameters = modifiedParameters;
|
|
||||||
|
|
||||||
this.externalGuarantor = externalGuarantor;
|
this.externalGuarantor = externalGuarantor;
|
||||||
|
|
||||||
/*** Fields for current customers serving as guarantors **/
|
/*** Fields for current customers serving as guarantors **/
|
||||||
this.existingClientId = existingClientId;
|
this.existingClientId = existingClientId;
|
||||||
|
|
||||||
/*** Fields for external persons serving as guarantors ***/
|
/*** Fields for external persons serving as guarantors ***/
|
||||||
this.firstname = firstname;
|
this.firstname = firstname;
|
||||||
this.lastname = lastname;
|
this.lastname = lastname;
|
||||||
this.addressLine1 = addressLine1;
|
this.addressLine1 = addressLine1;
|
||||||
this.addressLine2 = addressLine2;
|
this.addressLine2 = addressLine2;
|
||||||
this.city = city;
|
this.city = city;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.zip = zip;
|
this.zip = zip;
|
||||||
this.country = country;
|
this.country = country;
|
||||||
this.mobileNumber = mobileNumber;
|
this.mobileNumber = mobileNumber;
|
||||||
this.housePhoneNumber = housePhoneNumber;
|
this.housePhoneNumber = housePhoneNumber;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.dob = dob;
|
this.dob = dob;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFirstname() {
|
public String getFirstname() {
|
||||||
return firstname;
|
return firstname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLastname() {
|
public String getLastname() {
|
||||||
return lastname;
|
return lastname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isExternalGuarantor() {
|
public Boolean isExternalGuarantor() {
|
||||||
return externalGuarantor;
|
return externalGuarantor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getExistingClientId() {
|
public Long getExistingClientId() {
|
||||||
return existingClientId;
|
return existingClientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAddressLine1() {
|
public String getAddressLine1() {
|
||||||
return addressLine1;
|
return addressLine1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAddressLine2() {
|
public String getAddressLine2() {
|
||||||
return addressLine2;
|
return addressLine2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCity() {
|
public String getCity() {
|
||||||
return city;
|
return city;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getState() {
|
public String getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getZip() {
|
public String getZip() {
|
||||||
return zip;
|
return zip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCountry() {
|
public String getCountry() {
|
||||||
return country;
|
return country;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMobileNumber() {
|
public String getMobileNumber() {
|
||||||
return mobileNumber;
|
return mobileNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHousePhoneNumber() {
|
public String getHousePhoneNumber() {
|
||||||
return housePhoneNumber;
|
return housePhoneNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getComment() {
|
public String getComment() {
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getModifiedParameters() {
|
public Set<String> getModifiedParameters() {
|
||||||
return modifiedParameters;
|
return modifiedParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDob() {
|
public String getDob() {
|
||||||
return dob;
|
return dob;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDateFormat() {
|
public String getDateFormat() {
|
||||||
return dateFormat;
|
return dateFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDateFormat(String dateFormat) {
|
public void setDateFormat(String dateFormat) {
|
||||||
this.dateFormat = dateFormat;
|
this.dateFormat = dateFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocale() {
|
public String getLocale() {
|
||||||
return locale;
|
return locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocale(String locale) {
|
public void setLocale(String locale) {
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-2
@@ -95,7 +95,7 @@ public interface PortfolioApiDataConversionService {
|
|||||||
|
|
||||||
CodeCommand convertJsonToCodeCommand(Long resourceIdentifier, String json);
|
CodeCommand convertJsonToCodeCommand(Long resourceIdentifier, String json);
|
||||||
|
|
||||||
SavingAccountCommand convertJsonToSavingAccountCommand(Long resourceIdentifier,String json);
|
SavingAccountCommand convertJsonToSavingAccountCommand(Long resourceIdentifier, String json);
|
||||||
|
|
||||||
GuarantorCommand convertJsonToGuarantorCommand(Long resourceIdentifier, Long loanId, String json);
|
GuarantorCommand convertJsonToGuarantorCommand(Long resourceIdentifier, Long loanId, String json);
|
||||||
}
|
}
|
||||||
+33
-55
@@ -1631,66 +1631,44 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuarantorCommand convertJsonToGuarantorCommand(
|
public GuarantorCommand convertJsonToGuarantorCommand(Long resourceIdentifier, Long loanId, String json) {
|
||||||
Long resourceIdentifier, Long loanId, String json) {
|
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||||
if (StringUtils.isBlank(json)) {
|
|
||||||
throw new InvalidJsonException();
|
|
||||||
}
|
|
||||||
|
|
||||||
Type typeOfMap = new TypeToken<Map<String, String>>() {
|
Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType();
|
||||||
}.getType();
|
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||||
Map<String, String> requestMap = gsonConverter
|
|
||||||
.fromJson(json, typeOfMap);
|
|
||||||
|
|
||||||
Set<String> supportedParams = new HashSet<String>(Arrays.asList(
|
Set<String> supportedParams = new HashSet<String>(Arrays.asList("externalGuarantor", "existingClientId", "firstname", "lastname",
|
||||||
"externalGuarantor", "existingClientId", "firstname",
|
"addressLine1", "addressLine2", "city", "state", "zip", "country", "mobileNumber", "housePhoneNumber", "comment", "dob",
|
||||||
"lastname", "addressLine1", "addressLine2", "city", "state",
|
"locale", "dateFormat"));
|
||||||
"zip", "country", "mobileNumber", "housePhoneNumber",
|
|
||||||
"comment", "dob", "locale", "dateFormat"));
|
|
||||||
|
|
||||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||||
|
|
||||||
Set<String> modifiedParameters = new HashSet<String>();
|
Set<String> modifiedParameters = new HashSet<String>();
|
||||||
|
|
||||||
boolean externalGuarantor = extractBooleanParameter(
|
boolean externalGuarantor = extractBooleanParameter("externalGuarantor", requestMap, modifiedParameters);
|
||||||
"externalGuarantor", requestMap, modifiedParameters);
|
|
||||||
|
|
||||||
Long existingClientId = extractLongParameter("existingClientId",
|
Long existingClientId = extractLongParameter("existingClientId", requestMap, modifiedParameters);
|
||||||
requestMap, modifiedParameters);
|
String firstname = extractStringParameter("firstname", requestMap, modifiedParameters);
|
||||||
String firstname = extractStringParameter("firstname", requestMap,
|
String lastname = extractStringParameter("lastname", requestMap, modifiedParameters);
|
||||||
modifiedParameters);
|
String addressLine1 = extractStringParameter("addressLine1", requestMap, modifiedParameters);
|
||||||
String lastname = extractStringParameter("lastname", requestMap,
|
String addressLine2 = extractStringParameter("addressLine2", requestMap, modifiedParameters);
|
||||||
modifiedParameters);
|
String city = extractStringParameter("city", requestMap, modifiedParameters);
|
||||||
String addressLine1 = extractStringParameter("addressLine1",
|
String state = extractStringParameter("state", requestMap, modifiedParameters);
|
||||||
requestMap, modifiedParameters);
|
String zip = extractStringParameter("zip", requestMap, modifiedParameters);
|
||||||
String addressLine2 = extractStringParameter("addressLine2",
|
String country = extractStringParameter("country", requestMap, modifiedParameters);
|
||||||
requestMap, modifiedParameters);
|
String mobileNumber = extractStringParameter("mobileNumber", requestMap, modifiedParameters);
|
||||||
String city = extractStringParameter("city", requestMap,
|
String housePhoneNumber = extractStringParameter("housePhoneNumber", requestMap, modifiedParameters);
|
||||||
modifiedParameters);
|
String comment = extractStringParameter("comment", requestMap, modifiedParameters);
|
||||||
String state = extractStringParameter("state", requestMap,
|
String dob = extractStringParameter("dob", requestMap, modifiedParameters);
|
||||||
modifiedParameters);
|
|
||||||
String zip = extractStringParameter("zip", requestMap,
|
|
||||||
modifiedParameters);
|
|
||||||
String country = extractStringParameter("country", requestMap,
|
|
||||||
modifiedParameters);
|
|
||||||
String mobileNumber = extractStringParameter("mobileNumber",
|
|
||||||
requestMap, modifiedParameters);
|
|
||||||
String housePhoneNumber = extractStringParameter("housePhoneNumber",
|
|
||||||
requestMap, modifiedParameters);
|
|
||||||
String comment = extractStringParameter("comment", requestMap,
|
|
||||||
modifiedParameters);
|
|
||||||
String dob = extractStringParameter("dob", requestMap,
|
|
||||||
modifiedParameters);
|
|
||||||
// workaround for passing locale info to data table api
|
|
||||||
final String dateFormat = (String) requestMap.get("dateFormat");
|
|
||||||
final String locale = (String) requestMap.get("locale");
|
|
||||||
|
|
||||||
GuarantorCommand command = new GuarantorCommand(modifiedParameters,
|
// workaround for passing locale info to data table api
|
||||||
existingClientId, firstname, lastname, externalGuarantor,
|
final String dateFormat = requestMap.get("dateFormat");
|
||||||
addressLine1, addressLine2, city, state, zip, country,
|
final String locale = requestMap.get("locale");
|
||||||
mobileNumber, housePhoneNumber, comment, dob);
|
|
||||||
command.setDateFormat(dateFormat);
|
GuarantorCommand command = new GuarantorCommand(modifiedParameters, existingClientId, firstname, lastname, externalGuarantor,
|
||||||
command.setLocale(locale);
|
addressLine1, addressLine2, city, state, zip, country, mobileNumber, housePhoneNumber, comment, dob);
|
||||||
return command;
|
command.setDateFormat(dateFormat);
|
||||||
}
|
command.setLocale(locale);
|
||||||
|
return command;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+73
-95
@@ -12,111 +12,89 @@ import org.mifosng.platform.exceptions.LoanNotFoundException;
|
|||||||
import org.mifosng.platform.loan.domain.Loan;
|
import org.mifosng.platform.loan.domain.Loan;
|
||||||
import org.mifosng.platform.loan.domain.LoanRepository;
|
import org.mifosng.platform.loan.domain.LoanRepository;
|
||||||
import org.mifosng.platform.noncore.ReadWriteNonCoreDataService;
|
import org.mifosng.platform.noncore.ReadWriteNonCoreDataService;
|
||||||
import org.mifosng.platform.organisation.domain.OfficeRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GuarantorReadPlatformServiceImpl implements
|
public class GuarantorReadPlatformServiceImpl implements GuarantorReadPlatformService {
|
||||||
GuarantorReadPlatformService {
|
|
||||||
|
|
||||||
private final LoanRepository loanRepository;
|
// Table for storing external Guarantor Details
|
||||||
private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
|
public static final String EXTERNAL_GUARANTOR_TABLE_NAME = "m_guarantor_external";
|
||||||
// Table for storing external Guarantor Details
|
|
||||||
public static final String EXTERNAL_GUARANTOR_TABLE_NAME = "m_guarantor_external";
|
|
||||||
|
|
||||||
@Autowired
|
private final LoanRepository loanRepository;
|
||||||
public GuarantorReadPlatformServiceImpl(
|
private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
|
||||||
final LoanRepository loanRepository,
|
|
||||||
final ReadWriteNonCoreDataService readWriteNonCoreDataService,
|
|
||||||
final OfficeRepository officeRepository) {
|
|
||||||
this.loanRepository = loanRepository;
|
|
||||||
this.readWriteNonCoreDataService = readWriteNonCoreDataService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Autowired
|
||||||
public boolean existsGuarantor(Long loanId) {
|
public GuarantorReadPlatformServiceImpl(final LoanRepository loanRepository,
|
||||||
Loan loan = validateLoanExists(loanId);
|
final ReadWriteNonCoreDataService readWriteNonCoreDataService) {
|
||||||
// return if internal guarantor exists
|
this.loanRepository = loanRepository;
|
||||||
if (loan.getGuarantor() != null) {
|
this.readWriteNonCoreDataService = readWriteNonCoreDataService;
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
// return if an external guarantor exists
|
|
||||||
if (null != getExternalGuarantor(loanId)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// else no guarantor exists
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuarantorData retrieveGuarantor(Long loanId) {
|
public boolean existsGuarantor(Long loanId) {
|
||||||
GuarantorData guarantorData = null;
|
Loan loan = retrieveLoanById(loanId);
|
||||||
Loan loan = validateLoanExists(loanId);
|
// return if internal guarantor exists
|
||||||
// does an internal guarantor exist
|
if (loan.getGuarantor() != null) { return true; }
|
||||||
if (loan.getGuarantor() != null) {
|
// return if an external guarantor exists
|
||||||
Client guarantor = loan.getGuarantor();
|
if (null != getExternalGuarantor(loanId)) { return true; }
|
||||||
LocalDate localDate = new LocalDate(guarantor.getJoiningDate());
|
// else no guarantor exists
|
||||||
guarantorData = new GuarantorData(guarantor.getId(),
|
return false;
|
||||||
guarantor.getFirstName(), guarantor.getLastName(),
|
}
|
||||||
guarantor.getExternalId(), guarantor.getOffice().getName(),
|
|
||||||
localDate);
|
|
||||||
} else {
|
|
||||||
guarantorData = getExternalGuarantor(loanId);
|
|
||||||
}
|
|
||||||
// throw error if guarantor does not exist
|
|
||||||
if (guarantorData == null) {
|
|
||||||
throw new GuarantorNotFoundException(loanId);
|
|
||||||
}
|
|
||||||
return guarantorData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @param loanId
|
public GuarantorData retrieveGuarantor(Long loanId) {
|
||||||
* @return
|
GuarantorData guarantorData = null;
|
||||||
*/
|
Loan loan = retrieveLoanById(loanId);
|
||||||
private Loan validateLoanExists(Long loanId) {
|
// does an internal guarantor exist
|
||||||
Loan loan = loanRepository.findOne(loanId);
|
if (loan.getGuarantor() != null) {
|
||||||
if (loan == null) {
|
Client guarantor = loan.getGuarantor();
|
||||||
throw new LoanNotFoundException(loanId);
|
LocalDate localDate = new LocalDate(guarantor.getJoiningDate());
|
||||||
}
|
guarantorData = new GuarantorData(guarantor.getId(), guarantor.getFirstName(), guarantor.getLastName(),
|
||||||
return loan;
|
guarantor.getExternalId(), guarantor.getOffice().getName(), localDate);
|
||||||
}
|
} else {
|
||||||
|
guarantorData = getExternalGuarantor(loanId);
|
||||||
|
}
|
||||||
|
// throw error if guarantor does not exist
|
||||||
|
if (guarantorData == null) { throw new GuarantorNotFoundException(loanId); }
|
||||||
|
return guarantorData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
private Loan retrieveLoanById(final Long loanId) {
|
||||||
* @param loanId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public GuarantorData getExternalGuarantor(Long loanId) {
|
|
||||||
GenericResultsetData genericResultDataSet = readWriteNonCoreDataService
|
|
||||||
.retrieveDataTableGenericResultSet(
|
|
||||||
EXTERNAL_GUARANTOR_TABLE_NAME, loanId, null, null);
|
|
||||||
if (genericResultDataSet.getData().size() == 1) {
|
|
||||||
List<String> guarantorRow = genericResultDataSet.getData().get(0)
|
|
||||||
.getRow();
|
|
||||||
String firstname = guarantorRow.get(1);
|
|
||||||
String lastname = guarantorRow.get(2);
|
|
||||||
|
|
||||||
LocalDate dateOfBirth = null;
|
// FIXME - KW - On the read side of services - we would prefer not to use the repository/ORM pattern
|
||||||
if (!StringUtils.isBlank(guarantorRow.get(3))) {
|
Loan loan = loanRepository.findOne(loanId);
|
||||||
dateOfBirth = new LocalDate(guarantorRow.get(3));
|
if (loan == null) { throw new LoanNotFoundException(loanId); }
|
||||||
}
|
return loan;
|
||||||
String addressLine1 = guarantorRow.get(4);
|
}
|
||||||
String addressLine2 = guarantorRow.get(5);
|
|
||||||
String city = guarantorRow.get(6);
|
|
||||||
String state = guarantorRow.get(7);
|
|
||||||
String country = guarantorRow.get(8);
|
|
||||||
String zip = guarantorRow.get(9);
|
|
||||||
String housePhoneNumber = guarantorRow.get(10);
|
|
||||||
String mobileNumber = guarantorRow.get(11);
|
|
||||||
String comment = guarantorRow.get(12);
|
|
||||||
GuarantorData guarantorData = new GuarantorData(firstname,
|
|
||||||
lastname, dateOfBirth, addressLine1, addressLine2, city,
|
|
||||||
state, zip, country, mobileNumber, housePhoneNumber,
|
|
||||||
comment);
|
|
||||||
return guarantorData;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GuarantorData getExternalGuarantor(final Long loanId) {
|
||||||
|
|
||||||
|
GenericResultsetData genericResultDataSet = readWriteNonCoreDataService.retrieveDataTableGenericResultSet(
|
||||||
|
EXTERNAL_GUARANTOR_TABLE_NAME, loanId, null, null);
|
||||||
|
if (genericResultDataSet.getData().size() == 1) {
|
||||||
|
List<String> guarantorRow = genericResultDataSet.getData().get(0).getRow();
|
||||||
|
String firstname = guarantorRow.get(1);
|
||||||
|
String lastname = guarantorRow.get(2);
|
||||||
|
|
||||||
|
LocalDate dateOfBirth = null;
|
||||||
|
if (!StringUtils.isBlank(guarantorRow.get(3))) {
|
||||||
|
dateOfBirth = new LocalDate(guarantorRow.get(3));
|
||||||
|
}
|
||||||
|
String addressLine1 = guarantorRow.get(4);
|
||||||
|
String addressLine2 = guarantorRow.get(5);
|
||||||
|
String city = guarantorRow.get(6);
|
||||||
|
String state = guarantorRow.get(7);
|
||||||
|
String country = guarantorRow.get(8);
|
||||||
|
String zip = guarantorRow.get(9);
|
||||||
|
String housePhoneNumber = guarantorRow.get(10);
|
||||||
|
String mobileNumber = guarantorRow.get(11);
|
||||||
|
String comment = guarantorRow.get(12);
|
||||||
|
GuarantorData guarantorData = new GuarantorData(firstname, lastname, dateOfBirth, addressLine1, addressLine2, city, state, zip,
|
||||||
|
country, mobileNumber, housePhoneNumber, comment);
|
||||||
|
return guarantorData;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+108
-146
@@ -19,164 +19,126 @@ import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
|
|||||||
import org.mifosng.platform.loan.domain.Loan;
|
import org.mifosng.platform.loan.domain.Loan;
|
||||||
import org.mifosng.platform.loan.domain.LoanRepository;
|
import org.mifosng.platform.loan.domain.LoanRepository;
|
||||||
import org.mifosng.platform.noncore.ReadWriteNonCoreDataService;
|
import org.mifosng.platform.noncore.ReadWriteNonCoreDataService;
|
||||||
import org.mifosng.platform.organisation.domain.OfficeRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GuarantorWritePlatformServiceImpl implements
|
public class GuarantorWritePlatformServiceImpl implements GuarantorWritePlatformService {
|
||||||
GuarantorWritePlatformService {
|
|
||||||
|
|
||||||
private final LoanRepository loanRepository;
|
// Table for storing external Guarantor Details
|
||||||
private final ClientRepository clientRepository;
|
public static final String EXTERNAL_GUARANTOR_TABLE_NAME = "m_guarantor_external";
|
||||||
private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
|
|
||||||
private final GuarantorReadPlatformService guarantorReadPlatformService;
|
|
||||||
// Table for storing external Guarantor Details
|
|
||||||
public static final String EXTERNAL_GUARANTOR_TABLE_NAME = "m_guarantor_external";
|
|
||||||
|
|
||||||
@Autowired
|
private final LoanRepository loanRepository;
|
||||||
public GuarantorWritePlatformServiceImpl(
|
private final ClientRepository clientRepository;
|
||||||
final LoanRepository loanRepository,
|
private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
|
||||||
final ReadWriteNonCoreDataService readWriteNonCoreDataService,
|
private final GuarantorReadPlatformService guarantorReadPlatformService;
|
||||||
final OfficeRepository officeRepository,
|
|
||||||
final ClientRepository clientRepository,
|
|
||||||
final GuarantorReadPlatformService guarantorReadPlatformService) {
|
|
||||||
this.loanRepository = loanRepository;
|
|
||||||
this.readWriteNonCoreDataService = readWriteNonCoreDataService;
|
|
||||||
this.clientRepository = clientRepository;
|
|
||||||
this.guarantorReadPlatformService = guarantorReadPlatformService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Autowired
|
||||||
@Transactional
|
public GuarantorWritePlatformServiceImpl(final LoanRepository loanRepository,
|
||||||
public void createGuarantor(Long loanId, GuarantorCommand command) {
|
final ReadWriteNonCoreDataService readWriteNonCoreDataService, final ClientRepository clientRepository,
|
||||||
GuarantorCommandValidator validator = new GuarantorCommandValidator(
|
final GuarantorReadPlatformService guarantorReadPlatformService) {
|
||||||
command);
|
this.loanRepository = loanRepository;
|
||||||
validator.validateForCreate();
|
this.readWriteNonCoreDataService = readWriteNonCoreDataService;
|
||||||
saveOrUpdateGuarantor(loanId, command);
|
this.clientRepository = clientRepository;
|
||||||
}
|
this.guarantorReadPlatformService = guarantorReadPlatformService;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void updateGuarantor(Long loanId, GuarantorCommand command) {
|
public void createGuarantor(final Long loanId, final GuarantorCommand command) {
|
||||||
GuarantorCommandValidator validator = new GuarantorCommandValidator(
|
GuarantorCommandValidator validator = new GuarantorCommandValidator(command);
|
||||||
command);
|
validator.validateForCreate();
|
||||||
validator.validateForUpdate();
|
saveOrUpdateGuarantor(loanId, command);
|
||||||
saveOrUpdateGuarantor(loanId, command);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removeGuarantor(Long loanId) {
|
public void updateGuarantor(final Long loanId, final GuarantorCommand command) {
|
||||||
Loan loan = validateLoanExists(loanId);
|
GuarantorCommandValidator validator = new GuarantorCommandValidator(command);
|
||||||
// remove internal guarantor, if any
|
validator.validateForUpdate();
|
||||||
if (loan.getGuarantor() != null) {
|
saveOrUpdateGuarantor(loanId, command);
|
||||||
loan.setGuarantor(null);
|
}
|
||||||
loanRepository.saveAndFlush(loan);
|
|
||||||
}
|
|
||||||
// remove external guarantor, if any
|
|
||||||
readWriteNonCoreDataService.deleteDatatableEntries(
|
|
||||||
EXTERNAL_GUARANTOR_TABLE_NAME, loanId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @param loanId
|
@Transactional
|
||||||
* @param command
|
public void removeGuarantor(final Long loanId) {
|
||||||
*/
|
Loan loan = retrieveLoanById(loanId);
|
||||||
private void saveOrUpdateGuarantor(Long loanId, GuarantorCommand command) {
|
// remove internal guarantor, if any
|
||||||
Loan loan = validateLoanExists(loanId);
|
if (loan.getGuarantor() != null) {
|
||||||
// mark an existing client as a guarantor
|
loan.setGuarantor(null);
|
||||||
if (command.isExternalGuarantor() == null
|
loanRepository.saveAndFlush(loan);
|
||||||
|| !command.isExternalGuarantor()) {
|
}
|
||||||
// can't set client as a guarantor to himself
|
// remove external guarantor, if any
|
||||||
if (loan.getClient().getId().equals(command.getExistingClientId())) {
|
readWriteNonCoreDataService.deleteDatatableEntries(EXTERNAL_GUARANTOR_TABLE_NAME, loanId);
|
||||||
throw new InvalidGuarantorException(
|
}
|
||||||
command.getExistingClientId(), loanId);
|
|
||||||
}
|
|
||||||
Client guarantor = clientRepository.findOne(command
|
|
||||||
.getExistingClientId());
|
|
||||||
if (guarantor == null) {
|
|
||||||
throw new ClientNotFoundException(command.getExistingClientId());
|
|
||||||
}
|
|
||||||
loan.setGuarantor(guarantor);
|
|
||||||
this.loanRepository.saveAndFlush(loan);
|
|
||||||
// also delete any existing External Guarantors
|
|
||||||
readWriteNonCoreDataService.deleteDatatableEntries(
|
|
||||||
EXTERNAL_GUARANTOR_TABLE_NAME, loanId);
|
|
||||||
}// or create an external guarantor
|
|
||||||
else {
|
|
||||||
Set<String> modifiedParameters = command.getModifiedParameters();
|
|
||||||
Map<String, String> modifiedParametersMap = new HashMap<String, String>();
|
|
||||||
/***
|
|
||||||
* TODO Vishwas: Check with JW/KW if using reflection here is a good
|
|
||||||
* idea
|
|
||||||
**/
|
|
||||||
Class<? extends GuarantorCommand> guarantorCommandClass = command
|
|
||||||
.getClass();
|
|
||||||
for (String modifiedParameter : modifiedParameters) {
|
|
||||||
Method method;
|
|
||||||
try {
|
|
||||||
if (modifiedParameter.equalsIgnoreCase("externalGuarantor")
|
|
||||||
|| modifiedParameter
|
|
||||||
.equalsIgnoreCase("existingClientId")) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
method = guarantorCommandClass.getMethod("get"
|
|
||||||
+ StringUtils.capitalize(modifiedParameter));
|
|
||||||
}
|
|
||||||
String columnName = StringUtils.join(StringUtils
|
|
||||||
.splitByCharacterTypeCamelCase(modifiedParameter),
|
|
||||||
'_');
|
|
||||||
modifiedParametersMap.put(columnName.toLowerCase(), method
|
|
||||||
.invoke(command).toString());
|
|
||||||
} catch (Exception e) {
|
|
||||||
// TODO: This block would ideally never be reached, could
|
|
||||||
// use an
|
|
||||||
// empty catch block instead?
|
|
||||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
|
||||||
ApiParameterError apiParameterError = ApiParameterError
|
|
||||||
.parameterError(
|
|
||||||
"validation.msg.validation.errors.exist",
|
|
||||||
"", modifiedParameter);
|
|
||||||
dataValidationErrors.add(apiParameterError);
|
|
||||||
throw new PlatformApiDataValidationException(
|
|
||||||
"validation.msg.validation.errors.exist",
|
|
||||||
"Invalid parameter passed for Creating updating Guarantor",
|
|
||||||
dataValidationErrors);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
private void saveOrUpdateGuarantor(final Long loanId, final GuarantorCommand command) {
|
||||||
|
Loan loan = retrieveLoanById(loanId);
|
||||||
|
// mark an existing client as a guarantor
|
||||||
|
if (command.isExternalGuarantor() == null || !command.isExternalGuarantor()) {
|
||||||
|
// can't set client as a guarantor to himself
|
||||||
|
if (loan.getClient().getId().equals(command.getExistingClientId())) { throw new InvalidGuarantorException(
|
||||||
|
command.getExistingClientId(), loanId); }
|
||||||
|
Client guarantor = clientRepository.findOne(command.getExistingClientId());
|
||||||
|
if (guarantor == null) { throw new ClientNotFoundException(command.getExistingClientId()); }
|
||||||
|
loan.setGuarantor(guarantor);
|
||||||
|
this.loanRepository.saveAndFlush(loan);
|
||||||
|
// also delete any existing External Guarantors
|
||||||
|
readWriteNonCoreDataService.deleteDatatableEntries(EXTERNAL_GUARANTOR_TABLE_NAME, loanId);
|
||||||
|
}// or create an external guarantor
|
||||||
|
else {
|
||||||
|
Set<String> modifiedParameters = command.getModifiedParameters();
|
||||||
|
Map<String, String> modifiedParametersMap = new HashMap<String, String>();
|
||||||
|
|
||||||
/*** update or create a new external Guarantor entry ***/
|
/***
|
||||||
modifiedParametersMap.put("locale", command.getLocale());
|
* TODO Vishwas: Check with JW/KW if using reflection here is a good
|
||||||
modifiedParametersMap.put("dateFormat", command.getDateFormat());
|
* idea
|
||||||
if (guarantorReadPlatformService.getExternalGuarantor(loanId) != null) {
|
**/
|
||||||
readWriteNonCoreDataService.updateDatatableEntryOnetoOne(
|
Class<? extends GuarantorCommand> guarantorCommandClass = command.getClass();
|
||||||
EXTERNAL_GUARANTOR_TABLE_NAME, loanId,
|
for (String modifiedParameter : modifiedParameters) {
|
||||||
modifiedParametersMap);
|
Method method;
|
||||||
} else {
|
try {
|
||||||
readWriteNonCoreDataService.newDatatableEntry(
|
if (modifiedParameter.equalsIgnoreCase("externalGuarantor") || modifiedParameter.equalsIgnoreCase("existingClientId")) {
|
||||||
EXTERNAL_GUARANTOR_TABLE_NAME, loanId,
|
continue;
|
||||||
modifiedParametersMap);
|
} else {
|
||||||
}
|
method = guarantorCommandClass.getMethod("get" + StringUtils.capitalize(modifiedParameter));
|
||||||
// finally unset any existing internal guarantors
|
}
|
||||||
if (loan.getGuarantor() != null) {
|
String columnName = StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(modifiedParameter), '_');
|
||||||
loan.setGuarantor(null);
|
modifiedParametersMap.put(columnName.toLowerCase(), method.invoke(command).toString());
|
||||||
this.loanRepository.saveAndFlush(loan);
|
} catch (Exception e) {
|
||||||
}
|
// TODO: This block would ideally never be reached, could
|
||||||
}
|
// use an
|
||||||
}
|
// empty catch block instead?
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
ApiParameterError apiParameterError = ApiParameterError.parameterError("validation.msg.validation.errors.exist", "",
|
||||||
|
modifiedParameter);
|
||||||
|
dataValidationErrors.add(apiParameterError);
|
||||||
|
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||||
|
"Invalid parameter passed for Creating updating Guarantor", dataValidationErrors);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
}
|
||||||
* @param loanId
|
|
||||||
* @return
|
/*** update or create a new external Guarantor entry ***/
|
||||||
*/
|
modifiedParametersMap.put("locale", command.getLocale());
|
||||||
private Loan validateLoanExists(Long loanId) {
|
modifiedParametersMap.put("dateFormat", command.getDateFormat());
|
||||||
Loan loan = loanRepository.findOne(loanId);
|
if (guarantorReadPlatformService.getExternalGuarantor(loanId) != null) {
|
||||||
if (loan == null) {
|
readWriteNonCoreDataService.updateDatatableEntryOnetoOne(EXTERNAL_GUARANTOR_TABLE_NAME, loanId, modifiedParametersMap);
|
||||||
throw new LoanNotFoundException(loanId);
|
} else {
|
||||||
}
|
readWriteNonCoreDataService.newDatatableEntry(EXTERNAL_GUARANTOR_TABLE_NAME, loanId, modifiedParametersMap);
|
||||||
return loan;
|
}
|
||||||
}
|
// finally unset any existing internal guarantors
|
||||||
|
if (loan.getGuarantor() != null) {
|
||||||
|
loan.setGuarantor(null);
|
||||||
|
this.loanRepository.saveAndFlush(loan);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Loan retrieveLoanById(final Long loanId) {
|
||||||
|
Loan loan = loanRepository.findOne(loanId);
|
||||||
|
if (loan == null) { throw new LoanNotFoundException(loanId); }
|
||||||
|
return loan;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user