Search in sources :

Example 96 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class SurveyValidator method validateEntity.

protected List<SurveyValidationResult> validateEntity(EntityDefinition entityDef) {
    List<SurveyValidationResult> results = new ArrayList<SurveyValidator.SurveyValidationResult>();
    List<NodeDefinition> childDefinitions = entityDef.getChildDefinitions();
    if (childDefinitions.size() == 0) {
        // empty entity
        results.add(new SurveyValidationResult(entityDef.getPath(), "survey.validation.error.empty_entity"));
    }
    if (entityDef.isMultiple()) {
        UIOptions uiOptions = ((CollectSurvey) entityDef.getSurvey()).getUIOptions();
        EntityDefinition parentEntity = entityDef.getParentEntityDefinition();
        if (parentEntity != null && parentEntity.isMultiple()) {
            Layout layout = uiOptions.getLayout(entityDef);
            Layout parentLayout = uiOptions.getLayout(parentEntity);
            if (TABLE == layout && TABLE == parentLayout) {
                results.add(new SurveyValidationResult(entityDef.getPath(), "survey.validation.error.nested_tables"));
            }
        }
    }
    if (entityDef.isVirtual()) {
        String generatorExpression = entityDef.getGeneratorExpression();
        String sourceEntityPath = Path.getAbsolutePath(generatorExpression);
        EntityDefinition sourceEntityDef = (EntityDefinition) entityDef.getParentDefinition().getDefinitionByPath(sourceEntityPath);
        for (NodeDefinition sourceChildDef : sourceEntityDef.getChildDefinitions()) {
            boolean skipNode = sourceChildDef instanceof AttributeDefinition && ((AttributeDefinition) sourceChildDef).getReferencedAttribute() != null;
            if (!skipNode) {
                if (entityDef.containsChildDefinition(sourceChildDef.getName())) {
                    NodeDefinition foundChildDef = entityDef.getChildDefinition(sourceChildDef.getName());
                    if (foundChildDef.getClass() != sourceChildDef.getClass()) {
                        results.add(new SurveyValidationResult(Flag.ERROR, entityDef.getPath(), "survey.validation.entity.error.invalid_virtual_node_type", foundChildDef.getName()));
                    }
                } else {
                    results.add(new SurveyValidationResult(Flag.WARNING, entityDef.getPath(), "survey.validation.entity.error.missing_virtual_node", sourceChildDef.getName()));
                }
            }
        }
        for (NodeDefinition virtualChildDef : entityDef.getChildDefinitions()) {
            if (!sourceEntityDef.containsChildDefinition(virtualChildDef.getName())) {
                results.add(new SurveyValidationResult(Flag.WARNING, entityDef.getPath(), "survey.validation.entity.error.source_node_not_found_for_virtual_node", virtualChildDef.getName(), sourceEntityDef.getName()));
            }
        }
    }
    return results;
}
Also used : UIOptions(org.openforis.collect.metamodel.ui.UIOptions) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Layout(org.openforis.collect.metamodel.ui.UIOptions.Layout) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 97 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class CollectRecord method updateRootEntityKeyValues.

private void updateRootEntityKeyValues() {
    Entity rootEntity = getRootEntity();
    if (rootEntity != null) {
        List<AttributeDefinition> keyAttributeDefinitions = rootEntity.getDefinition().getKeyAttributeDefinitions();
        rootEntityKeyValues = extractValues(keyAttributeDefinitions);
    }
}
Also used : Entity(org.openforis.idm.model.Entity) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 98 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class CollectRecord method extractValues.

private List<String> extractValues(List<AttributeDefinition> attrDefs) {
    List<String> values = new ArrayList<String>();
    for (AttributeDefinition keyDefn : attrDefs) {
        Attribute<?, ?> keyNode = this.findNodeByPath(keyDefn.getPath());
        if (keyNode == null || keyNode.isEmpty()) {
            // TODO throw error in this case?
            values.add(null);
        } else {
            if (!keyNode.isEmpty()) {
                String keyValue = keyNode.extractTextValue();
                values.add(keyValue);
            }
        }
    }
    return values;
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 99 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class DependencyGraphTest method attributeDefinition.

protected AttributeDefinition attributeDefinition(EntityDefinition parent, String name, String calculatedValueExpression, String relevantExpression, String validationExpression) {
    Schema schema = survey.getSchema();
    AttributeDefinition defn = schema.createTextAttributeDefinition();
    defn.setName(name);
    if (calculatedValueExpression != null) {
        defn.setCalculated(true);
        defn.addAttributeDefault(new AttributeDefault(calculatedValueExpression));
    }
    defn.setRelevantExpression(relevantExpression);
    if (validationExpression != null) {
        defn.addCheck(new CustomCheck(validationExpression));
    }
    parent.addChildDefinition(defn);
    survey.refreshSurveyDependencies();
    return defn;
}
Also used : CustomCheck(org.openforis.idm.metamodel.validation.CustomCheck) Schema(org.openforis.idm.metamodel.Schema) AttributeDefault(org.openforis.idm.metamodel.AttributeDefault) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 100 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class DependencyGraphTest method attribute.

private Attribute<?, ?> attribute(Entity parent, String name, String calculatedExpression, String relevantExpression, String validationExpression) {
    EntityDefinition parentDefn = parent.getDefinition();
    AttributeDefinition defn;
    try {
        defn = (AttributeDefinition) parentDefn.getChildDefinition(name);
    } catch (Exception e) {
        defn = attributeDefinition(parentDefn, name, calculatedExpression, relevantExpression, validationExpression);
    }
    Attribute<?, ?> attr = (Attribute<?, ?>) defn.createNode();
    parent.add(attr);
    return attr;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Aggregations

AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)107 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)47 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)37 ArrayList (java.util.ArrayList)33 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)27 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)21 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)20 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)18 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)18 CollectSurvey (org.openforis.collect.model.CollectSurvey)17 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)16 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)16 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)12 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)12 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)11 Schema (org.openforis.idm.metamodel.Schema)10 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 Entity (org.openforis.idm.model.Entity)9 Value (org.openforis.idm.model.Value)9 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)8