use of org.openforis.collect.model.CollectRecordSummary 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.CollectRecordSummary 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.CollectRecordSummary in project collect by openforis.
the class DataRestoreSummaryTask method execute.
@Override
protected void execute() throws Throwable {
if (fullSummary || dataSummaryFile == null) {
List<Integer> idsToImport = extractEntryIdsToImport();
for (Integer entryId : idsToImport) {
if (!isRunning()) {
break;
}
for (Step step : Step.values()) {
if (!isRunning()) {
break;
}
createSummaryForEntry(entryId, step);
}
}
} else {
CsvReader dataSummaryCSVReader = null;
try {
dataSummaryCSVReader = new CsvReader(dataSummaryFile);
dataSummaryCSVReader.readHeaders();
CsvLine line = dataSummaryCSVReader.readNextLine();
while (line != null) {
Integer entryId = line.getValue("entry_id", Integer.class);
String stepVal = line.getValue("step", String.class);
Step step = Step.valueOf(stepVal);
CollectRecordSummary recordSummary = new CollectRecordSummary();
recordSummary.setStep(step);
Integer rootEntityDefId = line.getValue("root_entity_id", Integer.class);
recordSummary.setRootEntityDefinitionId(rootEntityDefId);
Date creationDate = Dates.parseDateTime(line.getValue("created_on", String.class));
Date modifiedDate = Dates.parseDateTime(line.getValue("last_modified", String.class));
recordSummary.setCreationDate(creationDate);
recordSummary.setModifiedDate(modifiedDate);
StepSummary stepSummary = new StepSummary(step);
List<String> rootEntityKeyValues = Arrays.asList(line.getValue("key1", String.class), line.getValue("key2", String.class), line.getValue("key3", String.class));
stepSummary.setRootEntityKeyValues(rootEntityKeyValues);
stepSummary.setCreationDate(creationDate);
stepSummary.setModifiedDate(modifiedDate);
recordSummary.addStepSummary(stepSummary);
recordSummaryByEntryId.put(entryId, recordSummary);
for (Step s : Step.values()) {
if (s.beforeEqual(step)) {
addStepPerEntry(entryId, s);
incrementTotalPerStep(step);
incrementProcessedItems();
}
}
CollectRecordSummary oldRecord = findAlreadyExistingRecordSummary(entryId, step, rootEntityDefId, rootEntityKeyValues);
if (oldRecord != null) {
conflictingRecordByEntryId.put(entryId, oldRecord);
}
line = dataSummaryCSVReader.readNextLine();
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(dataSummaryCSVReader);
}
}
}
use of org.openforis.collect.model.CollectRecordSummary in project collect by openforis.
the class DataRestoreSummaryTask method findAlreadyExistingRecordSummary.
private CollectRecordSummary findAlreadyExistingRecordSummary(int entryId, Step step, int rootEntityDefId, List<String> rootEntityKeys) {
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(rootEntityDefId);
filter.setKeyValues(rootEntityKeys);
List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
switch(summaries.size()) {
case 0:
return null;
case 1:
return summaries.get(0);
default:
String errorMessage = String.format("Data file: %s - multiple records found in survey %s with key(s) %s", getEntryName(entryId, step), survey.getName(), rootEntityKeys);
throw new IllegalStateException(errorMessage);
}
}
use of org.openforis.collect.model.CollectRecordSummary 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);
}
}
Aggregations