Search in sources :

Example 21 with CollectRecordSummary

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

the class CSVDataImportProcessIntegrationTest 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)

Example 22 with CollectRecordSummary

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

the class ModelDaoIntegrationTest method testLoadRecordSummaries.

// @Test
public void testLoadRecordSummaries() {
    // get the first root entity
    EntityDefinition rootEntity = survey.getSchema().getFirstRootEntityDefinition();
    String rootEntityName = rootEntity.getName();
    int offset = 0;
    int maxNumberOfRecords = 1;
    RecordSummarySortField sortField = new RecordSummarySortField(Sortable.KEY1);
    RecordFilter filter = new RecordFilter(survey);
    filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntityName).getId());
    filter.setOffset(offset);
    filter.setMaxNumberOfRecords(maxNumberOfRecords);
    List<CollectRecordSummary> list = this.recordDao.loadSummaries(filter, Arrays.asList(sortField));
    assertNotNull(list);
    assertEquals(1, list.size());
    CollectRecordSummary summary = list.get(0);
    assertEquals(Step.ENTRY, summary.getStep());
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) RecordSummarySortField(org.openforis.collect.model.RecordSummarySortField) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 23 with CollectRecordSummary

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

the class RandomRecordGenerator method calculateRecordMeasurementsByKey.

private Map<RecordKey, Integer> calculateRecordMeasurementsByKey(CollectSurvey survey, final User user) {
    final List<AttributeDefinition> nonMeasurementKeyDefs = getNonMeasurementKeyDefs(survey);
    final Map<RecordKey, Integer> measurementsByRecordKey = new HashMap<RecordKey, Integer>();
    recordManager.visitSummaries(new RecordFilter(survey), null, new Visitor<CollectRecordSummary>() {

        public void visit(CollectRecordSummary summary) {
            if (summary.getCreatedBy().getId() != user.getId()) {
                List<String> keys = summary.getCurrentStepSummary().getRootEntityKeyValues();
                RecordKey nonMeasurementKey = new RecordKey(nonMeasurementKeyDefs, keys);
                Integer measurements = measurementsByRecordKey.get(nonMeasurementKey);
                if (measurements == null) {
                    measurements = 1;
                } else {
                    measurements += 1;
                }
                measurementsByRecordKey.put(nonMeasurementKey, measurements);
            }
        }
    });
    samplingDesignManager.visitItems(survey.getId(), 1, new Visitor<SamplingDesignItem>() {

        public void visit(SamplingDesignItem item) {
            RecordKey key = new RecordKey(nonMeasurementKeyDefs, item.getLevelCodes());
            Integer measurements = measurementsByRecordKey.get(key);
            if (measurements == null) {
                measurementsByRecordKey.put(key, 0);
            }
        }
    });
    return measurementsByRecordKey;
}
Also used : HashMap(java.util.HashMap) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) ArrayList(java.util.ArrayList) List(java.util.List) RecordFilter(org.openforis.collect.model.RecordFilter) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 24 with CollectRecordSummary

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

the class RecordIndexManager method indexAllRecords.

public void indexAllRecords(CollectSurvey survey, String rootEntity) throws RecordIndexException {
    cancelled = false;
    RecordFilter filter = new RecordFilter(survey);
    filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntity).getId());
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
    IndexWriter indexWriter = null;
    try {
        indexWriter = createIndexWriter();
        for (CollectRecordSummary s : summaries) {
            if (!cancelled) {
                Integer recordId = s.getId();
                deleteDocuments(indexWriter, recordId);
                CollectRecord record = recordManager.load(survey, recordId, s.getStep());
                index(indexWriter, record);
            } else {
                break;
            }
        }
    } catch (Exception e) {
        throw new RecordIndexException(e);
    } finally {
        close(indexWriter);
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) IndexWriter(org.apache.lucene.index.IndexWriter) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter) ParseException(org.apache.lucene.queryParser.ParseException) IOException(java.io.IOException)

Example 25 with CollectRecordSummary

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

the class RecordManager method isUnique.

/**
 * Returns false if another record with the same root entity key values exists.
 */
public boolean isUnique(CollectRecord record) {
    record.updateSummaryFields();
    CollectSurvey survey = (CollectSurvey) record.getSurvey();
    RecordFilter filter = new RecordFilter(survey, record.getRootEntityDefinitionId());
    filter.setKeyValues(record.getRootEntityKeyValues());
    filter.setIncludeNullConditionsForKeyValues(true);
    List<CollectRecordSummary> summaries = recordDao.loadSummaries(filter);
    for (CollectRecordSummary s : summaries) {
        if (!s.getId().equals(record.getId())) {
            return false;
        }
    }
    return true;
}
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