Search in sources :

Example 1 with RealValue

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

the class DataReportGeneratorIntegrationTest method testSimpleErrorReport.

@Test
public void testSimpleErrorReport() {
    EntityDefinition treeDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree");
    NumberAttributeDefinition dbhDef = (NumberAttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/dbh");
    DataQuery query = dataQuery().title("Find trees with invalid DBH").entity(treeDef).attribute(dbhDef).conditions("dbh > 20").type(invalidAttributeErrorType).severity(ErrorSeverity.ERROR).build();
    dataQueryManager.save(query, adminUser);
    DataQueryGroup queryGroup = new DataQueryGroup(survey);
    queryGroup.setTitle("Simple query group");
    queryGroup.addQuery(query);
    dataQueryGroupManager.save(queryGroup, adminUser);
    DataReportGeneratorJob job = jobManager.createJob(DataReportGeneratorJob.class);
    job.setQueryGroup(queryGroup);
    job.setRecordStep(Step.ENTRY);
    job.setActiveUser(adminUser);
    jobManager.start(job, false);
    DataReport report = job.getReport();
    DataReport reloadedReport = dataReportManager.loadById(survey, report.getId());
    List<DataReportItem> items = dataReportManager.loadItems(reloadedReport, 0, 100);
    assertFalse(items.isEmpty());
    assertEquals(1, items.size());
    DataReportItem item = items.get(0);
    CollectRecord record = recordManager.load(survey, item.getRecordId());
    assertEquals(Arrays.asList("10_117"), record.getRootEntityKeyValues());
    assertEquals(new RealValue(30.0d, dbhDef.getDefaultUnit()), item.extractAttributeValue());
}
Also used : RealValue(org.openforis.idm.model.RealValue) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) Test(org.junit.Test)

Example 2 with RealValue

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

the class ComparisonExpressionTest method testLtEqOnNumber.

@Test
public void testLtEqOnNumber() throws InvalidExpressionException {
    distanceToForest.setValue(new RealValue(8.98));
    distanceToForest.updateSummaryInfo();
    Assert.assertTrue(evaluateExpression(household, "distance_to_forest <= 10"));
}
Also used : RealValue(org.openforis.idm.model.RealValue) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 3 with RealValue

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

the class ComparisonExpressionTest method testGtOnNumber.

@Test
public void testGtOnNumber() throws InvalidExpressionException {
    distanceToForest.setValue(new RealValue(23.5));
    distanceToForest.updateSummaryInfo();
    Assert.assertTrue(evaluateExpression(household, "distance_to_forest > 10"));
}
Also used : RealValue(org.openforis.idm.model.RealValue) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 4 with RealValue

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

the class ComparisonExpressionTest method testEqOnNumber.

@Test
public void testEqOnNumber() throws InvalidExpressionException {
    distanceToForest.setValue(new RealValue(10.0));
    distanceToForest.updateSummaryInfo();
    Assert.assertTrue(evaluateExpression(household, "distance_to_forest = 10"));
}
Also used : RealValue(org.openforis.idm.model.RealValue) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 5 with RealValue

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

the class CSVDataImportJobIntegrationTest method newRecordsTest.

@Test
public void newRecordsTest() throws Exception {
    EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
    CSVDataImportJob process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId(), true, true, "2.0");
    assertTrue(process.isCompleted());
    assertTrue(process.getParsingErrors().isEmpty());
    {
        CollectRecord reloadedRecord = loadRecord("10_111");
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(200d), plotDistanceVal.getValue());
        assertEquals(meterUnit, plotDistanceVal.getUnit());
    }
    {
        CollectRecord reloadedRecord = loadRecord("10_114");
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(0.3d), plotDistanceVal.getValue());
        assertEquals(kilometerUnit, plotDistanceVal.getUnit());
    }
}
Also used : RealValue(org.openforis.idm.model.RealValue) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Aggregations

RealValue (org.openforis.idm.model.RealValue)14 Test (org.junit.Test)11 CollectRecord (org.openforis.collect.model.CollectRecord)7 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)7 AbstractTest (org.openforis.idm.AbstractTest)6 Entity (org.openforis.idm.model.Entity)6 RealAttribute (org.openforis.idm.model.RealAttribute)6 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)4 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)4 TextAttribute (org.openforis.idm.model.TextAttribute)2 DataParsingError (org.openforis.collect.io.data.CSVDataImportJob.DataParsingError)1 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)1 Unit (org.openforis.idm.metamodel.Unit)1