Search in sources :

Example 1 with ProcessStepProgressListener

use of org.openforis.concurrency.ProcessStepProgressListener in project collect by openforis.

the class RDBReportingRepositories method createRepositories.

@Override
public void createRepositories(String surveyName, String preferredLanguage, ProgressListener progressListener) {
    initializeRelationalSchemaDefinition(surveyName);
    ProcessProgressListener processProgressListener = new ProcessProgressListener(RecordStep.values().length);
    for (RecordStep step : RecordStep.values()) {
        try {
            createRepository(surveyName, step, preferredLanguage, new ProcessStepProgressListener(processProgressListener, progressListener));
            processProgressListener.stepCompleted();
        } catch (CollectRdbException e) {
            LOG.error("Error generating RDB for survey " + surveyName, e);
        }
    }
    updateMondrianSchemaFile(surveyName, preferredLanguage);
    writeSaikuDatasources(surveyName);
}
Also used : RecordStep(org.openforis.collect.event.RecordStep) ProcessStepProgressListener(org.openforis.concurrency.ProcessStepProgressListener) ProcessProgressListener(org.openforis.concurrency.ProcessProgressListener)

Example 2 with ProcessStepProgressListener

use of org.openforis.concurrency.ProcessStepProgressListener in project collect by openforis.

the class CollectRDBPublisher method insertData.

private void insertData(final CollectSurvey survey, String rootEntityName, final Step step, Connection targetConn, RelationalSchema relationalSchema, ProgressListener progressListener) throws IOException {
    // Insert data
    RecordFilter recordFilter = new RecordFilter(survey);
    recordFilter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntityName).getId());
    recordFilter.setStepGreaterOrEqual(step);
    final int total = recordManager.countRecords(recordFilter);
    if (LOG.isInfoEnabled()) {
        LOG.info("Total records: " + total);
    }
    final DatabaseExporter databaseExporter = createDatabaseExporter(relationalSchema, targetConn);
    ProcessProgressListener totalProgressListener = new ProcessProgressListener(2);
    databaseExporter.insertReferenceData(new ProcessStepProgressListener(totalProgressListener, progressListener));
    final ProcessStepProgressListener insertRecordsProgressListener = new ProcessStepProgressListener(totalProgressListener, progressListener);
    final AtomicInteger count = new AtomicInteger();
    recordManager.visitSummaries(recordFilter, null, new Visitor<CollectRecordSummary>() {

        public void visit(CollectRecordSummary summary) {
            try {
                CollectRecord record = recordManager.load(survey, summary.getId(), step, false);
                databaseExporter.insertRecordData(record, ProgressListener.NULL_PROGRESS_LISTENER);
            } catch (CollectRdbException e) {
                LOG.error(e.getMessage(), e);
            }
            insertRecordsProgressListener.progressMade(new Progress(count.addAndGet(1), total));
        }
    });
    databaseExporter.close();
    if (LOG.isInfoEnabled()) {
        LOG.info("All records exported");
        LOG.info("Adding constraints and indexes...");
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Progress(org.openforis.concurrency.Progress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JooqDatabaseExporter(org.openforis.collect.relational.jooq.JooqDatabaseExporter) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) ProcessStepProgressListener(org.openforis.concurrency.ProcessStepProgressListener) ProcessProgressListener(org.openforis.concurrency.ProcessProgressListener) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 3 with ProcessStepProgressListener

use of org.openforis.concurrency.ProcessStepProgressListener in project collect by openforis.

the class RDBReportingRepositories method insertRecords.

private void insertRecords(String surveyName, RecordStep recordStep, RelationalSchema targetSchema, Connection targetConn, ProgressListener progressListener) throws CollectRdbException {
    ProcessProgressListener processProgressListener = new ProcessProgressListener(2);
    CollectSurvey survey = surveyManager.get(surveyName);
    DatabaseExporter databaseUpdater = createRDBUpdater(targetSchema, targetConn);
    databaseUpdater.insertReferenceData(new ProcessStepProgressListener(processProgressListener, progressListener));
    processProgressListener.stepCompleted();
    RecordFilter recordFilter = new RecordFilter(survey);
    Step step = Step.fromRecordStep(recordStep);
    recordFilter.setStepGreaterOrEqual(step);
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(recordFilter);
    ProcessStepProgressListener recordInsertProcessListener = new ProcessStepProgressListener(processProgressListener, progressListener);
    recordInsertProcessListener.progressMade(new Progress(0, summaries.size()));
    long processedRecords = 0;
    for (CollectRecordSummary summary : summaries) {
        CollectRecord record = recordManager.load(survey, summary.getId(), step, false);
        databaseUpdater.insertRecordData(record, ProgressListener.NULL_PROGRESS_LISTENER);
        processedRecords++;
        recordInsertProcessListener.progressMade(new Progress(processedRecords, summaries.size()));
    }
    IOUtils.closeQuietly(databaseUpdater);
    processProgressListener.stepCompleted();
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Progress(org.openforis.concurrency.Progress) JooqDatabaseExporter(org.openforis.collect.relational.jooq.JooqDatabaseExporter) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) ProcessStepProgressListener(org.openforis.concurrency.ProcessStepProgressListener) ProcessProgressListener(org.openforis.concurrency.ProcessProgressListener) RecordStep(org.openforis.collect.event.RecordStep) Step(org.openforis.collect.model.CollectRecord.Step) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter)

Aggregations

ProcessProgressListener (org.openforis.concurrency.ProcessProgressListener)3 ProcessStepProgressListener (org.openforis.concurrency.ProcessStepProgressListener)3 RecordStep (org.openforis.collect.event.RecordStep)2 CollectRecord (org.openforis.collect.model.CollectRecord)2 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)2 RecordFilter (org.openforis.collect.model.RecordFilter)2 JooqDatabaseExporter (org.openforis.collect.relational.jooq.JooqDatabaseExporter)2 Progress (org.openforis.concurrency.Progress)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Step (org.openforis.collect.model.CollectRecord.Step)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1