List of usage examples for com.google.gson JsonObject has
public boolean has(String memberName)
From source file:com.gst.portfolio.address.domain.Address.java
License:Apache License
public static Address fromJsonObject(final JsonObject jsonObject, final CodeValue state_province, final CodeValue country) { String street = ""; String addressLine1 = ""; String addressLine2 = ""; String addressLine3 = ""; String townVillage = ""; String city = ""; String countyDistrict = ""; String postalCode = ""; BigDecimal latitude = BigDecimal.ZERO; BigDecimal longitude = BigDecimal.ZERO; String createdBy = ""; Locale locale = Locale.ENGLISH; String updatedBy = ""; LocalDate updatedOnDate = null; LocalDate createdOnDate = null; if (jsonObject.has("street")) { street = jsonObject.get("street").getAsString(); }/*from ww w .j ava 2 s .co m*/ if (jsonObject.has("addressLine1")) { addressLine1 = jsonObject.get("addressLine1").getAsString(); } if (jsonObject.has("addressLine2")) { addressLine2 = jsonObject.get("addressLine2").getAsString(); } if (jsonObject.has("addressLine3")) { addressLine3 = jsonObject.get("addressLine3").getAsString(); } if (jsonObject.has("townVillage")) { townVillage = jsonObject.get("townVillage").getAsString(); } if (jsonObject.has("city")) { city = jsonObject.get("city").getAsString(); } if (jsonObject.has("countyDistrict")) { countyDistrict = jsonObject.get("countyDistrict").getAsString(); } if (jsonObject.has("postalCode")) { postalCode = jsonObject.get("postalCode").getAsString(); } if (jsonObject.has("latitude")) { latitude = jsonObject.get("latitude").getAsBigDecimal(); } if (jsonObject.has("longitude")) { longitude = jsonObject.get("longitude").getAsBigDecimal(); } if (jsonObject.has("createdBy")) { createdBy = jsonObject.get("createdBy").getAsString(); } if (jsonObject.has("createdOn")) { String createdOn = jsonObject.get("createdOn").getAsString(); DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); createdOnDate = LocalDate.parse(createdOn, formatter); } if (jsonObject.has("updatedBy")) { updatedBy = jsonObject.get("updatedBy").getAsString(); } if (jsonObject.has("updatedOn")) { String updatedOn = jsonObject.get("updatedOn").getAsString(); DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); updatedOnDate = LocalDate.parse(updatedOn, formatter); } return new Address(street, addressLine1, addressLine2, addressLine3, townVillage, city, countyDistrict, state_province, country, postalCode, latitude, longitude, createdBy, createdOnDate, updatedBy, updatedOnDate); }
From source file:com.gst.portfolio.collateral.service.CollateralAssembler.java
License:Apache License
public Set<LoanCollateral> fromParsedJson(final JsonElement element) { final Set<LoanCollateral> collateralItems = new HashSet<>(); if (element.isJsonObject()) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); if (topLevelJsonElement.has("collateral") && topLevelJsonElement.get("collateral").isJsonArray()) { final JsonArray array = topLevelJsonElement.get("collateral").getAsJsonArray(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); for (int i = 0; i < array.size(); i++) { final JsonObject collateralItemElement = array.get(i).getAsJsonObject(); final Long id = this.fromApiJsonHelper.extractLongNamed("id", collateralItemElement); final Long collateralTypeId = this.fromApiJsonHelper.extractLongNamed("type", collateralItemElement); final CodeValue collateralType = this.codeValueRepository .findOneWithNotFoundDetection(collateralTypeId); final String description = this.fromApiJsonHelper.extractStringNamed("description", collateralItemElement); final BigDecimal value = this.fromApiJsonHelper.extractBigDecimalNamed("value", collateralItemElement, locale); if (id == null) { collateralItems.add(LoanCollateral.from(collateralType, value, description)); } else { final LoanCollateral loanCollateralItem = this.loanCollateralRepository.findOne(id); if (loanCollateralItem == null) { throw new CollateralNotFoundException(id); }//ww w. j a va 2 s .c o m loanCollateralItem.assembleFrom(collateralType, value, description); collateralItems.add(loanCollateralItem); } } } else { // no collaterals passed, use existing ones against loan } } return collateralItems; }
From source file:com.gst.portfolio.collectionsheet.data.CollectionSheetTransactionDataValidator.java
License:Apache License
private void validateAttendanceDetails(final JsonElement element, final DataValidatorBuilder baseDataValidator) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); if (element.isJsonObject()) { if (topLevelJsonElement.has(clientsAttendanceParamName) && topLevelJsonElement.get(clientsAttendanceParamName).isJsonArray()) { final JsonArray array = topLevelJsonElement.get(clientsAttendanceParamName).getAsJsonArray(); for (int i = 0; i < array.size(); i++) { final JsonObject attendanceElement = array.get(i).getAsJsonObject(); final Long clientId = this.fromApiJsonHelper.extractLongNamed(clientIdParamName, attendanceElement); final Long attendanceType = this.fromApiJsonHelper.extractLongNamed(attendanceTypeParamName, attendanceElement); baseDataValidator.reset() .parameter(clientsAttendanceParamName + "[" + i + "]." + clientIdParamName) .value(clientId).notNull().integerGreaterThanZero(); baseDataValidator.reset() .parameter(clientsAttendanceParamName + "[" + i + "]." + attendanceTypeParamName) .value(attendanceType).notNull().integerGreaterThanZero(); }/* w w w . j a va2s . c o m*/ } } }
From source file:com.gst.portfolio.collectionsheet.data.CollectionSheetTransactionDataValidator.java
License:Apache License
private void validateDisbursementTransactions(final JsonElement element, final DataValidatorBuilder baseDataValidator) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); if (element.isJsonObject()) { if (topLevelJsonElement.has(bulkDisbursementTransactionsParamName) && topLevelJsonElement.get(bulkDisbursementTransactionsParamName).isJsonArray()) { final JsonArray array = topLevelJsonElement.get(bulkDisbursementTransactionsParamName) .getAsJsonArray();//w ww .ja v a 2 s .co m for (int i = 0; i < array.size(); i++) { final JsonObject loanTransactionElement = array.get(i).getAsJsonObject(); final Long loanId = this.fromApiJsonHelper.extractLongNamed(loanIdParamName, loanTransactionElement); final BigDecimal disbursementAmount = this.fromApiJsonHelper .extractBigDecimalNamed(transactionAmountParamName, loanTransactionElement, locale); baseDataValidator.reset().parameter("bulktransaction" + "[" + i + "].loan.id").value(loanId) .notNull().integerGreaterThanZero(); baseDataValidator.reset().parameter("bulktransaction" + "[" + i + "].disbursement.amount") .value(disbursementAmount).notNull().zeroOrPositiveAmount(); } } } }
From source file:com.gst.portfolio.collectionsheet.data.CollectionSheetTransactionDataValidator.java
License:Apache License
private void validateRepaymentTransactions(final JsonElement element, final DataValidatorBuilder baseDataValidator) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); if (element.isJsonObject()) { if (topLevelJsonElement.has(bulkRepaymentTransactionsParamName) && topLevelJsonElement.get(bulkRepaymentTransactionsParamName).isJsonArray()) { final JsonArray array = topLevelJsonElement.get(bulkRepaymentTransactionsParamName) .getAsJsonArray();//from w ww .jav a 2 s.c o m for (int i = 0; i < array.size(); i++) { final JsonObject loanTransactionElement = array.get(i).getAsJsonObject(); final Long loanId = this.fromApiJsonHelper.extractLongNamed(loanIdParamName, loanTransactionElement); final BigDecimal disbursementAmount = this.fromApiJsonHelper .extractBigDecimalNamed(transactionAmountParamName, loanTransactionElement, locale); baseDataValidator.reset().parameter("bulktransaction" + "[" + i + "].loan.id").value(loanId) .notNull().integerGreaterThanZero(); baseDataValidator.reset().parameter("bulktransaction" + "[" + i + "].disbursement.amount") .value(disbursementAmount).notNull().zeroOrPositiveAmount(); validatePaymentDetails(baseDataValidator, loanTransactionElement, locale); } } } }
From source file:com.gst.portfolio.collectionsheet.data.CollectionSheetTransactionDataValidator.java
License:Apache License
private void validateSavingsDueTransactions(final JsonElement element, final DataValidatorBuilder baseDataValidator) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); if (element.isJsonObject()) { if (topLevelJsonElement.has(bulkSavingsDueTransactionsParamName) && topLevelJsonElement.get(bulkSavingsDueTransactionsParamName).isJsonArray()) { final JsonArray array = topLevelJsonElement.get(bulkSavingsDueTransactionsParamName) .getAsJsonArray();/*from ww w . j av a2s . c o m*/ for (int i = 0; i < array.size(); i++) { final JsonObject savingsTransactionElement = array.get(i).getAsJsonObject(); final Long savingsId = this.fromApiJsonHelper.extractLongNamed(savingsIdParamName, savingsTransactionElement); final BigDecimal dueAmount = this.fromApiJsonHelper .extractBigDecimalNamed(transactionAmountParamName, savingsTransactionElement, locale); baseDataValidator.reset().parameter("bulktransaction" + "[" + i + "].savings.id") .value(savingsId).notNull().integerGreaterThanZero(); baseDataValidator.reset().parameter("bulktransaction" + "[" + i + "].due.amount") .value(dueAmount).notNull().zeroOrPositiveAmount(); validatePaymentDetails(baseDataValidator, savingsTransactionElement, locale); } } } }
From source file:com.gst.portfolio.collectionsheet.serialization.CollectionSheetBulkDisbursalCommandFromApiJsonDeserializer.java
License:Apache License
@Override public CollectionSheetBulkDisbursalCommand commandFromApiJson(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }/*from w w w . j a va 2 s . c om*/ final JsonElement element = this.fromApiJsonHelper.parse(json); final JsonObject topLevelJsonElement = element.getAsJsonObject(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); final LocalDate transactionDate = this.fromApiJsonHelper.extractLocalDateNamed("transactionDate", element); final String note = this.fromApiJsonHelper.extractStringNamed("note", element); SingleDisbursalCommand[] loanDisbursementTransactions = null; if (element.isJsonObject()) { if (topLevelJsonElement.has("bulkDisbursementTransactions") && topLevelJsonElement.get("bulkDisbursementTransactions").isJsonArray()) { final JsonArray array = topLevelJsonElement.get("bulkDisbursementTransactions").getAsJsonArray(); loanDisbursementTransactions = new SingleDisbursalCommand[array.size()]; for (int i = 0; i < array.size(); i++) { final JsonObject loanTransactionElement = array.get(i).getAsJsonObject(); final Long loanId = this.fromApiJsonHelper.extractLongNamed("loanId", loanTransactionElement); final BigDecimal disbursementAmount = this.fromApiJsonHelper .extractBigDecimalNamed("transactionAmount", loanTransactionElement, locale); loanDisbursementTransactions[i] = new SingleDisbursalCommand(loanId, disbursementAmount, transactionDate); } } } return new CollectionSheetBulkDisbursalCommand(note, transactionDate, loanDisbursementTransactions); }
From source file:com.gst.portfolio.collectionsheet.serialization.CollectionSheetBulkRepaymentCommandFromApiJsonDeserializer.java
License:Apache License
public CollectionSheetBulkRepaymentCommand commandFromApiJson(final String json, final PaymentDetail paymentDetail) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }/*from w w w .j av a2 s . co m*/ final JsonElement element = this.fromApiJsonHelper.parse(json); final LocalDate transactionDate = this.fromApiJsonHelper.extractLocalDateNamed("transactionDate", element); final String note = this.fromApiJsonHelper.extractStringNamed("note", element); final JsonObject topLevelJsonElement = element.getAsJsonObject(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); SingleRepaymentCommand[] loanRepaymentTransactions = null; if (element.isJsonObject()) { if (topLevelJsonElement.has("bulkRepaymentTransactions") && topLevelJsonElement.get("bulkRepaymentTransactions").isJsonArray()) { final JsonArray array = topLevelJsonElement.get("bulkRepaymentTransactions").getAsJsonArray(); loanRepaymentTransactions = new SingleRepaymentCommand[array.size()]; for (int i = 0; i < array.size(); i++) { final JsonObject loanTransactionElement = array.get(i).getAsJsonObject(); final Long loanId = this.fromApiJsonHelper.extractLongNamed("loanId", loanTransactionElement); final BigDecimal transactionAmount = this.fromApiJsonHelper .extractBigDecimalNamed("transactionAmount", loanTransactionElement, locale); PaymentDetail detail = paymentDetail; if (paymentDetail == null) { detail = this.paymentDetailAssembler.fetchPaymentDetail(loanTransactionElement); } if (transactionAmount != null && transactionAmount.intValue() > 0) { loanRepaymentTransactions[i] = new SingleRepaymentCommand(loanId, transactionAmount, transactionDate, detail); } } } } return new CollectionSheetBulkRepaymentCommand(note, transactionDate, loanRepaymentTransactions); }
From source file:com.gst.portfolio.interestratechart.data.InterestRateChartDataValidator.java
License:Apache License
private void validateChartSlabs(JsonElement element, DataValidatorBuilder baseDataValidator, final boolean isPrimaryGroupingByAmount) { 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(); if (this.fromApiJsonHelper.parameterExists(idParamName, interstRateChartElement)) { final Long id = this.fromApiJsonHelper.extractLongNamed(idParamName, interstRateChartElement); baseDataValidator.reset().parameter(idParamName).value(id).notNull() .integerGreaterThanZero(); this.chartSlabDataValidator.validateChartSlabsUpdate(interstRateChartElement, baseDataValidator, locale, isPrimaryGroupingByAmount); } else { this.chartSlabDataValidator.validateChartSlabsCreate(interstRateChartElement, baseDataValidator, locale, isPrimaryGroupingByAmount); }//from w ww . jav a 2 s .c o m } } } }
From source file:com.gst.portfolio.interestratechart.data.InterestRateChartSlabDataValidator.java
License:Apache License
private void validateIncentives(JsonElement element, DataValidatorBuilder baseDataValidator, final Locale locale) { 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(); if (this.fromApiJsonHelper.parameterExists(InterestIncentiveApiConstants.idParamName, incentiveElement)) { final Long id = this.fromApiJsonHelper .extractLongNamed(InterestIncentiveApiConstants.idParamName, incentiveElement); baseDataValidator.reset().parameter(InterestIncentiveApiConstants.idParamName).value(id) .notNull().integerGreaterThanZero(); this.interestIncentiveDataValidator.validateIncentiveUpdate(incentiveElement, baseDataValidator, locale); } else { this.interestIncentiveDataValidator.validateIncentiveCreate(incentiveElement, baseDataValidator, locale); }/*from w w w . j a va 2s. co m*/ } } } }