use of org.openforis.collect.model.CollectRecord 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);
}
}
use of org.openforis.collect.model.CollectRecord 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;
}
use of org.openforis.collect.model.CollectRecord 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;
}
use of org.openforis.collect.model.CollectRecord 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;
}
use of org.openforis.collect.model.CollectRecord 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;
}
Aggregations