use of org.openforis.collect.model.User in project collect by openforis.
the class BaseVM method initUserGroupsModel.
protected void initUserGroupsModel() {
List<LabelledItem> items = new ArrayList<LabelledItem>();
User loggedUser = getLoggedUser();
List<UserGroup> userGroups = userGroupManager.findAllRelatedUserGroups(loggedUser);
for (UserGroup userGroup : userGroups) {
String label = userGroup.getName().equals(UserGroupManager.DEFAULT_PUBLIC_USER_GROUP_NAME) ? Labels.getLabel(PUBLIC_USER_GROUP_LABEL_KEY) : userGroup.getName().equals(userGroupManager.getDefaultPrivateUserGroupName(loggedUser)) ? Labels.getLabel(PRIVATE_USER_GROUP_LABEL_KEY) : userGroup.getLabel();
items.add(new LabelledItem(userGroup.getName(), label));
}
userGroupsModel = new BindingListModelListModel<LabelledItem>(new ListModelList<LabelledItem>(items));
userGroupsModel.setMultiple(false);
}
use of org.openforis.collect.model.User 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;
}
use of org.openforis.collect.model.User in project collect by openforis.
the class RecordController method startCsvDataExportJob.
@RequestMapping(value = "survey/{surveyId}/data/records/startcsvexport", method = POST)
@ResponseBody
public JobView startCsvDataExportJob(@PathVariable("surveyId") int surveyId, @RequestBody CSVExportParametersForm parameters) throws IOException {
User user = sessionManager.getLoggedUser();
CollectSurvey survey = surveyManager.getById(surveyId);
csvDataExportJob = jobManager.createJob(CSVDataExportJob.class);
csvDataExportJob.setSurvey(survey);
csvDataExportJob.setOutputFile(File.createTempFile("collect-csv-data-export", ".zip"));
CSVDataExportParameters exportParameters = parameters.toExportParameters(survey, user, userGroupManager);
csvDataExportJob.setParameters(exportParameters);
jobManager.start(csvDataExportJob);
return new JobView(csvDataExportJob);
}
use of org.openforis.collect.model.User in project collect by openforis.
the class RecordController method startValidationResportJob.
@RequestMapping(value = "survey/{surveyId}/data/records/validationreport", method = POST)
@ResponseBody
public JobProxy startValidationResportJob(@PathVariable("surveyId") int surveyId) {
User user = sessionManager.getLoggedUser();
Locale locale = sessionManager.getSessionState().getLocale();
CollectSurvey survey = surveyManager.getById(surveyId);
EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
ValidationReportJob job = jobManager.createJob(ValidationReportJob.class);
Input input = new Input();
input.setLocale(locale);
input.setReportType(ReportType.CSV);
RecordFilter recordFilter = createRecordFilter(survey, user, userGroupManager, rootEntityDef.getId(), false);
input.setRecordFilter(recordFilter);
job.setInput(input);
this.validationReportJob = job;
jobManager.start(job);
return new JobProxy(job);
}
use of org.openforis.collect.model.User in project collect by openforis.
the class SessionController method getLoggedUser.
@RequestMapping(value = "user", method = GET)
@ResponseBody
public UserForm getLoggedUser(HttpServletRequest request, HttpServletResponse response) {
SessionState sessionState = sessionManager.getSessionState();
User user = sessionState == null ? null : sessionState.getUser();
if (user == null) {
HttpResponses.setNoContentStatus(response);
return null;
}
if (sessionState.getLocale() == null) {
sessionState.setLocale(request.getLocale());
}
return new UserController.UserForm(user);
}
Aggregations