Skip to content

Commit

Permalink
MIFOSX-2195
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwasbabu committed Sep 8, 2015
1 parent 07f8812 commit 33d4a48
Showing 1 changed file with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,29 @@ public LoanChargeAssembler(final FromJsonHelper fromApiJsonHelper, final ChargeR
}

public Set<LoanCharge> fromParsedJson(final JsonElement element, Set<LoanDisbursementDetails> disbursementDetails) {
JsonArray jsonDisbursement = this.fromApiJsonHelper.extractJsonArrayNamed("disbursementData", element) ;
JsonArray jsonDisbursement = this.fromApiJsonHelper.extractJsonArrayNamed("disbursementData", element);
List<Long> disbursementChargeIds = new ArrayList<>();
if(jsonDisbursement != null && jsonDisbursement.size() > 0) {
for(int i = 0 ; i < jsonDisbursement.size(); i++) {

if (jsonDisbursement != null && jsonDisbursement.size() > 0) {
for (int i = 0; i < jsonDisbursement.size(); i++) {
final JsonObject jsonObject = jsonDisbursement.get(i).getAsJsonObject();
if(jsonObject != null && jsonObject.getAsJsonPrimitive(LoanApiConstants.loanChargeIdParameterName) != null){
if (jsonObject != null && jsonObject.getAsJsonPrimitive(LoanApiConstants.loanChargeIdParameterName) != null) {
String chargeIds = jsonObject.getAsJsonPrimitive(LoanApiConstants.loanChargeIdParameterName).getAsString();
if(chargeIds != null) {
if (chargeIds != null) {
if (chargeIds.indexOf(",") != -1) {
String[] chargeId = chargeIds.split(",");
for (String loanChargeId : chargeId) {
disbursementChargeIds.add(Long.parseLong(loanChargeId));
}
} else {
disbursementChargeIds.add(Long.parseLong(chargeIds)) ;
}
disbursementChargeIds.add(Long.parseLong(chargeIds));
}
}

}
}
}

final Set<LoanCharge> loanCharges = new HashSet<>();
final BigDecimal principal = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("principal", element);
final Integer numberOfRepayments = this.fromApiJsonHelper.extractIntegerWithLocaleNamed("numberOfRepayments", element);
Expand All @@ -103,8 +103,8 @@ public Set<LoanCharge> fromParsedJson(final JsonElement element, Set<LoanDisburs
final Integer chargeTimeType = this.fromApiJsonHelper.extractIntegerNamed("chargeTimeType", loanChargeElement, locale);
final Integer chargeCalculationType = this.fromApiJsonHelper.extractIntegerNamed("chargeCalculationType",
loanChargeElement, locale);
final LocalDate dueDate = this.fromApiJsonHelper
.extractLocalDateNamed("dueDate", loanChargeElement, dateFormat, locale);
final LocalDate dueDate = this.fromApiJsonHelper.extractLocalDateNamed("dueDate", loanChargeElement, dateFormat,
locale);
final Integer chargePaymentMode = this.fromApiJsonHelper.extractIntegerNamed("chargePaymentMode", loanChargeElement,
locale);
if (id == null) {
Expand Down Expand Up @@ -136,13 +136,16 @@ public Set<LoanCharge> fromParsedJson(final JsonElement element, Set<LoanDisburs
}
if (topLevelJsonElement.has("disbursementData") && topLevelJsonElement.get("disbursementData").isJsonArray()) {
final JsonArray disbursementArray = topLevelJsonElement.get("disbursementData").getAsJsonArray();
JsonObject disbursementDataElement = disbursementArray.get(0).getAsJsonObject();
expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed(
LoanApiConstants.disbursementDateParameterName, disbursementDataElement, dateFormat, locale);
if (disbursementArray.size() > 0) {
JsonObject disbursementDataElement = disbursementArray.get(0).getAsJsonObject();
expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed(
LoanApiConstants.disbursementDateParameterName, disbursementDataElement, dateFormat, locale);
}
}

if ((chargeDefinition.isPercentageOfDisbursementAmount() || chargeDefinition.isPercentageOfApprovedAmount() || chargeDefinition
.getChargeCalculation() == ChargeCalculationType.FLAT.getValue()) && disbursementDetails != null) {
if ((chargeDefinition.isPercentageOfDisbursementAmount() || chargeDefinition.isPercentageOfApprovedAmount()
|| chargeDefinition.getChargeCalculation() == ChargeCalculationType.FLAT.getValue())
&& disbursementDetails != null) {
LoanTrancheDisbursementCharge loanTrancheDisbursementCharge = null;
for (LoanDisbursementDetails disbursementDetail : disbursementDetails) {
if (chargeDefinition.getChargeTimeType() == ChargeTimeType.DISBURSEMENT.getValue()) {
Expand Down Expand Up @@ -201,10 +204,11 @@ public Set<LoanCharge> fromParsedJson(final JsonElement element, Set<LoanDisburs
} else {
final Long loanChargeId = id;
final LoanCharge loanCharge = this.loanChargeRepository.findOne(loanChargeId);
if(disbursementChargeIds.contains(loanChargeId) && loanCharge == null) {
//throw new LoanChargeNotFoundException(loanChargeId);
if (disbursementChargeIds.contains(loanChargeId) && loanCharge == null) {
// throw new
// LoanChargeNotFoundException(loanChargeId);
}
if(loanCharge != null) {
if (loanCharge != null) {
loanCharge.update(amount, dueDate, numberOfRepayments);
loanCharges.add(loanCharge);
}
Expand All @@ -215,7 +219,7 @@ public Set<LoanCharge> fromParsedJson(final JsonElement element, Set<LoanDisburs

return loanCharges;
}

public Set<Charge> getNewLoanTrancheCharges(final JsonElement element) {
final Set<Charge> associatedChargesForLoan = new HashSet<>();
if (element.isJsonObject()) {
Expand Down

0 comments on commit 33d4a48

Please sign in to comment.