Search in sources :

Example 1 with RecordSummaryProxy

use of org.openforis.collect.model.proxy.RecordSummaryProxy in project collect by openforis.

the class DataService method loadRecordSummaries.

/**
 * @param rootEntityName
 * @param offset
 * @param toIndex
 * @param orderByFieldName
 * @param filter
 *
 * @return map with "count" and "records" items
 */
@Secured(USER)
public Map<String, Object> loadRecordSummaries(String rootEntityName, int offset, int maxNumberOfRows, List<RecordSummarySortField> sortFields, String[] keyValues) {
    Map<String, Object> result = new HashMap<String, Object>();
    SessionState sessionState = sessionManager.getSessionState();
    CollectSurvey activeSurvey = sessionState.getActiveSurvey();
    Schema schema = activeSurvey.getSchema();
    EntityDefinition rootEntityDefinition = schema.getRootEntityDefinition(rootEntityName);
    RecordFilter filter = new RecordFilter(activeSurvey, rootEntityDefinition.getId());
    filter.setKeyValues(keyValues);
    filter.setOffset(offset);
    filter.setMaxNumberOfRecords(maxNumberOfRows);
    // load summaries
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter, sortFields);
    List<RecordSummaryProxy> proxies = RecordSummaryProxy.fromList(summaries, getProxyContext());
    result.put("records", proxies);
    // count total records
    int count = recordManager.countRecords(filter);
    result.put("count", count);
    return result;
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) HashMap(java.util.HashMap) Schema(org.openforis.idm.metamodel.Schema) RecordSummaryProxy(org.openforis.collect.model.proxy.RecordSummaryProxy) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) Secured(org.springframework.security.access.annotation.Secured)

Example 2 with RecordSummaryProxy

use of org.openforis.collect.model.proxy.RecordSummaryProxy in project collect by openforis.

the class DataService method loadRecordSummaries.

@Secured(USER)
public Map<String, Object> loadRecordSummaries(RecordFilterProxy filterProxy, List<RecordSummarySortField> sortFields, String localeStr) {
    Map<String, Object> result = new HashMap<String, Object>();
    CollectSurvey survey;
    if (filterProxy.getSurveyId() > 0) {
        survey = surveyManager.getById(filterProxy.getSurveyId());
    } else {
        SessionState sessionState = sessionManager.getSessionState();
        survey = sessionState.getActiveSurvey();
    }
    RecordFilter filter = filterProxy.toFilter(survey);
    // load summaries
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter, sortFields);
    Locale locale = LocaleUtils.toLocale(localeStr);
    ProxyContext proxyContext = new ProxyContext(locale, messageSource, surveyContext);
    List<RecordSummaryProxy> proxies = RecordSummaryProxy.fromList(summaries, proxyContext);
    result.put("records", proxies);
    // count total records
    int count = recordManager.countRecords(filter);
    result.put("count", count);
    return result;
}
Also used : Locale(java.util.Locale) SessionState(org.openforis.collect.web.session.SessionState) ProxyContext(org.openforis.collect.ProxyContext) HashMap(java.util.HashMap) RecordSummaryProxy(org.openforis.collect.model.proxy.RecordSummaryProxy) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

HashMap (java.util.HashMap)2 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 RecordFilter (org.openforis.collect.model.RecordFilter)2 RecordSummaryProxy (org.openforis.collect.model.proxy.RecordSummaryProxy)2 SessionState (org.openforis.collect.web.session.SessionState)2 Secured (org.springframework.security.access.annotation.Secured)2 Locale (java.util.Locale)1 ProxyContext (org.openforis.collect.ProxyContext)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 Schema (org.openforis.idm.metamodel.Schema)1