Search in sources :

Example 51 with RecordFilter

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

the class RecordManager method loadUniqueRecordSummaryByKeys.

public CollectRecordSummary loadUniqueRecordSummaryByKeys(CollectSurvey survey, String rootEntityName, String... keyValues) {
    RecordFilter filter = new RecordFilter(survey);
    filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntityName).getId());
    filter.setKeyValues(keyValues);
    List<CollectRecordSummary> oldRecords = loadSummaries(filter);
    if (oldRecords == null || oldRecords.isEmpty()) {
        return null;
    } else if (oldRecords.size() == 1) {
        return oldRecords.get(0);
    } else {
        throw new IllegalStateException(String.format("Multiple records found in survey %s with key(s): %s", survey.getName(), keyValues));
    }
}
Also used : CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 52 with RecordFilter

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

the class DataQueryExectutorTask method countTotalItems.

@Override
protected long countTotalItems() {
    RecordFilter recordsFilter = createRecordsFilter(false);
    int count = recordManager.countRecords(recordsFilter);
    return count;
}
Also used : RecordFilter(org.openforis.collect.model.RecordFilter)

Example 53 with RecordFilter

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

the class DataQueryExectutorTask method execute.

@Override
@Transactional
protected void execute() throws Throwable {
    CollectSurvey survey = input.query.getSurvey();
    DataQueryEvaluator queryEvaluator = createQueryEvaluator(input.query);
    RecordFilter filter = createRecordsFilter(true);
    List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(filter);
    Iterator<CollectRecordSummary> it = recordSummaries.iterator();
    while (it.hasNext() && isRunning()) {
        CollectRecordSummary recordSummary = (CollectRecordSummary) it.next();
        CollectRecord record = recordManager.load(survey, recordSummary.getId(), input.step, false);
        List<Node<?>> nodes = queryEvaluator.evaluate(record);
        for (Node<?> node : nodes) {
            processNode(node);
        }
        incrementProcessedItems();
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Node(org.openforis.idm.model.Node) CollectSurvey(org.openforis.collect.model.CollectSurvey) XPathDataQueryEvaluator(org.openforis.collect.datacleansing.xpath.XPathDataQueryEvaluator) RecordFilter(org.openforis.collect.model.RecordFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 54 with RecordFilter

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

the class DataQueryGroupExectutorTask method execute.

@Override
@Transactional
protected void execute() throws Throwable {
    CollectSurvey survey = input.getSurvey();
    RecordFilter filter = createRecordsFilter();
    List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(filter);
    Iterator<CollectRecordSummary> it = recordSummaries.iterator();
    while (it.hasNext() && isRunning()) {
        CollectRecordSummary recordSummary = (CollectRecordSummary) it.next();
        Date modifiedDate = recordSummary.getModifiedDate();
        if (lastRecordModifiedDate == null) {
            lastRecordModifiedDate = modifiedDate;
        } else if (modifiedDate.compareTo(lastRecordModifiedDate) > 0) {
            lastRecordModifiedDate = modifiedDate;
        }
        CollectRecord record = recordManager.load(survey, recordSummary.getId(), input.step, false);
        List<DataQuery> queries = input.getQueries();
        for (DataQuery query : queries) {
            DataQueryEvaluator queryEvaluator = createQueryEvaluator(query);
            List<Node<?>> nodes = queryEvaluator.evaluate(record);
            for (Node<?> node : nodes) {
                processNode(query, node);
            }
        }
        incrementProcessedItems();
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Node(org.openforis.idm.model.Node) Date(java.util.Date) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) XPathDataQueryEvaluator(org.openforis.collect.datacleansing.xpath.XPathDataQueryEvaluator) Transactional(org.springframework.transaction.annotation.Transactional)

Example 55 with RecordFilter

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

the class DataCleansingChainExectutorTask method createRecordsFilter.

private RecordFilter createRecordsFilter() {
    CollectSurvey survey = input.chain.getSurvey();
    EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
    Integer rootEntityId = rootEntityDef.getId();
    RecordFilter filter = new RecordFilter(survey);
    filter.setStep(input.step);
    filter.setRootEntityId(rootEntityId);
    filter.setOffset(0);
    filter.setMaxNumberOfRecords(input.maxRecords);
    return filter;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter)

Aggregations

RecordFilter (org.openforis.collect.model.RecordFilter)66 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)33 CollectSurvey (org.openforis.collect.model.CollectSurvey)27 CollectRecord (org.openforis.collect.model.CollectRecord)14 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Date (java.util.Date)10 User (org.openforis.collect.model.User)10 SessionState (org.openforis.collect.web.session.SessionState)7 Transactional (org.springframework.transaction.annotation.Transactional)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 File (java.io.File)5 HashMap (java.util.HashMap)5 CSVDataExportParameters (org.openforis.collect.io.data.csv.CSVDataExportParameters)5 Step (org.openforis.collect.model.CollectRecord.Step)5 IOException (java.io.IOException)4 SurveyBackupJob (org.openforis.collect.io.SurveyBackupJob)4 CSVDataExportJob (org.openforis.collect.io.data.CSVDataExportJob)4 Schema (org.openforis.idm.metamodel.Schema)4 Test (org.junit.Test)3