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