Search in sources :

Example 1 with Schema

use of cern.modesti.schema.Schema in project modesti by jlsalmon.

the class CoreValidationService method validateRequest.

public boolean validateRequest(Request request) {
    try {
        if (RequestType.DELETE.equals(request.getType())) {
            // Delete requests should not be validated
            return true;
        }
        boolean valid = true;
        Schema schema = schemaRepository.findOne(request.getDomain());
        // Reset all points and clear any error messages.
        for (Point point : request.getPoints()) {
            point.setValid(true);
            point.setErrors(new ArrayList<>());
        }
        if (environment.getProperty("modesti.disableValidator", Boolean.class, false) || request.isSkipCoreValidation()) {
            log.info("core validations disabled");
        } else {
            // Concatenate all categories and datasources
            List<Category> categories = new ArrayList<>(schema.getCategories());
            categories.addAll(schema.getDatasources());
            // Validate the mutually exclusive column group specifications.
            if (!validateMutualExclusions(request, categories)) {
                valid = false;
            }
            // column groups and mutually inclusive fields.
            if (!validateConstraints(request, categories)) {
                valid = false;
            }
            // values, min/max length, valid values etc.
            if (!validatePoints(request, categories)) {
                valid = false;
            }
        }
        request.setValid(valid);
        requestService.save(request);
        if (!valid) {
            log.info(format("request #%s failed validation, not invoking custom validator", request.getRequestId()));
            return false;
        }
        log.info(format("request #%s is valid, invoking custom validator", request.getRequestId()));
        RequestProvider plugin = requestProviderRegistry.getPluginFor(request);
        RequestValidator validator = getPluginRequestValidator(plugin.getMetadata().getId());
        if (validator == null) {
            log.info(format("custom validator not provided for request #%s", request.getRequestId()));
            return true;
        }
        valid = validator.validateRequest(request, schema);
        request.setValid(valid);
        requestService.save(request);
        return valid;
    } catch (RuntimeException e) {
        request.setValid(false);
        requestService.save(request);
        log.info(format("Unexpected error during validation phase for request #%s '%s'", request.getRequestId(), e.toString()), e);
        return false;
    }
}
Also used : Category(cern.modesti.schema.category.Category) Schema(cern.modesti.schema.Schema) ArrayList(java.util.ArrayList) RequestProvider(cern.modesti.plugin.RequestProvider) Point(cern.modesti.point.Point)

Example 2 with Schema

use of cern.modesti.schema.Schema in project modesti by jlsalmon.

the class RequestHistoryServiceImpl method initialiseChangeHistory.

@Override
public void initialiseChangeHistory(Request request) {
    log.info(format("creating new base history record for request #%s", request.getRequestId()));
    Schema schema = schemaRepository.findOne(request.getDomain());
    RequestHistoryImpl entry = new RequestHistoryImpl(new ObjectId().toString(), request.getRequestId(), schema.getIdProperty(), request, new ArrayList<>(), false);
    requestHistoryRepository.save(entry);
}
Also used : ObjectId(org.bson.types.ObjectId) Schema(cern.modesti.schema.Schema)

Aggregations

Schema (cern.modesti.schema.Schema)2 RequestProvider (cern.modesti.plugin.RequestProvider)1 Point (cern.modesti.point.Point)1 Category (cern.modesti.schema.category.Category)1 ArrayList (java.util.ArrayList)1 ObjectId (org.bson.types.ObjectId)1