MIFOSX-109: some formatting changes and removal of unused items.

This commit is contained in:
Keith Woodlock
2012-11-21 17:06:50 +00:00
parent e874efc3ac
commit 4101cfbcf5
7 changed files with 752 additions and 885 deletions
@@ -47,11 +47,9 @@ public class GuarantorsApiResource {
@Autowired
private PortfolioApiJsonSerializerService apiJsonSerializerService;
private static final Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("externalGuarantor", "existingClientId", "firstname",
"lastname", "addressLine1", "addressLine2", "city",
"state", "zip", "country", "mobileNumber",
"housePhoneNumber", "comment", "dob"));
private static final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("externalGuarantor", "existingClientId",
"firstname", "lastname", "addressLine1", "addressLine2", "city", "state", "zip", "country", "mobileNumber", "housePhoneNumber",
"comment", "dob"));
private final String SystemEntityType = "m_guarantor_external";
@@ -61,33 +59,25 @@ public class GuarantorsApiResource {
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveGuarantorDetails(@Context final UriInfo uriInfo,
@PathParam("loanId") final Long loanId) {
public String retrieveGuarantorDetails(@Context final UriInfo uriInfo, @PathParam("loanId") final Long loanId) {
context.authenticatedUser().validateHasReadPermission(SystemEntityType);
Set<String> responseParameters = ApiParameterHelper
.extractFieldsForResponseIfProvided(uriInfo
.getQueryParameters());
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
if (responseParameters.isEmpty()) {
responseParameters.addAll(typicalResponseParameters);
}
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo
.getQueryParameters());
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
GuarantorData guarantorData = guarantorReadPlatformService
.retrieveGuarantor(loanId);
GuarantorData guarantorData = guarantorReadPlatformService.retrieveGuarantor(loanId);
return this.apiJsonSerializerService.serializeGuarantorDataToJson(
prettyPrint, responseParameters, guarantorData);
return this.apiJsonSerializerService.serializeGuarantorDataToJson(prettyPrint, responseParameters, guarantorData);
}
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response createGuarantor(@PathParam("loanId") final Long loanId,
final String jsonRequestBody) {
public Response createGuarantor(@PathParam("loanId") final Long loanId, final String jsonRequestBody) {
final GuarantorCommand command = this.apiDataConversionService
.convertJsonToGuarantorCommand(null, loanId, jsonRequestBody);
final GuarantorCommand command = this.apiDataConversionService.convertJsonToGuarantorCommand(null, loanId, jsonRequestBody);
this.guarantorWritePlatformService.createGuarantor(loanId, command);
@@ -98,10 +88,8 @@ public class GuarantorsApiResource {
@PUT
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response updateGuarantor(@PathParam("loanId") final Long loanId,
final String jsonRequestBody) {
final GuarantorCommand command = this.apiDataConversionService
.convertJsonToGuarantorCommand(null, loanId, jsonRequestBody);
public Response updateGuarantor(@PathParam("loanId") final Long loanId, final String jsonRequestBody) {
final GuarantorCommand command = this.apiDataConversionService.convertJsonToGuarantorCommand(null, loanId, jsonRequestBody);
this.guarantorWritePlatformService.updateGuarantor(loanId, command);
@@ -110,11 +110,8 @@ public class LoansApiResource {
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveDetailsForNewLoanApplicationStepOne(
@QueryParam("clientId") final Long clientId,
@QueryParam("groupId") final Long groupId,
@QueryParam("productId") final Long productId,
@Context final UriInfo uriInfo) {
public String retrieveDetailsForNewLoanApplicationStepOne(@QueryParam("clientId") final Long clientId,
@QueryParam("groupId") final Long groupId, @QueryParam("productId") final Long productId, @Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission("LOAN");
@@ -125,14 +122,17 @@ public class LoansApiResource {
Collection<LoanProductData> productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup();
Collection<EnumOptionData> loanTermFrequencyTypeOptions = dropdownReadPlatformService.retrieveLoanTermFrequencyTypeOptions();
Collection<EnumOptionData> repaymentFrequencyTypeOptions = dropdownReadPlatformService.retrieveRepaymentFrequencyTypeOptions();
Collection<EnumOptionData> interestRateFrequencyTypeOptions = dropdownReadPlatformService.retrieveInterestRateFrequencyTypeOptions();
Collection<EnumOptionData> interestRateFrequencyTypeOptions = dropdownReadPlatformService
.retrieveInterestRateFrequencyTypeOptions();
Collection<EnumOptionData> amortizationTypeOptions = dropdownReadPlatformService.retrieveLoanAmortizationTypeOptions();
Collection<EnumOptionData> interestTypeOptions = dropdownReadPlatformService.retrieveLoanInterestTypeOptions();
Collection<EnumOptionData> interestCalculationPeriodTypeOptions = dropdownReadPlatformService.retrieveLoanInterestRateCalculatedInPeriodOptions();
Collection<EnumOptionData> interestCalculationPeriodTypeOptions = dropdownReadPlatformService
.retrieveLoanInterestRateCalculatedInPeriodOptions();
Collection<FundData> fundOptions = this.fundReadPlatformService.retrieveAllFunds();
Collection<TransactionProcessingStrategyData> repaymentStrategyOptions = this.dropdownReadPlatformService.retreiveTransactionProcessingStrategies();
Collection<TransactionProcessingStrategyData> repaymentStrategyOptions = this.dropdownReadPlatformService
.retreiveTransactionProcessingStrategies();
final boolean feeChargesOnly = false;
Collection<ChargeData> chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly);
@@ -155,9 +155,9 @@ public class LoansApiResource {
Collection<StaffData> allowedLoanOfficers = this.staffReadPlatformService.retrieveAllLoanOfficersByOffice(officeId);
final LoanAccountData newLoanAccount = new LoanAccountData(loanBasicDetails, convenienceDataRequired, null, null, null, charges,
productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions,
repaymentStrategyOptions, interestRateFrequencyTypeOptions,
amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions, fundOptions, chargeOptions, chargeTemplate, allowedLoanOfficers,null);
productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions, repaymentStrategyOptions,
interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions,
fundOptions, chargeOptions, chargeTemplate, allowedLoanOfficers, null);
return this.apiJsonSerializerService.serializeLoanAccountDataToJson(prettyPrint, responseParameters, newLoanAccount);
}
@@ -166,9 +166,7 @@ public class LoansApiResource {
@Path("{loanId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveLoanAccountDetails(
@PathParam("loanId") final Long loanId,
@Context final UriInfo uriInfo) {
public String retrieveLoanAccountDetails(@PathParam("loanId") final Long loanId, @Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission("LOAN");
@@ -189,7 +187,8 @@ public class LoansApiResource {
if (!associationParameters.isEmpty()) {
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;
@@ -213,16 +212,21 @@ public class LoansApiResource {
repaymentSchedule = this.loanReadPlatformService.retrieveRepaymentSchedule(loanId, loanBasicDetails.getCurrency(),
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.
final MonetaryCurrency currency = new MonetaryCurrency(loanBasicDetails.getCurrency().getCode(), loanBasicDetails.getCurrency().getDecimalPlaces());
// FIXME - KW - Waive feature was changed to waive interest at
// anytime so this permission checking is probably not needed -
// look into.
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")) {
loanRepaymentsCount = retrieveNonDisbursementTransactions(loanRepayments);
permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed, loanRepaymentsCount, existsGuarantor);
permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed,
loanRepaymentsCount, existsGuarantor);
}
convenienceDataRequired = true;
}
@@ -230,7 +234,8 @@ public class LoansApiResource {
if (associationParameters.contains("charges")) {
charges = this.chargeReadPlatformService.retrieveLoanCharges(loanId);
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.
}
}
}
@@ -265,12 +270,10 @@ public class LoansApiResource {
chargeTemplate = this.chargeReadPlatformService.retrieveLoanChargeTemplate();
}
final LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, convenienceDataRequired,
repaymentSchedule, loanRepayments, permissions, charges,
productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions,
repaymentStrategyOptions, interestRateFrequencyTypeOptions,
amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions,
fundOptions, chargeOptions, chargeTemplate, null, guarantorData);
final LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, convenienceDataRequired, repaymentSchedule,
loanRepayments, permissions, charges, productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions,
repaymentStrategyOptions, interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions,
interestCalculationPeriodTypeOptions, fundOptions, chargeOptions, chargeTemplate, null, guarantorData);
return this.apiJsonSerializerService.serializeLoanAccountDataToJson(prettyPrint, responseParameters, loanAccount);
}
@@ -280,7 +283,8 @@ public class LoansApiResource {
if (!CollectionUtils.isEmpty(loanRepayments)) {
for (LoanTransactionData transaction : loanRepayments) {
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
// should be set to true.
loanRepaymentsCount++;
}
}
@@ -291,10 +295,8 @@ public class LoansApiResource {
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String calculateLoanScheduleOrSubmitLoanApplication(
@QueryParam("command") final String commandParam,
@Context final UriInfo uriInfo,
final String jsonRequestBody) {
public String calculateLoanScheduleOrSubmitLoanApplication(@QueryParam("command") final String commandParam,
@Context final UriInfo uriInfo, final String jsonRequestBody) {
final LoanApplicationCommand command = this.apiDataConversionService.convertJsonToLoanApplicationCommand(null, jsonRequestBody);
@@ -322,9 +324,7 @@ public class LoansApiResource {
@Path("{loanId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String modifyLoanApplication(
@PathParam("loanId") final Long loanId,
final String jsonRequestBody) {
public String modifyLoanApplication(@PathParam("loanId") final Long loanId, final String jsonRequestBody) {
final LoanApplicationCommand command = this.apiDataConversionService.convertJsonToLoanApplicationCommand(loanId, jsonRequestBody);
@@ -348,8 +348,7 @@ public class LoansApiResource {
@Path("{loanId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response stateTransitions(@PathParam("loanId") final Long loanId,
@QueryParam("command") final String commandParam,
public Response stateTransitions(@PathParam("loanId") final Long loanId, @QueryParam("command") final String commandParam,
final String jsonRequestBody) {
LoanStateTransitionCommand command = this.apiDataConversionService.convertJsonToLoanStateTransitionCommand(loanId, jsonRequestBody);
@@ -357,55 +356,43 @@ public class LoansApiResource {
Response response = null;
if (is(commandParam, "reject")) {
EntityIdentifier identifier = this.loanWritePlatformService
.rejectLoan(command);
EntityIdentifier identifier = this.loanWritePlatformService.rejectLoan(command);
response = Response.ok().entity(identifier).build();
} else if (is(commandParam, "withdrewbyclient")) {
EntityIdentifier identifier = this.loanWritePlatformService
.withdrawLoan(command);
EntityIdentifier identifier = this.loanWritePlatformService.withdrawLoan(command);
response = Response.ok().entity(identifier).build();
} else if (is(commandParam, "approve")) {
EntityIdentifier identifier = this.loanWritePlatformService
.approveLoanApplication(command);
EntityIdentifier identifier = this.loanWritePlatformService.approveLoanApplication(command);
response = Response.ok().entity(identifier).build();
} else if (is(commandParam, "disburse")) {
EntityIdentifier identifier = this.loanWritePlatformService
.disburseLoan(command);
EntityIdentifier identifier = this.loanWritePlatformService.disburseLoan(command);
response = Response.ok().entity(identifier).build();
}
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(
loanId, command.getNote());
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(loanId, command.getNote());
if (is(commandParam, "undoapproval")) {
EntityIdentifier identifier = this.loanWritePlatformService
.undoLoanApproval(undoCommand);
EntityIdentifier identifier = this.loanWritePlatformService.undoLoanApproval(undoCommand);
response = Response.ok().entity(identifier).build();
} else if (is(commandParam, "undodisbursal")) {
EntityIdentifier identifier = this.loanWritePlatformService
.undoLoanDisbursal(undoCommand);
EntityIdentifier identifier = this.loanWritePlatformService.undoLoanDisbursal(undoCommand);
response = Response.ok().entity(identifier).build();
}
if (response == null) {
throw new UnrecognizedQueryParamException("command", commandParam);
}
if (response == null) { throw new UnrecognizedQueryParamException("command", commandParam); }
return response;
}
private boolean is(final String commandParam, final String commandValue) {
return StringUtils.isNotBlank(commandParam)
&& commandParam.trim().equalsIgnoreCase(commandValue);
return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue);
}
@POST
@Path("{loanId}/transactions")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response executeLoanTransaction(
@PathParam("loanId") final Long loanId,
@QueryParam("command") final String commandParam,
public Response executeLoanTransaction(@PathParam("loanId") final Long loanId, @QueryParam("command") final String commandParam,
final String jsonRequestBody) {
final LoanTransactionCommand command = this.apiDataConversionService.convertJsonToLoanTransactionCommand(loanId, jsonRequestBody);
@@ -423,9 +410,7 @@ public class LoansApiResource {
identifier = this.loanWritePlatformService.closeLoan(command);
}
if (identifier == null) {
throw new UnrecognizedQueryParamException("command", commandParam);
}
if (identifier == null) { throw new UnrecognizedQueryParamException("command", commandParam); }
return Response.ok().entity(identifier).build();
}
@@ -434,9 +419,7 @@ public class LoansApiResource {
@Path("{loanId}/transactions/template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveNewRepaymentDetails(
@PathParam("loanId") final Long loanId,
@QueryParam("command") final String commandParam,
public String retrieveNewRepaymentDetails(@PathParam("loanId") final Long loanId, @QueryParam("command") final String commandParam,
@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission("LOAN");
@@ -466,8 +449,7 @@ public class LoansApiResource {
@Path("{loanId}/transactions/{transactionId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveTransaction(@PathParam("loanId") final Long loanId,
@PathParam("transactionId") final Long transactionId,
public String retrieveTransaction(@PathParam("loanId") final Long loanId, @PathParam("transactionId") final Long transactionId,
@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission("LOAN");
@@ -484,17 +466,13 @@ public class LoansApiResource {
@Path("{loanId}/transactions/{transactionId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response adjustLoanTransaction(
@PathParam("loanId") final Long loanId,
@PathParam("transactionId") final Long transactionId,
public Response adjustLoanTransaction(@PathParam("loanId") final Long loanId, @PathParam("transactionId") final Long transactionId,
final String jsonRequestBody) {
final AdjustLoanTransactionCommand command = this.apiDataConversionService
.convertJsonToAdjustLoanTransactionCommand(loanId,
final AdjustLoanTransactionCommand command = this.apiDataConversionService.convertJsonToAdjustLoanTransactionCommand(loanId,
transactionId, jsonRequestBody);
EntityIdentifier identifier = this.loanWritePlatformService
.adjustLoanTransaction(command);
EntityIdentifier identifier = this.loanWritePlatformService.adjustLoanTransaction(command);
return Response.ok().entity(identifier).build();
}
@@ -503,9 +481,7 @@ public class LoansApiResource {
@Path("{loanId}/charges")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response addLoanCharge(
@PathParam("loanId") final Long loanId,
final String jsonRequestBody){
public Response addLoanCharge(@PathParam("loanId") final Long loanId, final String jsonRequestBody) {
final LoanChargeCommand command = this.apiDataConversionService.convertJsonToLoanChargeCommand(null, loanId, jsonRequestBody);
@@ -536,9 +512,7 @@ public class LoansApiResource {
@Path("{loanId}/charges/{chargeId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveLoanCharge(
@PathParam("loanId") final Long loanId,
@PathParam("chargeId") final Long loanChargeId,
public String retrieveLoanCharge(@PathParam("loanId") final Long loanId, @PathParam("chargeId") final Long loanChargeId,
@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission("LOAN");
@@ -555,12 +529,11 @@ public class LoansApiResource {
@Path("{loanId}/charges/{chargeId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String updateLoanCharge(
@PathParam("loanId") final Long loanId,
@PathParam("chargeId") final Long loanChargeId,
public String updateLoanCharge(@PathParam("loanId") final Long loanId, @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);
@@ -571,9 +544,7 @@ public class LoansApiResource {
@Path("{loanId}/charges/{chargeId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String waiveLoanCharge(
@PathParam("loanId") final Long loanId,
@PathParam("chargeId") final Long loanChargeId,
public String waiveLoanCharge(@PathParam("loanId") final Long loanId, @PathParam("chargeId") final Long loanChargeId,
@QueryParam("command") final String commandParam) {
final LoanChargeCommand command = LoanChargeCommand.forWaiver(loanChargeId, loanId);
@@ -593,9 +564,7 @@ public class LoansApiResource {
@Path("{loanId}/charges/{chargeId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String deleteLoanCharge(
@PathParam("loanId") final Long loanId,
@PathParam("chargeId") final Long loanChargeId){
public String deleteLoanCharge(@PathParam("loanId") final Long loanId, @PathParam("chargeId") final Long loanChargeId) {
final EntityIdentifier identifier = this.loanWritePlatformService.deleteLoanCharge(loanId, loanChargeId);
return this.apiJsonSerializerService.serializeEntityIdentifier(identifier);
@@ -605,9 +574,7 @@ public class LoansApiResource {
@Path("{loanId}/assign")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response assignLoanOfficer(
@PathParam("loanId") final Long loanId,
final String jsonRequestBody){
public Response assignLoanOfficer(@PathParam("loanId") final Long loanId, final String jsonRequestBody) {
final LoanReassignmentCommand command = this.apiDataConversionService.convertJsonToLoanReassignmentCommand(loanId, jsonRequestBody);
@@ -620,19 +587,16 @@ public class LoansApiResource {
@Path("{loanId}/assign/template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String assignLoanOfficerTemplate(
@PathParam("loanId") final Long loanId,
@Context final UriInfo uriInfo){
public String assignLoanOfficerTemplate(@PathParam("loanId") final Long loanId, @Context final UriInfo uriInfo) {
final Set<String> responseParameters = ApiParameterHelper
.extractFieldsForResponseIfProvided(uriInfo
.getQueryParameters());
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
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();
LoanReassignmentData loanReassignmentData = LoanReassignmentData.template(fromLoanOfficerId, allowedLoanOfficers, new LocalDate());
@@ -13,6 +13,7 @@ public class GuarantorCommand {
private final Long existingClientId;
/*** Fields for external persons serving as guarantors ***/
// FIXME - kw - what the details for collecting guarantors change? we are using datatable approach but fixing here?
private final String firstname;
private final String lastname;
private final String addressLine1;
@@ -32,14 +33,10 @@ public class GuarantorCommand {
private final Set<String> modifiedParameters;
public GuarantorCommand(final Set<String> modifiedParameters,
final Long existingClientId, final String firstname,
final String lastname, final Boolean externalGuarantor,
final String addressLine1, final String addressLine2,
final String city, final String state, final String zip,
final String country, final String mobileNumber,
final String housePhoneNumber, final String comment,
final String dob) {
public GuarantorCommand(final Set<String> modifiedParameters, final Long existingClientId, final String firstname,
final String lastname, final Boolean externalGuarantor, final String addressLine1, final String addressLine2,
final String city, final String state, final String zip, final String country, final String mobileNumber,
final String housePhoneNumber, final String comment, final String dob) {
this.modifiedParameters = modifiedParameters;
this.externalGuarantor = externalGuarantor;
@@ -1631,64 +1631,42 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
}
@Override
public GuarantorCommand convertJsonToGuarantorCommand(
Long resourceIdentifier, Long loanId, String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
public GuarantorCommand convertJsonToGuarantorCommand(Long resourceIdentifier, Long loanId, String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
Type typeOfMap = new TypeToken<Map<String, String>>() {
}.getType();
Map<String, String> requestMap = gsonConverter
.fromJson(json, typeOfMap);
Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType();
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(Arrays.asList(
"externalGuarantor", "existingClientId", "firstname",
"lastname", "addressLine1", "addressLine2", "city", "state",
"zip", "country", "mobileNumber", "housePhoneNumber",
"comment", "dob", "locale", "dateFormat"));
Set<String> supportedParams = new HashSet<String>(Arrays.asList("externalGuarantor", "existingClientId", "firstname", "lastname",
"addressLine1", "addressLine2", "city", "state", "zip", "country", "mobileNumber", "housePhoneNumber", "comment", "dob",
"locale", "dateFormat"));
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
boolean externalGuarantor = extractBooleanParameter(
"externalGuarantor", requestMap, modifiedParameters);
boolean externalGuarantor = extractBooleanParameter("externalGuarantor", requestMap, modifiedParameters);
Long existingClientId = extractLongParameter("existingClientId", requestMap, modifiedParameters);
String firstname = extractStringParameter("firstname", requestMap, modifiedParameters);
String lastname = extractStringParameter("lastname", requestMap, modifiedParameters);
String addressLine1 = extractStringParameter("addressLine1", requestMap, modifiedParameters);
String addressLine2 = extractStringParameter("addressLine2", requestMap, modifiedParameters);
String city = extractStringParameter("city", requestMap, modifiedParameters);
String state = extractStringParameter("state", requestMap, 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);
Long existingClientId = extractLongParameter("existingClientId",
requestMap, modifiedParameters);
String firstname = extractStringParameter("firstname", requestMap,
modifiedParameters);
String lastname = extractStringParameter("lastname", requestMap,
modifiedParameters);
String addressLine1 = extractStringParameter("addressLine1",
requestMap, modifiedParameters);
String addressLine2 = extractStringParameter("addressLine2",
requestMap, modifiedParameters);
String city = extractStringParameter("city", requestMap,
modifiedParameters);
String state = extractStringParameter("state", requestMap,
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");
final String dateFormat = requestMap.get("dateFormat");
final String locale = requestMap.get("locale");
GuarantorCommand command = new GuarantorCommand(modifiedParameters,
existingClientId, firstname, lastname, externalGuarantor,
addressLine1, addressLine2, city, state, zip, country,
mobileNumber, housePhoneNumber, comment, dob);
GuarantorCommand command = new GuarantorCommand(modifiedParameters, existingClientId, firstname, lastname, externalGuarantor,
addressLine1, addressLine2, city, state, zip, country, mobileNumber, housePhoneNumber, comment, dob);
command.setDateFormat(dateFormat);
command.setLocale(locale);
return command;
@@ -12,39 +12,32 @@ import org.mifosng.platform.exceptions.LoanNotFoundException;
import org.mifosng.platform.loan.domain.Loan;
import org.mifosng.platform.loan.domain.LoanRepository;
import org.mifosng.platform.noncore.ReadWriteNonCoreDataService;
import org.mifosng.platform.organisation.domain.OfficeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class GuarantorReadPlatformServiceImpl implements
GuarantorReadPlatformService {
public class GuarantorReadPlatformServiceImpl implements GuarantorReadPlatformService {
private final LoanRepository loanRepository;
private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
// Table for storing external Guarantor Details
public static final String EXTERNAL_GUARANTOR_TABLE_NAME = "m_guarantor_external";
private final LoanRepository loanRepository;
private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
@Autowired
public GuarantorReadPlatformServiceImpl(
final LoanRepository loanRepository,
final ReadWriteNonCoreDataService readWriteNonCoreDataService,
final OfficeRepository officeRepository) {
public GuarantorReadPlatformServiceImpl(final LoanRepository loanRepository,
final ReadWriteNonCoreDataService readWriteNonCoreDataService) {
this.loanRepository = loanRepository;
this.readWriteNonCoreDataService = readWriteNonCoreDataService;
}
@Override
public boolean existsGuarantor(Long loanId) {
Loan loan = validateLoanExists(loanId);
Loan loan = retrieveLoanById(loanId);
// return if internal guarantor exists
if (loan.getGuarantor() != null) {
return true;
}
if (loan.getGuarantor() != null) { return true; }
// return if an external guarantor exists
if (null != getExternalGuarantor(loanId)) {
return true;
}
if (null != getExternalGuarantor(loanId)) { return true; }
// else no guarantor exists
return false;
}
@@ -52,48 +45,36 @@ public class GuarantorReadPlatformServiceImpl implements
@Override
public GuarantorData retrieveGuarantor(Long loanId) {
GuarantorData guarantorData = null;
Loan loan = validateLoanExists(loanId);
Loan loan = retrieveLoanById(loanId);
// does an internal guarantor exist
if (loan.getGuarantor() != null) {
Client guarantor = loan.getGuarantor();
LocalDate localDate = new LocalDate(guarantor.getJoiningDate());
guarantorData = new GuarantorData(guarantor.getId(),
guarantor.getFirstName(), guarantor.getLastName(),
guarantor.getExternalId(), guarantor.getOffice().getName(),
localDate);
guarantorData = new GuarantorData(guarantor.getId(), 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);
}
if (guarantorData == null) { throw new GuarantorNotFoundException(loanId); }
return guarantorData;
}
/**
* @param loanId
* @return
*/
private Loan validateLoanExists(Long loanId) {
private Loan retrieveLoanById(final Long loanId) {
// FIXME - KW - On the read side of services - we would prefer not to use the repository/ORM pattern
Loan loan = loanRepository.findOne(loanId);
if (loan == null) {
throw new LoanNotFoundException(loanId);
}
if (loan == null) { throw new LoanNotFoundException(loanId); }
return loan;
}
/**
* @param loanId
* @return
*/
public GuarantorData getExternalGuarantor(Long loanId) {
GenericResultsetData genericResultDataSet = readWriteNonCoreDataService
.retrieveDataTableGenericResultSet(
@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();
List<String> guarantorRow = genericResultDataSet.getData().get(0).getRow();
String firstname = guarantorRow.get(1);
String lastname = guarantorRow.get(2);
@@ -110,13 +91,10 @@ public class GuarantorReadPlatformServiceImpl implements
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);
GuarantorData guarantorData = new GuarantorData(firstname, lastname, dateOfBirth, addressLine1, addressLine2, city, state, zip,
country, mobileNumber, housePhoneNumber, comment);
return guarantorData;
}
return null;
}
}
@@ -19,28 +19,24 @@ import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
import org.mifosng.platform.loan.domain.Loan;
import org.mifosng.platform.loan.domain.LoanRepository;
import org.mifosng.platform.noncore.ReadWriteNonCoreDataService;
import org.mifosng.platform.organisation.domain.OfficeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class GuarantorWritePlatformServiceImpl implements
GuarantorWritePlatformService {
public class GuarantorWritePlatformServiceImpl implements GuarantorWritePlatformService {
// Table for storing external Guarantor Details
public static final String EXTERNAL_GUARANTOR_TABLE_NAME = "m_guarantor_external";
private final LoanRepository loanRepository;
private final ClientRepository clientRepository;
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
public GuarantorWritePlatformServiceImpl(
final LoanRepository loanRepository,
final ReadWriteNonCoreDataService readWriteNonCoreDataService,
final OfficeRepository officeRepository,
final ClientRepository clientRepository,
public GuarantorWritePlatformServiceImpl(final LoanRepository loanRepository,
final ReadWriteNonCoreDataService readWriteNonCoreDataService, final ClientRepository clientRepository,
final GuarantorReadPlatformService guarantorReadPlatformService) {
this.loanRepository = loanRepository;
this.readWriteNonCoreDataService = readWriteNonCoreDataService;
@@ -50,100 +46,76 @@ public class GuarantorWritePlatformServiceImpl implements
@Override
@Transactional
public void createGuarantor(Long loanId, GuarantorCommand command) {
GuarantorCommandValidator validator = new GuarantorCommandValidator(
command);
public void createGuarantor(final Long loanId, final GuarantorCommand command) {
GuarantorCommandValidator validator = new GuarantorCommandValidator(command);
validator.validateForCreate();
saveOrUpdateGuarantor(loanId, command);
}
@Override
@Transactional
public void updateGuarantor(Long loanId, GuarantorCommand command) {
GuarantorCommandValidator validator = new GuarantorCommandValidator(
command);
public void updateGuarantor(final Long loanId, final GuarantorCommand command) {
GuarantorCommandValidator validator = new GuarantorCommandValidator(command);
validator.validateForUpdate();
saveOrUpdateGuarantor(loanId, command);
}
@Override
@Transactional
public void removeGuarantor(Long loanId) {
Loan loan = validateLoanExists(loanId);
public void removeGuarantor(final Long loanId) {
Loan loan = retrieveLoanById(loanId);
// remove internal guarantor, if any
if (loan.getGuarantor() != null) {
loan.setGuarantor(null);
loanRepository.saveAndFlush(loan);
}
// remove external guarantor, if any
readWriteNonCoreDataService.deleteDatatableEntries(
EXTERNAL_GUARANTOR_TABLE_NAME, loanId);
readWriteNonCoreDataService.deleteDatatableEntries(EXTERNAL_GUARANTOR_TABLE_NAME, loanId);
}
/**
* @param loanId
* @param command
*/
private void saveOrUpdateGuarantor(Long loanId, GuarantorCommand command) {
Loan loan = validateLoanExists(loanId);
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()) {
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());
}
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);
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();
Class<? extends GuarantorCommand> guarantorCommandClass = command.getClass();
for (String modifiedParameter : modifiedParameters) {
Method method;
try {
if (modifiedParameter.equalsIgnoreCase("externalGuarantor")
|| modifiedParameter
.equalsIgnoreCase("existingClientId")) {
if (modifiedParameter.equalsIgnoreCase("externalGuarantor") || modifiedParameter.equalsIgnoreCase("existingClientId")) {
continue;
} else {
method = guarantorCommandClass.getMethod("get"
+ StringUtils.capitalize(modifiedParameter));
method = guarantorCommandClass.getMethod("get" + StringUtils.capitalize(modifiedParameter));
}
String columnName = StringUtils.join(StringUtils
.splitByCharacterTypeCamelCase(modifiedParameter),
'_');
modifiedParametersMap.put(columnName.toLowerCase(), method
.invoke(command).toString());
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);
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);
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Invalid parameter passed for Creating updating Guarantor", dataValidationErrors);
}
}
@@ -152,13 +124,9 @@ public class GuarantorWritePlatformServiceImpl implements
modifiedParametersMap.put("locale", command.getLocale());
modifiedParametersMap.put("dateFormat", command.getDateFormat());
if (guarantorReadPlatformService.getExternalGuarantor(loanId) != null) {
readWriteNonCoreDataService.updateDatatableEntryOnetoOne(
EXTERNAL_GUARANTOR_TABLE_NAME, loanId,
modifiedParametersMap);
readWriteNonCoreDataService.updateDatatableEntryOnetoOne(EXTERNAL_GUARANTOR_TABLE_NAME, loanId, modifiedParametersMap);
} else {
readWriteNonCoreDataService.newDatatableEntry(
EXTERNAL_GUARANTOR_TABLE_NAME, loanId,
modifiedParametersMap);
readWriteNonCoreDataService.newDatatableEntry(EXTERNAL_GUARANTOR_TABLE_NAME, loanId, modifiedParametersMap);
}
// finally unset any existing internal guarantors
if (loan.getGuarantor() != null) {
@@ -168,15 +136,9 @@ public class GuarantorWritePlatformServiceImpl implements
}
}
/**
* @param loanId
* @return
*/
private Loan validateLoanExists(Long loanId) {
private Loan retrieveLoanById(final Long loanId) {
Loan loan = loanRepository.findOne(loanId);
if (loan == null) {
throw new LoanNotFoundException(loanId);
}
if (loan == null) { throw new LoanNotFoundException(loanId); }
return loan;
}
}