Search in sources :

Example 21 with NodeDefinition

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

the class StateDependencyMap method registerDependencies.

private void registerDependencies(EntityDefinition entityDefinition) {
    List<NodeDefinition> childDefinitions = entityDefinition.getChildDefinitions();
    for (NodeDefinition nodeDefinition : childDefinitions) {
        registerDependencies(nodeDefinition, nodeDefinition.getRelevantExpression(), relevantDependencies);
        registerDependencies(nodeDefinition, nodeDefinition.getRequiredExpression(), requiredDependencies);
        if (nodeDefinition instanceof AttributeDefinition) {
            registerDependencies((AttributeDefinition) nodeDefinition);
        } else {
            registerDependencies((EntityDefinition) nodeDefinition);
        }
    }
}
Also used : NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 22 with NodeDefinition

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

the class DataHandler method startChildNode.

public void startChildNode(String localName, Attributes attributes) {
    Entity entity = (Entity) node;
    NodeDefinition childDefn = getNodeDefinition(entity, localName, attributes);
    if (childDefn == null) {
        warn(localName, "Undefined node");
        pushIgnore();
    } else {
        ModelVersion version = record.getVersion();
        if (version == null || version.isApplicable(childDefn)) {
            Node<?> newNode = childDefn.createNode();
            entity.add(newNode);
            Integer stateValue = getNodeState();
            if (stateValue != null) {
                entity.setChildState(localName, stateValue);
            }
            this.node = newNode;
        } else {
            warn(localName, "Node definition is not applicable to the record version");
            pushIgnore();
        }
    }
}
Also used : Entity(org.openforis.idm.model.Entity) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ModelVersion(org.openforis.idm.metamodel.ModelVersion)

Example 23 with NodeDefinition

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

the class DataLoader method processRow.

private void processRow(CollectRecord record, Record row) throws DataInconsistencyException {
    Integer id = row.getValueAsInteger(DATA.ID);
    Integer parentId = row.getValueAsInteger(DATA.PARENT_ID);
    Integer defnId = row.getValueAsInteger(DATA.DEFINITION_ID);
    Node<?> o;
    if (parentId == null) {
        // Process root entity
        o = record.getRootEntity();
        Integer rootEntityDefnId = o.getDefinition().getId();
        if (!rootEntityDefnId.equals(defnId)) {
            throw new DataInconsistencyException(DATA.DEFINITION_ID + " " + defnId + " does not match " + RECORD.ROOT_ENTITY_ID + " " + rootEntityDefnId);
        }
    } else {
        // Process other objects
        Node<? extends NodeDefinition> parent = objectsById.get(parentId);
        if (parent == null) {
            throw new DataInconsistencyException("Parent " + parentId + " not yet loaded");
        }
        if (!(parent instanceof Entity)) {
            throw new DataInconsistencyException("Parent " + parentId + " not an entity");
        }
        NodeDefinition defn = record.getSurvey().getSchema().getById(defnId);
        if (defn == null) {
            throw new DataInconsistencyException("Unknown schema definition " + DATA.DEFINITION_ID);
        }
        NodeMapper mapper = NodeMapper.getInstance(defn.getClass());
        Node<?> o1 = mapper.addNode(defn, row, (Entity) parent);
        if (defn instanceof AttributeDefinition) {
            String remarks = row.getValue(DATA.REMARKS);
            String s = row.getValueAsString(DATA.SYMBOL);
            Character symbol = null;
            if (s != null && s.length() == 1) {
                symbol = s.charAt(0);
            }
            Attribute<?, ?> attribute = (Attribute<?, ?>) o1;
            attribute.setRemarks(remarks);
            attribute.setSymbol(symbol);
        }
        o = o1;
    }
    objectsById.put(id, o);
}
Also used : Entity(org.openforis.idm.model.Entity) Attribute(org.openforis.idm.model.Attribute) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) DataInconsistencyException(org.openforis.collect.persistence.DataInconsistencyException)

Example 24 with NodeDefinition

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

the class DataMarshaller method writeEntity.

private void writeEntity(Entity entity, Writer out) throws IOException {
    out.write("{");
    out.write("\"");
    out.write(entity.getName());
    out.write("\":{");
    EntityDefinition defn = entity.getDefinition();
    List<NodeDefinition> childDefns = defn.getChildDefinitions();
    for (int j = 0; j < childDefns.size(); j++) {
        if (j > 0) {
            out.write(",");
        }
        NodeDefinition childDef = childDefns.get(j);
        String name = childDef.getName();
        int childCount = entity.getCount(name);
        if (childCount > 0) {
            if (childDef.isMultiple()) {
                out.write("[");
                for (int i = 0; i < childCount; i++) {
                    if (i > 0) {
                        out.write(",");
                    }
                    Node<?> child = entity.get(name, i);
                    write(child, i, out);
                }
                out.write("]");
            } else {
                Node<?> child = entity.get(name, 0);
                write(child, 0, out);
            }
        }
    }
    out.write("}}");
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 25 with NodeDefinition

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

the class PathTest method testSingleAttributeWithIndex.

@Test
public void testSingleAttributeWithIndex() throws InvalidPathException {
    Entity cluster = getRootEntity();
    Entity plot = EntityBuilder.addEntity(cluster, "plot");
    Entity tree1 = EntityBuilder.addEntity(plot, "tree");
    EntityBuilder.addValue(tree1, "dbh", 12.2);
    Entity tree2 = EntityBuilder.addEntity(plot, "tree");
    RealAttribute dbh2 = EntityBuilder.addValue(tree2, "dbh", 15.7);
    Path path = Path.parse("tree[2]/dbh[1]");
    // Node
    List<Node<?>> res = path.evaluate(plot);
    Assert.assertEquals(1, res.size());
    Assert.assertEquals(dbh2, res.get(0));
    // Defn
    NodeDefinition def = path.evaluate(plot.getDefinition());
    Assert.assertEquals(dbh2.getDefinition(), def);
}
Also used : Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) Node(org.openforis.idm.model.Node) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

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