Search in sources :

Example 1 with Progress

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

the class JooqDatabaseExporter method insertReferenceData.

@Override
public void insertReferenceData(ProgressListener progressListener) {
    List<CodeTable> codeListTables = schema.getCodeListTables();
    long totalItems = codeListTables.size();
    long processedItems = 0;
    for (CodeTable codeTable : codeListTables) {
        DataExtractor extractor = DataExtractorFactory.getExtractor(codeTable);
        batchExecutor.executeInserts(extractor);
        processedItems++;
        progressListener.progressMade(new Progress(processedItems, totalItems));
    }
}
Also used : CodeTable(org.openforis.collect.relational.model.CodeTable) Progress(org.openforis.concurrency.Progress) DataExtractor(org.openforis.collect.relational.data.DataExtractor)

Example 2 with Progress

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

the class ZipFiles method extract.

public static void extract(ZipFile zipFile, File destinationFolder, ProgressListener progressListener) throws IOException {
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    if (progressListener != null) {
        progressListener.progressMade(new Progress(0, zipFile.size()));
    }
    int count = 0;
    while (entries.hasMoreElements()) {
        ZipEntry zipEntry = entries.nextElement();
        if (!zipEntry.isDirectory()) {
            String entryName = zipEntry.getName();
            File folder = getOrCreateEntryFolder(destinationFolder, entryName);
            String fileName = Files.extractFileName(entryName);
            File newFile = new File(folder, fileName);
            newFile.createNewFile();
            InputStream is = zipFile.getInputStream(zipEntry);
            FileUtils.copyInputStreamToFile(is, newFile);
        }
        count++;
        if (progressListener != null) {
            progressListener.progressMade(new Progress(count, zipFile.size()));
        }
    }
}
Also used : Progress(org.openforis.concurrency.Progress) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 3 with Progress

use of org.openforis.concurrency.Progress 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 4 with Progress

use of org.openforis.concurrency.Progress 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)

Example 5 with Progress

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

the class ReportingRepositoriesGeneratorJob method buildTasks.

@Override
protected void buildTasks() throws Throwable {
    addTask(new Task() {

        protected void execute() throws Throwable {
            reportingRepositories.createRepositories(survey.getName(), input.getLanguage(), new ProgressListener() {

                public void progressMade(Progress progress) {
                    setProcessedItems(progress.getProcessedItems());
                    setTotalItems(progress.getTotalItems());
                }
            });
        }
    });
}
Also used : Task(org.openforis.concurrency.Task) Progress(org.openforis.concurrency.Progress) ProgressListener(org.openforis.concurrency.ProgressListener)

Aggregations

Progress (org.openforis.concurrency.Progress)5 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 ProcessProgressListener (org.openforis.concurrency.ProcessProgressListener)2 ProcessStepProgressListener (org.openforis.concurrency.ProcessStepProgressListener)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 RecordStep (org.openforis.collect.event.RecordStep)1 Step (org.openforis.collect.model.CollectRecord.Step)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 DataExtractor (org.openforis.collect.relational.data.DataExtractor)1 CodeTable (org.openforis.collect.relational.model.CodeTable)1 ProgressListener (org.openforis.concurrency.ProgressListener)1 Task (org.openforis.concurrency.Task)1