public void validateForCreateRevenue(String json) {

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

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

    final JsonElement element = fromApiJsonHelper.parse(json);

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

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

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

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

    final JsonArray percentageParamsDataArray =
        fromApiJsonHelper.extractJsonArrayNamed("percentageParams", element);

    if (percentageParamsDataArray != null && percentageParamsDataArray.size() > 0) {
      String[] percentageParamsDataArrayAttributes = null;
      percentageParamsDataArrayAttributes = new String[percentageParamsDataArray.size()];
      int interactiveDataSize = percentageParamsDataArray.size();
      baseDataValidator.reset().parameter(null).value(interactiveDataSize).integerGreaterThanZero();

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

      for (String singleinteractiveData : percentageParamsDataArrayAttributes) {

        final JsonElement elements = fromApiJsonHelper.parse(singleinteractiveData);

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

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

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

        throwExceptionIfValidationWarningsExist(dataValidationErrors);
      }
    } else {
      final BigDecimal flat = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("flat", element);
      baseDataValidator.reset().parameter("flat").value(flat).notBlank();

      throwExceptionIfValidationWarningsExist(dataValidationErrors);
    }
  }
  public void validateForCreateInteractive(String json) {

    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("interactivedetail");

    final JsonElement element = fromApiJsonHelper.parse(json);

    final JsonArray interactiveDataArray =
        fromApiJsonHelper.extractJsonArrayNamed("activeData", element);
    String[] interactiveDataArrayAttributes = null;
    interactiveDataArrayAttributes = new String[interactiveDataArray.size()];
    int interactiveDataSize = interactiveDataArray.size();
    baseDataValidator.reset().parameter(null).value(interactiveDataSize).integerGreaterThanZero();

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

    for (String singleinteractiveData : interactiveDataArrayAttributes) {

      final JsonElement elements = fromApiJsonHelper.parse(singleinteractiveData);

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

      final String contentName = fromApiJsonHelper.extractStringNamed("contentName", elements);
      baseDataValidator.reset().parameter("contentName").value(contentName).notBlank();

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

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

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

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

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

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

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

      throwExceptionIfValidationWarningsExist(dataValidationErrors);
    }
  }
  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);
  }
コード例 #4
0
  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("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);
  }
  public void validateForCreateDeduction(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> dataValidatorErrors = new ArrayList<ApiParameterError>();
    final DataValidatorBuilder baseDataValidator =
        new DataValidatorBuilder(dataValidatorErrors).resource("operator.deduction");

    final JsonElement element = fromApiJsonHelper.parse(json);

    final JsonArray deductionData =
        fromApiJsonHelper.extractJsonArrayNamed("deductionData", element);

    String[] chStringArray = new String[deductionData.size()];
    int chStringArraySize = deductionData.size();
    /*baseDataValidator.reset().parameter(null).value(chStringArraySize).integerGreaterThanZero();*/

    for (int i = 0; i < chStringArraySize; i++) {
      chStringArray[i] = deductionData.get(i).toString();
    }

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

    for (String s : chStringArray) {

      final JsonElement el = fromApiJsonHelper.parse(s);

      final String deductionCode = fromApiJsonHelper.extractStringNamed("deductionCode", el);
      baseDataValidator.reset().parameter("deductionCode").value(deductionCode).notBlank();

      final BigDecimal deductionValue =
          fromApiJsonHelper.extractBigDecimalWithLocaleNamed("deductionValue", el);
      baseDataValidator
          .reset()
          .parameter("deductionValue")
          .value(deductionValue)
          .notBlank()
          .inMinAndMaxAmountRange(BigDecimal.ZERO, BigDecimal.valueOf(100));

      throwExceptionIfValidationWarningsExist(dataValidatorErrors);
    }
  }
  public void validateForUpdateDeductionCode(String json) {
    final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
    fromApiJsonHelper.checkForUnsupportedParameters(
        typeOfMap, json, supportedParametersForUpdateDeductionCode);

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

    final JsonElement element = fromApiJsonHelper.parse(json);

    final String deductionCode = fromApiJsonHelper.extractStringNamed("deductionCode", element);
    baseDataValidator.reset().parameter("deductionCode").value(deductionCode).notBlank();

    final BigDecimal deductionValue =
        fromApiJsonHelper.extractBigDecimalWithLocaleNamed("deductionValue", element);
    baseDataValidator.reset().parameter("deductionValue").value(deductionValue).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("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);
  }
コード例 #9
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);
  }
コード例 #10
0
  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, SAVINGS_PRODUCT_REQUEST_DATA_PARAMETERS);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
    final DataValidatorBuilder baseDataValidator =
        new DataValidatorBuilder(dataValidationErrors).resource(SAVINGS_PRODUCT_RESOURCE_NAME);
    final JsonElement element = fromApiJsonHelper.parse(json);

    final String name = fromApiJsonHelper.extractStringNamed(nameParamName, element);
    baseDataValidator
        .reset()
        .parameter(nameParamName)
        .value(name)
        .notBlank()
        .notExceedingLengthOf(100);

    final String description = fromApiJsonHelper.extractStringNamed(descriptionParamName, element);
    baseDataValidator
        .reset()
        .parameter(descriptionParamName)
        .value(description)
        .notBlank()
        .notExceedingLengthOf(500);

    final String currencyCode =
        fromApiJsonHelper.extractStringNamed(currencyCodeParamName, element);
    baseDataValidator.reset().parameter(currencyCodeParamName).value(currencyCode).notBlank();

    final Integer digitsAfterDecimal =
        fromApiJsonHelper.extractIntegerSansLocaleNamed(digitsAfterDecimalParamName, element);
    baseDataValidator
        .reset()
        .parameter(digitsAfterDecimalParamName)
        .value(digitsAfterDecimal)
        .notNull()
        .inMinMaxRange(0, 6);

    final Integer inMultiplesOf =
        fromApiJsonHelper.extractIntegerSansLocaleNamed(inMultiplesOfParamName, element);
    baseDataValidator
        .reset()
        .parameter(inMultiplesOfParamName)
        .value(inMultiplesOf)
        .ignoreIfNull()
        .integerZeroOrGreater();

    final BigDecimal nominalAnnualInterestRate =
        fromApiJsonHelper.extractBigDecimalWithLocaleNamed(
            nominalAnnualInterestRateParamName, element);
    baseDataValidator
        .reset()
        .parameter(nominalAnnualInterestRateParamName)
        .value(nominalAnnualInterestRate)
        .notNull()
        .zeroOrPositiveAmount();

    final Integer interestCompoundingPeriodType =
        fromApiJsonHelper.extractIntegerSansLocaleNamed(
            interestCompoundingPeriodTypeParamName, element);
    baseDataValidator
        .reset()
        .parameter(interestCompoundingPeriodTypeParamName)
        .value(interestCompoundingPeriodType)
        .notNull()
        .isOneOfTheseValues(SavingsCompoundingInterestPeriodType.integerValues());

    final Integer interestPostingPeriodType =
        fromApiJsonHelper.extractIntegerSansLocaleNamed(
            interestPostingPeriodTypeParamName, element);
    baseDataValidator
        .reset()
        .parameter(interestPostingPeriodTypeParamName)
        .value(interestPostingPeriodType)
        .notNull()
        .isOneOfTheseValues(SavingsPostingInterestPeriodType.integerValues());

    final Integer interestCalculationType =
        fromApiJsonHelper.extractIntegerSansLocaleNamed(interestCalculationTypeParamName, element);
    baseDataValidator
        .reset()
        .parameter(interestCalculationTypeParamName)
        .value(interestCalculationType)
        .notNull()
        .isOneOfTheseValues(SavingsInterestCalculationType.integerValues());

    final Integer interestCalculationDaysInYearType =
        fromApiJsonHelper.extractIntegerSansLocaleNamed(
            interestCalculationDaysInYearTypeParamName, element);
    baseDataValidator
        .reset()
        .parameter(interestCalculationDaysInYearTypeParamName)
        .value(interestCalculationDaysInYearType)
        .notNull()
        .isOneOfTheseValues(SavingsInterestCalculationDaysInYearType.integerValues());

    if (this.fromApiJsonHelper.parameterExists(minRequiredOpeningBalanceParamName, element)) {
      final BigDecimal minOpeningBalance =
          fromApiJsonHelper.extractBigDecimalWithLocaleNamed(
              minRequiredOpeningBalanceParamName, element);
      baseDataValidator
          .reset()
          .parameter(minRequiredOpeningBalanceParamName)
          .value(minOpeningBalance)
          .zeroOrPositiveAmount();
    }

    if (this.fromApiJsonHelper.parameterExists(lockinPeriodFrequencyParamName, element)) {

      final Integer lockinPeriodFrequency =
          fromApiJsonHelper.extractIntegerWithLocaleNamed(lockinPeriodFrequencyParamName, element);
      baseDataValidator
          .reset()
          .parameter(lockinPeriodFrequencyParamName)
          .value(lockinPeriodFrequency)
          .integerZeroOrGreater();

      if (lockinPeriodFrequency != null) {
        final Integer lockinPeriodFrequencyType =
            fromApiJsonHelper.extractIntegerSansLocaleNamed(
                lockinPeriodFrequencyTypeParamName, element);
        baseDataValidator
            .reset()
            .parameter(lockinPeriodFrequencyTypeParamName)
            .value(lockinPeriodFrequencyType)
            .notNull()
            .inMinMaxRange(0, 3);
      }
    }

    if (this.fromApiJsonHelper.parameterExists(lockinPeriodFrequencyTypeParamName, element)) {
      final Integer lockinPeriodFrequencyType =
          fromApiJsonHelper.extractIntegerSansLocaleNamed(
              lockinPeriodFrequencyTypeParamName, element);
      baseDataValidator
          .reset()
          .parameter(lockinPeriodFrequencyTypeParamName)
          .value(lockinPeriodFrequencyType)
          .inMinMaxRange(0, 3);

      if (lockinPeriodFrequencyType != null) {
        final Integer lockinPeriodFrequency =
            fromApiJsonHelper.extractIntegerWithLocaleNamed(
                lockinPeriodFrequencyParamName, element);
        baseDataValidator
            .reset()
            .parameter(lockinPeriodFrequencyParamName)
            .value(lockinPeriodFrequency)
            .notNull()
            .integerZeroOrGreater();
      }
    }

    if (this.fromApiJsonHelper.parameterExists(withdrawalFeeAmountParamName, element)) {

      final BigDecimal withdrawalFeeAmount =
          fromApiJsonHelper.extractBigDecimalWithLocaleNamed(withdrawalFeeAmountParamName, element);
      baseDataValidator
          .reset()
          .parameter(withdrawalFeeAmountParamName)
          .value(withdrawalFeeAmount)
          .zeroOrPositiveAmount();

      if (withdrawalFeeAmount != null) {
        final Integer withdrawalFeeType =
            fromApiJsonHelper.extractIntegerSansLocaleNamed(withdrawalFeeTypeParamName, element);
        baseDataValidator
            .reset()
            .parameter(withdrawalFeeTypeParamName)
            .value(withdrawalFeeType)
            .isOneOfTheseValues(SavingsWithdrawalFeesType.integerValues());
      }
    }

    if (this.fromApiJsonHelper.parameterExists(withdrawalFeeTypeParamName, element)) {
      final Integer withdrawalFeeType =
          fromApiJsonHelper.extractIntegerSansLocaleNamed(withdrawalFeeTypeParamName, element);
      baseDataValidator
          .reset()
          .parameter(withdrawalFeeTypeParamName)
          .value(withdrawalFeeType)
          .ignoreIfNull()
          .isOneOfTheseValues(1, 2);

      if (withdrawalFeeType != null) {
        final BigDecimal withdrawalFeeAmount =
            fromApiJsonHelper.extractBigDecimalWithLocaleNamed(
                withdrawalFeeAmountParamName, element);
        baseDataValidator
            .reset()
            .parameter(withdrawalFeeAmountParamName)
            .value(withdrawalFeeAmount)
            .notNull()
            .zeroOrPositiveAmount();
      }
    }

    if (this.fromApiJsonHelper.parameterExists(annualFeeAmountParamName, element)) {
      final BigDecimal annualFeeAmount =
          fromApiJsonHelper.extractBigDecimalWithLocaleNamed(annualFeeAmountParamName, element);
      baseDataValidator
          .reset()
          .parameter(annualFeeAmountParamName)
          .value(annualFeeAmount)
          .zeroOrPositiveAmount();

      if (annualFeeAmount != null) {
        MonthDay monthDayOfAnnualFee =
            fromApiJsonHelper.extractMonthDayNamed(annualFeeOnMonthDayParamName, element);
        baseDataValidator
            .reset()
            .parameter(annualFeeOnMonthDayParamName)
            .value(monthDayOfAnnualFee)
            .notNull();
      }
    }

    if (this.fromApiJsonHelper.parameterExists(annualFeeOnMonthDayParamName, element)) {

      MonthDay monthDayOfAnnualFee =
          fromApiJsonHelper.extractMonthDayNamed(annualFeeOnMonthDayParamName, element);
      if (monthDayOfAnnualFee != null) {
        final BigDecimal annualFeeAmount =
            fromApiJsonHelper.extractBigDecimalWithLocaleNamed(annualFeeAmountParamName, element);
        baseDataValidator
            .reset()
            .parameter(annualFeeAmountParamName)
            .value(annualFeeAmount)
            .notNull()
            .zeroOrPositiveAmount();
      }
    }

    // accounting related data validation
    final Integer accountingRuleType =
        fromApiJsonHelper.extractIntegerNamed("accountingRule", element, Locale.getDefault());
    baseDataValidator
        .reset()
        .parameter("accountingRule")
        .value(accountingRuleType)
        .notNull()
        .inMinMaxRange(1, 3);

    if (isCashBasedAccounting(accountingRuleType)) {

      final Long savingsControlAccountId =
          fromApiJsonHelper.extractLongNamed(
              SAVINGS_PRODUCT_ACCOUNTING_PARAMS.SAVINGS_CONTROL.getValue(), element);
      baseDataValidator
          .reset()
          .parameter(SAVINGS_PRODUCT_ACCOUNTING_PARAMS.SAVINGS_CONTROL.getValue())
          .value(savingsControlAccountId)
          .notNull()
          .integerGreaterThanZero();

      final Long savingsReferenceAccountId =
          fromApiJsonHelper.extractLongNamed(
              SAVINGS_PRODUCT_ACCOUNTING_PARAMS.SAVINGS_REFERENCE.getValue(), element);
      baseDataValidator
          .reset()
          .parameter(SAVINGS_PRODUCT_ACCOUNTING_PARAMS.SAVINGS_REFERENCE.getValue())
          .value(savingsReferenceAccountId)
          .notNull()
          .integerGreaterThanZero();

      final Long interestOnSavingsAccountId =
          fromApiJsonHelper.extractLongNamed(
              SAVINGS_PRODUCT_ACCOUNTING_PARAMS.INTEREST_ON_SAVINGS.getValue(), element);
      baseDataValidator
          .reset()
          .parameter(SAVINGS_PRODUCT_ACCOUNTING_PARAMS.INTEREST_ON_SAVINGS.getValue())
          .value(interestOnSavingsAccountId)
          .notNull()
          .integerGreaterThanZero();

      final Long incomeFromFeeId =
          fromApiJsonHelper.extractLongNamed(
              SAVINGS_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_FEES.getValue(), element);
      baseDataValidator
          .reset()
          .parameter(SAVINGS_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_FEES.getValue())
          .value(incomeFromFeeId)
          .notNull()
          .integerGreaterThanZero();

      validatePaymentChannelFundSourceMappings(baseDataValidator, element);
    }

    throwExceptionIfValidationWarningsExist(dataValidationErrors);
  }
  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);
  }
  @Override
  public CommandProcessingResult updateGameMediaAsset(JsonCommand command) {

    MediaAsset mediaAssetMaster = null;
    try {
      this.context.authenticatedUser();
      final Long mediaId = command.entityId();
      mediaAssetMaster = this.assetRepository.findOne(mediaId);

      if (mediaAssetMaster == null) {
        throw new NoMoviesFoundException(
            "error.media.assets.game.not.found", "No Game Asset Found");
      }

      final Map<String, Object> changes = mediaAssetMaster.updateForGame(command);
      if (!changes.isEmpty()) {
        assetRepository.save(mediaAssetMaster);
      }

      final JsonArray gameData = command.arrayOfParameterNamed("gameMediaData").getAsJsonArray();
      for (int i = 0; i < gameData.size(); i++) {
        String currentData = gameData.get(i).toString();
        final JsonElement element = fromApiJsonHelper.parse(currentData);

        final Long settlementId = fromApiJsonHelper.extractLongNamed("settlementId", element);
        if (settlementId == null) {

          final BigDecimal amount =
              fromApiJsonHelper.extractBigDecimalWithLocaleNamed("amount", element);
          final String category = fromApiJsonHelper.extractStringNamed("category", element);
          final String mediaContentProvider =
              fromApiJsonHelper.extractStringNamed("mediaContentProvider", element);
          final String mt = fromApiJsonHelper.extractStringNamed("mediaType", element);
          final Character mediaType = mt.equals("Flat") ? 'F' : 'P';
          final Long sequence = fromApiJsonHelper.extractLongNamed("sequence", element);
          final String source = fromApiJsonHelper.extractStringNamed("source", element);

          final Settlement settlement =
              Settlement.fromJson(
                  mediaId, amount, category, mediaContentProvider, mediaType, sequence, source);
          settlementJpaRepository.save(settlement);
        } else {
          final Settlement settlement = settlementJpaRepository.findOne(settlementId);
          if (settlement == null) {
            throw new SettlementNotFoundException();
          }

          final Map<String, Object> settlementChanges =
              settlement.update(element, fromApiJsonHelper, mediaId);

          if (!settlementChanges.isEmpty()) {
            settlementJpaRepository.save(settlement);
          }
        }
      }

    } catch (DataIntegrityViolationException dve) {
      handleCodeDataIntegrityIssues(command, dve);
      return new CommandProcessingResult(Long.valueOf(-1));
    }
    return new CommandProcessingResult(mediaAssetMaster.getId());
  }
  public void validateForCreateGameEvent(String json) {

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

    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("media.settlement");

    final JsonElement element = fromApiJsonHelper.parse(json);

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

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

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

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

    final String activityMonth = fromApiJsonHelper.extractStringNamed("activityMonth", element);
    baseDataValidator.reset().parameter("activityMonth").value(activityMonth).notBlank();

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

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

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

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

    final JsonArray interactiveDataArray =
        fromApiJsonHelper.extractJsonArrayNamed("activeData", element);
    String[] interactiveDataArrayAttributes = null;
    interactiveDataArrayAttributes = new String[interactiveDataArray.size()];
    int interactiveDataSize = interactiveDataArray.size();
    baseDataValidator
        .reset()
        .parameter("interactiveDataArray")
        .value(interactiveDataSize)
        .integerGreaterThanZero();

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

    for (String singleinteractiveData : interactiveDataArrayAttributes) {

      final JsonElement elements = fromApiJsonHelper.parse(singleinteractiveData);

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

      final String contentName = fromApiJsonHelper.extractStringNamed("contentName", elements);
      baseDataValidator.reset().parameter("contentName").value(contentName).notBlank();

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

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

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

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

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

      final Integer downloads =
          fromApiJsonHelper.extractIntegerWithLocaleNamed("downloads", elements);
      baseDataValidator
          .reset()
          .parameter("downloads")
          .value(downloads)
          .notBlank()
          .integerGreaterThanZero();

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

      throwExceptionIfValidationWarningsExist(dataValidationErrors);
    }

    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);
    }
  }
  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("media.settlement");

    final JsonElement element = fromApiJsonHelper.parse(json);

    /*final String partnerType = fromApiJsonHelper.extractStringNamed("partnerType", element);
    baseDataValidator.reset().parameter("partnerType").value(partnerType).notBlank().notExceedingLengthOf(50);

    final String mediaCategory = fromApiJsonHelper.extractStringNamed("mediaCategory", element);
    baseDataValidator.reset().parameter("mediaCategory").value(mediaCategory).notBlank().notExceedingLengthOf(50);*/

    final String partnerName = fromApiJsonHelper.extractStringNamed("partnerName", element);
    baseDataValidator
        .reset()
        .parameter("partnerName")
        .value(partnerName)
        .notBlank()
        .notExceedingLengthOf(100);

    final String partnerAddress = fromApiJsonHelper.extractStringNamed("partnerAddress", element);
    baseDataValidator
        .reset()
        .parameter("partnerAddress")
        .value(partnerAddress)
        .notBlank()
        .notExceedingLengthOf(255);

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

    final String contactNum = fromApiJsonHelper.extractStringNamed("contactNum", element);
    baseDataValidator
        .reset()
        .parameter("contactNum")
        .value(contactNum)
        .notBlank()
        .notExceedingLengthOf(11);

    final String emailId = fromApiJsonHelper.extractStringNamed("emailId", element);
    baseDataValidator
        .reset()
        .parameter("emailId")
        .value(emailId)
        .notBlank()
        .notExceedingLengthOf(100);

    if (fromApiJsonHelper.parameterExists("currencyCode", element)) {
      final BigDecimal currencyCode =
          fromApiJsonHelper.extractBigDecimalWithLocaleNamed("currencyCode", element);
      baseDataValidator
          .reset()
          .parameter("currencyCode")
          .value(currencyCode)
          .notBlank()
          .notExceedingLengthOf(255);
    }

    /*final String country = fromApiJsonHelper.extractStringNamed("country", element);
    baseDataValidator.reset().parameter("country").value(country).notBlank().notExceedingLengthOf(50);*/

    if (fromApiJsonHelper.parameterExists("currencyId", element)) {
      final Long currencyId = fromApiJsonHelper.extractLongNamed("currencyId", element);
      baseDataValidator.reset().parameter("currencyId").value(currencyId).notBlank();
    }

    if (fromApiJsonHelper.parameterExists("chData", element)) {

      final JsonArray chDataArray = fromApiJsonHelper.extractJsonArrayNamed("chData", element);

      String[] chStringArray = new String[chDataArray.size()];
      /*int chStringArraySize = chDataArray.size();*/
      /*baseDataValidator.reset().parameter(null).value(chStringArraySize).integerGreaterThanZero();*/

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

      for (String s : chStringArray) {

        final JsonElement el = fromApiJsonHelper.parse(s);
        final String channelPartnerName =
            fromApiJsonHelper.extractStringNamed("channelPartnerName", el);
        baseDataValidator
            .reset()
            .parameter("channelPartnerName")
            .value(channelPartnerName)
            .notBlank();

        /*final String channelPartnerAddress = fromApiJsonHelper.extractStringNamed("channelPartnerAddress", el);
        baseDataValidator.reset().parameter("channelPartnerAddress").value(channelPartnerAddress).notBlank();
        throwExceptionIfValidationWarningsExist(dataValidationErrors);*/
      }
    }

    throwExceptionIfValidationWarningsExist(dataValidationErrors);
  }