List of usage examples for com.google.gson JsonObject has
public boolean has(String memberName)
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 {//ww w . j a va 2 s .c o m 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 {/*from w ww .j av a 2 s .c o m*/ 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.gst.portfolio.loanproduct.service.LoanProductWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
private List<Charge> assembleListOfProductCharges(final JsonCommand command, final String currencyCode) { final List<Charge> charges = new ArrayList<>(); String loanProductCurrencyCode = command.stringValueOfParameterNamed("currencyCode"); if (loanProductCurrencyCode == null) { loanProductCurrencyCode = currencyCode; }//from w ww .ja v a 2 s . com if (command.parameterExists("charges")) { final JsonArray chargesArray = command.arrayOfParameterNamed("charges"); 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 (!loanProductCurrencyCode.equals(charge.getCurrencyCode())) { final String errorMessage = "Charge and Loan Product must have the same currency."; throw new InvalidCurrencyException("charge", "attach.to.loan.product", errorMessage); } charges.add(charge); } } } } return charges; }
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()); }/*from w w w .j a va 2 s . co 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(); }/* w w w . j av a 2 s . co 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); }// ww w . j a v a 2 s . co m } } } }
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(); }//from w w w.j av a 2s . 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.DepositProductAssembler.java
License:Apache License
public Set<Charge> assembleListOfSavingsProductCharges(final JsonCommand command, final String savingsProductCurrencyCode) { final Set<Charge> charges = new HashSet<>(); if (command.parameterExists(chargesParamName)) { final JsonArray chargesArray = command.arrayOfParameterNamed(chargesParamName); if (chargesArray != null) { for (int i = 0; i < chargesArray.size(); i++) { final JsonObject jsonObject = chargesArray.get(i).getAsJsonObject(); if (jsonObject.has(idParamName)) { final Long id = jsonObject.get(idParamName).getAsLong(); final Charge charge = this.chargeRepository.findOneWithNotFoundDetection(id); if (!charge.isSavingsCharge()) { final String errorMessage = "Charge with identifier " + charge.getId() + " cannot be applied to Savings product."; throw new ChargeCannotBeAppliedToException("savings.product", errorMessage, charge.getId()); }/*from www. j av a 2 s . c o m*/ if (!savingsProductCurrencyCode.equals(charge.getCurrencyCode())) { final String errorMessage = "Charge and Savings Product must have the same currency."; throw new InvalidCurrencyException("charge", "attach.to.savings.product", errorMessage); } charges.add(charge); } } } } return charges; }
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 w w w .j a v a2 s .c o m*/ 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; }