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;
}
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());
}
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;
}
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);
}
}
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;
}
Aggregations