Search in sources :

Example 1 with BasicUserProxy

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

the class RecordController method loadRecordSummaries.

@RequestMapping(value = "survey/{surveyId}/data/records/summary", method = GET)
@ResponseBody
public Map<String, Object> loadRecordSummaries(@PathVariable("surveyId") int surveyId, @Valid RecordSummarySearchParameters params) {
    CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveyId);
    User user = loadUser(params.getUserId(), params.getUsername());
    Map<String, Object> result = new HashMap<String, Object>();
    Schema schema = survey.getSchema();
    EntityDefinition rootEntityDefinition = params.getRootEntityName() == null ? schema.getFirstRootEntityDefinition() : schema.getRootEntityDefinition(params.getRootEntityName());
    RecordFilter filter = createRecordFilter(survey, user, userGroupManager, rootEntityDefinition.getId(), false);
    filter.setKeyValues(params.getKeyValues());
    filter.setCaseSensitiveKeyValues(params.isCaseSensitiveKeyValues());
    if (CollectionUtils.isEmpty(filter.getQualifiers())) {
        // filter by qualifiers only if not already done by user group qualifiers
        filter.setQualifiers(params.getQualifierValues());
    }
    filter.setSummaryValues(params.getSummaryValues());
    if (filter.getOwnerIds() == null && params.getOwnerIds() != null && params.getOwnerIds().length > 0) {
        filter.setOwnerIds(Arrays.asList(params.getOwnerIds()));
    }
    filter.setOffset(params.getOffset());
    filter.setMaxNumberOfRecords(params.getMaxNumberOfRows());
    // load summaries
    List<CollectRecordSummary> summaries = params.isFullSummary() ? recordManager.loadFullSummaries(filter, params.getSortFields()) : recordManager.loadSummaries(filter, params.getSortFields());
    result.put("records", toProxies(summaries));
    // count total records
    int count = recordManager.countRecords(filter);
    result.put("count", count);
    if (params.isIncludeOwners()) {
        Set<User> owners = recordManager.loadDistinctOwners(createRecordFilter(survey, user, userGroupManager, rootEntityDefinition.getId(), false));
        Set<BasicUserProxy> ownerProxies = Proxies.fromSet(owners, BasicUserProxy.class);
        result.put("owners", ownerProxies);
    }
    return result;
}
Also used : User(org.openforis.collect.model.User) HashMap(java.util.HashMap) Schema(org.openforis.idm.metamodel.Schema) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) BasicUserProxy(org.openforis.collect.model.proxy.BasicUserProxy) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

HashMap (java.util.HashMap)1 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 RecordFilter (org.openforis.collect.model.RecordFilter)1 User (org.openforis.collect.model.User)1 BasicUserProxy (org.openforis.collect.model.proxy.BasicUserProxy)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 Schema (org.openforis.idm.metamodel.Schema)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1