Search in sources :

Example 1 with RecordSummarySortField

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());
}
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 2 with RecordSummarySortField

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;
}
Also used : RecordSummarySortField(org.openforis.collect.model.RecordSummarySortField) OfcRecordRecord(org.openforis.collect.persistence.jooq.tables.records.OfcRecordRecord) CollectRecord(org.openforis.collect.model.CollectRecord) OfcRecordDataRecord(org.openforis.collect.persistence.jooq.tables.records.OfcRecordDataRecord) Record(org.jooq.Record)

Aggregations

RecordSummarySortField (org.openforis.collect.model.RecordSummarySortField)2 Record (org.jooq.Record)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)1 RecordFilter (org.openforis.collect.model.RecordFilter)1 OfcRecordDataRecord (org.openforis.collect.persistence.jooq.tables.records.OfcRecordDataRecord)1 OfcRecordRecord (org.openforis.collect.persistence.jooq.tables.records.OfcRecordRecord)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1