Search in sources :

Example 26 with NodeDefinition

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

the class PathTest method testMultipleFieldPathWithIndex.

@Test
public void testMultipleFieldPathWithIndex() throws InvalidPathException {
    Entity cluster = getRootEntity();
    Entity plot = EntityBuilder.addEntity(cluster, "plot");
    EntityBuilder.addEntity(plot, "tree");
    Entity tree2 = EntityBuilder.addEntity(plot, "tree");
    EntityBuilder.addValue(tree2, "dbh", 12.2);
    RealAttribute dbh2 = EntityBuilder.addValue(tree2, "dbh", 15.7);
    Path path = Path.parse("tree[2]/dbh[2]/value");
    // Node
    List<Node<?>> res = path.evaluate(plot);
    Assert.assertEquals(1, res.size());
    Assert.assertEquals(15.7, ((Field<?>) res.get(0)).getValue());
    // Defn
    NodeDefinition def = path.evaluate(plot.getDefinition());
    Assert.assertEquals(dbh2.getDefinition().getFieldDefinition("value"), 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)

Example 27 with NodeDefinition

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

the class DataPersister method insertRow.

private int insertRow(CollectRecord record, Node<? extends NodeDefinition> node, Integer parentId, int idx) {
    Integer defnId = node.getDefinition().getId();
    if (defnId == null) {
        throw new IllegalArgumentException("Null schema object definition id");
    }
    int dataRowId = jooqFactory.nextval(DATA_ID_SEQ).intValue();
    InsertSetMoreStep<?> insert = jooqFactory.insertInto(DATA).set(DATA.ID, dataRowId).set(DATA.DEFINITION_ID, defnId).set(DATA.RECORD_ID, record.getId()).set(DATA.IDX, idx + 1).set(DATA.PARENT_ID, parentId);
    NodeDefinition defn = node.getDefinition();
    Class<? extends NodeDefinition> defnClass = defn.getClass();
    if (node instanceof Attribute) {
        Attribute<?, ?> attr = (Attribute<?, ?>) node;
        if (attr.getRemarks() != null) {
            insert.set(DATA.REMARKS, attr.getRemarks());
        }
        if (attr.getSymbol() != null) {
            insert.set(DATA.SYMBOL, attr.getSymbol().toString());
        }
    }
    NodeMapper mapper = NodeMapper.getInstance(defnClass);
    mapper.setFields(node, insert);
    insert.execute();
    return dataRowId;
}
Also used : Attribute(org.openforis.idm.model.Attribute) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 28 with NodeDefinition

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

the class ProtostuffSerializationTest method testSkipRemovedAttribute.

@Test
public void testSkipRemovedAttribute() throws Exception {
    // Set up
    Survey survey = getTestSurvey();
    // assignFakeNodeDefinitionIds(survey.getSchema());
    Record record1 = createTestRecord(survey);
    Entity cluster1 = record1.getRootEntity();
    // Write
    ModelSerializer ser = new ModelSerializer(10000);
    byte[] data = ser.toByteArray(cluster1);
    // remove attribute from record before comparing it with the new one
    cluster1.remove("crew_no", 0);
    // remove node definition from schema
    Schema schema = survey.getSchema();
    EntityDefinition clusterDefn = schema.getRootEntityDefinition("cluster");
    NodeDefinition crewNumDefn = clusterDefn.getChildDefinition("crew_no");
    clusterDefn.removeChildDefinition(crewNumDefn);
    Record record2 = new Record(survey, "2.0", "cluster");
    ser.mergeFrom(data, record2.getRootEntity());
    // Compare
    Assert.assertTrue(record1.getRootEntity().deepEquals(record2.getRootEntity()));
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Test(org.junit.Test)

Example 29 with NodeDefinition

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

the class ProtostuffSerializationTest method testSkipRemovedEntity.

@Test
public void testSkipRemovedEntity() throws Exception {
    // Set up
    Survey survey = getTestSurvey();
    // assignFakeNodeDefinitionIds(survey.getSchema());
    Record record1 = createTestRecord(survey);
    Entity cluster1 = record1.getRootEntity();
    // Write
    ModelSerializer ser = new ModelSerializer(10000);
    byte[] data = ser.toByteArray(cluster1);
    // remove data
    cluster1.remove("map_sheet", 1);
    cluster1.remove("map_sheet", 0);
    Schema schema = survey.getSchema();
    EntityDefinition clusterDefn = schema.getRootEntityDefinition("cluster");
    NodeDefinition mapSheetDefn = clusterDefn.getChildDefinition("map_sheet");
    clusterDefn.removeChildDefinition(mapSheetDefn);
    Record record2 = new Record(survey, "2.0", "cluster");
    ser.mergeFrom(data, record2.getRootEntity());
    // Compare
    Assert.assertTrue(record1.getRootEntity().deepEquals(record2.getRootEntity()));
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Test(org.junit.Test)

Example 30 with NodeDefinition

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

the class AttributeVM method generateEntityAlias.

@Command
public void generateEntityAlias() {
    AttributeDefinitionFormObject<?> fo = (AttributeDefinitionFormObject<?>) formObject;
    String referencedAttributePath = fo.getReferencedAttributePath();
    EntityDefinition sourceDef = editedItem.getParentEntityDefinition();
    String aliasName = sourceDef + "_alias";
    NodeDefinition referencedAttributeDef = editedItem.getDefinitionByPath(referencedAttributePath);
    EntityDefinition parentDef = referencedAttributeDef.getNearestAncestorMultipleEntity();
    if (parentDef.containsChildDefinition(aliasName)) {
        MessageUtil.showError("survey.schema.attribute.generate_entity_alias.error.alias_already_existing", aliasName, parentDef.getName());
    } else {
        EntityDefinition aliasDef = schemaUpdater.generateAlias(sourceDef, editedItem.getName(), parentDef, referencedAttributeDef.getName());
        ((CollectSurvey) aliasDef.getSurvey()).getUIOptions().setLayout(aliasDef, Layout.TABLE);
        aliasDef.rename(aliasName);
        dispatchSchemaChangedCommand();
        MessageUtil.showInfo("survey.schema.attribute.generate_entity_alias.generation_successfull", aliasName, parentDef.getName());
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) AttributeDefinitionFormObject(org.openforis.collect.designer.form.AttributeDefinitionFormObject) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

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