Search in sources :

Example 1 with ParseRecordResult

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

the class XMLDataImportProcess method parseRecord.

private ParseRecordResult parseRecord(Reader reader, boolean validateAndLoadReferences) throws IOException {
    dataUnmarshaller.setRecordValidationEnabled(validateAndLoadReferences);
    ParseRecordResult result = dataUnmarshaller.parse(reader);
    if (result.isSuccess()) {
        CollectRecord record = result.getRecord();
        if (validateAndLoadReferences) {
            recordUserLoader.adjustUserReferences(record);
        }
    }
    return result;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) ParseRecordResult(org.openforis.collect.persistence.xml.DataUnmarshaller.ParseRecordResult)

Example 2 with ParseRecordResult

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

the class XMLParsingRecordProvider method provideRecordParsingResult.

@Override
public ParseRecordResult provideRecordParsingResult(int entryId, Step step) throws IOException {
    String entryName = getEntryName(entryId, step);
    InputStream entryIS = backupFileExtractor.findEntryInputStream(entryName);
    if (entryIS == null) {
        return null;
    }
    InputStreamReader reader = OpenForisIOUtils.toReader(entryIS);
    ParseRecordResult parseRecordResult = parseRecord(reader, step);
    if (parseRecordResult.isSuccess()) {
        CollectRecord record = parseRecordResult.getRecord();
        recordUserLoader.adjustUserReferences(record);
        recordUpdater.initializeRecord(record);
    }
    return parseRecordResult;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ParseRecordResult(org.openforis.collect.persistence.xml.DataUnmarshaller.ParseRecordResult)

Example 3 with ParseRecordResult

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

the class XMLParsingRecordProvider method parseRecord.

private ParseRecordResult parseRecord(Reader reader, Step step) throws IOException {
    ParseRecordResult result = dataUnmarshaller.parse(reader);
    if (result.isSuccess()) {
        CollectRecord record = result.getRecord();
        record.setStep(step);
        record.setDataStep(step);
        // ignore rejected information
        record.setState(null);
    }
    return result;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) ParseRecordResult(org.openforis.collect.persistence.xml.DataUnmarshaller.ParseRecordResult)

Example 4 with ParseRecordResult

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

the class DataRestoreSummaryTask method createSummaryForEntry.

private void createSummaryForEntry(int entryId, Step step) throws IOException, DataParsingExeption {
    ParseRecordResult recordParsingResult = recordProvider.provideRecordParsingResult(entryId, step);
    if (recordParsingResult == null) {
        return;
    }
    CollectRecord parsedRecord = recordParsingResult.getRecord();
    if (!recordParsingResult.isSuccess()) {
        createParsingErrorSummary(entryId, step, recordParsingResult);
    } else if (isToBeIncluded(parsedRecord)) {
        createRecordParsedCorrectlySummary(entryId, step, recordParsingResult);
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) ParseRecordResult(org.openforis.collect.persistence.xml.DataUnmarshaller.ParseRecordResult)

Example 5 with ParseRecordResult

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

the class DataRestoreTask method reportRecordParsingErrors.

private void reportRecordParsingErrors(int entryId, RecordParsingException e) {
    Step recordStep = e.getRecordStep();
    String entryName = recordProvider.getEntryName(entryId, recordStep);
    ParseRecordResult parseResult = e.getParseRecordResult();
    for (NodeUnmarshallingError failure : parseResult.getFailures()) {
        errors.add(new RecordImportError(entryId, entryName, recordStep, String.format("%s : %s", failure.getPath(), failure.getMessage()), Level.ERROR));
    }
    for (NodeUnmarshallingError warn : parseResult.getWarnings()) {
        errors.add(new RecordImportError(entryId, entryName, recordStep, String.format("%s : %s", warn.getPath(), warn.getMessage()), Level.WARNING));
    }
}
Also used : NodeUnmarshallingError(org.openforis.collect.persistence.xml.NodeUnmarshallingError) Step(org.openforis.collect.model.CollectRecord.Step) RecordStep(org.openforis.collect.event.RecordStep) ParseRecordResult(org.openforis.collect.persistence.xml.DataUnmarshaller.ParseRecordResult)

Aggregations

ParseRecordResult (org.openforis.collect.persistence.xml.DataUnmarshaller.ParseRecordResult)12 CollectRecord (org.openforis.collect.model.CollectRecord)7 InputStream (java.io.InputStream)5 InputStreamReader (java.io.InputStreamReader)4 Step (org.openforis.collect.model.CollectRecord.Step)3 MainStep (org.openforis.collect.io.data.DataImportState.MainStep)2 SubStep (org.openforis.collect.io.data.DataImportState.SubStep)2 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 NodeUnmarshallingError (org.openforis.collect.persistence.xml.NodeUnmarshallingError)2 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ZipEntry (java.util.zip.ZipEntry)1 Test (org.junit.Test)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1 RecordStep (org.openforis.collect.event.RecordStep)1