Search in sources :

Example 1 with NodeProcessor

use of org.openforis.collect.model.NodeProcessor in project collect by openforis.

the class DataCleansingChainIntegrationTest method countResults.

private int countResults(DataQuery query) {
    final List<Node<?>> nodes = new ArrayList<Node<?>>();
    DataQueryExecutorJob job = jobManager.createJob(DataQueryExecutorJob.class);
    DataQueryExecutorJobInput dataQueryExecutorJobInput = new DataQueryExecutorJobInput(query, Step.ENTRY, new NodeProcessor() {

        public void process(Node<?> node) throws Exception {
            nodes.add(node);
        }
    });
    job.setInput(dataQueryExecutorJobInput);
    jobManager.start(job, false);
    return nodes.size();
}
Also used : DataQueryExecutorJobInput(org.openforis.collect.datacleansing.DataQueryExecutorJob.DataQueryExecutorJobInput) NodeProcessor(org.openforis.collect.model.NodeProcessor) Node(org.openforis.idm.model.Node) ArrayList(java.util.ArrayList) IdmlParseException(org.openforis.idm.metamodel.xml.IdmlParseException) SurveyValidationException(org.openforis.collect.manager.exception.SurveyValidationException) SurveyImportException(org.openforis.collect.persistence.SurveyImportException)

Example 2 with NodeProcessor

use of org.openforis.collect.model.NodeProcessor in project collect by openforis.

the class QueryExecutorIntegrationTest method testSimpleQuery.

@Test
public void testSimpleQuery() {
    // select region from tree where dbh > 20
    DataQuery query = new DataQuery(survey);
    EntityDefinition treeDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree");
    AttributeDefinition dbhDef = (AttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/dbh");
    query.setEntityDefinition(treeDef);
    query.setAttributeDefinition(dbhDef);
    query.setConditions("dbh > 20");
    final List<Node<?>> nodes = new ArrayList<Node<?>>();
    DataQueryExecutorJob job = jobManager.createJob(DataQueryExecutorJob.class);
    DataQueryExecutorJobInput input = new DataQueryExecutorJobInput(query, Step.ENTRY, new NodeProcessor() {

        public void process(Node<?> node) {
            nodes.add(node);
        }
    });
    job.setInput(input);
    jobManager.start(job, false);
    assertFalse(nodes.isEmpty());
    // first result
    Node<?> node = nodes.get(0);
    assertTrue(node instanceof Attribute);
    CollectRecord record = (CollectRecord) node.getRecord();
    assertEquals(Arrays.asList("10_117"), record.getRootEntityKeyValues());
}
Also used : DataQueryExecutorJobInput(org.openforis.collect.datacleansing.DataQueryExecutorJob.DataQueryExecutorJobInput) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) NodeProcessor(org.openforis.collect.model.NodeProcessor) Attribute(org.openforis.idm.model.Attribute) Node(org.openforis.idm.model.Node) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 3 with NodeProcessor

use of org.openforis.collect.model.NodeProcessor in project collect by openforis.

the class GeoDataController method loadGeometryValues.

@RequestMapping(value = "survey/{surveyId}/data/geometries.json", method = GET)
@ResponseBody
public List<GeometryNodeInfo> loadGeometryValues(@PathVariable int surveyId, @RequestParam int attributeId, @RequestParam String srsId, @RequestParam int recordOffset, @RequestParam int maxNumberOfRecords) throws Exception {
    final List<GeometryNodeInfo> result = new ArrayList<GeometryNodeInfo>();
    CollectSurvey survey = surveyManager.loadSurvey(surveyId);
    processNodes(survey, recordOffset, maxNumberOfRecords, attributeId, new NodeProcessor() {

        public void process(Node<?> node) throws Exception {
            if (!node.isEmpty()) {
                result.add(new GeometryNodeInfo((TextAttribute) node));
            }
        }
    });
    return result;
}
Also used : NodeProcessor(org.openforis.collect.model.NodeProcessor) ArrayList(java.util.ArrayList) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ArrayList (java.util.ArrayList)3 NodeProcessor (org.openforis.collect.model.NodeProcessor)3 DataQueryExecutorJobInput (org.openforis.collect.datacleansing.DataQueryExecutorJob.DataQueryExecutorJobInput)2 Node (org.openforis.idm.model.Node)2 Test (org.junit.Test)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1 SurveyValidationException (org.openforis.collect.manager.exception.SurveyValidationException)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 SurveyImportException (org.openforis.collect.persistence.SurveyImportException)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 IdmlParseException (org.openforis.idm.metamodel.xml.IdmlParseException)1 Attribute (org.openforis.idm.model.Attribute)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1