Search in sources :

Example 36 with RecordFilter

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

the class RecordFileBackupTask method countTotalItems.

@Override
protected long countTotalItems() {
    if (hasFileAttributeDefinitions()) {
        RecordFilter filter = new RecordFilter(survey);
        filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntityName).getId());
        int count = recordManager.countRecords(filter);
        return count;
    } else {
        return 0;
    }
}
Also used : RecordFilter(org.openforis.collect.model.RecordFilter)

Example 37 with RecordFilter

use of org.openforis.collect.model.RecordFilter 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 38 with RecordFilter

use of org.openforis.collect.model.RecordFilter 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)

Example 39 with RecordFilter

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

the class RecordDao method countRecords.

public int countRecords(CollectSurvey survey, int rootDefinitionId, String... keyValues) {
    RecordFilter filter = new RecordFilter(survey, rootDefinitionId);
    filter.setKeyValues(keyValues);
    return countRecords(filter);
}
Also used : RecordFilter(org.openforis.collect.model.RecordFilter)

Example 40 with RecordFilter

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

the class CSVDataImportJobIntegrationTest method loadRecord.

private CollectRecord loadRecord(String key) {
    RecordFilter filter = new RecordFilter(survey);
    filter.setRootEntityId(survey.getSchema().getRootEntityDefinition("cluster").getId());
    filter.setKeyValues(Arrays.asList(key));
    List<CollectRecordSummary> summaries = recordDao.loadSummaries(filter);
    assertEquals(1, summaries.size());
    CollectRecordSummary summary = summaries.get(0);
    CollectRecord reloadedRecord = recordManager.load(survey, summary.getId(), summary.getStep());
    return reloadedRecord;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter)

Aggregations

RecordFilter (org.openforis.collect.model.RecordFilter)66 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)33 CollectSurvey (org.openforis.collect.model.CollectSurvey)27 CollectRecord (org.openforis.collect.model.CollectRecord)14 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Date (java.util.Date)10 User (org.openforis.collect.model.User)10 SessionState (org.openforis.collect.web.session.SessionState)7 Transactional (org.springframework.transaction.annotation.Transactional)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 File (java.io.File)5 HashMap (java.util.HashMap)5 CSVDataExportParameters (org.openforis.collect.io.data.csv.CSVDataExportParameters)5 Step (org.openforis.collect.model.CollectRecord.Step)5 IOException (java.io.IOException)4 SurveyBackupJob (org.openforis.collect.io.SurveyBackupJob)4 CSVDataExportJob (org.openforis.collect.io.data.CSVDataExportJob)4 Schema (org.openforis.idm.metamodel.Schema)4 Test (org.junit.Test)3