Search in sources :

Example 16 with NodeDefinition

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

the class MinCountDependencyGraph method determineDependents.

@Override
protected Set<NodePathPointer> determineDependents(NodePointer source) throws InvalidExpressionException {
    NodeDefinition def = source.getChildDefinition();
    Survey survey = def.getSurvey();
    Set<NodePathPointer> minCountDependencies = survey.getMinCountDependencies(def);
    return filterByVersion(minCountDependencies, source.getModelVersion());
}
Also used : Survey(org.openforis.idm.metamodel.Survey) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 17 with NodeDefinition

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

the class NodePointerDependencyGraph method toItems.

@Override
protected Collection<NodePointer> toItems(Node<?> node) {
    if (node instanceof Entity) {
        EntityDefinition def = (EntityDefinition) node.getDefinition();
        List<NodeDefinition> defs = def.getChildDefinitionsInVersion(node.getModelVersion());
        List<NodePointer> result = new ArrayList<NodePointer>(defs.size());
        for (NodeDefinition childDef : defs) {
            result.add(new NodePointer((Entity) node, childDef));
        }
        return result;
    } else if (node.getParent() != null) {
        return Collections.singleton(new NodePointer(node));
    } else {
        return Collections.emptySet();
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ArrayList(java.util.ArrayList)

Example 18 with NodeDefinition

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

the class EntitySchema method writeTo.

@Override
public void writeTo(Output out, Entity entity) throws IOException {
    List<Node<? extends NodeDefinition>> children = entity.getChildren();
    for (Node<?> node : children) {
        if (isNodeToBeSaved(node)) {
            out.writeUInt32(DEFINITION_ID_FIELD_NUMBER, node.getDefinition().getId(), false);
            out.writeObject(NODE_FIELD_NUMBER, node, getSchema(node.getClass()), false);
        }
    }
    EntityDefinition definition = entity.getDefinition();
    List<NodeDefinition> childDefinitions = definition.getChildDefinitions();
    for (NodeDefinition childDefinition : childDefinitions) {
        State childState = entity.getChildState(childDefinition);
        out.writeInt32(CHILD_NODE_STATE_FIELD_NUMBER, childState.intValue(), false);
        out.writeInt32(CHILD_DEFINITION_ID_FIELD_NUMBER, childDefinition.getId(), false);
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 19 with NodeDefinition

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

the class MaxCountDependencyGraph method determineDependents.

@Override
protected Set<NodePathPointer> determineDependents(NodePointer source) throws InvalidExpressionException {
    NodeDefinition def = source.getChildDefinition();
    Survey survey = def.getSurvey();
    Set<NodePathPointer> dependentPointers = survey.getMaxCountDependencies(def);
    return filterByVersion(dependentPointers, source.getModelVersion());
}
Also used : Survey(org.openforis.idm.metamodel.Survey) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 20 with NodeDefinition

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

the class StateDependencyMap method registerDependencies.

private void registerDependencies(NodeDefinition nodeDefinition, String expression, Map<Integer, Map<String, String>> dependencies) {
    if (StringUtils.isNotBlank(expression)) {
        List<String> referencedPaths = getReferencedPaths(expression);
        for (String path : referencedPaths) {
            try {
                String normalizedPath = getNormalizedPath(path);
                SchemaPathExpression schemaExpression = new SchemaPathExpression(normalizedPath);
                EntityDefinition parentDefinition = nodeDefinition.getParentDefinition();
                NodeDefinition dependantNode = schemaExpression.evaluate(parentDefinition);
                String sourcePath = dependantNode.getPath();
                String destinationPath = nodeDefinition.getPath();
                String relativePath = getRelativePath(sourcePath, destinationPath);
                Integer surveyId = nodeDefinition.getSurvey().getId();
                Map<String, String> dependenciesMap = getDependenciesMap(dependencies, surveyId);
                dependenciesMap.put(sourcePath, relativePath);
            } catch (Exception e) {
                if (LOG.isErrorEnabled()) {
                    LOG.error("Unable to register dependency for node " + nodeDefinition.getPath() + " with expression " + path, e);
                }
            }
        }
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) SchemaPathExpression(org.openforis.idm.metamodel.expression.SchemaPathExpression) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException)

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