public void validateForCreateCurrency(String json) {

    final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
    fromApiJsonHelper.checkForUnsupportedParameters(
        typeOfMap, json, supportedParametersforGameEvent);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
    final DataValidatorBuilder baseDataValidator =
        new DataValidatorBuilder(dataValidationErrors).resource("currency");

    final JsonElement element = fromApiJsonHelper.parse(json);

    final Long sourceCurrency = fromApiJsonHelper.extractLongNamed("sourceCurrency", element);
    baseDataValidator.reset().parameter("sourceCurrency").value(sourceCurrency).notBlank();

    final Long targetCurrency = fromApiJsonHelper.extractLongNamed("targetCurrency", element);
    baseDataValidator.reset().parameter("targetCurrency").value(targetCurrency).notBlank();

    final BigDecimal exchangeRate =
        fromApiJsonHelper.extractBigDecimalWithLocaleNamed("exchangeRate", element);
    baseDataValidator
        .reset()
        .parameter("exchangeRate")
        .value(exchangeRate)
        .notBlank()
        .notExceedingLengthOf(50);

    final LocalDate startDate = fromApiJsonHelper.extractLocalDateNamed("startDate", element);
    baseDataValidator.reset().parameter("startDate").value(startDate).notBlank();

    final LocalDate endDate = fromApiJsonHelper.extractLocalDateNamed("endDate", element);
    baseDataValidator.reset().parameter("endDate").value(endDate).notBlank();

    throwExceptionIfValidationWarningsExist(dataValidationErrors);
  }
  public void validateForCreate(final String json) {
    if (StringUtils.isBlank(json)) {
      throw new InvalidJsonException();
    }

    final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
    fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
    final DataValidatorBuilder baseDataValidator =
        new DataValidatorBuilder(dataValidationErrors).resource("onetimesale");

    final JsonElement element = fromApiJsonHelper.parse(json);

    final LocalDate saleDate = fromApiJsonHelper.extractLocalDateNamed("saleDate", element);
    baseDataValidator.reset().parameter("saleDate").value(saleDate).notBlank();
    final Long itemId = fromApiJsonHelper.extractLongNamed("itemId", element);
    baseDataValidator.reset().parameter("itemId").value(itemId).notNull();
    final String quantity = fromApiJsonHelper.extractStringNamed("quantity", element);
    baseDataValidator
        .reset()
        .parameter("quantity")
        .value(quantity)
        .notBlank()
        .integerGreaterThanZero()
        .notExceedingLengthOf(50);
    final Long discountId = fromApiJsonHelper.extractLongNamed("discountId", element);
    baseDataValidator.reset().parameter("discountId").value(discountId).notNull();
    final String chargeCode = fromApiJsonHelper.extractStringNamed("chargeCode", element);
    baseDataValidator.reset().parameter("chargeCode").value(chargeCode).notBlank();
    final BigDecimal totalPrice =
        fromApiJsonHelper.extractBigDecimalWithLocaleNamed("totalPrice", element);
    baseDataValidator.reset().parameter("totalPrice").value(totalPrice).notNull();
    final BigDecimal unitPrice =
        fromApiJsonHelper.extractBigDecimalWithLocaleNamed("unitPrice", element);
    baseDataValidator.reset().parameter("unitPrice").value(unitPrice).notNull();

    throwExceptionIfValidationWarningsExist(dataValidationErrors);
  }
  public void validateForCreate(final String json) {
    if (StringUtils.isBlank(json)) {
      throw new InvalidJsonException();
    }

    final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
    fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
    final DataValidatorBuilder baseDataValidator =
        new DataValidatorBuilder(dataValidationErrors).resource("addons");
    final JsonElement element = fromApiJsonHelper.parse(json);
    final Long contractId = fromApiJsonHelper.extractLongNamed("contractId", element);
    baseDataValidator.reset().parameter("contractId").value(contractId).notNull();
    final LocalDate startDate = fromApiJsonHelper.extractLocalDateNamed("startDate", element);
    baseDataValidator.reset().parameter("startDate").value(startDate).notBlank();
    final JsonArray addonServicesArray =
        fromApiJsonHelper.extractJsonArrayNamed("addonServices", element);
    String[] serviceParameters = null;
    serviceParameters = new String[addonServicesArray.size()];
    int arraysize = addonServicesArray.size();
    baseDataValidator.reset().parameter(null).value(arraysize).integerGreaterThanZero();
    for (int i = 0; i < addonServicesArray.size(); i++) {
      serviceParameters[i] = addonServicesArray.get(i).toString();
    }

    for (String serviceParameter : serviceParameters) {

      final JsonElement attributeElement = fromApiJsonHelper.parse(serviceParameter);
      final Long serviceId = fromApiJsonHelper.extractLongNamed("serviceId", attributeElement);
      baseDataValidator.reset().parameter("serviceId").value(serviceId).notNull();
      final BigDecimal price =
          fromApiJsonHelper.extractBigDecimalWithLocaleNamed("price", attributeElement);
      baseDataValidator.reset().parameter("price").value(price).notNull();
    }

    throwExceptionIfValidationWarningsExist(dataValidationErrors);
  }
  public void validateForCreate(final String json) {
    if (StringUtils.isBlank(json)) {
      throw new InvalidJsonException();
    }

    final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
    fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
    final DataValidatorBuilder baseDataValidator =
        new DataValidatorBuilder(dataValidationErrors).resource("itemsale");

    final JsonElement element = fromApiJsonHelper.parse(json);

    final String agentId = fromApiJsonHelper.extractStringNamed("agentId", element);
    baseDataValidator.reset().parameter("agentId").value(agentId).notNull();
    final String itemId = fromApiJsonHelper.extractStringNamed("itemId", element);
    baseDataValidator.reset().parameter("itemId").value(itemId).notNull();
    final LocalDate purchaseDate = fromApiJsonHelper.extractLocalDateNamed("purchaseDate", element);
    baseDataValidator.reset().parameter("purchaseDate").value(purchaseDate).notBlank();

    final Long orderQuantity = fromApiJsonHelper.extractLongNamed("orderQuantity", element);
    baseDataValidator
        .reset()
        .parameter("orderQuantity")
        .value(orderQuantity)
        .notNull()
        .integerGreaterThanZero();
    final BigDecimal chargeAmount =
        fromApiJsonHelper.extractBigDecimalWithLocaleNamed("chargeAmount", element);
    baseDataValidator.reset().parameter("chargeAmount").value(chargeAmount).notNull();
    final BigDecimal taxAmount =
        fromApiJsonHelper.extractBigDecimalWithLocaleNamed("taxAmount", element);
    baseDataValidator.reset().parameter("taxAmount").value(chargeAmount).notNull();

    throwExceptionIfValidationWarningsExist(dataValidationErrors);
  }
Exemplo n.º 5
0
  private LoanApplicationTerms assembleLoanApplicationTermsFrom(
      final JsonElement element, final LoanProduct loanProduct) {

    final MonetaryCurrency currency = loanProduct.getCurrency();
    final ApplicationCurrency applicationCurrency =
        this.applicationCurrencyRepository.findOneWithNotFoundDetection(currency);

    // loan terms
    final Integer loanTermFrequency =
        fromApiJsonHelper.extractIntegerWithLocaleNamed("loanTermFrequency", element);
    final Integer loanTermFrequencyType =
        fromApiJsonHelper.extractIntegerWithLocaleNamed("loanTermFrequencyType", element);
    final PeriodFrequencyType loanTermPeriodFrequencyType =
        PeriodFrequencyType.fromInt(loanTermFrequencyType);

    final Integer numberOfRepayments =
        fromApiJsonHelper.extractIntegerWithLocaleNamed("numberOfRepayments", element);
    final Integer repaymentEvery =
        fromApiJsonHelper.extractIntegerWithLocaleNamed("repaymentEvery", element);
    final Integer repaymentFrequencyType =
        fromApiJsonHelper.extractIntegerWithLocaleNamed("repaymentFrequencyType", element);
    final PeriodFrequencyType repaymentPeriodFrequencyType =
        PeriodFrequencyType.fromInt(repaymentFrequencyType);

    final Integer amortizationType =
        fromApiJsonHelper.extractIntegerWithLocaleNamed("amortizationType", element);
    final AmortizationMethod amortizationMethod = AmortizationMethod.fromInt(amortizationType);

    // interest terms
    final Integer interestType =
        fromApiJsonHelper.extractIntegerWithLocaleNamed("interestType", element);
    final InterestMethod interestMethod = InterestMethod.fromInt(interestType);

    final Integer interestCalculationPeriodType =
        fromApiJsonHelper.extractIntegerWithLocaleNamed("interestCalculationPeriodType", element);
    final InterestCalculationPeriodMethod interestCalculationPeriodMethod =
        InterestCalculationPeriodMethod.fromInt(interestCalculationPeriodType);

    final BigDecimal interestRatePerPeriod =
        fromApiJsonHelper.extractBigDecimalWithLocaleNamed("interestRatePerPeriod", element);
    final PeriodFrequencyType interestRatePeriodFrequencyType =
        loanProduct.getInterestPeriodFrequencyType();

    final BigDecimal annualNominalInterestRate =
        this.aprCalculator.calculateFrom(interestRatePeriodFrequencyType, interestRatePerPeriod);

    // disbursement details
    final BigDecimal principal =
        this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("principal", element);
    final Money principalMoney = Money.of(currency, principal);

    final LocalDate expectedDisbursementDate =
        this.fromApiJsonHelper.extractLocalDateNamed("expectedDisbursementDate", element);
    final LocalDate repaymentsStartingFromDate =
        this.fromApiJsonHelper.extractLocalDateNamed("repaymentsStartingFromDate", element);
    LocalDate calculatedRepaymentsStartingFromDate = repaymentsStartingFromDate;
    final Boolean synchDisbursement =
        fromApiJsonHelper.extractBooleanNamed("syncDisbursementWithMeeting", element);
    final Long calendarId = this.fromApiJsonHelper.extractLongNamed("calendarId", element);
    Calendar calendar = null;
    if ((synchDisbursement != null && synchDisbursement.booleanValue())
        || (calendarId != null && calendarId != 0)) {
      calendar = this.calendarRepository.findOne(calendarId);
      if (calendar == null) {
        throw new CalendarNotFoundException(calendarId);
      }

      // validate repayment frequency and interval with meeting frequency and interval
      PeriodFrequencyType meetingPeriodFrequency =
          CalendarHelper.getMeetingPeriodFrequencyType(calendar.getRecurrence());
      validateRepaymentFrequencyIsSameAsMeetingFrequency(
          meetingPeriodFrequency.getValue(),
          repaymentFrequencyType,
          CalendarHelper.getInterval(calendar.getRecurrence()),
          repaymentEvery);
    }

    if (synchDisbursement != null && synchDisbursement.booleanValue()) {
      validateDisbursementDateWithMeetingDates(expectedDisbursementDate, calendar);
    }

    // if calendar is attached (not null) then reschedule repayment dates according to meeting
    if (null != calendar) {
      // TODO : AA - Is it require to reset repaymentsStartingFromDate or
      // set only if it is not provided (or null)
      // Currently provided repaymentsStartingFromDate takes precedence over system generated next
      // meeting date
      if (calculatedRepaymentsStartingFromDate == null) {
        // FIXME: AA - Possibility of having next meeting date immediately after disbursement date,
        // need to have minimum number of days gap between disbursement and first repayment date.
        final String frequency =
            CalendarHelper.getMeetingFrequencyFromPeriodFrequencyType(repaymentPeriodFrequencyType);
        calculatedRepaymentsStartingFromDate =
            CalendarHelper.getFirstRepaymentMeetingDate(
                calendar, expectedDisbursementDate, repaymentEvery, frequency);
      } else { // validate user provided repaymentsStartFromDate
        validateRepaymentsStartDateWithMeetingDates(repaymentsStartingFromDate, calendar);
      }
    }
    // grace details
    final Integer graceOnPrincipalPayment =
        this.fromApiJsonHelper.extractIntegerWithLocaleNamed("graceOnPrincipalPayment", element);
    final Integer graceOnInterestPayment =
        this.fromApiJsonHelper.extractIntegerWithLocaleNamed("graceOnInterestPayment", element);
    final Integer graceOnInterestCharged =
        this.fromApiJsonHelper.extractIntegerWithLocaleNamed("graceOnInterestCharged", element);
    final LocalDate interestChargedFromDate =
        fromApiJsonHelper.extractLocalDateNamed("interestChargedFromDate", element);

    // other
    final BigDecimal inArrearsTolerance =
        this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("inArrearsTolerance", element);
    final Money inArrearsToleranceMoney = Money.of(currency, inArrearsTolerance);

    return LoanApplicationTerms.assembleFrom(
        applicationCurrency,
        loanTermFrequency,
        loanTermPeriodFrequencyType,
        numberOfRepayments,
        repaymentEvery,
        repaymentPeriodFrequencyType,
        amortizationMethod,
        interestMethod,
        interestRatePerPeriod,
        interestRatePeriodFrequencyType,
        annualNominalInterestRate,
        interestCalculationPeriodMethod,
        principalMoney,
        expectedDisbursementDate,
        repaymentsStartingFromDate,
        calculatedRepaymentsStartingFromDate,
        graceOnPrincipalPayment,
        graceOnInterestPayment,
        graceOnInterestCharged,
        interestChargedFromDate,
        inArrearsToleranceMoney);
  }
  public void validateForCreate(String json) {

    if (StringUtils.isBlank(json)) {
      throw new InvalidJsonException();
    }

    final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
    fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
    final DataValidatorBuilder baseDataValidator =
        new DataValidatorBuilder(dataValidationErrors).resource("payment");

    final JsonElement element = fromApiJsonHelper.parse(json);

    // final LocalDate paymentDate = fromApiJsonHelper.extractLocalDateNamed("paymentDate",
    // element);
    final String paymentCode = fromApiJsonHelper.extractStringNamed("paymentCode", element);
    final BigDecimal amountPaid =
        fromApiJsonHelper.extractBigDecimalWithLocaleNamed("amountPaid", element);
    // final String remarks = fromApiJsonHelper.extractStringNamed("remarks", element);

    /*String receiptNo = fromApiJsonHelper.extractStringNamed("receiptNo", element);
    baseDataValidator.reset().parameter("receiptNo").value(receiptNo).notBlank().notExceedingLengthOf(20);*/
    //	baseDataValidator.reset().parameter("paymentDate").value(paymentDate)
    // .notBlank().notExceedingLengthOf(100);
    baseDataValidator
        .reset()
        .parameter("paymentCode")
        .value(paymentCode)
        .notBlank()
        .notExceedingLengthOf(100);
    baseDataValidator
        .reset()
        .parameter("amountPaid")
        .value(amountPaid)
        .notBlank()
        .notExceedingLengthOf(100);
    // baseDataValidator.reset().parameter("remarks").value(remarks)
    // .notBlank().notExceedingLengthOf(100);
    if (fromApiJsonHelper.parameterExists("isChequeSelected", element)) {
      String isChequeSelected = fromApiJsonHelper.extractStringNamed("isChequeSelected", element);
      if (isChequeSelected.equalsIgnoreCase("yes")) {
        if (fromApiJsonHelper.parameterExists("chequeNo", element)) {
          String chequeNo = fromApiJsonHelper.extractStringNamed("chequeNo", element);
          baseDataValidator
              .reset()
              .parameter("chequeNo")
              .value(chequeNo)
              .notBlank()
              .notExceedingLengthOf(20);
        }
        if (fromApiJsonHelper.parameterExists("chequeDate", element)) {
          LocalDate chequeDate = fromApiJsonHelper.extractLocalDateNamed("chequeDate", element);
          baseDataValidator.reset().parameter("chequeDate").value(chequeDate).notBlank();
        }
        if (fromApiJsonHelper.parameterExists("bankName", element)) {
          String bankName = fromApiJsonHelper.extractStringNamed("bankName", element);
          baseDataValidator
              .reset()
              .parameter("bankName")
              .value(bankName)
              .notBlank()
              .notExceedingLengthOf(100);
        }
        if (fromApiJsonHelper.parameterExists("branchName", element)) {
          String branchName = fromApiJsonHelper.extractStringNamed("branchName", element);
          baseDataValidator
              .reset()
              .parameter("branchName")
              .value(branchName)
              .notBlank()
              .notExceedingLengthOf(100);
        }
      }
    }

    throwExceptionIfValidationWarningsExist(dataValidationErrors);
  }
  public void validateForCreatePartnerGame(final String json) {
    if (StringUtils.isBlank(json)) {
      throw new InvalidJsonException();
    }

    final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
    fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
    final DataValidatorBuilder baseDataValidator =
        new DataValidatorBuilder(dataValidationErrors).resource("media.settlement");

    final JsonElement element = fromApiJsonHelper.parse(json);

    final Long partnerName = fromApiJsonHelper.extractLongNamed("partnerName", element);
    baseDataValidator.reset().parameter("partnerName").value(partnerName).notBlank();

    final Long gamePlaySource = fromApiJsonHelper.extractLongNamed("gamePlaySource", element);
    baseDataValidator.reset().parameter("gamePlaySource").value(gamePlaySource).notBlank();

    final Long royaltyValue = fromApiJsonHelper.extractLongNamed("royaltyValue", element);
    baseDataValidator.reset().parameter("royaltyValue").value(royaltyValue).notBlank();

    final Long royaltySequence = fromApiJsonHelper.extractLongNamed("royaltySequence", element);
    baseDataValidator.reset().parameter("royaltySequence").value(royaltySequence).notBlank();

    throwExceptionIfValidationWarningsExist(dataValidationErrors);

    final JsonArray gameMediaPartnerDataArray =
        fromApiJsonHelper.extractJsonArrayNamed("gameMediaPartnerData", element);
    String[] gameMediaPartnerDataAttributes = null;
    gameMediaPartnerDataAttributes = new String[gameMediaPartnerDataArray.size()];
    int gameMediaPartnerDataSize = gameMediaPartnerDataArray.size();
    baseDataValidator
        .reset()
        .parameter(null)
        .value(gameMediaPartnerDataSize)
        .integerGreaterThanZero();

    for (int i = 0; i < gameMediaPartnerDataArray.size(); i++) {
      gameMediaPartnerDataAttributes[i] = gameMediaPartnerDataArray.get(i).toString();
    }

    for (String singleGameMediaPartnerData : gameMediaPartnerDataAttributes) {

      final JsonElement elements = fromApiJsonHelper.parse(singleGameMediaPartnerData);

      final LocalDate gDate = fromApiJsonHelper.extractLocalDateNamed("gDate", elements);
      baseDataValidator.reset().parameter("gDate").value(gDate).notBlank();

      if (fromApiJsonHelper.parameterExists("game", elements)) {
        final String game = fromApiJsonHelper.extractStringNamed("game", elements);
        baseDataValidator.reset().parameter("game").value(game).notBlank();
      } else if (fromApiJsonHelper.parameterExists("gameL", elements)) {
        final String gameL = fromApiJsonHelper.extractStringNamed("gameL", elements);
        baseDataValidator.reset().parameter("gameL").value(gameL).notBlank();
      }

      final BigDecimal overwriteRoyaltyValue =
          fromApiJsonHelper.extractBigDecimalWithLocaleNamed("overwriteRoyaltyValue", elements);
      baseDataValidator
          .reset()
          .parameter("overwriteRoyaltyValue")
          .value(overwriteRoyaltyValue)
          .notBlank();

      final Long playSource = fromApiJsonHelper.extractLongNamed("playSource", elements);
      baseDataValidator.reset().parameter("playSource").value(playSource).notBlank();

      final BigDecimal price =
          fromApiJsonHelper.extractBigDecimalWithLocaleNamed("price", elements);
      baseDataValidator.reset().parameter("price").value(price).notBlank();

      final Long sequence = fromApiJsonHelper.extractLongNamed("sequence", elements);
      baseDataValidator.reset().parameter("sequence").value(sequence).notBlank();

      throwExceptionIfValidationWarningsExist(dataValidationErrors);
    }
  }