Example usage for com.google.gson JsonArray size

List of usage examples for com.google.gson JsonArray size

Introduction

In this page you can find the example usage for com.google.gson JsonArray size.

Prototype

public int size() 

Source Link

Document

Returns the number of elements in the array.

Usage

From source file:com.gst.infrastructure.dataqueries.service.EntityDatatableChecksWritePlatformServiceImpl.java

License:Apache License

@Transactional
@Override/*from w  ww .  ja va  2 s  .co  m*/
public boolean saveDatatables(final Long status, final String entity, final Long entityId, final Long productId,
        final JsonArray datatableDatas) {
    final AppUser user = this.context.authenticatedUser();
    boolean isMakerCheckerEnabled = false;
    if (datatableDatas != null && datatableDatas.size() > 0) {
        for (JsonElement element : datatableDatas) {
            final String datatableName = this.fromApiJsonHelper.extractStringNamed("registeredTableName",
                    element);
            final JsonObject datatableData = this.fromApiJsonHelper.extractJsonObjectNamed("data", element);

            if (datatableName == null || datatableData == null) {
                final ApiParameterError error = ApiParameterError.generalError(
                        "registeredTableName.and.data.parameters.must.be.present.in.each.list.items.in.datatables",
                        "registeredTableName and data parameters must be present in each list items in datatables");
                List<ApiParameterError> errors = new ArrayList<>();
                errors.add(error);
                throw new PlatformApiDataValidationException(errors);
            }
            final String taskPermissionName = "CREATE_" + datatableName;
            user.validateHasPermissionTo(taskPermissionName);
            if (this.configurationDomainService.isMakerCheckerEnabledForTask(taskPermissionName)) {
                isMakerCheckerEnabled = true;
            }
            try {
                this.readWriteNonCoreDataService.createNewDatatableEntry(datatableName, entityId,
                        datatableData.toString());
            } catch (PlatformApiDataValidationException e) {
                List<ApiParameterError> errors = e.getErrors();
                for (ApiParameterError error : e.getErrors()) {
                    error.setParameterName("datatables." + datatableName + "." + error.getParameterName());
                }
                throw e;
            }
        }
    }
    return isMakerCheckerEnabled;
}

From source file:com.gst.infrastructure.dataqueries.service.ReportWritePlatformServiceImpl.java

License:Apache License

private Set<ReportParameterUsage> assembleSetOfReportParameterUsages(final Report report,
        final JsonCommand command) {

    Set<ReportParameterUsage> reportParameterUsages = null;

    if (command.parameterExists("reportParameters")) {
        final JsonArray reportParametersArray = command.arrayOfParameterNamed("reportParameters");
        if (reportParametersArray != null) {

            reportParameterUsages = new HashSet<>();

            for (int i = 0; i < reportParametersArray.size(); i++) {

                final JsonObject jsonObject = reportParametersArray.get(i).getAsJsonObject();

                Long id = null;//w ww  .j  a  va 2 s  .c  o  m
                ReportParameterUsage reportParameterUsageItem = null;
                ReportParameter reportParameter = null;
                String reportParameterName = null;

                if (jsonObject.has("id")) {
                    final String idStr = jsonObject.get("id").getAsString();
                    if (StringUtils.isNotBlank(idStr)) {
                        id = Long.parseLong(idStr);
                    }
                }

                if (id != null) {
                    // existing report parameter usage
                    reportParameterUsageItem = this.reportParameterUsageRepository.findOne(id);
                    if (reportParameterUsageItem == null) {
                        throw new ReportParameterNotFoundException(id);
                    }

                    // check parameter
                    if (jsonObject.has("parameterId")) {
                        final Long parameterId = jsonObject.get("parameterId").getAsLong();
                        reportParameter = this.reportParameterRepository.findOne(parameterId);
                        if (reportParameter == null
                                || !reportParameterUsageItem.hasParameterIdOf(parameterId)) {
                            //
                            throw new ReportParameterNotFoundException(parameterId);
                        }
                    }

                    if (jsonObject.has("reportParameterName")) {
                        reportParameterName = jsonObject.get("reportParameterName").getAsString();
                        reportParameterUsageItem.updateParameterName(reportParameterName);
                    }
                } else {
                    // new report parameter usage
                    if (jsonObject.has("parameterId")) {
                        final Long parameterId = jsonObject.get("parameterId").getAsLong();
                        reportParameter = this.reportParameterRepository.findOne(parameterId);
                        if (reportParameter == null) {
                            throw new ReportParameterNotFoundException(parameterId);
                        }
                    } else {
                        throw new PlatformDataIntegrityException(
                                "error.msg.parameter.id.mandatory.in.report.parameter",
                                "parameterId column is mandatory in Report Parameter Entry");
                    }

                    if (jsonObject.has("reportParameterName")) {
                        reportParameterName = jsonObject.get("reportParameterName").getAsString();
                    }

                    reportParameterUsageItem = new ReportParameterUsage(report, reportParameter,
                            reportParameterName);
                }

                reportParameterUsages.add(reportParameterUsageItem);
            }
        }
    }

    return reportParameterUsages;
}

From source file:com.gst.infrastructure.hooks.service.HookWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

private Set<HookResource> assembleSetOfEvents(final JsonArray eventsArray) {

    final Set<HookResource> allEvents = new HashSet<>();

    for (int i = 0; i < eventsArray.size(); i++) {

        final JsonObject eventElement = eventsArray.get(i).getAsJsonObject();

        final String entityName = this.fromApiJsonHelper.extractStringNamed(entityNameParamName, eventElement);
        final String actionName = this.fromApiJsonHelper.extractStringNamed(actionNameParamName, eventElement);
        final HookResource event = HookResource.createNewWithoutHook(entityName, actionName);
        allEvents.add(event);//  w w  w.  j  a  va  2s.  c o m
    }

    return allEvents;
}

From source file:com.gst.organisation.holiday.data.HolidayDataValidator.java

License:Apache License

public void validateForCreate(final String json) {

    if (StringUtils.isBlank(json)) {
        throw new InvalidJsonException();
    }/*from  www .  ja  v  a  2  s . com*/

    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json,
            HolidayApiConstants.HOLIDAY_CREATE_OR_UPDATE_REQUEST_DATA_PARAMETERS);
    final JsonElement element = this.fromApiJsonHelper.parse(json);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();

    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(HolidayApiConstants.HOLIDAY_RESOURCE_NAME);

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

    final LocalDate fromDate = this.fromApiJsonHelper
            .extractLocalDateNamed(HolidayApiConstants.fromDateParamName, element);
    baseDataValidator.reset().parameter(HolidayApiConstants.fromDateParamName).value(fromDate).notNull();

    final LocalDate toDate = this.fromApiJsonHelper.extractLocalDateNamed(HolidayApiConstants.toDateParamName,
            element);
    baseDataValidator.reset().parameter(HolidayApiConstants.toDateParamName).value(toDate).notNull();

    final LocalDate repaymentsRescheduledTo = this.fromApiJsonHelper
            .extractLocalDateNamed(HolidayApiConstants.repaymentsRescheduledToParamName, element);
    baseDataValidator.reset().parameter(HolidayApiConstants.repaymentsRescheduledToParamName)
            .value(repaymentsRescheduledTo).notNull();

    Set<Long> offices = null;
    final JsonObject topLevelJsonElement = element.getAsJsonObject();

    if (topLevelJsonElement.has(HolidayApiConstants.officesParamName)
            && topLevelJsonElement.get(HolidayApiConstants.officesParamName).isJsonArray()) {

        final JsonArray array = topLevelJsonElement.get(HolidayApiConstants.officesParamName).getAsJsonArray();
        if (array.size() > 0) {
            offices = new HashSet<>(array.size());
            for (int i = 0; i < array.size(); i++) {
                final JsonObject officeElement = array.get(i).getAsJsonObject();
                final Long officeId = this.fromApiJsonHelper
                        .extractLongNamed(HolidayApiConstants.officeIdParamName, officeElement);
                baseDataValidator.reset().parameter(HolidayApiConstants.officesParamName).value(officeId)
                        .notNull();
                offices.add(officeId);
            }
        }
    }
    baseDataValidator.reset().parameter(HolidayApiConstants.officesParamName).value(offices).notNull();
    throwExceptionIfValidationWarningsExist(dataValidationErrors);
}

From source file:com.gst.organisation.holiday.data.HolidayDataValidator.java

License:Apache License

public void validateForUpdate(final String json) {

    if (StringUtils.isBlank(json)) {
        throw new InvalidJsonException();
    }/*from   ww w  .  ja v  a2 s  . co  m*/

    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json,
            HolidayApiConstants.HOLIDAY_CREATE_OR_UPDATE_REQUEST_DATA_PARAMETERS);
    final JsonElement element = this.fromApiJsonHelper.parse(json);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();

    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(HolidayApiConstants.HOLIDAY_RESOURCE_NAME);

    if (this.fromApiJsonHelper.parameterExists(HolidayApiConstants.nameParamName, element)) {
        final String name = this.fromApiJsonHelper.extractStringNamed(HolidayApiConstants.nameParamName,
                element);
        baseDataValidator.reset().parameter(HolidayApiConstants.nameParamName).value(name).notNull()
                .notExceedingLengthOf(100);
    }

    if (this.fromApiJsonHelper.parameterExists(HolidayApiConstants.fromDateParamName, element)) {
        final LocalDate fromDate = this.fromApiJsonHelper
                .extractLocalDateNamed(HolidayApiConstants.fromDateParamName, element);
        baseDataValidator.reset().parameter(HolidayApiConstants.fromDateParamName).value(fromDate).notNull();
    }

    if (this.fromApiJsonHelper.parameterExists(HolidayApiConstants.toDateParamName, element)) {
        final LocalDate toDate = this.fromApiJsonHelper
                .extractLocalDateNamed(HolidayApiConstants.toDateParamName, element);
        baseDataValidator.reset().parameter(HolidayApiConstants.toDateParamName).value(toDate).notNull();
    }

    if (this.fromApiJsonHelper.parameterExists(HolidayApiConstants.repaymentsRescheduledToParamName, element)) {
        final LocalDate repaymentsRescheduledTo = this.fromApiJsonHelper
                .extractLocalDateNamed(HolidayApiConstants.repaymentsRescheduledToParamName, element);
        baseDataValidator.reset().parameter(HolidayApiConstants.repaymentsRescheduledToParamName)
                .value(repaymentsRescheduledTo).notNull();
    }

    Set<Long> offices = null;
    final JsonObject topLevelJsonElement = element.getAsJsonObject();
    if (this.fromApiJsonHelper.parameterExists(HolidayApiConstants.officesParamName, element)) {
        if (topLevelJsonElement.has(HolidayApiConstants.officesParamName)
                && topLevelJsonElement.get(HolidayApiConstants.officesParamName).isJsonArray()) {

            final JsonArray array = topLevelJsonElement.get(HolidayApiConstants.officesParamName)
                    .getAsJsonArray();
            if (array.size() > 0) {
                offices = new HashSet<>(array.size());
                for (int i = 0; i < array.size(); i++) {
                    final JsonObject officeElement = array.get(i).getAsJsonObject();
                    final Long officeId = this.fromApiJsonHelper
                            .extractLongNamed(HolidayApiConstants.officeIdParamName, officeElement);
                    baseDataValidator.reset().parameter(HolidayApiConstants.officesParamName).value(officeId)
                            .notNull();
                    offices.add(officeId);
                }
            }
        }
        baseDataValidator.reset().parameter(HolidayApiConstants.officesParamName).value(offices).notNull();
        throwExceptionIfValidationWarningsExist(dataValidationErrors);
    }
}

From source file:com.gst.organisation.holiday.service.HolidayWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

private Set<Office> getSelectedOffices(final JsonCommand command) {
    Set<Office> offices = null;
    final JsonObject topLevelJsonElement = this.fromApiJsonHelper.parse(command.json()).getAsJsonObject();
    if (topLevelJsonElement.has(HolidayApiConstants.officesParamName)
            && topLevelJsonElement.get(HolidayApiConstants.officesParamName).isJsonArray()) {

        final JsonArray array = topLevelJsonElement.get(HolidayApiConstants.officesParamName).getAsJsonArray();
        offices = new HashSet<>(array.size());
        for (int i = 0; i < array.size(); i++) {
            final JsonObject officeElement = array.get(i).getAsJsonObject();
            final Long officeId = this.fromApiJsonHelper.extractLongNamed(HolidayApiConstants.officeIdParamName,
                    officeElement);//  w ww . ja v a2s .  c  o m
            final Office office = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
            offices.add(office);
        }
    }
    return offices;
}

From source file:com.gst.organisation.provisioning.serialization.ProvisioningCriteriaDefinitionJsonDeserializer.java

License:Apache License

public void validateForCreate(final String json) {
    if (StringUtils.isBlank(json)) {
        throw new ProvisioningCriteriaCannotBeCreatedException(
                "error.msg.provisioningcriteria.cannot.be.created",
                "criterianame, loanproducts[], provisioningcriteria[] params are missing in the request");

    }/*w  w w  . j av a  2s.c om*/
    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersForCreate);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource("provisioningcriteria");
    final JsonElement element = this.fromApiJsonHelper.parse(json);
    final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(element.getAsJsonObject());
    final String name = this.fromApiJsonHelper
            .extractStringNamed(ProvisioningCriteriaConstants.JSON_CRITERIANAME_PARAM, element);
    baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_CRITERIANAME_PARAM).value(name)
            .notBlank().notExceedingLengthOf(200);

    // if the param present, then we should have the loan product ids. If
    // not we will load all loan products
    if (this.fromApiJsonHelper.parameterExists(ProvisioningCriteriaConstants.JSON_LOANPRODUCTS_PARAM,
            element)) {
        JsonArray jsonloanProducts = this.fromApiJsonHelper
                .extractJsonArrayNamed(ProvisioningCriteriaConstants.JSON_LOANPRODUCTS_PARAM, element);
        baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_LOANPRODUCTS_PARAM)
                .value(jsonloanProducts).jsonArrayNotEmpty();
        // check for unsupported params
        int i = 0;
        for (JsonElement obj : jsonloanProducts) {
            this.fromApiJsonHelper.checkForUnsupportedParameters(obj.getAsJsonObject(),
                    loanProductSupportedParams);
            Long productId = this.fromApiJsonHelper.extractLongNamed("id", obj.getAsJsonObject());
            baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_LOANPRODUCTS_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_LOAN_PRODUCT_ID_PARAM, i + 1)
                    .value(productId).notNull().longGreaterThanZero();
            i++;
        }
    }

    if (this.fromApiJsonHelper
            .parameterExists(ProvisioningCriteriaConstants.JSON_PROVISIONING_DEFINITIONS_PARAM, element)) {
        JsonArray jsonProvisioningCriteria = this.fromApiJsonHelper.extractJsonArrayNamed(
                ProvisioningCriteriaConstants.JSON_PROVISIONING_DEFINITIONS_PARAM, element);
        baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_PROVISIONING_DEFINITIONS_PARAM)
                .value(jsonProvisioningCriteria).jsonArrayNotEmpty();
        for (int i = 0; i < jsonProvisioningCriteria.size(); i++) {
            JsonObject jsonObject = jsonProvisioningCriteria.get(i).getAsJsonObject();
            this.fromApiJsonHelper.checkForUnsupportedParameters(jsonObject,
                    provisioningcriteriaSupportedParams);
            final Long categoryId = this.fromApiJsonHelper
                    .extractLongNamed(ProvisioningCriteriaConstants.JSON_CATEOGRYID_PARAM, jsonObject);
            baseDataValidator.reset()
                    .parameter(ProvisioningCriteriaConstants.JSON_PROVISIONING_DEFINITIONS_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_CATEOGRYID_PARAM, i + 1)
                    .value(categoryId).notNull().longGreaterThanZero();

            Long minimumAge = this.fromApiJsonHelper
                    .extractLongNamed(ProvisioningCriteriaConstants.JSON_MINIMUM_AGE_PARAM, jsonObject);
            baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_MINIMUM_AGE_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_MINIMUM_AGE_PARAM, i + 1)
                    .value(minimumAge).notNull().longZeroOrGreater();

            Long maximumAge = this.fromApiJsonHelper
                    .extractLongNamed(ProvisioningCriteriaConstants.JSON_MAXIMUM_AGE_PARAM, jsonObject);
            baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_MAXIMUM_AGE_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_MAXIMUM_AGE_PARAM, i + 1)
                    .value(maximumAge).notNull().longGreaterThanNumber(
                            ProvisioningCriteriaConstants.JSON_MINIMUM_AGE_PARAM, minimumAge, (i + 1));

            BigDecimal provisioningpercentage = this.fromApiJsonHelper.extractBigDecimalNamed(
                    ProvisioningCriteriaConstants.JSON_PROVISIONING_PERCENTAGE_PARAM, jsonObject, locale);
            baseDataValidator.reset()
                    .parameter(ProvisioningCriteriaConstants.JSON_PROVISIONING_PERCENTAGE_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_PROVISIONING_PERCENTAGE_PARAM,
                            i + 1)
                    .value(provisioningpercentage).notNull().zeroOrPositiveAmount();

            Long liabilityAccountId = this.fromApiJsonHelper
                    .extractLongNamed(ProvisioningCriteriaConstants.JSON_LIABILITY_ACCOUNT_PARAM, jsonObject);
            baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_LIABILITY_ACCOUNT_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_LIABILITY_ACCOUNT_PARAM, i + 1)
                    .value(liabilityAccountId).notNull().longGreaterThanZero();

            Long expenseAccountId = this.fromApiJsonHelper
                    .extractLongNamed(ProvisioningCriteriaConstants.JSON_EXPENSE_ACCOUNT_PARAM, jsonObject);
            baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_EXPENSE_ACCOUNT_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_EXPENSE_ACCOUNT_PARAM, i + 1)
                    .value(expenseAccountId).notNull().longGreaterThanZero();
        }
    } else {
        baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_PROVISIONING_DEFINITIONS_PARAM)
                .jsonArrayNotEmpty();
    }

    if (!dataValidationErrors.isEmpty()) {
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }
}

From source file:com.gst.organisation.provisioning.serialization.ProvisioningCriteriaDefinitionJsonDeserializer.java

License:Apache License

public void validateForUpdate(final String json) {
    if (StringUtils.isBlank(json)) {
        throw new ProvisioningCriteriaCannotBeCreatedException(
                "error.msg.provisioningcriteria.cannot.be.updated", "update params are missing in the request");

    }//from w w  w . j  av  a 2 s  . c  o  m
    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersForUpdate);

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource("provisioningcriteria");
    final JsonElement element = this.fromApiJsonHelper.parse(json);
    final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(element.getAsJsonObject());

    if (this.fromApiJsonHelper.parameterExists(ProvisioningCriteriaConstants.JSON_CRITERIANAME_PARAM,
            element)) {
        final String name = this.fromApiJsonHelper
                .extractStringNamed(ProvisioningCriteriaConstants.JSON_CRITERIANAME_PARAM, element);
        baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_CRITERIANAME_PARAM).value(name)
                .notBlank().notExceedingLengthOf(200);
    }

    // if the param present, then we should have the loan product ids. If
    // not we will load all loan products
    if (this.fromApiJsonHelper.parameterExists(ProvisioningCriteriaConstants.JSON_LOANPRODUCTS_PARAM,
            element)) {
        JsonArray jsonloanProducts = this.fromApiJsonHelper
                .extractJsonArrayNamed(ProvisioningCriteriaConstants.JSON_LOANPRODUCTS_PARAM, element);
        baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_LOANPRODUCTS_PARAM)
                .value(jsonloanProducts).jsonArrayNotEmpty();
        // check for unsupported params
        int i = 0;
        for (JsonElement obj : jsonloanProducts) {
            Long productId = this.fromApiJsonHelper.extractLongNamed("id", obj.getAsJsonObject());
            baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_LOANPRODUCTS_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_LOAN_PRODUCT_ID_PARAM, i + 1)
                    .value(productId).notNull().longGreaterThanZero();
            i++;
        }
    }

    if (this.fromApiJsonHelper
            .parameterExists(ProvisioningCriteriaConstants.JSON_PROVISIONING_DEFINITIONS_PARAM, element)) {
        JsonArray jsonProvisioningCriteria = this.fromApiJsonHelper.extractJsonArrayNamed(
                ProvisioningCriteriaConstants.JSON_PROVISIONING_DEFINITIONS_PARAM, element);
        baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_PROVISIONING_DEFINITIONS_PARAM)
                .value(jsonProvisioningCriteria).jsonArrayNotEmpty();
        for (int i = 0; i < jsonProvisioningCriteria.size(); i++) {
            // check for unsupported params
            JsonObject jsonObject = jsonProvisioningCriteria.get(i).getAsJsonObject();
            final Long categoryId = this.fromApiJsonHelper
                    .extractLongNamed(ProvisioningCriteriaConstants.JSON_CATEOGRYID_PARAM, jsonObject);
            baseDataValidator.reset()
                    .parameter(ProvisioningCriteriaConstants.JSON_PROVISIONING_DEFINITIONS_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_CATEOGRYID_PARAM, i + 1)
                    .value(categoryId).notNull().longGreaterThanZero();

            Long minimumAge = this.fromApiJsonHelper
                    .extractLongNamed(ProvisioningCriteriaConstants.JSON_MINIMUM_AGE_PARAM, jsonObject);
            baseDataValidator.reset()
                    .parameter(ProvisioningCriteriaConstants.JSON_PROVISIONING_DEFINITIONS_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_MINIMUM_AGE_PARAM, i + 1)
                    .value(minimumAge).notNull().longZeroOrGreater();

            Long maximumAge = this.fromApiJsonHelper
                    .extractLongNamed(ProvisioningCriteriaConstants.JSON_MAXIMUM_AGE_PARAM, jsonObject);
            baseDataValidator.reset().parameter(ProvisioningCriteriaConstants.JSON_MAXIMUM_AGE_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_MAXIMUM_AGE_PARAM, i + 1)
                    .value(maximumAge).notNull().longGreaterThanNumber(
                            ProvisioningCriteriaConstants.JSON_MINIMUM_AGE_PARAM, minimumAge, (i + 1));

            BigDecimal provisioningpercentage = this.fromApiJsonHelper.extractBigDecimalNamed(
                    ProvisioningCriteriaConstants.JSON_PROVISIONING_PERCENTAGE_PARAM, jsonObject, locale);
            baseDataValidator.reset()
                    .parameter(ProvisioningCriteriaConstants.JSON_PROVISIONING_DEFINITIONS_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_PROVISIONING_PERCENTAGE_PARAM,
                            i + 1)
                    .value(provisioningpercentage).notNull().zeroOrPositiveAmount();

            Long liabilityAccountId = this.fromApiJsonHelper
                    .extractLongNamed(ProvisioningCriteriaConstants.JSON_LIABILITY_ACCOUNT_PARAM, jsonObject);
            baseDataValidator.reset()
                    .parameter(ProvisioningCriteriaConstants.JSON_PROVISIONING_DEFINITIONS_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_LIABILITY_ACCOUNT_PARAM, i + 1)
                    .value(liabilityAccountId).notNull().longGreaterThanZero();

            Long expenseAccountId = this.fromApiJsonHelper
                    .extractLongNamed(ProvisioningCriteriaConstants.JSON_EXPENSE_ACCOUNT_PARAM, jsonObject);
            baseDataValidator.reset()
                    .parameter(ProvisioningCriteriaConstants.JSON_PROVISIONING_DEFINITIONS_PARAM)
                    .parameterAtIndexArray(ProvisioningCriteriaConstants.JSON_EXPENSE_ACCOUNT_PARAM, i + 1)
                    .value(expenseAccountId).notNull().longGreaterThanZero();
        }
    }

    if (!dataValidationErrors.isEmpty()) {
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }

}

From source file:com.gst.portfolio.address.service.AddressWritePlatformServiceImpl.java

License:Apache License

@Override
public CommandProcessingResult addNewClientAddress(final Client client, final JsonCommand command) {
    CodeValue stateIdobj = null;//from   w  w w. j  av a2  s  .c o  m
    CodeValue countryIdObj = null;
    long stateId;
    long countryId;
    ClientAddress clientAddressobj = new ClientAddress();
    final JsonArray addressArray = command.arrayOfParameterNamed("address");

    for (int i = 0; i < addressArray.size(); i++) {
        final JsonObject jsonObject = addressArray.get(i).getAsJsonObject();

        // validate every address
        this.fromApiJsonDeserializer.validateForCreate(jsonObject.toString(), true);

        if (jsonObject.get("stateProvinceId") != null) {
            stateId = jsonObject.get("stateProvinceId").getAsLong();
            stateIdobj = this.codeValueRepository.getOne(stateId);
        }

        if (jsonObject.get("countryId") != null) {
            countryId = jsonObject.get("countryId").getAsLong();
            countryIdObj = this.codeValueRepository.getOne(countryId);
        }

        final long addressTypeId = jsonObject.get("addressTypeId").getAsLong();
        final CodeValue addressTypeIdObj = this.codeValueRepository.getOne(addressTypeId);

        final Address add = Address.fromJsonObject(jsonObject, stateIdobj, countryIdObj);
        this.addressRepository.save(add);
        final Long addressid = add.getId();
        final Address addobj = this.addressRepository.getOne(addressid);

        final boolean isActive = jsonObject.get("isActive").getAsBoolean();

        clientAddressobj = ClientAddress.fromJson(isActive, client, addobj, addressTypeIdObj);
        this.clientAddressRepository.save(clientAddressobj);

    }

    return new CommandProcessingResultBuilder().withCommandId(command.commandId())
            .withEntityId(clientAddressobj.getId()).build();
}

From source file:com.gst.portfolio.collateral.service.CollateralAssembler.java

License:Apache License

public Set<LoanCollateral> fromParsedJson(final JsonElement element) {

    final Set<LoanCollateral> collateralItems = new HashSet<>();

    if (element.isJsonObject()) {
        final JsonObject topLevelJsonElement = element.getAsJsonObject();

        if (topLevelJsonElement.has("collateral") && topLevelJsonElement.get("collateral").isJsonArray()) {
            final JsonArray array = topLevelJsonElement.get("collateral").getAsJsonArray();
            final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
            for (int i = 0; i < array.size(); i++) {

                final JsonObject collateralItemElement = array.get(i).getAsJsonObject();

                final Long id = this.fromApiJsonHelper.extractLongNamed("id", collateralItemElement);
                final Long collateralTypeId = this.fromApiJsonHelper.extractLongNamed("type",
                        collateralItemElement);
                final CodeValue collateralType = this.codeValueRepository
                        .findOneWithNotFoundDetection(collateralTypeId);
                final String description = this.fromApiJsonHelper.extractStringNamed("description",
                        collateralItemElement);
                final BigDecimal value = this.fromApiJsonHelper.extractBigDecimalNamed("value",
                        collateralItemElement, locale);

                if (id == null) {
                    collateralItems.add(LoanCollateral.from(collateralType, value, description));
                } else {
                    final LoanCollateral loanCollateralItem = this.loanCollateralRepository.findOne(id);
                    if (loanCollateralItem == null) {
                        throw new CollateralNotFoundException(id);
                    }//from   w w  w . java 2  s. c  om

                    loanCollateralItem.assembleFrom(collateralType, value, description);

                    collateralItems.add(loanCollateralItem);
                }
            }
        } else {
            // no collaterals passed, use existing ones against loan
        }

    }

    return collateralItems;
}