Search in sources :

Example 1 with DataUnmarshaller

use of org.openforis.collect.persistence.xml.DataUnmarshaller 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 2 with DataUnmarshaller

use of org.openforis.collect.persistence.xml.DataUnmarshaller in project collect by openforis.

the class DataMarshallerIntegrationTest method parseRecord.

private ParseRecordResult parseRecord(CollectSurvey survey, String xml) throws IOException, DataUnmarshallerException {
    DataUnmarshaller dataUnmarshaller = new DataUnmarshaller(survey);
    StringReader reader = new StringReader(xml);
    ParseRecordResult result = dataUnmarshaller.parse(reader);
    return result;
}
Also used : DataUnmarshaller(org.openforis.collect.persistence.xml.DataUnmarshaller) StringReader(java.io.StringReader) ParseRecordResult(org.openforis.collect.persistence.xml.DataUnmarshaller.ParseRecordResult)

Example 3 with DataUnmarshaller

use of org.openforis.collect.persistence.xml.DataUnmarshaller in project collect by openforis.

the class XMLParsingRecordProvider method init.

@Override
public void init(ProgressListener progressListener) throws Exception {
    this.backupFileExtractor = new NewBackupFileExtractor(file);
    this.backupFileExtractor.init(progressListener);
    this.dataUnmarshaller = new DataUnmarshaller(existingSurvey == null ? packagedSurvey : existingSurvey, packagedSurvey);
    this.dataUnmarshaller.setRecordValidationEnabled(validateRecords);
    this.dataUnmarshaller.setIgnoreDuplicateRecordKeyValidationErrors(ignoreDuplicateRecordKeyValidationErrors);
    this.dataUnmarshaller.setRecordApplicationVersion(backupFileExtractor.getInfo().getCollectVersion());
    this.recordUpdater = new RecordUpdater();
    this.recordUpdater.setValidateAfterUpdate(validateRecords);
    initializeRecordUserLoader();
}
Also used : DataUnmarshaller(org.openforis.collect.persistence.xml.DataUnmarshaller) NewBackupFileExtractor(org.openforis.collect.io.NewBackupFileExtractor) RecordUpdater(org.openforis.collect.model.RecordUpdater)

Example 4 with DataUnmarshaller

use of org.openforis.collect.persistence.xml.DataUnmarshaller in project collect by openforis.

the class BackupDataExtractor method init.

public void init() throws ZipException, IOException {
    this.fileExtractor = new BackupFileExtractor(zipFile);
    this.oldFormat = this.fileExtractor.isOldFormat();
    this.dataUnmarshaller = new DataUnmarshaller(survey);
    this.zipEntries = zipFile.entries();
    this.initialized = true;
}
Also used : DataUnmarshaller(org.openforis.collect.persistence.xml.DataUnmarshaller) BackupFileExtractor(org.openforis.collect.io.BackupFileExtractor)

Aggregations

DataUnmarshaller (org.openforis.collect.persistence.xml.DataUnmarshaller)4 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ZipException (java.util.zip.ZipException)1 BackupFileExtractor (org.openforis.collect.io.BackupFileExtractor)1 NewBackupFileExtractor (org.openforis.collect.io.NewBackupFileExtractor)1 MainStep (org.openforis.collect.io.data.DataImportState.MainStep)1 SubStep (org.openforis.collect.io.data.DataImportState.SubStep)1 SurveyValidationException (org.openforis.collect.manager.exception.SurveyValidationException)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 Step (org.openforis.collect.model.CollectRecord.Step)1 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)1 RecordUpdater (org.openforis.collect.model.RecordUpdater)1 RecordPersistenceException (org.openforis.collect.persistence.RecordPersistenceException)1 ParseRecordResult (org.openforis.collect.persistence.xml.DataUnmarshaller.ParseRecordResult)1 NodeUnmarshallingError (org.openforis.collect.persistence.xml.NodeUnmarshallingError)1