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;
}
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;
}
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;
}
Aggregations