Search in sources :

Example 1 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class DataExportService method fullExport.

@Transactional
public Proxy fullExport(boolean includeRecordFiles, boolean onlyOwnedRecords, String[] rootEntityKeyValues) {
    SessionState sessionState = sessionManager.getSessionState();
    CollectSurvey survey = sessionState.getActiveSurvey();
    return fullExport(survey, includeRecordFiles, onlyOwnedRecords, rootEntityKeyValues, false);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectSurvey(org.openforis.collect.model.CollectSurvey) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class DataExportService 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 3 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class DataExportService method export.

@Transactional
public Proxy export(String rootEntityName, int stepNumber, Integer entityId, boolean includeAllAncestorAttributes, boolean includeEnumeratedEntities, boolean includeCompositeAttributeMergedColumn, boolean codeAttributeExpanded, boolean onlyOwnedRecords, String[] rootEntityKeyValues, boolean includeKMLColumnForCoordinates, boolean includeCodeItemLabelColumn, String headingSource, String languageCode, boolean includeGroupingLabels) throws IOException {
    if (dataExportProcess == null || !dataExportProcess.getStatus().isRunning()) {
        resetJobs();
        SessionState sessionState = sessionManager.getSessionState();
        CollectSurvey survey = sessionState.getActiveSurvey();
        File outputFile = File.createTempFile("collect_data_export_" + survey.getName(), ".zip");
        Step step = Step.valueOf(stepNumber);
        // prepare record filter
        Schema schema = survey.getSchema();
        EntityDefinition rootEntityDefn = schema.getRootEntityDefinition(rootEntityName);
        RecordFilter recordFilter = createRecordFilter(survey, rootEntityDefn.getId(), onlyOwnedRecords, rootEntityKeyValues);
        // filter by record step
        recordFilter.setStepGreaterOrEqual(step);
        // instantiate process
        CSVDataExportProcess process = appContext.getBean(CSVDataExportProcess.class);
        process.setOutputFile(outputFile);
        process.setRecordFilter(recordFilter);
        process.setEntityId(entityId);
        process.setAlwaysGenerateZipFile(true);
        CSVDataExportParameters config = new CSVDataExportParameters();
        config.setIncludeAllAncestorAttributes(includeAllAncestorAttributes);
        config.setIncludeEnumeratedEntities(includeEnumeratedEntities);
        config.setIncludeCompositeAttributeMergedColumn(includeCompositeAttributeMergedColumn);
        config.setIncludeKMLColumnForCoordinates(includeKMLColumnForCoordinates);
        config.setCodeAttributeExpanded(codeAttributeExpanded);
        config.setIncludeCodeItemLabelColumn(includeCodeItemLabelColumn);
        config.setHeadingSource(HeadingSource.valueOf(headingSource));
        config.setLanguageCode(languageCode);
        config.setIncludeGroupingLabels(includeGroupingLabels);
        process.setConfiguration(config);
        process.init();
        // start process
        dataExportProcess = process;
        ExecutorServiceUtil.executeInCachedPool(process);
    }
    return getCurrentJob();
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CSVDataExportProcess(org.openforis.collect.io.data.CSVDataExportProcess) Schema(org.openforis.idm.metamodel.Schema) Step(org.openforis.collect.model.CollectRecord.Step) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) CollectSurvey(org.openforis.collect.model.CollectSurvey) File(java.io.File) RecordFilter(org.openforis.collect.model.RecordFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class DataService method loadRecordSummaries.

/**
 * @param rootEntityName
 * @param offset
 * @param toIndex
 * @param orderByFieldName
 * @param filter
 *
 * @return map with "count" and "records" items
 */
@Secured(USER)
public Map<String, Object> loadRecordSummaries(String rootEntityName, int offset, int maxNumberOfRows, List<RecordSummarySortField> sortFields, String[] keyValues) {
    Map<String, Object> result = new HashMap<String, Object>();
    SessionState sessionState = sessionManager.getSessionState();
    CollectSurvey activeSurvey = sessionState.getActiveSurvey();
    Schema schema = activeSurvey.getSchema();
    EntityDefinition rootEntityDefinition = schema.getRootEntityDefinition(rootEntityName);
    RecordFilter filter = new RecordFilter(activeSurvey, rootEntityDefinition.getId());
    filter.setKeyValues(keyValues);
    filter.setOffset(offset);
    filter.setMaxNumberOfRecords(maxNumberOfRows);
    // load summaries
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter, sortFields);
    List<RecordSummaryProxy> proxies = RecordSummaryProxy.fromList(summaries, getProxyContext());
    result.put("records", proxies);
    // count total records
    int count = recordManager.countRecords(filter);
    result.put("count", count);
    return result;
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) HashMap(java.util.HashMap) Schema(org.openforis.idm.metamodel.Schema) RecordSummaryProxy(org.openforis.collect.model.proxy.RecordSummaryProxy) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) 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 5 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class DataService method loadRecord.

@Secured(USER)
public RecordProxy loadRecord(int id, Integer stepNumber) {
    SessionState sessionState = sessionManager.getSessionState();
    final CollectSurvey survey = sessionState.getActiveSurvey();
    Step step = stepNumber == null ? null : Step.valueOf(stepNumber);
    CollectRecord record = step == null ? recordManager.load(survey, id) : recordManager.load(survey, id, step);
    sessionManager.setActiveRecord(record);
    return toProxy(record);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) RecordStep(org.openforis.collect.event.RecordStep) Step(org.openforis.collect.model.CollectRecord.Step) CollectSurvey(org.openforis.collect.model.CollectSurvey) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

SessionState (org.openforis.collect.web.session.SessionState)44 CollectSurvey (org.openforis.collect.model.CollectSurvey)18 User (org.openforis.collect.model.User)16 CollectRecord (org.openforis.collect.model.CollectRecord)15 Secured (org.springframework.security.access.annotation.Secured)13 Step (org.openforis.collect.model.CollectRecord.Step)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 RecordFilter (org.openforis.collect.model.RecordFilter)7 Locale (java.util.Locale)5 RecordStep (org.openforis.collect.event.RecordStep)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 File (java.io.File)3 HashMap (java.util.HashMap)3 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)3 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)3 Transactional (org.springframework.transaction.annotation.Transactional)3 IOException (java.io.IOException)2 Date (java.util.Date)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 BulkRecordMoveJob (org.openforis.collect.io.data.BulkRecordMoveJob)2