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.SubmitLoanApplicationCommand;
|
||||
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.LoanAccountData;
|
||||
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.ApiJsonSerializerService;
|
||||
import org.mifosng.platform.api.infrastructure.ApiParameterHelper;
|
||||
import org.mifosng.platform.charge.service.ChargeReadPlatformService;
|
||||
import org.mifosng.platform.exceptions.UnrecognizedQueryParamException;
|
||||
import org.mifosng.platform.loan.service.CalculationPlatformService;
|
||||
import org.mifosng.platform.loan.service.LoanReadPlatformService;
|
||||
@@ -57,6 +59,9 @@ public class LoansApiResource {
|
||||
@Autowired
|
||||
private LoanWritePlatformService loanWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
private ChargeReadPlatformService chargeReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
private CalculationPlatformService calculationPlatformService;
|
||||
|
||||
@@ -118,11 +123,12 @@ public class LoansApiResource {
|
||||
Collection<LoanRepaymentPeriodData> repaymentSchedule = null;
|
||||
LoanAccountSummaryData summary = null;
|
||||
LoanPermissionData permissions = null;
|
||||
|
||||
Collection<ChargeData> charges = null;
|
||||
|
||||
Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (!associationParameters.isEmpty()) {
|
||||
if (associationParameters.contains("all")) {
|
||||
responseParameters.addAll(Arrays.asList("summary", "repaymentSchedule", "loanRepayments", "permissions", "convenienceData"));
|
||||
responseParameters.addAll(Arrays.asList("summary", "repaymentSchedule", "loanRepayments", "permissions", "convenienceData", "charges"));
|
||||
} else {
|
||||
responseParameters.addAll(associationParameters);
|
||||
}
|
||||
@@ -134,9 +140,11 @@ public class LoansApiResource {
|
||||
|
||||
boolean isWaiveAllowed = summary.isWaiveAllowed(loanBasicDetails.getInArrearsTolerance());
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ public class LoanAccountData {
|
||||
|
||||
private LoanConvenienceData convenienceData;
|
||||
|
||||
private Collection<ChargeData> charges;
|
||||
|
||||
protected LoanAccountData() {
|
||||
//
|
||||
}
|
||||
@@ -57,11 +59,12 @@ public class LoanAccountData {
|
||||
LoanAccountSummaryData summary,
|
||||
Collection<LoanRepaymentPeriodData> repaymentSchedule,
|
||||
Collection<LoanRepaymentTransactionData> loanRepayments,
|
||||
LoanPermissionData permissions) {
|
||||
LoanPermissionData permissions, Collection<ChargeData> charges) {
|
||||
this.summary = summary;
|
||||
this.repaymentSchedule = repaymentSchedule;
|
||||
this.loanRepayments = loanRepayments;
|
||||
this.permissions = permissions;
|
||||
this.charges = charges;
|
||||
|
||||
int maxSubmittedOnOffsetFromToday = basicDetails
|
||||
.getMaxSubmittedOnOffsetFromToday();
|
||||
@@ -384,4 +387,11 @@ public class LoanAccountData {
|
||||
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();
|
||||
}
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, String>>(){}.getType();
|
||||
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType();
|
||||
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
Set<String> supportedParams = new HashSet<String>(
|
||||
Arrays.asList("clientId", "productId", "externalId", "fundId", "transactionProcessingStrategyId",
|
||||
"principal", "inArrearsTolerance", "interestRatePerPeriod", "repaymentEvery", "numberOfRepayments",
|
||||
"loanTermFrequency", "loanTermFrequencyType",
|
||||
"loanTermFrequency", "loanTermFrequencyType", "charges",
|
||||
"repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType",
|
||||
"expectedDisbursementDate", "repaymentsStartingFromDate", "interestChargedFromDate", "submittedOnDate", "submittedOnNote",
|
||||
"locale", "dateFormat")
|
||||
@@ -487,7 +487,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
||||
JsonElement element = parser.parse(json);
|
||||
if (element.isJsonObject()) {
|
||||
JsonObject object = element.getAsJsonObject();
|
||||
if (object.has("charges")) {
|
||||
if (object.has("charges") && object.get("charges").isJsonArray()) {
|
||||
modifiedParameters.add("charges");
|
||||
JsonArray array = object.get("charges").getAsJsonArray();
|
||||
charges = new LoanChargeCommand[array.size()];
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ public class GoogleGsonApiJsonSerializerService implements
|
||||
"closedOnDate", "expectedMaturityDate",
|
||||
"lifeCycleStatusId", "lifeCycleStatusText",
|
||||
"lifeCycleStatusDate", "summary", "repaymentSchedule",
|
||||
"loanRepayments", "permissions", "convenienceData"));
|
||||
"loanRepayments", "permissions", "convenienceData", "charges"));
|
||||
|
||||
private static final Set<String> LOAN_TRANSACTION_DATA_PARAMETERS = new HashSet<String>(
|
||||
Arrays.asList("id", "transactionType", "date", "principal",
|
||||
|
||||
+2
@@ -15,4 +15,6 @@ public interface ChargeReadPlatformService {
|
||||
Collection<ChargeData> retrieveLoanApplicableCharges();
|
||||
|
||||
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});
|
||||
}
|
||||
|
||||
@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
|
||||
public Collection<ChargeData> retrieveLoanApplicableCharges() {
|
||||
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";
|
||||
}
|
||||
|
||||
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
|
||||
public ChargeData mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
Long id = rs.getLong("id");
|
||||
|
||||
@@ -185,7 +185,7 @@ public class LoanAssembler {
|
||||
}
|
||||
charges.add(new LoanCharge(loan, charge, loanChargeCommand));
|
||||
}
|
||||
} else {
|
||||
} else if (loanChargesArray == null) {
|
||||
for (Charge productCharge : product.getCharges()){
|
||||
charges.add(new LoanCharge(loan, productCharge));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user