Search in sources :

Example 1 with UserGroup

use of org.openforis.collect.model.UserGroup in project collect by openforis.

the class UserGroupDao method findByUser.

public List<UserGroup> findByUser(User user) {
    DSLContext dsl = dsl();
    List<UserGroup> result = dsl.selectFrom(OFC_USERGROUP).where(OFC_USERGROUP.ID.in(dsl.select(OFC_USER_USERGROUP.GROUP_ID).from(OFC_USER_USERGROUP).where(OFC_USER_USERGROUP.USER_ID.eq(user.getId())))).orderBy(OFC_USERGROUP.PARENT_ID, OFC_USERGROUP.NAME).fetchInto(UserGroup.class);
    return result;
}
Also used : DSLContext(org.jooq.DSLContext) UserGroup(org.openforis.collect.model.UserGroup)

Example 2 with UserGroup

use of org.openforis.collect.model.UserGroup in project collect by openforis.

the class DataService method findAssignableCodeListItems.

/**
 * Gets the code list items assignable to the specified attribute.
 *
 * @param parentEntityId
 * @param attrName
 * @return
 */
@Secured(USER)
public List<CodeListItemProxy> findAssignableCodeListItems(int parentEntityId, String attrName) {
    CollectRecord record = getActiveRecord();
    CollectSurvey survey = (CollectSurvey) record.getSurvey();
    UserGroup surveyUserGroup = survey.getUserGroup();
    User user = sessionManager.getLoggedUser();
    final UserInGroup userInGroup = userGroupManager.findUserInGroupOrDescendants(surveyUserGroup, user);
    if (userInGroup == null) {
        throw new IllegalStateException(String.format("User %s not allowed to access survey %s", user.getUsername(), survey.getName()));
    }
    Entity parent = (Entity) record.getNodeByInternalId(parentEntityId);
    CodeAttributeDefinition def = (CodeAttributeDefinition) parent.getDefinition().getChildDefinition(attrName);
    List<CodeListItem> items = codeListManager.loadValidItems(parent, def);
    List<CodeListItem> filteredItems = new ArrayList<CodeListItem>(items);
    // filter by user group qualifier (if any)
    UserGroup group = userGroupManager.loadById(userInGroup.getGroupId());
    String qualifierName = group.getQualifier1Name();
    String listHierarchicalLevelName = def.getList().isHierarchical() ? def.getHierarchicalLevel() : def.getListName();
    if (qualifierName != null && qualifierName.equals(listHierarchicalLevelName)) {
        CollectionUtils.filter(filteredItems, new Predicate<CodeListItem>() {

            public boolean evaluate(CodeListItem item) {
                return item.getCode().equals(group.getQualifier1Value());
            }
        });
    }
    List<CodeListItemProxy> result = CodeListItemProxy.fromList(filteredItems);
    List<Node<?>> selectedCodes = parent.getChildren(attrName);
    CodeListItemProxy.setSelectedItems(result, selectedCodes);
    return result;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) User(org.openforis.collect.model.User) UserInGroup(org.openforis.collect.model.UserInGroup) Node(org.openforis.idm.model.Node) ArrayList(java.util.ArrayList) UserGroup(org.openforis.collect.model.UserGroup) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) CodeListItem(org.openforis.idm.metamodel.CodeListItem) CodeListItemProxy(org.openforis.collect.metamodel.proxy.CodeListItemProxy) Secured(org.springframework.security.access.annotation.Secured)

Example 3 with UserGroup

use of org.openforis.collect.model.UserGroup in project collect by openforis.

the class DataRestoreTask method validateInput.

@Override
protected void validateInput() throws Throwable {
    super.validateInput();
    UserGroup surveyGroup = targetSurvey.getUserGroup();
    String surveyName = targetSurvey.getName();
    if (surveyGroup == null) {
        throw new IllegalStateException(String.format("No user group for survey %s found", surveyName));
    }
    UserInGroup userInGroup = userGroupManager.findUserInGroupOrDescendants(surveyGroup, user);
    if (userInGroup == null || !DATA_RESTORE_ALLOWED_USER_GROUP_ROLES.contains(userInGroup.getRole())) {
        throw new IllegalStateException(String.format("User %s is not allowed to restore data for survey %s", user.getUsername(), surveyName));
    }
}
Also used : UserInGroup(org.openforis.collect.model.UserInGroup) UserGroup(org.openforis.collect.model.UserGroup)

Example 4 with UserGroup

use of org.openforis.collect.model.UserGroup 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 5 with UserGroup

use of org.openforis.collect.model.UserGroup in project collect by openforis.

the class SurveyController method startSurveyFileImport.

@RequestMapping(value = "startimport", method = POST)
@ResponseBody
public Response startSurveyFileImport(@Valid SurveyImportParameters params, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        Response res = new Response();
        res.setErrorStatus();
        res.addObject("errors", bindingResult.getFieldErrors());
        return res;
    }
    String surveyName = params.getName();
    UserGroup userGroup = userGroupManager.loadById(params.getUserGroupId());
    String uploadedFileNameExtension = FilenameUtils.getExtension(this.uploadedSurveyFile.getName());
    AbstractSurveyRestoreJob job;
    if (Files.XML_FILE_EXTENSION.equalsIgnoreCase(uploadedFileNameExtension)) {
        job = jobManager.createJob(XMLSurveyRestoreJob.class);
    } else if (COLLECT_EARTH_PROJECT_FILE_EXTENSION.equalsIgnoreCase(uploadedFileNameExtension)) {
        job = jobManager.createJob(CESurveyRestoreJob.class);
    } else {
        job = jobManager.createJob(SurveyRestoreJob.class);
    }
    job.setFile(this.uploadedSurveyFile);
    job.setSurveyName(surveyName);
    job.setSurveyUri(uploadedSurveyInfo == null ? null : uploadedSurveyInfo.getSurveyUri());
    job.setUserGroup(userGroup);
    job.setRestoreIntoPublishedSurvey(false);
    job.setValidateSurvey(false);
    job.setActiveUser(sessionManager.getLoggedUser());
    jobManager.start(job);
    this.surveyImportJob = job;
    Response res = new Response();
    res.setObject(new SurveyImportJobView(job));
    return res;
}
Also used : Response(org.openforis.commons.web.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) AbstractSurveyRestoreJob(org.openforis.collect.io.AbstractSurveyRestoreJob) XMLSurveyRestoreJob(org.openforis.collect.io.XMLSurveyRestoreJob) UserGroup(org.openforis.collect.model.UserGroup) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

UserGroup (org.openforis.collect.model.UserGroup)26 CollectSurvey (org.openforis.collect.model.CollectSurvey)7 UserInGroup (org.openforis.collect.model.UserInGroup)7 ArrayList (java.util.ArrayList)6 User (org.openforis.collect.model.User)4 Timestamp (java.sql.Timestamp)3 LabelledItem (org.openforis.collect.designer.model.LabelledItem)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 AbstractSurveyRestoreJob (org.openforis.collect.io.AbstractSurveyRestoreJob)2 XMLSurveyRestoreJob (org.openforis.collect.io.XMLSurveyRestoreJob)2 SurveySummary (org.openforis.collect.model.SurveySummary)2 Response (org.openforis.commons.web.Response)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1