Search in sources :

Example 91 with NodeDefinition

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

the class CSVDataExportProcess method getEntitiesToExport.

private Collection<EntityDefinition> getEntitiesToExport() {
    final Collection<EntityDefinition> result = new ArrayList<EntityDefinition>();
    Schema schema = recordFilter.getSurvey().getSchema();
    if (entityId == null) {
        EntityDefinition rootEntity = schema.getRootEntityDefinition(recordFilter.getRootEntityId());
        rootEntity.traverse(new NodeDefinitionVisitor() {

            @Override
            public void visit(NodeDefinition node) {
                if (node instanceof EntityDefinition && node.isMultiple()) {
                    result.add((EntityDefinition) node);
                }
            }
        });
    } else {
        EntityDefinition entity = (EntityDefinition) schema.getDefinitionById(entityId);
        result.add(entity);
    }
    return result;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Schema(org.openforis.idm.metamodel.Schema) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Example 92 with NodeDefinition

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

the class AutomaticColumnProvider method createProviders.

private static List<ColumnProvider> createProviders(CSVDataExportParameters config, EntityDefinition rowDefn, List<String> exclusions) {
    List<ColumnProvider> cols = new ArrayList<ColumnProvider>();
    CollectSurvey survey = (CollectSurvey) rowDefn.getSurvey();
    CollectAnnotations surveyAnnotations = survey.getAnnotations();
    List<NodeDefinition> childDefinitions = rowDefn.getChildDefinitions();
    for (NodeDefinition childDefn : childDefinitions) {
        if (includeChild(exclusions, childDefn)) {
            if (childDefn instanceof EntityDefinition) {
                createEntityProviders(config, (EntityDefinition) childDefn, cols);
            } else if (childDefn instanceof AttributeDefinition && surveyAnnotations.isIncludedInDataExport(childDefn)) {
                cols.add(ColumnProviders.createAttributeProvider(config, (AttributeDefinition) childDefn));
            }
        }
    }
    return cols;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 93 with NodeDefinition

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

the class DescendantNodeFilter method accept.

@Override
public boolean accept(Node<?> node) {
    NodeDefinition nodeDef = node.getDefinition();
    if (!(nodeDef instanceof EntityDefinition) || !descendantAttributeDefinition.isDescendantOf((EntityDefinition) nodeDef)) {
        return false;
    }
    Record record = node.getRecord();
    SurveyContext surveyContext = record.getSurveyContext();
    ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
    List<Node<?>> attributes = record.findNodesByPath(descendantAttributeDefinition.getPath());
    for (Node<?> attribute : attributes) {
        try {
            Entity parentEntity = attribute.getParent();
            if (parentEntity == node && expressionEvaluator.evaluateBoolean(parentEntity, attribute, descendantAttributeCondition)) {
                return true;
            }
        } catch (InvalidExpressionException e) {
            throw new RuntimeException(e);
        }
    }
    return false;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException) Node(org.openforis.idm.model.Node) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Record(org.openforis.idm.model.Record) ExpressionEvaluator(org.openforis.idm.model.expression.ExpressionEvaluator) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 94 with NodeDefinition

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

the class ValidationMessageBuilder method getPrettyFormatPath.

public String getPrettyFormatPath(Entity parentEntity, String childName, Locale locale) {
    EntityDefinition parentEntityDefn = parentEntity.getDefinition();
    NodeDefinition childDefn = parentEntityDefn.getChildDefinition(childName);
    String label = getPrettyLabelText(childDefn, locale);
    if (parentEntity.getParent() != null && parentEntity.getParent() != null) {
        String parentEntityPath = getPrettyFormatPath(parentEntity, locale);
        return parentEntityPath + PRETTY_PATH_SEPARATOR + label;
    } else {
        return label;
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 95 with NodeDefinition

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

the class ValidationMessageBuilder method getComparisonCheckMessageArg.

protected String getComparisonCheckMessageArg(Attribute<?, ?> attribute, String expression, Locale locale) {
    if (StringUtils.isNotBlank(expression)) {
        String result = expression;
        Survey survey = attribute.getSurvey();
        Schema schema = survey.getSchema();
        SurveyContext surveyContext = survey.getContext();
        ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
        try {
            Entity parentEntity = attribute.getParent();
            EntityDefinition parentDefinition = parentEntity.getDefinition();
            Set<String> referencedPaths = expressionEvaluator.determineReferencedPaths(expression);
            for (String path : referencedPaths) {
                String absolutePath = parentDefinition.getPath() + PATH_SEPARATOR + path;
                NodeDefinition nodeDefinition = schema.getDefinitionByPath(absolutePath);
                String label = getPrettyLabelText(nodeDefinition, locale);
                result = result.replaceAll(nodeDefinition.getName(), label);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return result;
    } else {
        return expression;
    }
}
Also used : Entity(org.openforis.idm.model.Entity) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ExpressionEvaluator(org.openforis.idm.model.expression.ExpressionEvaluator) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Aggregations

NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)173 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)70 ArrayList (java.util.ArrayList)42 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)27 Schema (org.openforis.idm.metamodel.Schema)24 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)22 CollectSurvey (org.openforis.collect.model.CollectSurvey)20 Entity (org.openforis.idm.model.Entity)19 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)16 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)14 UITab (org.openforis.collect.metamodel.ui.UITab)12 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)11 Survey (org.openforis.idm.metamodel.Survey)11 Test (org.junit.Test)10 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)9 ModelVersion (org.openforis.idm.metamodel.ModelVersion)9 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)8 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)8 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)8 Node (org.openforis.idm.model.Node)8