Search in sources :

Example 6 with CollectRecordSummary

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

the class DataBackupTask method execute.

@Override
protected void execute() throws Throwable {
    List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(recordFilter);
    if (CollectionUtils.isNotEmpty(recordSummaries) && steps != null && steps.length > 0) {
        for (CollectRecordSummary summary : recordSummaries) {
            for (Step step : steps) {
                if (isRunning()) {
                    if (step.getStepNumber() <= summary.getStep().getStepNumber()) {
                        backup(summary, step);
                        incrementProcessedItems();
                    }
                } else {
                    break;
                }
            }
            if (isRunning()) {
                writeSummaryEntry(summary);
            }
        }
    }
}
Also used : CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Step(org.openforis.collect.model.CollectRecord.Step)

Example 7 with CollectRecordSummary

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

the class XMLDataExportProcess method loadAllSummaries.

private List<CollectRecordSummary> loadAllSummaries() {
    RecordFilter filter = new RecordFilter(survey);
    filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntityName).getId());
    filter.setModifiedSince(modifiedSince);
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
    return summaries;
}
Also used : CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 8 with CollectRecordSummary

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

the class XMLDataExportProcess method startProcessing.

@Override
public void startProcessing() throws Exception {
    super.startProcessing();
    try {
        List<CollectRecordSummary> recordSummaries = loadAllSummaries();
        if (recordSummaries != null && steps != null && steps.length > 0) {
            if (outputFile.exists()) {
                outputFile.delete();
                outputFile.createNewFile();
            }
            FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
            ZipOutputStream zipOutputStream = new ZipOutputStream(bufferedOutputStream);
            backup(zipOutputStream, recordSummaries);
            zipOutputStream.flush();
            zipOutputStream.close();
        }
    } catch (Exception e) {
        status.error();
        LOG.error("Error during data export", e);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) RecordFileException(org.openforis.collect.manager.exception.RecordFileException) IOException(java.io.IOException)

Example 9 with CollectRecordSummary

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

the class XMLDataImportProcess method createDataImportSummary.

private void createDataImportSummary() throws DataImportExeption {
    try {
        state.setSubStep(SubStep.RUNNING);
        summary = null;
        packagedSurvey = extractPackagedSurvey();
        existingSurvey = loadExistingSurvey();
        validatePackagedSurvey();
        if (existingSurvey == null) {
            dataUnmarshaller = new DataUnmarshaller(packagedSurvey);
        } else {
            dataUnmarshaller = new DataUnmarshaller(existingSurvey, packagedSurvey);
        }
        Map<Step, Integer> totalPerStep = new HashMap<CollectRecord.Step, Integer>();
        for (Step step : Step.values()) {
            totalPerStep.put(step, 0);
        }
        Map<Integer, CollectRecord> packagedRecords = new HashMap<Integer, CollectRecord>();
        Map<Integer, List<Step>> packagedStepsPerRecord = new HashMap<Integer, List<Step>>();
        Map<String, List<NodeUnmarshallingError>> packagedSkippedFileErrors = new HashMap<String, List<NodeUnmarshallingError>>();
        Map<Integer, CollectRecordSummary> conflictingPackagedRecords = new HashMap<Integer, CollectRecordSummary>();
        Map<Integer, Map<Step, List<NodeUnmarshallingError>>> warnings = new HashMap<Integer, Map<Step, List<NodeUnmarshallingError>>>();
        state.setTotal(backupFileExtractor.size());
        state.resetCount();
        List<String> entryNames = backupFileExtractor.getEntryNames();
        for (String entryName : entryNames) {
            if (state.getSubStep() != DataImportState.SubStep.RUNNING) {
                break;
            }
            if (!RecordEntry.isValidRecordEntry(entryName)) {
                continue;
            }
            createSummaryForEntry(entryName, packagedSkippedFileErrors, packagedRecords, packagedStepsPerRecord, totalPerStep, conflictingPackagedRecords, warnings);
        }
        if (state.getSubStep() == SubStep.RUNNING) {
            String oldSurveyName = existingSurvey == null ? null : existingSurvey.getName();
            summary = createSummary(packagedSkippedFileErrors, oldSurveyName, totalPerStep, packagedRecords, packagedStepsPerRecord, conflictingPackagedRecords, warnings);
            state.setSubStep(DataImportState.SubStep.COMPLETE);
        }
        includesRecordFiles = backupFileExtractor.isIncludingRecordFiles();
    } catch (Exception e) {
        state.setSubStep(SubStep.ERROR);
        state.setErrorMessage(e.getMessage());
        LOG.error(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(backupFileExtractor);
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) HashMap(java.util.HashMap) NodeUnmarshallingError(org.openforis.collect.persistence.xml.NodeUnmarshallingError) MainStep(org.openforis.collect.io.data.DataImportState.MainStep) SubStep(org.openforis.collect.io.data.DataImportState.SubStep) Step(org.openforis.collect.model.CollectRecord.Step) IdmlParseException(org.openforis.idm.metamodel.xml.IdmlParseException) SurveyValidationException(org.openforis.collect.manager.exception.SurveyValidationException) ZipException(java.util.zip.ZipException) RecordPersistenceException(org.openforis.collect.persistence.RecordPersistenceException) IOException(java.io.IOException) DataUnmarshaller(org.openforis.collect.persistence.xml.DataUnmarshaller) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with CollectRecordSummary

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

the class XMLDataImportProcess method createSummary.

private DataImportSummary createSummary(Map<String, List<NodeUnmarshallingError>> packagedSkippedFileErrors, String surveyName, Map<Step, Integer> totalPerStep, Map<Integer, CollectRecord> packagedRecords, Map<Integer, List<Step>> packagedStepsPerRecord, Map<Integer, CollectRecordSummary> conflictingPackagedRecords, Map<Integer, Map<Step, List<NodeUnmarshallingError>>> warnings) {
    DataImportSummary summary = new DataImportSummary();
    summary.setSurveyName(surveyName);
    List<DataImportSummaryItem> recordsToImport = new ArrayList<DataImportSummaryItem>();
    Set<Integer> entryIds = packagedRecords.keySet();
    for (Integer entryId : entryIds) {
        CollectRecord record = packagedRecords.get(entryId);
        if (!conflictingPackagedRecords.containsKey(entryId)) {
            List<Step> steps = packagedStepsPerRecord.get(entryId);
            DataImportSummaryItem item = new DataImportSummaryItem(entryId, CollectRecordSummary.fromRecord(record), steps);
            item.setWarnings(warnings.get(entryId));
            recordsToImport.add(item);
        }
    }
    List<DataImportSummaryItem> conflictingRecordItems = new ArrayList<DataImportSummaryItem>();
    Set<Integer> conflictingEntryIds = conflictingPackagedRecords.keySet();
    for (Integer entryId : conflictingEntryIds) {
        CollectRecord record = packagedRecords.get(entryId);
        CollectRecordSummary conflictingRecord = conflictingPackagedRecords.get(entryId);
        List<Step> steps = packagedStepsPerRecord.get(entryId);
        DataImportSummaryItem item = new DataImportSummaryItem(entryId, CollectRecordSummary.fromRecord(record), steps, conflictingRecord);
        item.setWarnings(warnings.get(entryId));
        conflictingRecordItems.add(item);
    }
    summary.setRecordsToImport(recordsToImport);
    summary.setConflictingRecords(conflictingRecordItems);
    List<FileErrorItem> packagedSkippedFileErrorsList = new ArrayList<DataImportSummary.FileErrorItem>();
    Set<String> skippedFileNames = packagedSkippedFileErrors.keySet();
    for (String fileName : skippedFileNames) {
        List<NodeUnmarshallingError> nodeErrors = packagedSkippedFileErrors.get(fileName);
        FileErrorItem fileErrorItem = new FileErrorItem(fileName, nodeErrors);
        packagedSkippedFileErrorsList.add(fileErrorItem);
    }
    summary.setSkippedFileErrors(packagedSkippedFileErrorsList);
    summary.setTotalPerStep(totalPerStep);
    return summary;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) NodeUnmarshallingError(org.openforis.collect.persistence.xml.NodeUnmarshallingError) ArrayList(java.util.ArrayList) FileErrorItem(org.openforis.collect.io.data.DataImportSummary.FileErrorItem) MainStep(org.openforis.collect.io.data.DataImportState.MainStep) SubStep(org.openforis.collect.io.data.DataImportState.SubStep) Step(org.openforis.collect.model.CollectRecord.Step) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary)

Aggregations

CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)55 RecordFilter (org.openforis.collect.model.RecordFilter)33 CollectRecord (org.openforis.collect.model.CollectRecord)25 Step (org.openforis.collect.model.CollectRecord.Step)21 CollectSurvey (org.openforis.collect.model.CollectSurvey)15 IOException (java.io.IOException)8 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 User (org.openforis.collect.model.User)5 Transactional (org.springframework.transaction.annotation.Transactional)5 MainStep (org.openforis.collect.io.data.DataImportState.MainStep)4 SubStep (org.openforis.collect.io.data.DataImportState.SubStep)4 StepSummary (org.openforis.collect.model.CollectRecordSummary.StepSummary)4 Schema (org.openforis.idm.metamodel.Schema)4 List (java.util.List)3 Test (org.junit.Test)3 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2