Search in sources :

Example 1 with DataQueryExecutorJobInput

use of org.openforis.collect.datacleansing.DataQueryExecutorJob.DataQueryExecutorJobInput 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 DataQueryExecutorJobInput

use of org.openforis.collect.datacleansing.DataQueryExecutorJob.DataQueryExecutorJobInput 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 DataQueryExecutorJobInput

use of org.openforis.collect.datacleansing.DataQueryExecutorJob.DataQueryExecutorJobInput in project collect by openforis.

the class DataQueryController method startTest.

@RequestMapping(value = "start-test.json", method = RequestMethod.POST)
@ResponseBody
public Response startTest(@Validated DataQueryForm form, @RequestParam Step recordStep, BindingResult result) {
    List<ObjectError> errors = result.getAllErrors();
    if (errors.isEmpty()) {
        CollectSurvey survey = sessionManager.getActiveSurvey();
        DataQuery query = new DataQuery(survey);
        form.copyTo(query);
        testJob = collectJobManager.createJob(DataQueryExecutorJob.class);
        testJob.setInput(new DataQueryExecutorJobInput(query, recordStep, new MemoryStoreDataQueryResultItemProcessor(query), TEST_MAX_RECORDS));
        collectJobManager.start(testJob);
        return new Response();
    } else {
        return new SimpleFormUpdateResponse(errors);
    }
}
Also used : DataQueryExecutorJobInput(org.openforis.collect.datacleansing.DataQueryExecutorJob.DataQueryExecutorJobInput) Response(org.openforis.commons.web.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) ObjectError(org.springframework.validation.ObjectError) DataQueryExecutorJob(org.openforis.collect.datacleansing.DataQueryExecutorJob) DataQuery(org.openforis.collect.datacleansing.DataQuery) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DataQueryExecutorJobInput (org.openforis.collect.datacleansing.DataQueryExecutorJob.DataQueryExecutorJobInput)3 ArrayList (java.util.ArrayList)2 NodeProcessor (org.openforis.collect.model.NodeProcessor)2 Node (org.openforis.idm.model.Node)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Test (org.junit.Test)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1 DataQuery (org.openforis.collect.datacleansing.DataQuery)1 DataQueryExecutorJob (org.openforis.collect.datacleansing.DataQueryExecutorJob)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 Response (org.openforis.commons.web.Response)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 ObjectError (org.springframework.validation.ObjectError)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1