use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class DataRestoreSummaryTask method findAlreadyExistingFullRecordSummary.
private CollectRecordSummary findAlreadyExistingFullRecordSummary(int entryId, Step step, CollectRecord parsedRecord) {
List<String> keyValues = parsedRecord.getRootEntityKeyValues();
Entity rootEntity = parsedRecord.getRootEntity();
int rootEntityDefId = rootEntity.getDefinition().getId();
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(rootEntityDefId);
filter.setKeyValues(keyValues);
List<CollectRecordSummary> oldRecordSummaries = recordManager.loadSummaries(filter);
if (oldRecordSummaries == null || oldRecordSummaries.isEmpty()) {
return null;
} else if (oldRecordSummaries.size() == 1) {
CollectRecordSummary summary = oldRecordSummaries.get(0);
CollectRecord record = recordManager.load(survey, summary.getId(), summary.getStep(), fullSummary);
CollectRecordSummary recordSummary = CollectRecordSummary.fromRecord(record);
recordSummary.setFiles(recordFileManager.getAllFiles(record));
return recordSummary;
} else {
String errorMessage = String.format("Data file: %s - multiple records found in survey %s with key(s) %s", getEntryName(entryId, step), survey.getName(), keyValues);
throw new IllegalStateException(errorMessage);
}
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class DataRestoreSummaryTask method createRecordParsedCorrectlySummary.
private void createRecordParsedCorrectlySummary(int entryId, Step step, ParseRecordResult parseRecordResult) {
CollectRecord parsedRecord = parseRecordResult.getRecord();
CollectRecordSummary recordSummary = CollectRecordSummary.fromRecord(parsedRecord);
recordSummaryByEntryId.put(entryId, recordSummary);
addStepPerEntry(entryId, step);
CollectRecordSummary oldRecord = findAlreadyExistingFullRecordSummary(entryId, step, parsedRecord);
if (oldRecord != null) {
conflictingRecordByEntryId.put(entryId, oldRecord);
}
if (parseRecordResult.hasWarnings()) {
addWarningsPerStep(entryId, step, parseRecordResult.getWarnings());
}
incrementTotalPerStep(step);
incrementProcessedItems();
}
use of org.openforis.collect.model.CollectRecord 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);
}
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordFileRestoreTask method importRecordFiles.
private void importRecordFiles(int entryId) throws IOException, DataImportExeption, RecordPersistenceException, RecordParsingException {
CollectRecord lastStepBackupRecord = getLastStepBackupRecord(entryId);
if (lastStepBackupRecord == null) {
throw new IllegalStateException("Error parsing record for entry: " + entryId);
}
CollectRecordSummary storedRecordSummary = findStoredRecordSummary(lastStepBackupRecord);
if (overwriteStrategy == OVERWRITE_OLDER && isNewer(lastStepBackupRecord, storedRecordSummary) || overwriteStrategy == ONLY_SPECIFIED || overwriteStrategy == OVERWRITE_ALL) {
CollectRecord storedRecord = recordManager.load(survey, storedRecordSummary.getId(), storedRecordSummary.getStep(), false);
importRecordFiles(storedRecord);
}
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordFileRestoreTask method getLastStepBackupRecord.
private CollectRecord getLastStepBackupRecord(int entryId) throws IOException, RecordParsingException {
Step[] steps = Step.values();
for (int i = steps.length - 1; i >= 0; i--) {
Step step = steps[i];
CollectRecord record = recordProvider.provideRecord(entryId, step);
if (record != null) {
return record;
}
}
return null;
}
Aggregations