use of org.openforis.concurrency.ProcessProgressListener 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);
}
use of org.openforis.concurrency.ProcessProgressListener 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...");
}
}
use of org.openforis.concurrency.ProcessProgressListener 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();
}
Aggregations