Search in sources :

Example 11 with CollectSurvey

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

the class DataQueryGroupExectutorTask method createRecordsFilter.

private RecordFilter createRecordsFilter() {
    CollectSurvey survey = input.getSurvey();
    RecordFilter filter = new RecordFilter(survey);
    filter.setStep(input.step);
    filter.setOffset(0);
    filter.setMaxNumberOfRecords(input.maxRecords);
    return filter;
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 12 with CollectSurvey

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

the class DataCleansingChainExectutorTask method execute.

@Override
@Transactional
protected void execute() throws Throwable {
    CollectSurvey survey = input.chain.getSurvey();
    RecordFilter filter = createRecordsFilter();
    List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(filter);
    datasetSize = recordSummaries.size();
    lastRecordModifiedDate = null;
    // Delete records in bulk if needed
    Set<Integer> recordIdsToBeDeleted = new TreeSet<Integer>();
    Iterator<CollectRecordSummary> it = recordSummaries.iterator();
    while (it.hasNext() && isRunning()) {
        CollectRecordSummary recordSummary = (CollectRecordSummary) it.next();
        udpateLastRecordModifiedDate(recordSummary);
        CollectRecord record = recordManager.load(survey, recordSummary.getId(), input.step, false);
        boolean recordCleansed = false;
        for (DataCleansingStep step : input.chain.getSteps()) {
            DataCleansingStepExecutionResult stepExecutionResult = executeStep(record, step);
            if (stepExecutionResult != null) {
                recordCleansed = true;
                if (stepExecutionResult == DataCleansingStepExecutionResult.RECORD_TO_BE_DELETED) {
                    recordIdsToBeDeleted.add(record.getId());
                    break;
                }
            }
        }
        if (recordCleansed) {
            cleansedRecords++;
        }
        incrementProcessedItems();
    }
    recordManager.deleteByIds(recordIdsToBeDeleted);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) TreeSet(java.util.TreeSet) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with CollectSurvey

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

the class CodeTableDataExtractor method getCodeListService.

private CodeListService getCodeListService() {
    CollectSurvey survey = (CollectSurvey) table.getCodeList().getSurvey();
    SurveyContext context = survey.getContext();
    CodeListService codeListService = context.getCodeListService();
    return codeListService;
}
Also used : CodeListService(org.openforis.idm.metamodel.CodeListService) CollectSurvey(org.openforis.collect.model.CollectSurvey) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 14 with CollectSurvey

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

use of org.openforis.collect.model.CollectSurvey 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)

Aggregations

CollectSurvey (org.openforis.collect.model.CollectSurvey)329 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)53 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)40 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)38 CollectRecord (org.openforis.collect.model.CollectRecord)30 RecordFilter (org.openforis.collect.model.RecordFilter)27 Transactional (org.springframework.transaction.annotation.Transactional)26 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)25 ArrayList (java.util.ArrayList)23 File (java.io.File)21 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)21 Secured (org.springframework.security.access.annotation.Secured)20 User (org.openforis.collect.model.User)19 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)19 SessionState (org.openforis.collect.web.session.SessionState)18 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)17 Test (org.junit.Test)16 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)15 CodeList (org.openforis.idm.metamodel.CodeList)15 Schema (org.openforis.idm.metamodel.Schema)15