Search in sources :

Example 11 with Entity

use of org.openforis.idm.model.Entity 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 12 with Entity

use of org.openforis.idm.model.Entity 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 13 with Entity

use of org.openforis.idm.model.Entity in project collect by openforis.

the class IDMFunctionsTest method testDistinctValuesFunctionWithEmptyList.

@Test
public void testDistinctValuesFunctionWithEmptyList() throws InvalidExpressionException {
    Entity plot1 = EntityBuilder.addEntity(cluster, "plot");
    EntityBuilder.addValue(plot1, "no", new Code("1"));
    Entity plot2 = EntityBuilder.addEntity(cluster, "plot");
    EntityBuilder.addValue(plot2, "no", new Code("2"));
    Entity plot3 = EntityBuilder.addEntity(cluster, "plot");
    // duplicate value
    EntityBuilder.addValue(plot3, "no", new Code("1"));
    String expr = ExpressionFactory.IDM_PREFIX + ":" + "distinct-values(plot/accessibility)";
    Object result = evaluateExpression(expr);
    Assert.assertNull(result);
}
Also used : Entity(org.openforis.idm.model.Entity) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Example 14 with Entity

use of org.openforis.idm.model.Entity in project collect by openforis.

the class ModelPathExpressionTest method testIteratePath2.

@Test
public void testIteratePath2() throws InvalidExpressionException {
    String entityName = "plot";
    Entity plot1 = EntityBuilder.addEntity(cluster, entityName);
    EntityBuilder.addValue(plot1, "no", new Code("1"));
    Entity plot2 = EntityBuilder.addEntity(cluster, entityName);
    EntityBuilder.addValue(plot2, "no", new Code("1"));
    Entity plot3 = EntityBuilder.addEntity(cluster, entityName);
    EntityBuilder.addValue(plot3, "no", new Code("1"));
    String expr = "plot/no";
    List<Node<?>> list = iterateExpression(expr, cluster);
    Assert.assertEquals(3, list.size());
}
Also used : Entity(org.openforis.idm.model.Entity) Node(org.openforis.idm.model.Node) Code(org.openforis.idm.model.Code) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 15 with Entity

use of org.openforis.idm.model.Entity in project collect by openforis.

the class ModelPathExpressionTest method testParent.

@Test
public void testParent() throws InvalidExpressionException {
    Entity plot = EntityBuilder.addEntity(cluster, "plot");
    List<Node<?>> plots = iterateExpression("parent()", plot);
    Assert.assertEquals(1, plots.size());
}
Also used : Entity(org.openforis.idm.model.Entity) Node(org.openforis.idm.model.Node) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Aggregations

Entity (org.openforis.idm.model.Entity)164 Test (org.junit.Test)88 CollectRecord (org.openforis.collect.model.CollectRecord)37 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)36 Code (org.openforis.idm.model.Code)35 RealAttribute (org.openforis.idm.model.RealAttribute)25 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)23 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)19 Node (org.openforis.idm.model.Node)19 AbstractTest (org.openforis.idm.AbstractTest)18 Date (org.openforis.idm.model.Date)16 ArrayList (java.util.ArrayList)14 CodeAttribute (org.openforis.idm.model.CodeAttribute)14 Time (org.openforis.idm.model.Time)12 GregorianCalendar (java.util.GregorianCalendar)9 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)9 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)9 TextAttribute (org.openforis.idm.model.TextAttribute)9 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)8 Attribute (org.openforis.idm.model.Attribute)8