MIFOSX-53 updated GET method. Fixed minor problems.
This commit is contained in:
@@ -25,6 +25,7 @@ import org.mifosng.platform.api.commands.LoanStateTransitionCommand;
|
|||||||
import org.mifosng.platform.api.commands.LoanTransactionCommand;
|
import org.mifosng.platform.api.commands.LoanTransactionCommand;
|
||||||
import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
|
import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
|
||||||
import org.mifosng.platform.api.commands.UndoStateTransitionCommand;
|
import org.mifosng.platform.api.commands.UndoStateTransitionCommand;
|
||||||
|
import org.mifosng.platform.api.data.ChargeData;
|
||||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||||
import org.mifosng.platform.api.data.LoanAccountData;
|
import org.mifosng.platform.api.data.LoanAccountData;
|
||||||
import org.mifosng.platform.api.data.LoanAccountSummaryData;
|
import org.mifosng.platform.api.data.LoanAccountSummaryData;
|
||||||
@@ -38,6 +39,7 @@ import org.mifosng.platform.api.data.NewLoanData;
|
|||||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||||
import org.mifosng.platform.api.infrastructure.ApiJsonSerializerService;
|
import org.mifosng.platform.api.infrastructure.ApiJsonSerializerService;
|
||||||
import org.mifosng.platform.api.infrastructure.ApiParameterHelper;
|
import org.mifosng.platform.api.infrastructure.ApiParameterHelper;
|
||||||
|
import org.mifosng.platform.charge.service.ChargeReadPlatformService;
|
||||||
import org.mifosng.platform.exceptions.UnrecognizedQueryParamException;
|
import org.mifosng.platform.exceptions.UnrecognizedQueryParamException;
|
||||||
import org.mifosng.platform.loan.service.CalculationPlatformService;
|
import org.mifosng.platform.loan.service.CalculationPlatformService;
|
||||||
import org.mifosng.platform.loan.service.LoanReadPlatformService;
|
import org.mifosng.platform.loan.service.LoanReadPlatformService;
|
||||||
@@ -57,6 +59,9 @@ public class LoansApiResource {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private LoanWritePlatformService loanWritePlatformService;
|
private LoanWritePlatformService loanWritePlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ChargeReadPlatformService chargeReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CalculationPlatformService calculationPlatformService;
|
private CalculationPlatformService calculationPlatformService;
|
||||||
|
|
||||||
@@ -118,11 +123,12 @@ public class LoansApiResource {
|
|||||||
Collection<LoanRepaymentPeriodData> repaymentSchedule = null;
|
Collection<LoanRepaymentPeriodData> repaymentSchedule = null;
|
||||||
LoanAccountSummaryData summary = null;
|
LoanAccountSummaryData summary = null;
|
||||||
LoanPermissionData permissions = null;
|
LoanPermissionData permissions = null;
|
||||||
|
Collection<ChargeData> charges = null;
|
||||||
|
|
||||||
Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
if (!associationParameters.isEmpty()) {
|
if (!associationParameters.isEmpty()) {
|
||||||
if (associationParameters.contains("all")) {
|
if (associationParameters.contains("all")) {
|
||||||
responseParameters.addAll(Arrays.asList("summary", "repaymentSchedule", "loanRepayments", "permissions", "convenienceData"));
|
responseParameters.addAll(Arrays.asList("summary", "repaymentSchedule", "loanRepayments", "permissions", "convenienceData", "charges"));
|
||||||
} else {
|
} else {
|
||||||
responseParameters.addAll(associationParameters);
|
responseParameters.addAll(associationParameters);
|
||||||
}
|
}
|
||||||
@@ -134,9 +140,11 @@ public class LoansApiResource {
|
|||||||
|
|
||||||
boolean isWaiveAllowed = summary.isWaiveAllowed(loanBasicDetails.getInArrearsTolerance());
|
boolean isWaiveAllowed = summary.isWaiveAllowed(loanBasicDetails.getInArrearsTolerance());
|
||||||
permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed, loanRepayments.size());
|
permissions = this.loanReadPlatformService.retrieveLoanPermissions(loanBasicDetails, isWaiveAllowed, loanRepayments.size());
|
||||||
|
|
||||||
|
charges = this.chargeReadPlatformService.retrieveLoanCharges(loanId);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, summary, repaymentSchedule, loanRepayments, permissions);
|
LoanAccountData loanAccount = new LoanAccountData(loanBasicDetails, summary, repaymentSchedule, loanRepayments, permissions, charges);
|
||||||
|
|
||||||
return this.apiJsonSerializerService.serialzieLoanAccountDataToJson(prettyPrint, responseParameters, loanAccount);
|
return this.apiJsonSerializerService.serialzieLoanAccountDataToJson(prettyPrint, responseParameters, loanAccount);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ public class LoanAccountData {
|
|||||||
|
|
||||||
private LoanConvenienceData convenienceData;
|
private LoanConvenienceData convenienceData;
|
||||||
|
|
||||||
|
private Collection<ChargeData> charges;
|
||||||
|
|
||||||
protected LoanAccountData() {
|
protected LoanAccountData() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
@@ -57,11 +59,12 @@ public class LoanAccountData {
|
|||||||
LoanAccountSummaryData summary,
|
LoanAccountSummaryData summary,
|
||||||
Collection<LoanRepaymentPeriodData> repaymentSchedule,
|
Collection<LoanRepaymentPeriodData> repaymentSchedule,
|
||||||
Collection<LoanRepaymentTransactionData> loanRepayments,
|
Collection<LoanRepaymentTransactionData> loanRepayments,
|
||||||
LoanPermissionData permissions) {
|
LoanPermissionData permissions, Collection<ChargeData> charges) {
|
||||||
this.summary = summary;
|
this.summary = summary;
|
||||||
this.repaymentSchedule = repaymentSchedule;
|
this.repaymentSchedule = repaymentSchedule;
|
||||||
this.loanRepayments = loanRepayments;
|
this.loanRepayments = loanRepayments;
|
||||||
this.permissions = permissions;
|
this.permissions = permissions;
|
||||||
|
this.charges = charges;
|
||||||
|
|
||||||
int maxSubmittedOnOffsetFromToday = basicDetails
|
int maxSubmittedOnOffsetFromToday = basicDetails
|
||||||
.getMaxSubmittedOnOffsetFromToday();
|
.getMaxSubmittedOnOffsetFromToday();
|
||||||
@@ -384,4 +387,11 @@ public class LoanAccountData {
|
|||||||
this.lifeCycleStatusId = lifeCycleStatusId;
|
this.lifeCycleStatusId = lifeCycleStatusId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<ChargeData> getCharges() {
|
||||||
|
return charges;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCharges(Collection<ChargeData> charges) {
|
||||||
|
this.charges = charges;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+4
-4
@@ -436,13 +436,13 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
|||||||
throw new InvalidJsonException();
|
throw new InvalidJsonException();
|
||||||
}
|
}
|
||||||
|
|
||||||
Type typeOfMap = new TypeToken<Map<String, String>>(){}.getType();
|
Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType();
|
||||||
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||||
|
|
||||||
Set<String> supportedParams = new HashSet<String>(
|
Set<String> supportedParams = new HashSet<String>(
|
||||||
Arrays.asList("clientId", "productId", "externalId", "fundId", "transactionProcessingStrategyId",
|
Arrays.asList("clientId", "productId", "externalId", "fundId", "transactionProcessingStrategyId",
|
||||||
"principal", "inArrearsTolerance", "interestRatePerPeriod", "repaymentEvery", "numberOfRepayments",
|
"principal", "inArrearsTolerance", "interestRatePerPeriod", "repaymentEvery", "numberOfRepayments",
|
||||||
"loanTermFrequency", "loanTermFrequencyType",
|
"loanTermFrequency", "loanTermFrequencyType", "charges",
|
||||||
"repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType",
|
"repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType",
|
||||||
"expectedDisbursementDate", "repaymentsStartingFromDate", "interestChargedFromDate", "submittedOnDate", "submittedOnNote",
|
"expectedDisbursementDate", "repaymentsStartingFromDate", "interestChargedFromDate", "submittedOnDate", "submittedOnNote",
|
||||||
"locale", "dateFormat")
|
"locale", "dateFormat")
|
||||||
@@ -487,7 +487,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
|||||||
JsonElement element = parser.parse(json);
|
JsonElement element = parser.parse(json);
|
||||||
if (element.isJsonObject()) {
|
if (element.isJsonObject()) {
|
||||||
JsonObject object = element.getAsJsonObject();
|
JsonObject object = element.getAsJsonObject();
|
||||||
if (object.has("charges")) {
|
if (object.has("charges") && object.get("charges").isJsonArray()) {
|
||||||
modifiedParameters.add("charges");
|
modifiedParameters.add("charges");
|
||||||
JsonArray array = object.get("charges").getAsJsonArray();
|
JsonArray array = object.get("charges").getAsJsonArray();
|
||||||
charges = new LoanChargeCommand[array.size()];
|
charges = new LoanChargeCommand[array.size()];
|
||||||
|
|||||||
+1
-1
@@ -152,7 +152,7 @@ public class GoogleGsonApiJsonSerializerService implements
|
|||||||
"closedOnDate", "expectedMaturityDate",
|
"closedOnDate", "expectedMaturityDate",
|
||||||
"lifeCycleStatusId", "lifeCycleStatusText",
|
"lifeCycleStatusId", "lifeCycleStatusText",
|
||||||
"lifeCycleStatusDate", "summary", "repaymentSchedule",
|
"lifeCycleStatusDate", "summary", "repaymentSchedule",
|
||||||
"loanRepayments", "permissions", "convenienceData"));
|
"loanRepayments", "permissions", "convenienceData", "charges"));
|
||||||
|
|
||||||
private static final Set<String> LOAN_TRANSACTION_DATA_PARAMETERS = new HashSet<String>(
|
private static final Set<String> LOAN_TRANSACTION_DATA_PARAMETERS = new HashSet<String>(
|
||||||
Arrays.asList("id", "transactionType", "date", "principal",
|
Arrays.asList("id", "transactionType", "date", "principal",
|
||||||
|
|||||||
+2
@@ -15,4 +15,6 @@ public interface ChargeReadPlatformService {
|
|||||||
Collection<ChargeData> retrieveLoanApplicableCharges();
|
Collection<ChargeData> retrieveLoanApplicableCharges();
|
||||||
|
|
||||||
Collection<ChargeData> retrieveLoanProductCharges(Long loanProductId);
|
Collection<ChargeData> retrieveLoanProductCharges(Long loanProductId);
|
||||||
|
|
||||||
|
Collection<ChargeData> retrieveLoanCharges(Long loanId);
|
||||||
}
|
}
|
||||||
|
|||||||
+21
@@ -105,6 +105,17 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
|
|||||||
return this.jdbcTemplate.query(sql, rm, new Object[] {loanProductId});
|
return this.jdbcTemplate.query(sql, rm, new Object[] {loanProductId});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<ChargeData> retrieveLoanCharges(Long loanId) {
|
||||||
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
|
ChargeMapper rm = new ChargeMapper();
|
||||||
|
|
||||||
|
String sql = "select " + rm.loanChargeSchema() + " where c.is_deleted=0 and lc.loan_id=?";
|
||||||
|
|
||||||
|
return this.jdbcTemplate.query(sql, rm, new Object[] {loanId});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ChargeData> retrieveLoanApplicableCharges() {
|
public Collection<ChargeData> retrieveLoanApplicableCharges() {
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
@@ -131,6 +142,16 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
|
|||||||
return chargeSchema() + " join m_product_loan_charge plc on plc.charge_id = c.id";
|
return chargeSchema() + " join m_product_loan_charge plc on plc.charge_id = c.id";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String loanChargeSchema(){
|
||||||
|
return "c.id as id, c.name as name, lc.amount as amount, c.currency_code as currencyCode, " +
|
||||||
|
"c.charge_applies_to_enum as chargeAppliesTo, lc.charge_time_enum as chargeTime, " +
|
||||||
|
"lc.charge_calculation_enum as chargeCalculation, is_active as active, oc.name as currencyName, " +
|
||||||
|
"oc.decimal_places as currencyDecimalPlaces, oc.display_symbol as currencyDisplaySymbol, " +
|
||||||
|
"oc.internationalized_name_code as currencyNameCode from m_charge c " +
|
||||||
|
"join m_organisation_currency oc on c.currency_code = oc.code " +
|
||||||
|
"join m_loan_charge lc on lc.charge_id = c.id ";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChargeData mapRow(ResultSet rs, int rowNum) throws SQLException {
|
public ChargeData mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||||
Long id = rs.getLong("id");
|
Long id = rs.getLong("id");
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ public class LoanAssembler {
|
|||||||
}
|
}
|
||||||
charges.add(new LoanCharge(loan, charge, loanChargeCommand));
|
charges.add(new LoanCharge(loan, charge, loanChargeCommand));
|
||||||
}
|
}
|
||||||
} else {
|
} else if (loanChargesArray == null) {
|
||||||
for (Charge productCharge : product.getCharges()){
|
for (Charge productCharge : product.getCharges()){
|
||||||
charges.add(new LoanCharge(loan, productCharge));
|
charges.add(new LoanCharge(loan, productCharge));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user