Search in sources :

Example 26 with CollectRecord

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);
    }
}
Also used : Entity(org.openforis.idm.model.Entity) CollectRecord(org.openforis.collect.model.CollectRecord) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 27 with CollectRecord

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();
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary)

Example 28 with CollectRecord

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);
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) ParseRecordResult(org.openforis.collect.persistence.xml.DataUnmarshaller.ParseRecordResult)

Example 29 with CollectRecord

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);
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary)

Example 30 with CollectRecord

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Step(org.openforis.collect.model.CollectRecord.Step)

Aggregations

CollectRecord (org.openforis.collect.model.CollectRecord)141 Entity (org.openforis.idm.model.Entity)36 Test (org.junit.Test)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)29 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)29 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)27 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)24 Step (org.openforis.collect.model.CollectRecord.Step)23 User (org.openforis.collect.model.User)19 SessionState (org.openforis.collect.web.session.SessionState)15 RecordFilter (org.openforis.collect.model.RecordFilter)14 Transactional (org.springframework.transaction.annotation.Transactional)14 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)12 Secured (org.springframework.security.access.annotation.Secured)12 ArrayList (java.util.ArrayList)11 Date (org.openforis.idm.model.Date)10 GregorianCalendar (java.util.GregorianCalendar)9 Code (org.openforis.idm.model.Code)9 RealAttribute (org.openforis.idm.model.RealAttribute)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9