use of org.openforis.collect.model.RecordSummarySortField 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.RecordSummarySortField in project collect by openforis.
the class RecordDao method createSelectSummariesQuery.
private SelectQuery<Record> createSelectSummariesQuery(RecordFilter filter, List<RecordSummarySortField> sortFields) {
SelectQuery<Record> q = dsl.selectQuery();
q.addSelect(RECORD_FULL_SUMMARY_FIELDS);
Field<String> ownerNameField = OFC_USER.USERNAME.as(RecordSummarySortField.Sortable.OWNER_NAME.name());
q.addSelect(ownerNameField);
q.addFrom(OFC_RECORD);
// join with user table to get owner name
q.addJoin(OFC_USER, JoinType.LEFT_OUTER_JOIN, OFC_RECORD.OWNER_ID.equal(OFC_USER.ID));
addRecordSummaryFilterConditions(q, filter);
// add limit
if (filter.getOffset() != null && filter.getMaxNumberOfRecords() != null) {
q.addLimit(filter.getOffset(), filter.getMaxNumberOfRecords());
}
// add ordering fields
if (sortFields != null) {
for (RecordSummarySortField sortField : sortFields) {
addOrderBy(q, sortField, ownerNameField);
}
}
// always order by ID to avoid pagination issues
q.addOrderBy(OFC_RECORD.ID);
return q;
}
Aggregations