Search in sources :

Example 6 with TextAttribute

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

the class CSVDataImportJobIntegrationTest method validTest.

@Test
public void validTest() throws Exception {
    {
        CollectRecord record = createTestRecord(survey, "10_111");
        recordDao.insert(record);
        assertEquals(Integer.valueOf(0), record.getErrors());
    }
    {
        CollectRecord record = createTestRecord(survey, "10_114");
        recordDao.insert(record);
    }
    EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
    CSVDataImportJob process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId());
    assertTrue(process.isCompleted());
    assertTrue(process.getParsingErrors().isEmpty());
    {
        CollectRecord reloadedRecord = loadRecord("10_111");
        assertEquals(Integer.valueOf(1), reloadedRecord.getErrors());
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDirection = (RealAttribute) cluster.getChild("plot_direction");
        RealValue plotDirectionVal = plotDirection.getValue();
        assertEquals(Double.valueOf(50d), plotDirectionVal.getValue());
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(200d), plotDistanceVal.getValue());
        assertEquals(meterUnit, plotDistanceVal.getUnit());
        TextAttribute gpsModel = (TextAttribute) cluster.getChild("gps_model");
        assertEquals("GPS MAP 62S", gpsModel.getValue().getValue());
        assertEquals(2, cluster.getCount("map_sheet"));
        {
            TextAttribute mapSheet = (TextAttribute) cluster.getChild("map_sheet", 0);
            assertEquals("new map sheet 1", mapSheet.getValue().getValue());
        }
        {
            TextAttribute mapSheet = (TextAttribute) cluster.getChild("map_sheet", 1);
            assertEquals("new map sheet 2", mapSheet.getValue().getValue());
        }
    }
    {
        CollectRecord reloadedRecord = loadRecord("10_114");
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDirection = (RealAttribute) cluster.getChild("plot_direction");
        RealValue plotDirectionVal = plotDirection.getValue();
        assertEquals(Double.valueOf(40d), plotDirectionVal.getValue());
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(0.3d), plotDistanceVal.getValue());
        assertEquals(kilometerUnit, plotDistanceVal.getUnit());
        TextAttribute gpsModel = (TextAttribute) cluster.getChild("gps_model");
        assertEquals("GPS MAP 62S", gpsModel.getValue().getValue());
    }
}
Also used : RealValue(org.openforis.idm.model.RealValue) CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) TextAttribute(org.openforis.idm.model.TextAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 7 with TextAttribute

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

the class TextAttributeMapper method setFields.

@Override
void setFields(Node<?> node, InsertSetStep<?> insert) {
    TextAttribute t = (TextAttribute) node;
    String value = t.getValue();
    insert.set(Data.DATA.TEXT1, value);
}
Also used : TextAttribute(org.openforis.idm.model.TextAttribute)

Example 8 with TextAttribute

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

the class ComparisonCheckTest method testTextLtConstant.

@Test
public void testTextLtConstant() {
    ComparisonCheck check = new ComparisonCheck();
    check.setLessThanExpression("-1");
    TextAttribute mapSheet = EntityBuilder.addValue(cluster, "map_sheet", "1");
    ValidationResultFlag result = check.evaluate(mapSheet);
    assertEquals(ERROR, result);
}
Also used : TextAttribute(org.openforis.idm.model.TextAttribute) Test(org.junit.Test)

Example 9 with TextAttribute

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

the class ComparisonCheckTest method testTextGtConstant.

@Test
public void testTextGtConstant() throws Exception {
    ComparisonCheck check = new ComparisonCheck();
    check.setGreaterThanExpression("-1");
    TextAttribute mapSheet = EntityBuilder.addValue(cluster, "map_sheet", "1");
    ValidationResultFlag result = check.evaluate(mapSheet);
    assertEquals(OK, result);
}
Also used : TextAttribute(org.openforis.idm.model.TextAttribute) Test(org.junit.Test)

Example 10 with TextAttribute

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

the class RecordUpdaterTest method testInitializeCalculatedAttributeInNestedNode.

@Test
public void testInitializeCalculatedAttributeInNestedNode() {
    record(rootEntityDef(entityDef("details", attributeDef("accessibility")), entityDef("tree", attributeDef("angle"), attributeDef("height").calculated("number(angle) * 2"), attributeDef("double_height").calculated("number(height) * 2", "parent()/details/accessibility = 'true'")).multiple()), entity("details", NodeBuilder.attribute("accessibility", "true")), entity("tree", NodeBuilder.attribute("angle", "10")));
    TextAttribute doubleHeight = record.findNodeByPath("/root/tree[1]/double_height");
    assertEquals("40.0", ((TextValue) doubleHeight.getValue()).getValue());
}
Also used : TextAttribute(org.openforis.idm.model.TextAttribute) Test(org.junit.Test)

Aggregations

TextAttribute (org.openforis.idm.model.TextAttribute)20 Test (org.junit.Test)19 Entity (org.openforis.idm.model.Entity)5 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)2 CollectRecord (org.openforis.collect.model.CollectRecord)2 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)2 RealAttribute (org.openforis.idm.model.RealAttribute)2 RealValue (org.openforis.idm.model.RealValue)2 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)1