Example usage for com.google.gson JsonObject getAsJsonPrimitive

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

Introduction

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

Prototype

public JsonPrimitive getAsJsonPrimitive(String memberName) 

Source Link

Document

Convenience method to get the specified member as a JsonPrimitive element.

Usage

From source file:com.google.iosched.model.DataModelHelper.java

License:Open Source License

public static JsonPrimitive getMapValue(JsonElement map, String key, Converter converter,
        String defaultValueStr) {
    JsonPrimitive defaultValue = null;//from   w  w  w . j  ava2 s. c  o m
    if (defaultValueStr != null) {
        defaultValue = new JsonPrimitive(defaultValueStr);
        if (converter != null)
            defaultValue = converter.convert(defaultValue);
    }
    if (map == null || !map.isJsonArray()) {
        return defaultValue;
    }
    for (JsonElement el : map.getAsJsonArray()) {
        if (!el.isJsonObject()) {
            continue;
        }
        JsonObject obj = el.getAsJsonObject();
        if (!obj.has("name") || !obj.has("value")) {
            continue;
        }
        if (key.equals(obj.getAsJsonPrimitive("name").getAsString())) {
            JsonElement value = obj.get("value");
            if (!value.isJsonPrimitive()) {
                throw new ConverterException(value, converter, "Expected a JsonPrimitive");
            }
            if (converter != null)
                value = converter.convert(value);
            return value.getAsJsonPrimitive();
        }
    }
    return defaultValue;
}

From source file:com.google.samples.apps.iosched.server.schedule.model.DataExtractor.java

License:Open Source License

@Deprecated
private void setRelatedVideos(JsonObject origin, JsonObject dest) {
    JsonArray related = getAsArray(origin, InputJsonKeys.VendorAPISource.Topics.related);
    if (related == null) {
        return;//from w  w w.  j a va 2s .c o  m
    }
    for (JsonElement el : related) {
        if (!el.isJsonObject()) {
            continue;
        }
        JsonObject obj = el.getAsJsonObject();
        if (!obj.has("name") || !obj.has("values")) {
            continue;
        }

        if (InputJsonKeys.VendorAPISource.Topics.RELATED_NAME_VIDEO
                .equals(obj.getAsJsonPrimitive("name").getAsString())) {

            JsonElement values = obj.get("values");
            if (!values.isJsonArray()) {
                continue;
            }

            // As per the data specification, related content is formatted as
            // "video1 title1\nvideo2 title2\n..."
            StringBuilder relatedContentStr = new StringBuilder();
            for (JsonElement value : values.getAsJsonArray()) {
                String relatedSessionId = value.getAsString();
                JsonObject relatedVideo = videoSessionsById.get(relatedSessionId);
                if (relatedVideo != null) {
                    JsonElement vid = get(relatedVideo, OutputJsonKeys.VideoLibrary.vid);
                    JsonElement title = get(relatedVideo, OutputJsonKeys.VideoLibrary.title);
                    if (vid != null && title != null) {
                        relatedContentStr.append(vid.getAsString()).append(" ").append(title.getAsString())
                                .append("\n");
                    }
                }
            }
            set(new JsonPrimitive(relatedContentStr.toString()), dest, OutputJsonKeys.Sessions.relatedContent);
        }
    }
}

From source file:com.google.samples.apps.iosched.server.schedule.model.DataExtractor.java

License:Open Source License

private void setRelatedContent(JsonObject origin, JsonObject dest) {
    JsonArray related = getAsArray(origin, InputJsonKeys.VendorAPISource.Topics.related);
    JsonArray outputArray = new JsonArray();

    if (related == null) {
        return;/*from  www .j a  va2 s.  c o m*/
    }
    for (JsonElement el : related) {
        if (!el.isJsonObject()) {
            continue;
        }
        JsonObject obj = el.getAsJsonObject();
        if (!obj.has("name") || !obj.has("values")) {
            continue;
        }

        if (InputJsonKeys.VendorAPISource.Topics.RELATED_NAME_SESSIONS
                .equals(obj.getAsJsonPrimitive("name").getAsString())) {

            JsonElement values = obj.get("topics");
            if (!values.isJsonArray()) {
                continue;
            }

            // As per the data specification, related content is formatted as
            // "video1 title1\nvideo2 title2\n..."
            for (JsonElement topic : values.getAsJsonArray()) {
                if (!topic.isJsonObject()) {
                    continue;
                }

                JsonObject topicObj = topic.getAsJsonObject();

                String id = get(topicObj, InputJsonKeys.VendorAPISource.RelatedTopics.id).getAsString();
                String title = get(topicObj, InputJsonKeys.VendorAPISource.RelatedTopics.title).getAsString();

                if (id != null && title != null) {
                    JsonObject outputObj = new JsonObject();
                    set(new JsonPrimitive(id), outputObj, OutputJsonKeys.RelatedContent.id);
                    set(new JsonPrimitive(title), outputObj, OutputJsonKeys.RelatedContent.title);
                    outputArray.add(outputObj);
                }
            }
            set(outputArray, dest, OutputJsonKeys.Sessions.relatedContent);
        }
    }
}

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) {//  ww w.j a  v  a2  s .co 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 {/* ww w . java 2s. co 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.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();//from   w w  w.  jav  a2  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.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   w w w  . j a  v a 2 s. com*/
                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;
}

From source file:com.gst.portfolio.loanproduct.domain.LoanProduct.java

License:Apache License

private static void assembleVaritions(final JsonCommand command,
        final Set<LoanProductBorrowerCycleVariations> loanProductBorrowerCycleVariations, Integer paramType,
        String variationParameterName) {
    if (command.parameterExists(variationParameterName)) {
        final JsonArray variationArray = command.arrayOfParameterNamed(variationParameterName);
        if (variationArray != null && variationArray.size() > 0) {
            int i = 0;
            do {//from w ww  .j  a v  a2 s .com
                final JsonObject jsonObject = variationArray.get(i).getAsJsonObject();
                BigDecimal defaultValue = null;
                BigDecimal minValue = null;
                BigDecimal maxValue = null;
                Integer cycleNumber = null;
                Integer valueUsageCondition = null;
                if (jsonObject.has(LoanProductConstants.defaultValueParameterName)
                        && jsonObject.get(LoanProductConstants.defaultValueParameterName).isJsonPrimitive()) {
                    defaultValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.defaultValueParameterName)
                            .getAsBigDecimal();
                }
                if (jsonObject.has(LoanProductConstants.minValueParameterName)
                        && jsonObject.get(LoanProductConstants.minValueParameterName).isJsonPrimitive()
                        && StringUtils.isNotBlank(
                                (jsonObject.get(LoanProductConstants.minValueParameterName).getAsString()))) {
                    minValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.minValueParameterName)
                            .getAsBigDecimal();
                }
                if (jsonObject.has(LoanProductConstants.maxValueParameterName)
                        && jsonObject.get(LoanProductConstants.maxValueParameterName).isJsonPrimitive()
                        && StringUtils.isNotBlank(
                                (jsonObject.get(LoanProductConstants.maxValueParameterName).getAsString()))) {
                    maxValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.maxValueParameterName)
                            .getAsBigDecimal();
                }
                if (jsonObject.has(LoanProductConstants.borrowerCycleNumberParamName) && jsonObject
                        .get(LoanProductConstants.borrowerCycleNumberParamName).isJsonPrimitive()) {
                    cycleNumber = jsonObject
                            .getAsJsonPrimitive(LoanProductConstants.borrowerCycleNumberParamName).getAsInt();
                }
                if (jsonObject.has(LoanProductConstants.valueConditionTypeParamName)
                        && jsonObject.get(LoanProductConstants.valueConditionTypeParamName).isJsonPrimitive()) {
                    valueUsageCondition = jsonObject
                            .getAsJsonPrimitive(LoanProductConstants.valueConditionTypeParamName).getAsInt();
                }
                LoanProductBorrowerCycleVariations borrowerCycleVariations = new LoanProductBorrowerCycleVariations(
                        cycleNumber, paramType, valueUsageCondition, minValue, maxValue, defaultValue);
                loanProductBorrowerCycleVariations.add(borrowerCycleVariations);
                i++;
            } while (i < variationArray.size());
        }
    }
}

From source file:com.gst.portfolio.loanproduct.domain.LoanProduct.java

License:Apache License

private void updateBorrowerCycleVaritions(final JsonCommand command, Integer paramType,
        String variationParameterName, final Map<String, Object> actualChanges, List<Long> variationIds) {
    if (command.parameterExists(variationParameterName)) {
        final JsonArray variationArray = command.arrayOfParameterNamed(variationParameterName);
        if (variationArray != null && variationArray.size() > 0) {
            int i = 0;
            do {/*ww w. j  a v a  2s .  com*/
                final JsonObject jsonObject = variationArray.get(i).getAsJsonObject();
                BigDecimal defaultValue = null;
                BigDecimal minValue = null;
                BigDecimal maxValue = null;
                Integer cycleNumber = null;
                Integer valueUsageCondition = null;
                Long id = null;
                if (jsonObject.has(LoanProductConstants.defaultValueParameterName)
                        && jsonObject.get(LoanProductConstants.defaultValueParameterName).isJsonPrimitive()) {
                    defaultValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.defaultValueParameterName)
                            .getAsBigDecimal();
                }
                if (jsonObject.has(LoanProductConstants.minValueParameterName)
                        && jsonObject.get(LoanProductConstants.minValueParameterName).isJsonPrimitive()
                        && StringUtils.isNotBlank(
                                (jsonObject.get(LoanProductConstants.minValueParameterName).getAsString()))) {
                    minValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.minValueParameterName)
                            .getAsBigDecimal();
                }
                if (jsonObject.has(LoanProductConstants.maxValueParameterName)
                        && jsonObject.get(LoanProductConstants.maxValueParameterName).isJsonPrimitive()
                        && StringUtils.isNotBlank(
                                (jsonObject.get(LoanProductConstants.maxValueParameterName).getAsString()))) {
                    maxValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.maxValueParameterName)
                            .getAsBigDecimal();
                }
                if (jsonObject.has(LoanProductConstants.borrowerCycleNumberParamName) && jsonObject
                        .get(LoanProductConstants.borrowerCycleNumberParamName).isJsonPrimitive()) {
                    cycleNumber = jsonObject
                            .getAsJsonPrimitive(LoanProductConstants.borrowerCycleNumberParamName).getAsInt();
                }
                if (jsonObject.has(LoanProductConstants.valueConditionTypeParamName)
                        && jsonObject.get(LoanProductConstants.valueConditionTypeParamName).isJsonPrimitive()) {
                    valueUsageCondition = jsonObject
                            .getAsJsonPrimitive(LoanProductConstants.valueConditionTypeParamName).getAsInt();
                }
                if (jsonObject.has(LoanProductConstants.borrowerCycleIdParameterName)
                        && jsonObject.get(LoanProductConstants.borrowerCycleIdParameterName).isJsonPrimitive()
                        && StringUtils.isNotBlank((jsonObject
                                .get(LoanProductConstants.borrowerCycleIdParameterName).getAsString()))) {
                    id = jsonObject.getAsJsonPrimitive(LoanProductConstants.borrowerCycleIdParameterName)
                            .getAsLong();
                }
                LoanProductBorrowerCycleVariations borrowerCycleVariations = new LoanProductBorrowerCycleVariations(
                        cycleNumber, paramType, valueUsageCondition, minValue, maxValue, defaultValue);
                if (id == null) {
                    borrowerCycleVariations.updateLoanProduct(this);
                    this.borrowerCycleVariations.add(borrowerCycleVariations);
                    actualChanges.put("borrowerCycleParamType", paramType);
                } else {
                    variationIds.remove(id);
                    LoanProductBorrowerCycleVariations existingCycleVariation = fetchLoanProductBorrowerCycleVariationById(
                            id);
                    if (!existingCycleVariation.equals(borrowerCycleVariations)) {
                        existingCycleVariation.copy(borrowerCycleVariations);
                        actualChanges.put("borrowerCycleId", id);
                    }
                }
                i++;
            } while (i < variationArray.size());
        }
    }
}

From source file:com.haulmont.restapi.controllers.EntitiesController.java

License:Apache License

@PostMapping("/{entityName}/search")
public ResponseEntity<String> searchEntitiesListPost(@PathVariable String entityName,
        @RequestBody String requestBodyJson) {
    EntitiesSearchResult entitiesSearchResult = entitiesControllerManager.searchEntities(entityName,
            requestBodyJson);// w  w w  .  j av  a2 s .  c  o m
    ResponseEntity.BodyBuilder responseBuilder = ResponseEntity.status(HttpStatus.OK);
    JsonObject requestJsonObject = new JsonParser().parse(requestBodyJson).getAsJsonObject();
    JsonPrimitive returnCount = requestJsonObject.getAsJsonPrimitive("returnCount");
    if (returnCount != null && returnCount.getAsBoolean()) {
        responseBuilder.header("X-Total-Count", entitiesSearchResult.getCount().toString());
    }
    return responseBuilder.body(entitiesSearchResult.getJson());
}