Search in sources :

Example 1 with RecordOperations

use of org.openforis.collect.manager.RecordManager.RecordOperations in project collect by openforis.

the class DataRestoreTask method importEntries.

private void importEntries(int entryId) throws IOException, MissingStepsException {
    try {
        RecordOperationGenerator operationGenerator = new RecordOperationGenerator(recordProvider, recordManager, entryId, user, includeRecordPredicate, overwriteStrategy);
        RecordOperations recordOperations = operationGenerator.generate();
        if (!recordOperations.isEmpty()) {
            updateBuffer.append(recordOperations);
        }
    } catch (MissingStepsException e) {
        reportMissingStepsErrors(entryId, e);
    } catch (RecordParsingException e) {
        reportRecordParsingErrors(entryId, e);
    }
}
Also used : RecordOperations(org.openforis.collect.manager.RecordManager.RecordOperations)

Example 2 with RecordOperations

use of org.openforis.collect.manager.RecordManager.RecordOperations 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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Step(org.openforis.collect.model.CollectRecord.Step) RecordOperations(org.openforis.collect.manager.RecordManager.RecordOperations)

Aggregations

RecordOperations (org.openforis.collect.manager.RecordManager.RecordOperations)2 CollectRecord (org.openforis.collect.model.CollectRecord)1 Step (org.openforis.collect.model.CollectRecord.Step)1 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)1