List of usage examples for com.google.gson JsonElement isJsonObject
public boolean isJsonObject()
From source file:com.gst.portfolio.loanaccount.serialization.VariableLoanScheduleFromApiJsonValidator.java
License:Apache License
public void validateSchedule(final String json, final Loan loan) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }/* w w w . ja v a2 s . c om*/ final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.variableSchedulesupportedParameters); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("loan"); if (!loan.isSubmittedAndPendingApproval()) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( "account.is.not.submitted.and.pending.state", "Loan is not in submited state"); throw new PlatformApiDataValidationException(dataValidationErrors); } final JsonElement element = this.fromApiJsonHelper.parse(json); if (loan.loanProduct().allowVariabeInstallments()) { if (element.isJsonObject() && this.fromApiJsonHelper.parameterExists(LoanApiConstants.exceptionParamName, element)) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); final JsonObject exceptionObject = topLevelJsonElement .getAsJsonObject(LoanApiConstants.exceptionParamName); this.fromApiJsonHelper.checkForUnsupportedParameters(exceptionObject, this.variableSchedulesupportedArrayParameters); if (this.fromApiJsonHelper.parameterExists(LoanApiConstants.modifiedinstallmentsParamName, exceptionObject) && exceptionObject.get(LoanApiConstants.modifiedinstallmentsParamName).isJsonArray()) { final JsonArray modificationsArray = exceptionObject .get(LoanApiConstants.modifiedinstallmentsParamName).getAsJsonArray(); validateLoanTermVariations(loan, baseDataValidator, dateFormat, locale, modificationsArray, this.variableScheduleModifiedParameters, LoanApiConstants.modifiedinstallmentsParamName); } if (this.fromApiJsonHelper.parameterExists(LoanApiConstants.newinstallmentsParamName, exceptionObject) && exceptionObject.get(LoanApiConstants.newinstallmentsParamName).isJsonArray()) { final JsonArray array = exceptionObject.get(LoanApiConstants.newinstallmentsParamName) .getAsJsonArray(); validateLoanTermVariations(loan, baseDataValidator, dateFormat, locale, array, this.variableScheduleNewInstallmentParameters, LoanApiConstants.newinstallmentsParamName); } if (this.fromApiJsonHelper.parameterExists(LoanApiConstants.deletedinstallmentsParamName, exceptionObject) && exceptionObject.get(LoanApiConstants.deletedinstallmentsParamName).isJsonArray()) { final JsonArray array = exceptionObject.get(LoanApiConstants.deletedinstallmentsParamName) .getAsJsonArray(); validateLoanTermVariations(loan, baseDataValidator, dateFormat, locale, array, this.variableScheduleDeleteInstallmentParameters, LoanApiConstants.deletedinstallmentsParamName); } } } else { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("variable.schedule.not.supported", "Loan schedule modification not allowed"); } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } }
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 .ja v 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); }//from w ww. ja va 2 s. co m } } } } return associatedChargesForLoan; }
From source file:com.gst.portfolio.meeting.service.MeetingWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
private Collection<ClientAttendance> getClientsAttendance(final Meeting meeting, final JsonCommand command) { final Collection<ClientAttendance> clientsAttendance = new ArrayList<>(); Collection<Group> childGroups = null; if (meeting.isCenterEntity()) { childGroups = this.groupRepository.findByParentId(meeting.entityId()); }/* w w w . jav a 2s . c o m*/ final String json = command.json(); final JsonElement element = this.fromApiJsonHelper.parse(json); 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 Integer attendanceTypeId = this.fromApiJsonHelper .extractIntegerSansLocaleNamed(attendanceTypeParamName, attendanceElement); final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId, true); if (meeting.isGroupEntity() && !client.isChildOfGroup(meeting.entityId())) { throw new ClientNotInGroupException(clientId, meeting.entityId()); } else if (meeting.isCenterEntity()) { if (childGroups != null && !childGroups.isEmpty()) { boolean isChildClient = false; for (final Group group : childGroups) { if (group.isChildClient(clientId)) { isChildClient = true; break; } } if (!isChildClient) { final String defaultUserMessage = "Client with identifier " + clientId + " is not in center " + meeting.entityId(); throw new ClientNotInGroupException("client.not.in.center", defaultUserMessage, clientId, meeting.entityId()); } } } final ClientAttendance clientAttendance = ClientAttendance.createClientAttendance(client, meeting, attendanceTypeId); clientsAttendance.add(clientAttendance); } } } return clientsAttendance; }
From source file:com.gst.portfolio.savings.data.DepositAccountDataValidator.java
License:Apache License
private void validateSavingsCharges(final JsonElement element, final DataValidatorBuilder baseDataValidator) { if (element.isJsonObject()) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); final String monthDayFormat = this.fromApiJsonHelper .extractMonthDayFormatParameter(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); baseDataValidator.reset().parameter(chargeIdParamName).value(chargeId).longGreaterThanZero(); final BigDecimal amount = this.fromApiJsonHelper.extractBigDecimalNamed(amountParamName, savingsChargeElement, locale); baseDataValidator.reset().parameter(amountParamName).value(amount).notNull().positiveAmount(); if (this.fromApiJsonHelper.parameterExists(feeOnMonthDayParamName, savingsChargeElement)) { final MonthDay monthDay = this.fromApiJsonHelper.extractMonthDayNamed( feeOnMonthDayParamName, savingsChargeElement, monthDayFormat, locale); baseDataValidator.reset().parameter(feeOnMonthDayParamName).value(monthDay).notNull(); }//from w w w.j a va2s. c o m if (this.fromApiJsonHelper.parameterExists(feeIntervalParamName, savingsChargeElement)) { final Integer feeInterval = this.fromApiJsonHelper.extractIntegerNamed(feeIntervalParamName, savingsChargeElement, Locale.getDefault()); baseDataValidator.reset().parameter(feeIntervalParamName).value(feeInterval).notNull() .inMinMaxRange(1, 12); } } } } }
From source file:com.gst.portfolio.savings.data.DepositProductDataValidator.java
License:Apache License
private void validateChartsData(JsonElement element, DataValidatorBuilder baseDataValidator) { if (element.isJsonObject()) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); if (topLevelJsonElement.has(chartsParamName) && topLevelJsonElement.get(chartsParamName).isJsonArray()) { final JsonArray array = topLevelJsonElement.get(chartsParamName).getAsJsonArray(); for (int i = 0; i < array.size(); i++) { final JsonObject interestRateChartElement = array.get(i).getAsJsonObject(); final String json = this.fromApiJsonHelper.toJson(interestRateChartElement); // chart for create if (!this.fromApiJsonHelper.parameterExists(idParamName, interestRateChartElement)) { this.chartDataValidator.validateForCreate(json, baseDataValidator); } else { // chart for update this.chartDataValidator.validateForUpdate(json, baseDataValidator); }/*from w w w. j a v a2s .com*/ } } } }
From source file:com.gst.portfolio.savings.domain.DepositAccountAssembler.java
License:Apache License
public Collection<SavingsAccountTransactionDTO> assembleBulkMandatorySavingsAccountTransactionDTOs( final JsonCommand command, final PaymentDetail paymentDetail) { AppUser user = getAppUserIfPresent(); final String json = command.json(); if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }// www . j a v a2 s . com final JsonElement element = this.fromApiJsonHelper.parse(json); final Collection<SavingsAccountTransactionDTO> savingsAccountTransactions = new ArrayList<>(); final LocalDate transactionDate = this.fromApiJsonHelper.extractLocalDateNamed(transactionDateParamName, element); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(element.getAsJsonObject()); final JsonObject topLevelJsonElement = element.getAsJsonObject(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); final DateTimeFormatter formatter = DateTimeFormat.forPattern(dateFormat).withLocale(locale); if (element.isJsonObject()) { if (topLevelJsonElement.has(bulkSavingsDueTransactionsParamName) && topLevelJsonElement.get(bulkSavingsDueTransactionsParamName).isJsonArray()) { final JsonArray array = topLevelJsonElement.get(bulkSavingsDueTransactionsParamName) .getAsJsonArray(); 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); PaymentDetail detail = paymentDetail; if (paymentDetail == null) { detail = this.paymentDetailAssembler.fetchPaymentDetail(savingsTransactionElement); } final SavingsAccountTransactionDTO savingsAccountTransactionDTO = new SavingsAccountTransactionDTO( formatter, transactionDate, dueAmount, detail, new Date(), savingsId, user); savingsAccountTransactions.add(savingsAccountTransactionDTO); } } } return savingsAccountTransactions; }
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()); }/* ww w . j a v a2s . 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); }//w w w . jav a 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.hadrion.comum.notificacao.NotificationLogReader.java
License:Apache License
private Link linkNamed(String aLinkName) { Link link = null;/*from www . j a v a 2 s . c o m*/ JsonElement linkElement = this.elementFrom(this.representation(), aLinkName); if (linkElement.isJsonObject()) { RepresentationReader rep = new RepresentationReader(linkElement.getAsJsonObject()); link = new Link(rep.stringValue("href"), rep.stringValue("rel"), rep.stringValue("title"), rep.stringValue("type")); } return link; }