List of usage examples for com.google.gson JsonArray get
public JsonElement get(int i)
From source file:com.gst.portfolio.savings.domain.DepositProductAssembler.java
License:Apache License
private Set<InterestRateChart> assembleListOfCharts(JsonCommand command, String currencyCode, DataValidatorBuilder baseDataValidator) { final Set<InterestRateChart> charts = new HashSet<>(); if (command.parameterExists(chartsParamName)) { final JsonArray chartsArray = command.arrayOfParameterNamed(chartsParamName); if (chartsArray != null) { for (int i = 0; i < chartsArray.size(); i++) { final JsonObject interstRateChartElement = chartsArray.get(i).getAsJsonObject(); InterestRateChart chart = this.chartAssembler.assembleFrom(interstRateChartElement, currencyCode, baseDataValidator); charts.add(chart);//from ww w . j a v a 2 s.co m } } } return charts; }
From source file:com.gst.portfolio.savings.domain.FixedDepositProduct.java
License:Apache License
private void updateCharts(JsonCommand command, Map<String, Object> actualChanges, final DataValidatorBuilder baseDataValidator) { final Map<String, Object> deletedCharts = new HashMap<>(); final Map<String, Object> chartsChanges = new HashMap<>(); if (command.hasParameter(DepositsApiConstants.chartsParamName)) { final JsonArray array = command.arrayOfParameterNamed(DepositsApiConstants.chartsParamName); if (array != null) { for (int i = 0; i < array.size(); i++) { final JsonObject chartElement = array.get(i).getAsJsonObject(); JsonCommand chartCommand = JsonCommand.fromExistingCommand(command, chartElement); if (chartCommand.parameterExists(idParamName)) { final Long chartId = chartCommand.longValueOfParameterNamed(idParamName); final InterestRateChart chart = this.findChart(chartId); if (chart == null) { baseDataValidator.parameter(idParamName).value(chartId) .failWithCode("no.chart.associated.with.id"); } else if (chartCommand.parameterExists(deleteParamName)) { if (this.removeChart(chart)) { deletedCharts.put(idParamName, chartId); }/* w w w . j ava 2 s. c om*/ } else { chart.update(chartCommand, chartsChanges, baseDataValidator, this.setOfCharts(), this.currency().getCode()); } } else { // assemble chart final InterestRateChart newChart = this.chartAssembler.assembleFrom(chartElement, this.currency().getCode(), baseDataValidator); this.addChart(newChart); } } } } // this.validateCharts(baseDataValidator); // add chart changes to actual changes list. if (!chartsChanges.isEmpty()) { actualChanges.put(InterestRateChartApiConstants.chartSlabs, chartsChanges); } // add deleted chart to actual changes if (!deletedCharts.isEmpty()) { actualChanges.put("deletedChartSlabs", deletedCharts); } }
From source file:com.gst.portfolio.savings.domain.SavingsAccountChargeAssembler.java
License:Apache License
public Set<SavingsAccountCharge> fromParsedJson(final JsonElement element, final String productCurrencyCode) { final Set<SavingsAccountCharge> savingsAccountCharges = new HashSet<>(); if (element.isJsonObject()) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement); final String monthDayFormat = this.fromApiJsonHelper .extractMonthDayFormatParameter(topLevelJsonElement); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); if (topLevelJsonElement.has(chargesParamName) && topLevelJsonElement.get(chargesParamName).isJsonArray()) { final JsonArray array = topLevelJsonElement.get(chargesParamName).getAsJsonArray(); for (int i = 0; i < array.size(); i++) { final JsonObject savingsChargeElement = array.get(i).getAsJsonObject(); final Long id = this.fromApiJsonHelper.extractLongNamed(idParamName, savingsChargeElement); final Long chargeId = this.fromApiJsonHelper.extractLongNamed(chargeIdParamName, savingsChargeElement); final BigDecimal amount = this.fromApiJsonHelper.extractBigDecimalNamed(amountParamName, savingsChargeElement, locale); final Integer chargeTimeType = this.fromApiJsonHelper .extractIntegerNamed(chargeTimeTypeParamName, savingsChargeElement, locale); final Integer chargeCalculationType = this.fromApiJsonHelper .extractIntegerNamed(chargeCalculationTypeParamName, savingsChargeElement, locale); final LocalDate dueDate = this.fromApiJsonHelper.extractLocalDateNamed(dueAsOfDateParamName, savingsChargeElement, dateFormat, locale); final MonthDay feeOnMonthDay = this.fromApiJsonHelper.extractMonthDayNamed( feeOnMonthDayParamName, savingsChargeElement, monthDayFormat, locale); final Integer feeInterval = this.fromApiJsonHelper.extractIntegerNamed(feeIntervalParamName, savingsChargeElement, locale); if (id == null) { final Charge chargeDefinition = this.chargeRepository .findOneWithNotFoundDetection(chargeId); if (!chargeDefinition.isSavingsCharge()) { final String errorMessage = "Charge with identifier " + chargeDefinition.getId() + " cannot be applied to Savings product."; throw new ChargeCannotBeAppliedToException("savings.product", errorMessage, chargeDefinition.getId()); }/*from www. j a v a 2 s . c om*/ ChargeTimeType chargeTime = null; if (chargeTimeType != null) { chargeTime = ChargeTimeType.fromInt(chargeTimeType); } ChargeCalculationType chargeCalculation = null; if (chargeCalculationType != null) { chargeCalculation = ChargeCalculationType.fromInt(chargeCalculationType); } final boolean status = true; final SavingsAccountCharge savingsAccountCharge = SavingsAccountCharge .createNewWithoutSavingsAccount(chargeDefinition, amount, chargeTime, chargeCalculation, dueDate, status, feeOnMonthDay, feeInterval); savingsAccountCharges.add(savingsAccountCharge); } else { final Long savingsAccountChargeId = id; final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository .findOne(savingsAccountChargeId); if (savingsAccountCharge == null) { throw new SavingsAccountChargeNotFoundException(savingsAccountChargeId); } savingsAccountCharge.update(amount, dueDate, feeOnMonthDay, feeInterval); savingsAccountCharges.add(savingsAccountCharge); } } } } this.validateSavingsCharges(savingsAccountCharges, productCurrencyCode); return savingsAccountCharges; }
From source file:com.gst.portfolio.savings.domain.SavingsProductChargeAssembler.java
License:Apache License
public Set<SavingsAccountCharge> fromParsedJson(final JsonElement element) { final Set<SavingsAccountCharge> savingsAccountCharges = new HashSet<>(); 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(chargesParamName) && topLevelJsonElement.get(chargesParamName).isJsonArray()) { final JsonArray array = topLevelJsonElement.get(chargesParamName).getAsJsonArray(); for (int i = 0; i < array.size(); i++) { final JsonObject savingsChargeElement = array.get(i).getAsJsonObject(); final Long id = this.fromApiJsonHelper.extractLongNamed(idParamName, savingsChargeElement); final Long chargeId = this.fromApiJsonHelper.extractLongNamed(chargeIdParamName, savingsChargeElement); final BigDecimal amount = this.fromApiJsonHelper.extractBigDecimalNamed(amountParamName, savingsChargeElement, locale); final Integer chargeTimeType = this.fromApiJsonHelper .extractIntegerNamed(chargeTimeTypeParamName, savingsChargeElement, locale); final Integer chargeCalculationType = this.fromApiJsonHelper .extractIntegerNamed(chargeCalculationTypeParamName, savingsChargeElement, locale); final LocalDate dueDate = this.fromApiJsonHelper.extractLocalDateNamed(dueAsOfDateParamName, savingsChargeElement, dateFormat, locale); final MonthDay feeOnMonthDay = this.fromApiJsonHelper .extractMonthDayNamed(feeOnMonthDayParamName, savingsChargeElement); final Integer feeInterval = this.fromApiJsonHelper.extractIntegerNamed(feeIntervalParamName, savingsChargeElement, locale); if (id == null) { final Charge chargeDefinition = this.chargeRepository .findOneWithNotFoundDetection(chargeId); final ChargeTimeType chargeTime = null; if (chargeTimeType != null) { ChargeTimeType.fromInt(chargeTimeType); }//from w w w .j a va 2 s . c o m final ChargeCalculationType chargeCalculation = null; if (chargeCalculationType != null) { ChargeCalculationType.fromInt(chargeCalculationType); } final SavingsAccountCharge savingsAccountCharge = SavingsAccountCharge .createNewWithoutSavingsAccount(chargeDefinition, amount, chargeTime, chargeCalculation, dueDate, true, feeOnMonthDay, feeInterval); savingsAccountCharges.add(savingsAccountCharge); } else { final Long savingsAccountChargeId = id; final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository .findOne(savingsAccountChargeId); if (savingsAccountCharge == null) { throw new SavingsAccountChargeNotFoundException(savingsAccountChargeId); } savingsAccountCharge.update(amount, dueDate, null, null); savingsAccountCharges.add(savingsAccountCharge); } } } } return savingsAccountCharges; }
From source file:com.gst.portfolio.shareaccounts.serialization.ShareAccountDataSerializer.java
License:Apache License
private Set<ShareAccountCharge> assembleListOfAccountCharges(final JsonElement element, final String currencyCode) { final Set<ShareAccountCharge> charges = new HashSet<>(); if (this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.charges_paramname, element)) { JsonArray chargesArray = this.fromApiJsonHelper .extractJsonArrayNamed(ShareAccountApiConstants.charges_paramname, element); if (chargesArray != null) { for (int i = 0; i < chargesArray.size(); i++) { final JsonObject jsonObject = chargesArray.get(i).getAsJsonObject(); if (jsonObject.has("chargeId")) { final Long id = jsonObject.get("chargeId").getAsLong(); BigDecimal amount = jsonObject.get("amount").getAsBigDecimal(); final Charge charge = this.chargeRepository.findOneWithNotFoundDetection(id); if (!currencyCode.equals(charge.getCurrencyCode())) { final String errorMessage = "Charge and Share Account must have the same currency."; throw new InvalidCurrencyException("charge", "attach.to.share.account", errorMessage); }//from w w w . j av a2 s . c o m ChargeTimeType chargeTime = null; ChargeCalculationType chargeCalculation = null; Boolean status = Boolean.TRUE; ShareAccountCharge accountCharge = ShareAccountCharge.createNewWithoutShareAccount(charge, amount, chargeTime, chargeCalculation, status); charges.add(accountCharge); } } } } return charges; }
From source file:com.gst.portfolio.shareproducts.serialization.ShareProductDataSerializer.java
License:Apache License
private Set<Charge> assembleListOfProductCharges(final JsonElement element, final String currencyCode) { final Set<Charge> charges = new HashSet<>(); if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.charges_paramname, element)) { JsonArray chargesArray = this.fromApiJsonHelper .extractJsonArrayNamed(ShareProductApiConstants.charges_paramname, element); if (chargesArray != null) { for (int i = 0; i < chargesArray.size(); i++) { final JsonObject jsonObject = chargesArray.get(i).getAsJsonObject(); if (jsonObject.has("id")) { final Long id = jsonObject.get("id").getAsLong(); final Charge charge = this.chargeRepository.findOneWithNotFoundDetection(id); if (!currencyCode.equals(charge.getCurrencyCode())) { final String errorMessage = "Charge and Share Product must have the same currency."; throw new InvalidCurrencyException("charge", "attach.to.share.product", errorMessage); }/*w ww. ja v a 2s . co m*/ charges.add(charge); } } } } return charges; }
From source file:com.gst.portfolio.tax.serialization.TaxValidator.java
License:Apache License
public void validateForTaxGroupCreate(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }// ww w .ja v a 2 s. c o m final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedTaxGroupParameters); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("tax.group"); final JsonElement element = this.fromApiJsonHelper.parse(json); final String name = this.fromApiJsonHelper.extractStringNamed(TaxApiConstants.nameParamName, element); baseDataValidator.reset().parameter(TaxApiConstants.nameParamName).value(name).notBlank(); final JsonArray taxComponents = this.fromApiJsonHelper .extractJsonArrayNamed(TaxApiConstants.taxComponentsParamName, element); baseDataValidator.reset().parameter(TaxApiConstants.taxComponentsParamName).value(taxComponents).notBlank(); final JsonObject topLevelJsonElement = element.getAsJsonObject(); if (topLevelJsonElement.get(TaxApiConstants.taxComponentsParamName).isJsonArray()) { final JsonArray array = topLevelJsonElement.get(TaxApiConstants.taxComponentsParamName) .getAsJsonArray(); baseDataValidator.reset().parameter(TaxApiConstants.taxComponentsParamName).value(array.size()) .integerGreaterThanZero(); for (int i = 1; i <= array.size(); i++) { final JsonObject taxComponent = array.get(i - 1).getAsJsonObject(); final String arrayObjectJson = this.fromApiJsonHelper.toJson(taxComponent); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, arrayObjectJson, supportedTaxGroupTaxComponentsCreateParameters); final Long taxComponentId = this.fromApiJsonHelper .extractLongNamed(TaxApiConstants.taxComponentIdParamName, taxComponent); baseDataValidator.reset().parameter(TaxApiConstants.taxComponentsParamName) .parameterAtIndexArray(TaxApiConstants.taxComponentIdParamName, i).value(taxComponentId) .notNull().longGreaterThanZero(); } } throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:com.gst.portfolio.tax.serialization.TaxValidator.java
License:Apache License
public void validateForTaxGroupUpdate(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }//w ww . j av a 2 s .com final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedTaxGroupParameters); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("tax.group"); final JsonElement element = this.fromApiJsonHelper.parse(json); if (this.fromApiJsonHelper.parameterExists(TaxApiConstants.nameParamName, element)) { final String name = this.fromApiJsonHelper.extractStringNamed(TaxApiConstants.nameParamName, element); baseDataValidator.reset().parameter(TaxApiConstants.nameParamName).value(name).notBlank(); } if (this.fromApiJsonHelper.parameterExists(TaxApiConstants.taxComponentsParamName, element)) { final JsonArray taxComponents = this.fromApiJsonHelper .extractJsonArrayNamed(TaxApiConstants.taxComponentsParamName, element); baseDataValidator.reset().parameter(TaxApiConstants.taxComponentsParamName).value(taxComponents) .notBlank(); final JsonObject topLevelJsonElement = element.getAsJsonObject(); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); if (topLevelJsonElement.get(TaxApiConstants.taxComponentsParamName).isJsonArray()) { final JsonArray array = topLevelJsonElement.get(TaxApiConstants.taxComponentsParamName) .getAsJsonArray(); for (int i = 1; i <= array.size(); i++) { final JsonObject taxComponent = array.get(i - 1).getAsJsonObject(); final String arrayObjectJson = this.fromApiJsonHelper.toJson(taxComponent); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, arrayObjectJson, supportedTaxGroupTaxComponentsUpdateParameters); final Long taxComponentId = this.fromApiJsonHelper .extractLongNamed(TaxApiConstants.taxComponentIdParamName, taxComponent); final Long taxMappingId = this.fromApiJsonHelper .extractLongNamed(TaxApiConstants.taxComponentIdParamName, taxComponent); if (taxMappingId == null) { baseDataValidator.reset() .parameter(TaxApiConstants.taxComponentsParamName + "." + TaxApiConstants.taxComponentIdParamName + ".at.index." + i) .value(taxComponentId).notNull().longGreaterThanZero(); } else { baseDataValidator.reset() .parameter(TaxApiConstants.taxComponentsParamName + "." + TaxApiConstants.taxComponentIdParamName + ".at.index." + i) .value(taxComponentId).longGreaterThanZero(); baseDataValidator.reset() .parameter(TaxApiConstants.taxComponentsParamName + "." + TaxApiConstants.idParamName + ".at.index." + i) .value(taxMappingId).longGreaterThanZero(); } final LocalDate endDate = this.fromApiJsonHelper.extractLocalDateNamed( TaxApiConstants.endDateParamName, taxComponent, dateFormat, locale); baseDataValidator.reset() .parameter(TaxApiConstants.taxComponentsParamName + "." + TaxApiConstants.endDateParamName + ".at.index." + i) .value(endDate).ignoreIfNull().validateDateAfter(DateUtils.getLocalDateOfTenant()); final LocalDate startDate = this.fromApiJsonHelper.extractLocalDateNamed( TaxApiConstants.startDateParamName, taxComponent, dateFormat, locale); if (endDate != null && startDate != null) { baseDataValidator.reset() .parameter(TaxApiConstants.taxComponentsParamName + ".at.index." + i) .failWithCode("start.date.end.date.both.should.not.be.present", startDate, endDate); } } } } throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:com.gst.portfolio.tax.service.TaxAssembler.java
License:Apache License
public Set<TaxGroupMappings> assembleTaxGroupMappingsFrom(final JsonCommand command, boolean isUpdate) { Set<TaxGroupMappings> groupMappings = new HashSet<>(); final JsonElement element = command.parsedJson(); final JsonObject topLevelJsonElement = element.getAsJsonObject(); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); if (topLevelJsonElement.get(TaxApiConstants.taxComponentsParamName).isJsonArray()) { final JsonArray array = topLevelJsonElement.get(TaxApiConstants.taxComponentsParamName) .getAsJsonArray();/*ww w . j av a 2s .c o m*/ for (int i = 0; i < array.size(); i++) { final JsonObject taxComponent = array.get(i).getAsJsonObject(); final Long mappingId = this.fromApiJsonHelper.extractLongNamed(TaxApiConstants.idParamName, taxComponent); final Long taxComponentId = this.fromApiJsonHelper .extractLongNamed(TaxApiConstants.taxComponentIdParamName, taxComponent); TaxComponent component = null; if (taxComponentId != null) { component = this.taxComponentRepositoryWrapper.findOneWithNotFoundDetection(taxComponentId); } LocalDate startDate = this.fromApiJsonHelper.extractLocalDateNamed( TaxApiConstants.startDateParamName, taxComponent, dateFormat, locale); final LocalDate endDate = this.fromApiJsonHelper .extractLocalDateNamed(TaxApiConstants.endDateParamName, taxComponent, dateFormat, locale); if (endDate == null && startDate == null) { startDate = DateUtils.getLocalDateOfTenant(); } TaxGroupMappings mappings = null; if (isUpdate && mappingId != null) { mappings = TaxGroupMappings.createTaxGroupMappings(mappingId, component, endDate); } else { mappings = TaxGroupMappings.createTaxGroupMappings(component, startDate); } groupMappings.add(mappings); } } return groupMappings; }
From source file:com.gst.portfolio.transfer.service.TransferWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
private List<Client> assembleListOfClients(final JsonCommand command) { final List<Client> clients = new ArrayList<>(); if (command.parameterExists(TransferApiConstants.clients)) { final JsonArray clientsArray = command.arrayOfParameterNamed(TransferApiConstants.clients); if (clientsArray != null) { for (int i = 0; i < clientsArray.size(); i++) { final JsonObject jsonObject = clientsArray.get(i).getAsJsonObject(); if (jsonObject.has(TransferApiConstants.idParamName)) { final Long id = jsonObject.get(TransferApiConstants.idParamName).getAsLong(); final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(id); clients.add(client); }//from w ww . j av a 2 s .co m } } } return clients; }