Search in sources :

Example 6 with Field

use of cern.modesti.schema.field.Field in project modesti by jlsalmon.

the class CoreValidationService method validateMutualExclusions.

private boolean validateMutualExclusions(Request request, List<Category> categories) {
    boolean valid = true;
    for (Category category : categories) {
        if (category.getExcludes() == null) {
            continue;
        }
        for (String exclude : category.getExcludes()) {
            // Get the excluded category
            for (Category cat : categories) {
                if (cat.getId().equals(exclude)) {
                    Category excludedCategory = cat;
                    // so, say something like "Fields in the "Alarms" group cannot be used if fields in the "Commands" group have been specified.".
                    for (Point point : request.getNonEmptyPoints()) {
                        List<Field> emptyFields = point.getEmptyFields(category.getFields());
                        // If at least one of the fields of this category are filled, then we must check the excluded category.
                        if (emptyFields.size() != category.getFields().size()) {
                            emptyFields = point.getEmptyFields(excludedCategory.getFields());
                            if (emptyFields.size() != excludedCategory.getFields().size()) {
                                point.setValid(false);
                                valid = false;
                                point.addErrorMessage(category.getId(), "", "Fields in the '" + category.getName() + "' group cannot be used if fields in the '" + excludedCategory.getName() + "' group have been specified.");
                            }
                        }
                    }
                }
            }
        }
    }
    return valid;
}
Also used : AutocompleteField(cern.modesti.schema.field.AutocompleteField) Field(cern.modesti.schema.field.Field) OptionsField(cern.modesti.schema.field.OptionsField) Category(cern.modesti.schema.category.Category) Point(cern.modesti.point.Point)

Example 7 with Field

use of cern.modesti.schema.field.Field in project modesti by jlsalmon.

the class SchemaInitialiser method mergeCategories.

/**
 * Merge two {@link Category} instances, copying the fields defined in the
 * overriding category to the overridden category.
 *
 * @param overridden the base category to merge into
 * @param override   the overriding category to merge from
 * @return a new category containing the result of the merge
 */
private Category mergeCategories(Category overridden, Category override) {
    overridden = new CategoryImpl((CategoryImpl) overridden);
    List<Field> newFields = new ArrayList<>();
    List<Field> oldFields = overridden.getFields();
    for (Field newField : override.getFields()) {
        if (!oldFields.contains(newField)) {
            newFields.add(newField);
        } else {
            oldFields.set(oldFields.indexOf(newField), mergeFields(oldFields.get(oldFields.indexOf(newField)), newField));
        }
    }
    // Copy the editable state list.
    if (override.getEditable() != null) {
        overridden.setEditable(override.getEditable());
    }
    // Copy the constraint list
    if (override.getConstraints() != null) {
        overridden.setConstraints(override.getConstraints());
    }
    overridden.getFields().addAll(newFields);
    return overridden;
}
Also used : CategoryImpl(cern.modesti.schema.category.CategoryImpl) Field(cern.modesti.schema.field.Field)

Example 8 with Field

use of cern.modesti.schema.field.Field in project modesti by jlsalmon.

the class SchemaInitialiser method mergeFields.

/**
 * Merge two {@link Field} instances, copying the fields defined in the
 * overriding field to the overridden field.
 *
 * @param overridden the base field to merge into
 * @param override   the overriding field to merge from
 * @return a new field containing the result of the merge
 */
private Field mergeFields(Field overridden, Field override) {
    // Make a copy to avoid accidentally overriding the core schema
    Field copy = SerializationUtils.clone(overridden);
    BeanUtils.copyProperties(override, copy);
    return copy;
}
Also used : Field(cern.modesti.schema.field.Field)

Aggregations

Field (cern.modesti.schema.field.Field)8 Point (cern.modesti.point.Point)5 Category (cern.modesti.schema.category.Category)3 CategoryImpl (cern.modesti.schema.category.CategoryImpl)2 AutocompleteField (cern.modesti.schema.field.AutocompleteField)2 OptionsField (cern.modesti.schema.field.OptionsField)2 Constraint (cern.modesti.schema.category.Constraint)1 Datasource (cern.modesti.schema.category.Datasource)1 DatasourceImpl (cern.modesti.schema.category.DatasourceImpl)1 SchemaPostProcessor (cern.modesti.schema.spi.SchemaPostProcessor)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteStreams (com.google.common.io.ByteStreams)1 File (java.io.File)1 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 JarURLConnection (java.net.JarURLConnection)1 URISyntaxException (java.net.URISyntaxException)1 URLConnection (java.net.URLConnection)1 StandardCharsets (java.nio.charset.StandardCharsets)1 java.util (java.util)1