Search in sources :

Example 36 with CollectRecordSummary

use of org.openforis.collect.model.CollectRecordSummary in project collect by openforis.

the class DataRestoreSummaryTask method createConflictingRecordItems.

private List<DataImportSummaryItem> createConflictingRecordItems() {
    List<DataImportSummaryItem> conflictingRecordItems = new ArrayList<DataImportSummaryItem>();
    Set<Integer> conflictingEntryIds = conflictingRecordByEntryId.keySet();
    for (Integer entryId : conflictingEntryIds) {
        CollectRecordSummary recordSummary = recordSummaryByEntryId.get(entryId);
        CollectRecordSummary conflictingRecord = conflictingRecordByEntryId.get(entryId);
        Set<Step> steps = stepsByEntryId.get(entryId);
        DataImportSummaryItem item = new DataImportSummaryItem(entryId, recordSummary, new ArrayList<Step>(steps), conflictingRecord);
        item.setWarnings(warningsByEntryId.get(entryId));
        conflictingRecordItems.add(item);
    }
    return conflictingRecordItems;
}
Also used : CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) ArrayList(java.util.ArrayList) Step(org.openforis.collect.model.CollectRecord.Step)

Example 37 with CollectRecordSummary

use of org.openforis.collect.model.CollectRecordSummary in project collect by openforis.

the class DataRestoreSummaryTask method createRecordToImportItems.

private List<DataImportSummaryItem> createRecordToImportItems() {
    List<DataImportSummaryItem> recordsToImport = new ArrayList<DataImportSummaryItem>();
    Set<Integer> entryIds = recordSummaryByEntryId.keySet();
    for (Integer entryId : entryIds) {
        if (!conflictingRecordByEntryId.containsKey(entryId)) {
            Set<Step> steps = stepsByEntryId.get(entryId);
            CollectRecordSummary recordSummary = recordSummaryByEntryId.get(entryId);
            DataImportSummaryItem item = new DataImportSummaryItem(entryId, recordSummary, new ArrayList<Step>(steps));
            item.setWarnings(warningsByEntryId.get(entryId));
            recordsToImport.add(item);
        }
    }
    return recordsToImport;
}
Also used : CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) ArrayList(java.util.ArrayList) Step(org.openforis.collect.model.CollectRecord.Step)

Example 38 with CollectRecordSummary

use of org.openforis.collect.model.CollectRecordSummary in project collect by openforis.

the class RecordFileBackupTask method execute.

@Override
protected void execute() throws Throwable {
    if (!hasFileAttributeDefinitions()) {
        return;
    }
    RecordFilter filter = new RecordFilter(survey);
    filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntityName).getId());
    recordManager.visitSummaries(filter, new Visitor<CollectRecordSummary>() {

        public void visit(CollectRecordSummary summary) {
            try {
                backup(summary);
                incrementProcessedItems();
            } catch (Exception e) {
                addSkippedRecord(summary);
                log.error(String.format("Error backing up record files for record with id %d and keys %s", summary.getId(), summary.getRootEntityKeyValues().toString()));
            }
        }
    }, new Predicate<CollectRecordSummary>() {

        public boolean evaluate(CollectRecordSummary s) {
            return !isRunning();
        }
    });
}
Also used : CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter) RecordFileException(org.openforis.collect.manager.exception.RecordFileException) IOException(java.io.IOException)

Example 39 with CollectRecordSummary

use of org.openforis.collect.model.CollectRecordSummary in project collect by openforis.

the class RecordFileRestoreTask method findStoredRecordSummary.

private CollectRecordSummary findStoredRecordSummary(CollectRecord record) {
    List<String> recordKeys = record.getRootEntityKeyValues();
    RecordFilter filter = new RecordFilter(survey);
    filter.setRootEntityId(record.getRootEntityDefinitionId());
    filter.setKeyValues(recordKeys);
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
    if (summaries.size() == 1) {
        CollectRecordSummary summary = summaries.get(0);
        return summary;
    } else if (summaries.size() == 0) {
        throw new RuntimeException(String.format("Record with keys %s not found", recordKeys.toString()));
    } else {
        throw new RuntimeException(String.format("Multiple records found with keys %s not found", recordKeys.toString()));
    }
}
Also used : CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 40 with CollectRecordSummary

use of org.openforis.collect.model.CollectRecordSummary in project collect by openforis.

the class RecordOperationGenerator method findAlreadyExistingRecordSummary.

private CollectRecordSummary findAlreadyExistingRecordSummary(CollectRecord parsedRecord) {
    CollectSurvey survey = (CollectSurvey) parsedRecord.getSurvey();
    RecordFilter filter = new RecordFilter(survey);
    filter.setRootEntityId(parsedRecord.getRootEntityDefinitionId());
    filter.setKeyValues(parsedRecord.getRootEntityKeyValues());
    List<CollectRecordSummary> summaries = recordManager.loadFullSummaries(filter, null);
    switch(summaries.size()) {
        case 0:
            return null;
        case 1:
            return summaries.get(0);
        default:
            throw new IllegalArgumentException(String.format("Multiple records with keys %s found for survey %s", parsedRecord.getRootEntityKeyValues(), survey.getName()));
    }
}
Also used : CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter)

Aggregations

CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)55 RecordFilter (org.openforis.collect.model.RecordFilter)33 CollectRecord (org.openforis.collect.model.CollectRecord)25 Step (org.openforis.collect.model.CollectRecord.Step)21 CollectSurvey (org.openforis.collect.model.CollectSurvey)15 IOException (java.io.IOException)8 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 User (org.openforis.collect.model.User)5 Transactional (org.springframework.transaction.annotation.Transactional)5 MainStep (org.openforis.collect.io.data.DataImportState.MainStep)4 SubStep (org.openforis.collect.io.data.DataImportState.SubStep)4 StepSummary (org.openforis.collect.model.CollectRecordSummary.StepSummary)4 Schema (org.openforis.idm.metamodel.Schema)4 List (java.util.List)3 Test (org.junit.Test)3 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2