use of org.openforis.collect.model.CollectRecord.Step in project collect by openforis.
the class XMLDataImportProcess method createSummaryForEntry.
private void createSummaryForEntry(String entryName, Map<String, List<NodeUnmarshallingError>> packagedSkippedFileErrors, Map<Integer, CollectRecord> packagedRecords, Map<Integer, List<Step>> packagedStepsPerRecord, Map<Step, Integer> totalPerStep, Map<Integer, CollectRecordSummary> conflictingPackagedRecords, Map<Integer, Map<Step, List<NodeUnmarshallingError>>> warnings) throws IOException, DataParsingExeption {
RecordEntry recordEntry = RecordEntry.parse(entryName);
Step step = recordEntry.getStep();
InputStream is = backupFileExtractor.findEntryInputStream(entryName);
InputStreamReader reader = OpenForisIOUtils.toReader(is);
ParseRecordResult parseRecordResult = parseRecord(reader, false);
CollectRecord parsedRecord = parseRecordResult.getRecord();
if (!parseRecordResult.isSuccess()) {
List<NodeUnmarshallingError> failures = parseRecordResult.getFailures();
packagedSkippedFileErrors.put(entryName, failures);
} else if (includeRecordPredicate == null || includeRecordPredicate.evaluate(parsedRecord)) {
int entryId = recordEntry.getRecordId();
CollectRecord recordSummary = createRecordSummary(parsedRecord);
packagedRecords.put(entryId, recordSummary);
List<Step> stepsPerRecord = packagedStepsPerRecord.get(entryId);
if (stepsPerRecord == null) {
stepsPerRecord = new ArrayList<CollectRecord.Step>();
packagedStepsPerRecord.put(entryId, stepsPerRecord);
}
stepsPerRecord.add(step);
Integer totalPerStep1 = totalPerStep.get(step);
totalPerStep.put(step, totalPerStep1 + 1);
CollectRecordSummary oldRecord = findAlreadyExistingRecordSummary(parsedRecord);
if (oldRecord != null) {
conflictingPackagedRecords.put(entryId, oldRecord);
}
if (parseRecordResult.hasWarnings()) {
Map<Step, List<NodeUnmarshallingError>> warningsPerEntry = warnings.get(entryId);
if (warningsPerEntry == null) {
warningsPerEntry = new HashMap<CollectRecord.Step, List<NodeUnmarshallingError>>();
warnings.put(entryId, warningsPerEntry);
}
warningsPerEntry.put(step, parseRecordResult.getWarnings());
}
}
state.incrementCount();
}
use of org.openforis.collect.model.CollectRecord.Step in project collect by openforis.
the class XMLParsingRecordProvider method findEntryIds.
@Override
public List<Integer> findEntryIds() {
Set<Integer> result = new TreeSet<Integer>();
for (Step step : Step.values()) {
int stepNumber = step.getStepNumber();
String path = (backupFileExtractor.isOldFormat() ? "" : SurveyBackupJob.DATA_FOLDER + SurveyBackupJob.ZIP_FOLDER_SEPARATOR) + stepNumber;
if (backupFileExtractor.containsEntriesInPath(path)) {
List<String> listEntriesInPath = backupFileExtractor.listFilesInFolder(path);
for (String entry : listEntriesInPath) {
String entryId = FilenameUtils.getBaseName(entry);
result.add(Integer.parseInt(entryId));
}
}
}
return new ArrayList<Integer>(result);
}
use of org.openforis.collect.model.CollectRecord.Step in project collect by openforis.
the class DataRestoreSummaryTask method createConflictingRecordItems.
private List<DataImportSummaryItem> createConflictingRecordItems() {
List<DataImportSummaryItem> conflictingRecordItems = new ArrayList<DataImportSummaryItem>();
Set<Integer> conflictingEntryIds = conflictingRecordByEntryId.keySet();
for (Integer entryId : conflictingEntryIds) {
CollectRecordSummary recordSummary = recordSummaryByEntryId.get(entryId);
CollectRecordSummary conflictingRecord = conflictingRecordByEntryId.get(entryId);
Set<Step> steps = stepsByEntryId.get(entryId);
DataImportSummaryItem item = new DataImportSummaryItem(entryId, recordSummary, new ArrayList<Step>(steps), conflictingRecord);
item.setWarnings(warningsByEntryId.get(entryId));
conflictingRecordItems.add(item);
}
return conflictingRecordItems;
}
use of org.openforis.collect.model.CollectRecord.Step in project collect by openforis.
the class DataRestoreSummaryTask method createRecordToImportItems.
private List<DataImportSummaryItem> createRecordToImportItems() {
List<DataImportSummaryItem> recordsToImport = new ArrayList<DataImportSummaryItem>();
Set<Integer> entryIds = recordSummaryByEntryId.keySet();
for (Integer entryId : entryIds) {
if (!conflictingRecordByEntryId.containsKey(entryId)) {
Set<Step> steps = stepsByEntryId.get(entryId);
CollectRecordSummary recordSummary = recordSummaryByEntryId.get(entryId);
DataImportSummaryItem item = new DataImportSummaryItem(entryId, recordSummary, new ArrayList<Step>(steps));
item.setWarnings(warningsByEntryId.get(entryId));
recordsToImport.add(item);
}
}
return recordsToImport;
}
use of org.openforis.collect.model.CollectRecord.Step in project collect by openforis.
the class DataRestoreTask method reportMissingStepsErrors.
private void reportMissingStepsErrors(int entryId, MissingStepsException e) {
Step originalStep = e.getOperations().getOriginalStep();
String entryName = recordProvider.getEntryName(entryId, originalStep);
errors.add(new RecordImportError(entryId, entryName, originalStep, "Missing data for step", Level.ERROR));
}
Aggregations