use of org.openforis.collect.model.CollectRecord.Step 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));
}
}
use of org.openforis.collect.model.CollectRecord.Step in project collect by openforis.
the class RecordEntry method parse.
public static RecordEntry parse(String zipEntryName) throws DataParsingExeption {
// for backward compatibility with previous generated backup files
String zipEntryNameFixed = zipEntryName.replace("\\", XMLDataExportProcess.ZIP_DIRECTORY_SEPARATOR);
String[] entryNameSplitted = zipEntryNameFixed.split(XMLDataExportProcess.ZIP_DIRECTORY_SEPARATOR);
if (entryNameSplitted.length != 2) {
throw new DataParsingExeption("Packaged file format exception: wrong zip entry name: " + zipEntryName);
}
// step
String stepNumStr = entryNameSplitted[0];
int stepNumber = Integer.parseInt(stepNumStr);
Step step = Step.valueOf(stepNumber);
// file name
String fileName = entryNameSplitted[1];
String baseName = FilenameUtils.getBaseName(fileName);
int recordId = Integer.parseInt(baseName);
RecordEntry result = new RecordEntry(step, recordId);
return result;
}
use of org.openforis.collect.model.CollectRecord.Step 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;
}
use of org.openforis.collect.model.CollectRecord.Step in project collect by openforis.
the class RecordOperationGenerator method generate.
public RecordOperations generate() throws IOException, MissingStepsException, RecordParsingException {
RecordOperations operations = new RecordOperations();
boolean firstStepToBeProcessed = true;
CollectRecordSummary existingRecordSummary = null;
int workflowSequenceNumber = -1;
boolean newRecord = true;
for (Step step : Step.values()) {
CollectRecord parsedRecord = recordProvider.provideRecord(entryId, step);
if (parsedRecord == null || !isToBeProcessed(parsedRecord)) {
continue;
}
setDefaultValues(parsedRecord);
if (firstStepToBeProcessed) {
existingRecordSummary = findAlreadyExistingRecordSummary(parsedRecord);
newRecord = existingRecordSummary == null;
if (newRecord) {
insertRecordDataUntilStep(operations, parsedRecord, step);
workflowSequenceNumber = calculateStepDataSequenceNumber(existingRecordSummary, step);
} else {
Step existingRecordStep = existingRecordSummary.getStep();
operations.initializeRecordId(existingRecordSummary.getId());
operations.setOriginalStep(existingRecordStep);
if (overwriteStrategy == OVERWRITE_OLDER && isNewer(parsedRecord, existingRecordSummary) || overwriteStrategy == ONLY_SPECIFIED || overwriteStrategy == OVERWRITE_ALL) {
// overwrite existing record data
parsedRecord.setId(existingRecordSummary.getId());
boolean insertNewDataStep = step.after(existingRecordStep);
workflowSequenceNumber = calculateStepDataSequenceNumber(existingRecordSummary, step);
operations.addUpdate(parsedRecord, step, insertNewDataStep, workflowSequenceNumber);
}
}
firstStepToBeProcessed = false;
} else {
boolean insertNewDataStep = newRecord ? true : step.after(operations.getOriginalStep());
workflowSequenceNumber = calculateStepDataSequenceNumber(existingRecordSummary, step);
operations.addUpdate(parsedRecord, step, insertNewDataStep, workflowSequenceNumber);
}
}
return operations;
}
use of org.openforis.collect.model.CollectRecord.Step in project collect by openforis.
the class RecordStatsGenerator method generate.
public RecordsStats generate(int surveyId, Date[] period) {
final RecordsStats stats = new RecordsStats(period);
CollectSurvey survey = surveyManager.getById(surveyId);
recordManager.visitSummaries(new RecordFilter(survey), null, new Visitor<CollectRecordSummary>() {
public void visit(CollectRecordSummary s) {
for (Entry<Step, StepSummary> entry : s.getStepSummaries().entrySet()) {
Step step = entry.getKey();
StepSummary stepSummary = entry.getValue();
if (stepSummary.getCreationDate() != null) {
PointStats pointStats = stats.getOrCreateDailyStats(stepSummary.getCreationDate());
switch(step) {
case ENTRY:
pointStats.incrementCreated();
break;
case CLEANSING:
pointStats.incrementEntered();
break;
case ANALYSIS:
pointStats.incrementCleansed();
break;
}
}
}
if (s.getModifiedDate() != null) {
PointStats pointStats = stats.getOrCreateDailyStats(s.getModifiedDate());
pointStats.incrementModified();
}
}
}, true);
stats.finalize();
return stats;
}
Aggregations