Search in sources :

Example 26 with RecordFilter

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

the class RecordIndexManager method indexAllRecords.

public void indexAllRecords(CollectSurvey survey, String rootEntity) throws RecordIndexException {
    cancelled = false;
    RecordFilter filter = new RecordFilter(survey);
    filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntity).getId());
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
    IndexWriter indexWriter = null;
    try {
        indexWriter = createIndexWriter();
        for (CollectRecordSummary s : summaries) {
            if (!cancelled) {
                Integer recordId = s.getId();
                deleteDocuments(indexWriter, recordId);
                CollectRecord record = recordManager.load(survey, recordId, s.getStep());
                index(indexWriter, record);
            } else {
                break;
            }
        }
    } catch (Exception e) {
        throw new RecordIndexException(e);
    } finally {
        close(indexWriter);
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) IndexWriter(org.apache.lucene.index.IndexWriter) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter) ParseException(org.apache.lucene.queryParser.ParseException) IOException(java.io.IOException)

Example 27 with RecordFilter

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

the class RecordManager method isUnique.

/**
 * Returns false if another record with the same root entity key values exists.
 */
public boolean isUnique(CollectRecord record) {
    record.updateSummaryFields();
    CollectSurvey survey = (CollectSurvey) record.getSurvey();
    RecordFilter filter = new RecordFilter(survey, record.getRootEntityDefinitionId());
    filter.setKeyValues(record.getRootEntityKeyValues());
    filter.setIncludeNullConditionsForKeyValues(true);
    List<CollectRecordSummary> summaries = recordDao.loadSummaries(filter);
    for (CollectRecordSummary s : summaries) {
        if (!s.getId().equals(record.getId())) {
            return false;
        }
    }
    return true;
}
Also used : CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 28 with RecordFilter

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

the class RecordManager method determineLastStep.

private Step determineLastStep(CollectSurvey survey, int recordId) {
    RecordFilter filter = new RecordFilter(survey);
    filter.setRecordId(recordId);
    List<CollectRecordSummary> summaries = recordDao.loadSummaries(filter, null);
    if (summaries.isEmpty()) {
        return null;
    } else {
        CollectRecordSummary summary = summaries.get(0);
        return summary.getStep();
    }
}
Also used : CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 29 with RecordFilter

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

the class RecordValidationProcess method startProcessing.

@Override
@Transactional(propagation = Propagation.SUPPORTS)
public void startProcessing() throws Exception {
    super.startProcessing();
    validateParameters();
    status.setTotal(recordManager.countRecords(new RecordFilter(survey)));
    Schema schema = survey.getSchema();
    List<EntityDefinition> rootEntities = schema.getRootEntityDefinitions();
    for (EntityDefinition rootEntityDef : rootEntities) {
        RecordFilter filter = new RecordFilter(survey, rootEntityDef.getId());
        List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
        for (CollectRecordSummary summary : summaries) {
            // print(outputStream, "Start validating record: " + recordKey);
            if (status.isRunning()) {
                Step step = summary.getStep();
                Integer recordId = summary.getId();
                recordManager.validateAndSave(survey, user, sessionId, recordId, step);
                status.incrementProcessed();
            // long elapsedMillis = System.currentTimeMillis() - start;
            // print(outputStream, "Validation of record " + recordKey + " completed in " + elapsedMillis + " millis");
            }
        }
    }
    if (status.isRunning()) {
        status.complete();
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Schema(org.openforis.idm.metamodel.Schema) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Step(org.openforis.collect.model.CollectRecord.Step) RecordFilter(org.openforis.collect.model.RecordFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with RecordFilter

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

the class DataQueryController method startExport.

@RequestMapping(value = "start-export.json", method = RequestMethod.POST)
@ResponseBody
public Response startExport(@Validated DataQueryForm form, @RequestParam Step recordStep) throws Exception {
    CollectSurvey survey = sessionManager.getActiveSurvey();
    DataQuery query = new DataQuery(survey);
    form.copyTo(query);
    exportJob = collectJobManager.createJob(CSVDataExportJob.class);
    exportJob.setOutputFile(File.createTempFile("data-query-export", ".csv"));
    CSVDataExportParameters parameters = new CSVDataExportParameters();
    RecordFilter recordFilter = new RecordFilter(survey);
    recordFilter.setStepGreaterOrEqual(recordStep);
    parameters.setRecordFilter(recordFilter);
    parameters.setEntityId(query.getEntityDefinitionId());
    parameters.setAlwaysGenerateZipFile(false);
    parameters.setNodeFilter(new DescendantNodeFilter(query.getAttributeDefinition(), query.getConditions()));
    exportJob.setParameters(parameters);
    collectJobManager.start(exportJob);
    /*
		csvExportItemProcessor = new CSVWriterDataQueryResultItemProcessor(query);
		csvExportItemProcessor.init();
		exportJob = collectJobManager.createJob(DataQueryExecutorJob.class);
		exportJob.setInput(new DataQueryExecutorJobInput(query, recordStep, csvExportItemProcessor));
		collectJobManager.start(exportJob);
		*/
    Response response = new Response();
    return response;
}
Also used : Response(org.openforis.commons.web.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) DescendantNodeFilter(org.openforis.collect.io.data.DescendantNodeFilter) DataQuery(org.openforis.collect.datacleansing.DataQuery) CSVDataExportJob(org.openforis.collect.io.data.CSVDataExportJob) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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