Search in sources :

Example 61 with RecordFilter

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

the class DataService method loadRecordSummaries.

@Secured(USER)
public Map<String, Object> loadRecordSummaries(RecordFilterProxy filterProxy, List<RecordSummarySortField> sortFields, String localeStr) {
    Map<String, Object> result = new HashMap<String, Object>();
    CollectSurvey survey;
    if (filterProxy.getSurveyId() > 0) {
        survey = surveyManager.getById(filterProxy.getSurveyId());
    } else {
        SessionState sessionState = sessionManager.getSessionState();
        survey = sessionState.getActiveSurvey();
    }
    RecordFilter filter = filterProxy.toFilter(survey);
    // load summaries
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter, sortFields);
    Locale locale = LocaleUtils.toLocale(localeStr);
    ProxyContext proxyContext = new ProxyContext(locale, messageSource, surveyContext);
    List<RecordSummaryProxy> proxies = RecordSummaryProxy.fromList(summaries, proxyContext);
    result.put("records", proxies);
    // count total records
    int count = recordManager.countRecords(filter);
    result.put("count", count);
    return result;
}
Also used : Locale(java.util.Locale) SessionState(org.openforis.collect.web.session.SessionState) ProxyContext(org.openforis.collect.ProxyContext) HashMap(java.util.HashMap) RecordSummaryProxy(org.openforis.collect.model.proxy.RecordSummaryProxy) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) Secured(org.springframework.security.access.annotation.Secured)

Example 62 with RecordFilter

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

the class RDBReportingRepositories method getInfo.

@Override
public ReportingRepositoryInfo getInfo(String surveyName) {
    Date rdbFileDate = localRDBStorageManager.getRDBFileDate(surveyName, RecordStep.ENTRY);
    if (rdbFileDate == null) {
        return null;
    } else {
        ReportingRepositoryInfo info = new ReportingRepositoryInfo();
        info.setLastUpdate(rdbFileDate);
        RecordFilter filter = new RecordFilter(surveyManager.get(surveyName));
        filter.setModifiedSince(rdbFileDate);
        info.setUpdatedRecordsSinceLastUpdate(recordManager.countRecords(filter));
        return info;
    }
}
Also used : ReportingRepositoryInfo(org.openforis.collect.reporting.ReportingRepositoryInfo) Date(java.util.Date) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 63 with RecordFilter

use of org.openforis.collect.model.RecordFilter 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 64 with RecordFilter

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

the class BackupRestoreController method createRecordFilter.

private RecordFilter createRecordFilter(CollectSurvey survey, Integer rootEntityId, boolean onlyOwnedRecords, String[] rootEntityKeyValues) {
    RecordFilter recordFilter = new RecordFilter(survey, rootEntityId);
    // filter by record owner
    if (onlyOwnedRecords) {
        SessionState sessionState = sessionManager.getSessionState();
        User user = sessionState.getUser();
        recordFilter.setOwnerId(user.getId());
    }
    // filter by root entity keys
    recordFilter.setKeyValues(rootEntityKeyValues);
    return recordFilter;
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) User(org.openforis.collect.model.User) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 65 with RecordFilter

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

the class BackupRestoreController method startFullExport.

@Transactional
public JobProxy startFullExport(CollectSurvey survey, boolean includeRecordFiles, boolean onlyOwnedRecords, String[] rootEntityKeyValues, boolean full) {
    if (backupJob == null || !backupJob.isRunning()) {
        resetJobs();
        RecordFilter filter = createRecordFilter(survey, null, onlyOwnedRecords, rootEntityKeyValues);
        SurveyBackupJob job = jobManager.createJob(SurveyBackupJob.class);
        job.setFull(full);
        if (full) {
            job.setOutputFormat(OutputFormat.DESKTOP_FULL);
        } else {
            job.setOutputFormat(OutputFormat.ONLY_DATA);
        }
        job.setSurvey(survey);
        job.setIncludeData(true);
        job.setIncludeRecordFiles(includeRecordFiles);
        job.setRecordFilter(filter);
        backupJob = job;
        jobManager.start(job);
    }
    return getCurrentJob();
}
Also used : SurveyBackupJob(org.openforis.collect.io.SurveyBackupJob) RecordFilter(org.openforis.collect.model.RecordFilter) Transactional(org.springframework.transaction.annotation.Transactional)

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