Example usage for com.google.gson JsonObject has

List of usage examples for com.google.gson JsonObject has

Introduction

In this page you can find the example usage for com.google.gson JsonObject has.

Prototype

public boolean has(String memberName) 

Source Link

Document

Convenience method to check if a member with the specified name is present in this object.

Usage

From source file:com.gst.portfolio.interestratechart.service.InterestIncentiveAssembler.java

License:Apache License

public Collection<InterestIncentives> assembleIncentivesFrom(final JsonElement element,
        InterestRateChartSlab interestRateChartSlab, final Locale locale) {
    final Collection<InterestIncentives> interestIncentivesSet = new HashSet<>();

    if (element.isJsonObject()) {
        final JsonObject topLevelJsonElement = element.getAsJsonObject();
        if (topLevelJsonElement.has(incentivesParamName)
                && topLevelJsonElement.get(incentivesParamName).isJsonArray()) {
            final JsonArray array = topLevelJsonElement.get(incentivesParamName).getAsJsonArray();
            for (int i = 0; i < array.size(); i++) {
                final JsonObject incentiveElement = array.get(i).getAsJsonObject();
                final InterestIncentives incentives = this.assembleFrom(incentiveElement, interestRateChartSlab,
                        locale);//ww w . j av a  2 s  . c o  m
                interestIncentivesSet.add(incentives);
            }
        }
    }

    return interestIncentivesSet;
}

From source file:com.gst.portfolio.interestratechart.service.InterestRateChartSlabAssembler.java

License:Apache License

public Collection<InterestRateChartSlab> assembleChartSlabsFrom(final JsonElement element,
        String currencyCode) {//  ww w  .  j  av a  2 s.  c  o  m
    final Collection<InterestRateChartSlab> interestRateChartSlabsSet = new HashSet<>();

    if (element.isJsonObject()) {
        final JsonObject topLevelJsonElement = element.getAsJsonObject();
        final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
        if (topLevelJsonElement.has(chartSlabs) && topLevelJsonElement.get(chartSlabs).isJsonArray()) {
            final JsonArray array = topLevelJsonElement.get(chartSlabs).getAsJsonArray();
            for (int i = 0; i < array.size(); i++) {
                final JsonObject interstRateChartElement = array.get(i).getAsJsonObject();
                final InterestRateChartSlab chartSlab = this.assembleChartSlabs(null, interstRateChartElement,
                        currencyCode, locale);
                interestRateChartSlabsSet.add(chartSlab);
            }
        }
    }

    return interestRateChartSlabsSet;
}

From source file:com.gst.portfolio.loanaccount.domain.Loan.java

License:Apache License

private Map<String, String> getDateFormatAndLocale(final JsonCommand jsonCommand) {
    Map<String, String> returnObject = new HashMap<>();
    JsonElement jsonElement = jsonCommand.parsedJson();
    if (jsonElement.isJsonObject()) {
        JsonObject topLevel = jsonElement.getAsJsonObject();
        if (topLevel.has(LoanApiConstants.dateFormatParameterName)
                && topLevel.get(LoanApiConstants.dateFormatParameterName).isJsonPrimitive()) {
            final JsonPrimitive primitive = topLevel.get(LoanApiConstants.dateFormatParameterName)
                    .getAsJsonPrimitive();
            returnObject.put(LoanApiConstants.dateFormatParameterName, primitive.getAsString());
        }//from  w  ww  .j av a2s . c o m
        if (topLevel.has(LoanApiConstants.localeParameterName)
                && topLevel.get(LoanApiConstants.localeParameterName).isJsonPrimitive()) {
            final JsonPrimitive primitive = topLevel.get(LoanApiConstants.localeParameterName)
                    .getAsJsonPrimitive();
            String localeString = primitive.getAsString();
            returnObject.put(LoanApiConstants.localeParameterName, localeString);
        }
    }
    return returnObject;
}

From source file:com.gst.portfolio.loanaccount.domain.Loan.java

License:Apache License

private Map<String, Object> parseDisbursementDetails(final JsonObject jsonObject, String dateFormat,
        Locale locale) {/*from www . ja v  a 2 s .  c  o m*/
    Map<String, Object> returnObject = new HashMap<>();
    if (jsonObject.get(LoanApiConstants.disbursementDateParameterName) != null
            && jsonObject.get(LoanApiConstants.disbursementDateParameterName).isJsonPrimitive()) {
        final JsonPrimitive primitive = jsonObject.get(LoanApiConstants.disbursementDateParameterName)
                .getAsJsonPrimitive();
        final String valueAsString = primitive.getAsString();
        if (StringUtils.isNotBlank(valueAsString)) {
            LocalDate date = JsonParserHelper.convertFrom(valueAsString,
                    LoanApiConstants.disbursementDateParameterName, dateFormat, locale);
            if (date != null) {
                returnObject.put(LoanApiConstants.disbursementDateParameterName, date.toDate());
            }
        }
    }

    if (jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).isJsonPrimitive() && StringUtils
            .isNotBlank((jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).getAsString()))) {
        BigDecimal principal = jsonObject
                .getAsJsonPrimitive(LoanApiConstants.disbursementPrincipalParameterName).getAsBigDecimal();
        returnObject.put(LoanApiConstants.disbursementPrincipalParameterName, principal);
    }

    if (jsonObject.has(LoanApiConstants.disbursementIdParameterName)
            && jsonObject.get(LoanApiConstants.disbursementIdParameterName).isJsonPrimitive() && StringUtils
                    .isNotBlank((jsonObject.get(LoanApiConstants.disbursementIdParameterName).getAsString()))) {
        Long id = jsonObject.getAsJsonPrimitive(LoanApiConstants.disbursementIdParameterName).getAsLong();
        returnObject.put(LoanApiConstants.disbursementIdParameterName, id);
    }

    if (jsonObject.has(LoanApiConstants.loanChargeIdParameterName)
            && jsonObject.get(LoanApiConstants.loanChargeIdParameterName).isJsonPrimitive() && StringUtils
                    .isNotBlank((jsonObject.get(LoanApiConstants.loanChargeIdParameterName).getAsString()))) {
        returnObject.put(LoanApiConstants.loanChargeIdParameterName,
                jsonObject.getAsJsonPrimitive(LoanApiConstants.loanChargeIdParameterName).getAsString());
    }
    return returnObject;
}

From source file:com.gst.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java

License:Apache License

private List<DisbursementData> fetchDisbursementData(final JsonObject command) {
    final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(command);
    final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(command);
    List<DisbursementData> disbursementDatas = new ArrayList<>();
    if (command.has(LoanApiConstants.disbursementDataParameterName)) {
        final JsonArray disbursementDataArray = command
                .getAsJsonArray(LoanApiConstants.disbursementDataParameterName);
        if (disbursementDataArray != null && disbursementDataArray.size() > 0) {
            int i = 0;
            do {/*w  w  w .j av a2 s .c  o  m*/
                final JsonObject jsonObject = disbursementDataArray.get(i).getAsJsonObject();
                LocalDate expectedDisbursementDate = null;
                BigDecimal principal = null;

                if (jsonObject.has(LoanApiConstants.disbursementDateParameterName)) {
                    expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed(
                            LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale);
                }
                if (jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName)
                        && jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).isJsonPrimitive()
                        && StringUtils.isNotBlank((jsonObject
                                .get(LoanApiConstants.disbursementPrincipalParameterName).getAsString()))) {
                    principal = jsonObject
                            .getAsJsonPrimitive(LoanApiConstants.disbursementPrincipalParameterName)
                            .getAsBigDecimal();
                }
                disbursementDatas
                        .add(new DisbursementData(null, expectedDisbursementDate, null, principal, null, null));
                i++;
            } while (i < disbursementDataArray.size());
        }
    }
    return disbursementDatas;
}

From source file:com.gst.portfolio.loanaccount.serialization.LoanApplicationCommandFromApiJsonHelper.java

License:Apache License

private void validateDisbursementsAreDatewiseOrdered(JsonElement element,
        final DataValidatorBuilder baseDataValidator) {
    final JsonObject topLevelJsonElement = element.getAsJsonObject();
    final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
    final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement);
    final JsonArray variationArray = this.fromApiJsonHelper
            .extractJsonArrayNamed(LoanApiConstants.disbursementDataParameterName, element);
    if (variationArray != null) {
        for (int i = 0; i < variationArray.size(); i++) {
            final JsonObject jsonObject1 = variationArray.get(i).getAsJsonObject();
            if (jsonObject1.has(LoanApiConstants.disbursementDateParameterName)) {
                LocalDate date1 = this.fromApiJsonHelper.extractLocalDateNamed(
                        LoanApiConstants.disbursementDateParameterName, jsonObject1, dateFormat, locale);

                for (int j = i + 1; j < variationArray.size(); j++) {
                    final JsonObject jsonObject2 = variationArray.get(j).getAsJsonObject();
                    if (jsonObject2.has(LoanApiConstants.disbursementDateParameterName)) {
                        LocalDate date2 = this.fromApiJsonHelper.extractLocalDateNamed(
                                LoanApiConstants.disbursementDateParameterName, jsonObject2, dateFormat,
                                locale);
                        if (date1.isAfter(date2)) {
                            baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
                                    .failWithCode(LoanApiConstants.DISBURSEMENT_DATES_NOT_IN_ORDER);
                        }/* ww  w. j  av a2 s.c  o m*/
                    }
                }
            }

        }
    }
}

From source file:com.gst.portfolio.loanaccount.serialization.LoanApplicationCommandFromApiJsonHelper.java

License:Apache License

public void validateLoanMultiDisbursementdate(final JsonElement element,
        final DataValidatorBuilder baseDataValidator, LocalDate expectedDisbursement,
        BigDecimal totalPrincipal) {

    this.validateDisbursementsAreDatewiseOrdered(element, baseDataValidator);

    final JsonObject topLevelJsonElement = element.getAsJsonObject();
    final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
    final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement);
    if (this.fromApiJsonHelper.parameterExists(LoanApiConstants.disbursementDataParameterName, element)
            && expectedDisbursement != null && totalPrincipal != null) {
        BigDecimal tatalDisbursement = BigDecimal.ZERO;
        boolean isFirstinstallmentOnExpectedDisbursementDate = false;
        final JsonArray variationArray = this.fromApiJsonHelper
                .extractJsonArrayNamed(LoanApiConstants.disbursementDataParameterName, element);
        List<LocalDate> expectedDisbursementDates = new ArrayList<>();
        if (variationArray != null && variationArray.size() > 0) {
            int i = 0;
            do {/* w w  w .j a va 2  s . co m*/
                final JsonObject jsonObject = variationArray.get(i).getAsJsonObject();
                if (jsonObject.has(LoanApiConstants.disbursementDateParameterName)
                        && jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName)) {
                    LocalDate expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed(
                            LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale);
                    if (expectedDisbursementDates.contains(expectedDisbursementDate)) {
                        baseDataValidator.reset().parameter(LoanApiConstants.disbursementDateParameterName)
                                .failWithCode(LoanApiConstants.DISBURSEMENT_DATE_UNIQUE_ERROR);
                    }
                    if (expectedDisbursementDate.isBefore(expectedDisbursement)) {
                        baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
                                .failWithCode(LoanApiConstants.DISBURSEMENT_DATE_BEFORE_ERROR);
                    }
                    expectedDisbursementDates.add(expectedDisbursementDate);

                    BigDecimal principal = this.fromApiJsonHelper.extractBigDecimalNamed(
                            LoanApiConstants.disbursementPrincipalParameterName, jsonObject, locale);
                    baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
                            .parameterAtIndexArray(LoanApiConstants.disbursementPrincipalParameterName, i)
                            .value(principal).notBlank();
                    if (principal != null) {
                        tatalDisbursement = tatalDisbursement.add(principal);
                    }

                    baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
                            .parameterAtIndexArray(LoanApiConstants.disbursementDateParameterName, i)
                            .value(expectedDisbursementDate).notNull();

                    if (expectedDisbursement.equals(expectedDisbursementDate)) {
                        isFirstinstallmentOnExpectedDisbursementDate = true;
                    }

                }
                i++;
            } while (i < variationArray.size());
            if (!isFirstinstallmentOnExpectedDisbursementDate) {
                baseDataValidator.reset().parameter(LoanApiConstants.disbursementDateParameterName)
                        .failWithCode(LoanApiConstants.DISBURSEMENT_DATE_START_WITH_ERROR);
            }

            if (tatalDisbursement.compareTo(totalPrincipal) == 1) {
                baseDataValidator.reset().parameter(LoanApiConstants.disbursementPrincipalParameterName)
                        .failWithCode(LoanApiConstants.APPROVED_AMOUNT_IS_LESS_THAN_SUM_OF_TRANCHES);
            }
            final String interestTypeParameterName = "interestType";
            final Integer interestType = this.fromApiJsonHelper
                    .extractIntegerSansLocaleNamed(interestTypeParameterName, element);
            baseDataValidator.reset().parameter(interestTypeParameterName).value(interestType).ignoreIfNull()
                    .integerSameAsNumber(InterestMethod.DECLINING_BALANCE.getValue());

        }

    }

}

From source file:com.gst.portfolio.loanaccount.service.LoanChargeAssembler.java

License:Apache License

public Set<LoanCharge> fromParsedJson(final JsonElement element,
        List<LoanDisbursementDetails> disbursementDetails) {
    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++) {
            final JsonObject jsonObject = jsonDisbursement.get(i).getAsJsonObject();
            if (jsonObject != null
                    && jsonObject.getAsJsonPrimitive(LoanApiConstants.loanChargeIdParameterName) != null) {
                String chargeIds = jsonObject.getAsJsonPrimitive(LoanApiConstants.loanChargeIdParameterName)
                        .getAsString();//w  w  w .  jav a  2 s .  c om
                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));
                    }
                }

            }
        }
    }

    final Set<LoanCharge> loanCharges = new HashSet<>();
    final BigDecimal principal = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("principal", element);
    final Integer numberOfRepayments = this.fromApiJsonHelper
            .extractIntegerWithLocaleNamed("numberOfRepayments", element);
    final Long productId = this.fromApiJsonHelper.extractLongNamed("productId", element);
    final LoanProduct loanProduct = this.loanProductRepository.findOne(productId);
    if (loanProduct == null) {
        throw new LoanProductNotFoundException(productId);
    }
    final boolean isMultiDisbursal = loanProduct.isMultiDisburseLoan();
    LocalDate expectedDisbursementDate = null;

    if (element.isJsonObject()) {
        final JsonObject topLevelJsonElement = element.getAsJsonObject();
        final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement);
        final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
        if (topLevelJsonElement.has("charges") && topLevelJsonElement.get("charges").isJsonArray()) {
            final JsonArray array = topLevelJsonElement.get("charges").getAsJsonArray();
            for (int i = 0; i < array.size(); i++) {

                final JsonObject loanChargeElement = array.get(i).getAsJsonObject();

                final Long id = this.fromApiJsonHelper.extractLongNamed("id", loanChargeElement);
                final Long chargeId = this.fromApiJsonHelper.extractLongNamed("chargeId", loanChargeElement);
                final BigDecimal amount = this.fromApiJsonHelper.extractBigDecimalNamed("amount",
                        loanChargeElement, locale);
                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 Integer chargePaymentMode = this.fromApiJsonHelper
                        .extractIntegerNamed("chargePaymentMode", loanChargeElement, locale);
                if (id == null) {
                    final Charge chargeDefinition = this.chargeRepository
                            .findOneWithNotFoundDetection(chargeId);

                    if (chargeDefinition.isOverdueInstallment()) {

                        final String defaultUserMessage = "Installment charge cannot be added to the loan.";
                        throw new LoanChargeCannotBeAddedException("loanCharge", "overdue.charge",
                                defaultUserMessage, null, chargeDefinition.getName());
                    }

                    ChargeTimeType chargeTime = null;
                    if (chargeTimeType != null) {
                        chargeTime = ChargeTimeType.fromInt(chargeTimeType);
                    }
                    ChargeCalculationType chargeCalculation = null;
                    if (chargeCalculationType != null) {
                        chargeCalculation = ChargeCalculationType.fromInt(chargeCalculationType);
                    }
                    ChargePaymentMode chargePaymentModeEnum = null;
                    if (chargePaymentMode != null) {
                        chargePaymentModeEnum = ChargePaymentMode.fromInt(chargePaymentMode);
                    }
                    if (!isMultiDisbursal) {
                        final LoanCharge loanCharge = LoanCharge.createNewWithoutLoan(chargeDefinition,
                                principal, amount, chargeTime, chargeCalculation, dueDate,
                                chargePaymentModeEnum, numberOfRepayments);
                        loanCharges.add(loanCharge);
                    } else {
                        if (topLevelJsonElement.has("disbursementData")
                                && topLevelJsonElement.get("disbursementData").isJsonArray()) {
                            final JsonArray disbursementArray = topLevelJsonElement.get("disbursementData")
                                    .getAsJsonArray();
                            if (disbursementArray.size() > 0) {
                                JsonObject disbursementDataElement = disbursementArray.get(0).getAsJsonObject();
                                expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed(
                                        LoanApiConstants.disbursementDateParameterName, disbursementDataElement,
                                        dateFormat, locale);
                            }
                        }

                        if (ChargeTimeType.DISBURSEMENT.getValue()
                                .equals(chargeDefinition.getChargeTimeType())) {
                            for (LoanDisbursementDetails disbursementDetail : disbursementDetails) {
                                LoanTrancheDisbursementCharge loanTrancheDisbursementCharge = null;
                                if (chargeDefinition.isPercentageOfApprovedAmount()
                                        && disbursementDetail.expectedDisbursementDateAsLocalDate()
                                                .equals(expectedDisbursementDate)) {
                                    final LoanCharge loanCharge = LoanCharge.createNewWithoutLoan(
                                            chargeDefinition, principal, amount, chargeTime, chargeCalculation,
                                            dueDate, chargePaymentModeEnum, numberOfRepayments);
                                    loanCharges.add(loanCharge);
                                    if (loanCharge.isTrancheDisbursementCharge()) {
                                        loanTrancheDisbursementCharge = new LoanTrancheDisbursementCharge(
                                                loanCharge, disbursementDetail);
                                        loanCharge.updateLoanTrancheDisbursementCharge(
                                                loanTrancheDisbursementCharge);
                                    }
                                } else {
                                    if (disbursementDetail.expectedDisbursementDateAsLocalDate()
                                            .equals(expectedDisbursementDate)) {
                                        final LoanCharge loanCharge = LoanCharge.createNewWithoutLoan(
                                                chargeDefinition, disbursementDetail.principal(), amount,
                                                chargeTime, chargeCalculation,
                                                disbursementDetail.expectedDisbursementDateAsLocalDate(),
                                                chargePaymentModeEnum, numberOfRepayments);
                                        loanCharges.add(loanCharge);
                                        if (loanCharge.isTrancheDisbursementCharge()) {
                                            loanTrancheDisbursementCharge = new LoanTrancheDisbursementCharge(
                                                    loanCharge, disbursementDetail);
                                            loanCharge.updateLoanTrancheDisbursementCharge(
                                                    loanTrancheDisbursementCharge);
                                        }
                                    }
                                }
                            }
                        } else if (ChargeTimeType.TRANCHE_DISBURSEMENT.getValue()
                                .equals(chargeDefinition.getChargeTimeType())) {
                            LoanTrancheDisbursementCharge loanTrancheDisbursementCharge = null;
                            for (LoanDisbursementDetails disbursementDetail : disbursementDetails) {
                                if (ChargeTimeType.TRANCHE_DISBURSEMENT.getValue()
                                        .equals(chargeDefinition.getChargeTimeType())) {
                                    final LoanCharge loanCharge = LoanCharge.createNewWithoutLoan(
                                            chargeDefinition, disbursementDetail.principal(), amount,
                                            chargeTime, chargeCalculation,
                                            disbursementDetail.expectedDisbursementDateAsLocalDate(),
                                            chargePaymentModeEnum, numberOfRepayments);
                                    loanCharges.add(loanCharge);
                                    loanTrancheDisbursementCharge = new LoanTrancheDisbursementCharge(
                                            loanCharge, disbursementDetail);
                                    loanCharge
                                            .updateLoanTrancheDisbursementCharge(loanTrancheDisbursementCharge);
                                }
                            }
                        } else {
                            final LoanCharge loanCharge = LoanCharge.createNewWithoutLoan(chargeDefinition,
                                    principal, amount, chargeTime, chargeCalculation, dueDate,
                                    chargePaymentModeEnum, numberOfRepayments);
                            loanCharges.add(loanCharge);
                        }
                    }
                } else {
                    final Long loanChargeId = id;
                    final LoanCharge loanCharge = this.loanChargeRepository.findOne(loanChargeId);
                    if (loanCharge != null) {
                        if (!loanCharge.isTrancheDisbursementCharge()
                                || disbursementChargeIds.contains(loanChargeId)) {
                            loanCharge.update(amount, dueDate, numberOfRepayments);
                            loanCharges.add(loanCharge);
                        }
                    }
                }
            }
        }
    }

    return loanCharges;
}

From source file:com.gst.portfolio.loanaccount.service.LoanChargeAssembler.java

License:Apache License

public Set<Charge> getNewLoanTrancheCharges(final JsonElement element) {
    final Set<Charge> associatedChargesForLoan = new HashSet<>();
    if (element.isJsonObject()) {
        final JsonObject topLevelJsonElement = element.getAsJsonObject();
        if (topLevelJsonElement.has("charges") && topLevelJsonElement.get("charges").isJsonArray()) {
            final JsonArray array = topLevelJsonElement.get("charges").getAsJsonArray();
            for (int i = 0; i < array.size(); i++) {
                final JsonObject loanChargeElement = array.get(i).getAsJsonObject();
                final Long id = this.fromApiJsonHelper.extractLongNamed("id", loanChargeElement);
                final Long chargeId = this.fromApiJsonHelper.extractLongNamed("chargeId", loanChargeElement);
                if (id == null) {
                    final Charge chargeDefinition = this.chargeRepository
                            .findOneWithNotFoundDetection(chargeId);
                    if (chargeDefinition.getChargeTimeType() == ChargeTimeType.TRANCHE_DISBURSEMENT
                            .getValue()) {
                        associatedChargesForLoan.add(chargeDefinition);
                    }// ww w .j a v  a 2 s.c om
                }
            }
        }
    }
    return associatedChargesForLoan;
}

From source file:com.gst.portfolio.loanaccount.service.LoanUtilService.java

License:Apache License

public List<LoanDisbursementDetails> fetchDisbursementData(final JsonObject command) {
    final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(command);
    final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(command);
    List<LoanDisbursementDetails> disbursementDatas = new ArrayList<>();
    if (command.has(LoanApiConstants.disbursementDataParameterName)) {
        final JsonArray disbursementDataArray = command
                .getAsJsonArray(LoanApiConstants.disbursementDataParameterName);
        if (disbursementDataArray != null && disbursementDataArray.size() > 0) {
            int i = 0;
            do {/*from   ww w .  j  a  v a2  s. co m*/
                final JsonObject jsonObject = disbursementDataArray.get(i).getAsJsonObject();
                Date expectedDisbursementDate = null;
                Date actualDisbursementDate = null;
                BigDecimal principal = null;

                if (jsonObject.has(LoanApiConstants.disbursementDateParameterName)) {
                    LocalDate date = this.fromApiJsonHelper.extractLocalDateNamed(
                            LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale);
                    if (date != null) {
                        expectedDisbursementDate = date.toDate();
                    }
                }
                if (jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName)
                        && jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).isJsonPrimitive()
                        && StringUtils.isNotBlank((jsonObject
                                .get(LoanApiConstants.disbursementPrincipalParameterName).getAsString()))) {
                    principal = jsonObject
                            .getAsJsonPrimitive(LoanApiConstants.disbursementPrincipalParameterName)
                            .getAsBigDecimal();
                }

                disbursementDatas.add(new LoanDisbursementDetails(expectedDisbursementDate,
                        actualDisbursementDate, principal));
                i++;
            } while (i < disbursementDataArray.size());
        }
    }
    return disbursementDatas;
}