Search in sources :

Example 1 with NodeUnmarshallingError

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

the class DataImportSummaryItemProxy method getWarnings.

@ExternalizedProperty
public List<NodeUnmarshallingErrorProxy> getWarnings() {
    List<NodeUnmarshallingError> result = new ArrayList<NodeUnmarshallingError>();
    Map<Step, List<NodeUnmarshallingError>> warnings = item.getWarnings();
    if (warnings != null) {
        Set<Step> steps = warnings.keySet();
        for (Step step : steps) {
            List<NodeUnmarshallingError> warningsPerStep = warnings.get(step);
            result.addAll(warningsPerStep);
        }
    }
    List<NodeUnmarshallingErrorProxy> proxies = NodeUnmarshallingErrorProxy.fromList(result);
    return proxies;
}
Also used : NodeUnmarshallingError(org.openforis.collect.persistence.xml.NodeUnmarshallingError) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Step(org.openforis.collect.model.CollectRecord.Step) ExternalizedProperty(org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)

Example 2 with NodeUnmarshallingError

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

use of org.openforis.collect.persistence.xml.NodeUnmarshallingError 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)

Example 4 with NodeUnmarshallingError

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

the class DataRestoreSummaryTask method createSkippedFileErrorItems.

private List<FileErrorItem> createSkippedFileErrorItems() {
    List<FileErrorItem> errorItems = new ArrayList<FileErrorItem>();
    Set<String> skippedFileNames = errorsByEntryName.keySet();
    for (String fileName : skippedFileNames) {
        List<NodeUnmarshallingError> nodeErrors = errorsByEntryName.get(fileName);
        FileErrorItem fileErrorItem = new FileErrorItem(fileName, nodeErrors);
        errorItems.add(fileErrorItem);
    }
    return errorItems;
}
Also used : NodeUnmarshallingError(org.openforis.collect.persistence.xml.NodeUnmarshallingError) FileErrorItem(org.openforis.collect.io.data.DataImportSummary.FileErrorItem) ArrayList(java.util.ArrayList)

Example 5 with NodeUnmarshallingError

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

NodeUnmarshallingError (org.openforis.collect.persistence.xml.NodeUnmarshallingError)7 ArrayList (java.util.ArrayList)6 Step (org.openforis.collect.model.CollectRecord.Step)5 List (java.util.List)3 MainStep (org.openforis.collect.io.data.DataImportState.MainStep)3 SubStep (org.openforis.collect.io.data.DataImportState.SubStep)3 CollectRecord (org.openforis.collect.model.CollectRecord)3 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 FileErrorItem (org.openforis.collect.io.data.DataImportSummary.FileErrorItem)2 ParseRecordResult (org.openforis.collect.persistence.xml.DataUnmarshaller.ParseRecordResult)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ZipException (java.util.zip.ZipException)1 ExternalizedProperty (org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)1 RecordStep (org.openforis.collect.event.RecordStep)1 SurveyValidationException (org.openforis.collect.manager.exception.SurveyValidationException)1 RecordPersistenceException (org.openforis.collect.persistence.RecordPersistenceException)1