List of usage examples for com.google.gson JsonArray get
public JsonElement get(int i)
From source file:com.gst.portfolio.address.service.AddressWritePlatformServiceImpl.java
License:Apache License
@Override public CommandProcessingResult addNewClientAddress(final Client client, final JsonCommand command) { CodeValue stateIdobj = null;//from ww w.j a v a 2 s .c om CodeValue countryIdObj = null; long stateId; long countryId; ClientAddress clientAddressobj = new ClientAddress(); final JsonArray addressArray = command.arrayOfParameterNamed("address"); for (int i = 0; i < addressArray.size(); i++) { final JsonObject jsonObject = addressArray.get(i).getAsJsonObject(); // validate every address this.fromApiJsonDeserializer.validateForCreate(jsonObject.toString(), true); if (jsonObject.get("stateProvinceId") != null) { stateId = jsonObject.get("stateProvinceId").getAsLong(); stateIdobj = this.codeValueRepository.getOne(stateId); } if (jsonObject.get("countryId") != null) { countryId = jsonObject.get("countryId").getAsLong(); countryIdObj = this.codeValueRepository.getOne(countryId); } final long addressTypeId = jsonObject.get("addressTypeId").getAsLong(); final CodeValue addressTypeIdObj = this.codeValueRepository.getOne(addressTypeId); final Address add = Address.fromJsonObject(jsonObject, stateIdobj, countryIdObj); this.addressRepository.save(add); final Long addressid = add.getId(); final Address addobj = this.addressRepository.getOne(addressid); final boolean isActive = jsonObject.get("isActive").getAsBoolean(); clientAddressobj = ClientAddress.fromJson(isActive, client, addobj, addressTypeIdObj); this.clientAddressRepository.save(clientAddressobj); } return new CommandProcessingResultBuilder().withCommandId(command.commandId()) .withEntityId(clientAddressobj.getId()).build(); }
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); }//from w w w.j av a 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(); }//from w w w . j a va 2s . co 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();/*from w w w .j a v a2s .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(); } } } }
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 ww w . j a v a2 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 w w w.j a v a 2 s.com*/ 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(); }/* w w w . j a v a2 s . com*/ 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 ww w .java2 s .c om 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.floatingrates.serialization.FloatingRateDataValidator.java
License:Apache License
private void validateRatePeriods(DataValidatorBuilder baseDataValidator, JsonElement element, boolean isBaseLendingRate, boolean isBLRModifiedAsNonBLR) { if (this.fromApiJsonHelper.parameterExists("ratePeriods", element)) { final JsonArray ratePeriods = this.fromApiJsonHelper.extractJsonArrayNamed("ratePeriods", element); baseDataValidator.reset().parameter("ratePeriods").value(ratePeriods).notBlank().jsonArrayNotEmpty(); if (ratePeriods != null) { List<LocalDate> fromDates = new ArrayList<>(); for (int i = 0; i < ratePeriods.size(); i++) { final JsonElement ratePeriod = ratePeriods.get(i); this.fromApiJsonHelper.checkForUnsupportedParameters(ratePeriod.getAsJsonObject(), this.supportedParametersForFloatingRatePeriods); final LocalDate fromDate = this.fromApiJsonHelper.extractLocalDateNamed("fromDate", ratePeriod); baseDataValidator.reset().parameter("fromDate").parameterAtIndexArray("fromDate", i + 1) .value(fromDate).notBlank() .validateDateAfter(DateUtils.getLocalDateOfTenant().plusDays(1)); if (fromDate != null) { fromDates.add(fromDate); }/*from ww w.j av a 2 s . c o m*/ final BigDecimal interestRatePerPeriod = this.fromApiJsonHelper .extractBigDecimalWithLocaleNamed("interestRate", ratePeriod); baseDataValidator.reset().parameter("interestRate").parameterAtIndexArray("interestRate", i + 1) .value(interestRatePerPeriod).notNull().zeroOrPositiveAmount(); if (this.fromApiJsonHelper.parameterExists("isDifferentialToBaseLendingRate", ratePeriod)) { final Boolean isDifferentialToBaseLendingRate = this.fromApiJsonHelper .extractBooleanNamed("isDifferentialToBaseLendingRate", ratePeriod); if (isDifferentialToBaseLendingRate == null) { baseDataValidator.reset().parameter("isDifferentialToBaseLendingRate") .parameterAtIndexArray("isDifferentialToBaseLendingRate", i + 1) .trueOrFalseRequired(false); } else if (isDifferentialToBaseLendingRate) { FloatingRate baseLendingRate = this.floatingRateRepository.retrieveBaseLendingRate(); if (baseLendingRate == null || isBLRModifiedAsNonBLR) { baseDataValidator.reset().parameter("isDifferentialToBaseLendingRate") .parameterAtIndexArray("isDifferentialToBaseLendingRate", i + 1) .value(isDifferentialToBaseLendingRate).failWithCode( "no.baselending.rate.defined", "Base Lending Rate doesn't exists"); } if (isBaseLendingRate) { baseDataValidator.reset().parameter("isDifferentialToBaseLendingRate") .parameterAtIndexArray("isDifferentialToBaseLendingRate", i + 1) .value(isDifferentialToBaseLendingRate) .failWithCode("cannot.be.true.for.baselendingrate", "isDifferentialToBaseLendingRate cannot be true for floating rate marked as Base Lending Rate."); } } } } Set<LocalDate> uniqueFromDates = new HashSet<>(fromDates); if (fromDates.size() != uniqueFromDates.size()) { baseDataValidator.reset().parameter("fromDate").failWithCode("multiple.same.date", "More than one entry in ratePeriods have same fromDate."); } } } }
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 ww w. j a v a 2 s . com } } } }