Search in sources :

Example 11 with User

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);
}
Also used : User(org.openforis.collect.model.User) LabelledItem(org.openforis.collect.designer.model.LabelledItem) ListModelList(org.zkoss.zul.ListModelList) ArrayList(java.util.ArrayList) UserGroup(org.openforis.collect.model.UserGroup)

Example 12 with User

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

Example 13 with User

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);
}
Also used : User(org.openforis.collect.model.User) JobView(org.openforis.collect.web.controller.CollectJobController.JobView) CSVDataExportJob(org.openforis.collect.io.data.CSVDataExportJob) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 14 with User

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);
}
Also used : Locale(java.util.Locale) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Input(org.openforis.collect.manager.ValidationReportJob.Input) CSVDataImportInput(org.openforis.collect.io.data.CSVDataImportJob.CSVDataImportInput) User(org.openforis.collect.model.User) JobProxy(org.openforis.concurrency.proxy.JobProxy) ValidationReportJob(org.openforis.collect.manager.ValidationReportJob) 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)

Example 15 with User

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);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) User(org.openforis.collect.model.User) UserForm(org.openforis.collect.web.controller.UserController.UserForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

User (org.openforis.collect.model.User)71 CollectRecord (org.openforis.collect.model.CollectRecord)19 CollectSurvey (org.openforis.collect.model.CollectSurvey)19 SessionState (org.openforis.collect.web.session.SessionState)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 Transactional (org.springframework.transaction.annotation.Transactional)11 RecordFilter (org.openforis.collect.model.RecordFilter)10 Test (org.junit.Test)8 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)6 RecordUpdater (org.openforis.collect.model.RecordUpdater)6 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)5 Date (java.util.Date)4 UserGroup (org.openforis.collect.model.UserGroup)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 Secured (org.springframework.security.access.annotation.Secured)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RecordStep (org.openforis.collect.event.RecordStep)3 Step (org.openforis.collect.model.CollectRecord.Step)3