Search in sources :

Example 21 with UserGroup

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

the class LocalUserGroupManager method findDescendantGroups.

@Override
public List<UserGroup> findDescendantGroups(UserGroup group) {
    List<UserGroup> result = new ArrayList<UserGroup>();
    List<Integer> childrenGroupIds = dao.findChildrenGroupIds(group.getId());
    for (Integer childId : childrenGroupIds) {
        UserGroup childGroup = loadById(childId);
        result.add(childGroup);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) UserGroup(org.openforis.collect.model.UserGroup)

Example 22 with UserGroup

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

the class LocalUserGroupManager method loadById.

@Override
public UserGroup loadById(Integer id) {
    UserGroup group = super.loadById(id);
    fillLazyLoadedFields(group);
    return group;
}
Also used : UserGroup(org.openforis.collect.model.UserGroup)

Example 23 with UserGroup

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

the class LocalUserGroupManager method getQualifiers.

@Override
public Map<String, String> getQualifiers(UserGroup group, User user) {
    UserInGroup userInGroup = findUserInGroupOrDescendants(group, user);
    if (userInGroup == null) {
        throw new IllegalArgumentException(String.format("User %s not allowed to see records for user group %s", user.getUsername(), group.getName()));
    }
    UserGroup associatedGroup = loadById(userInGroup.getGroupId());
    return associatedGroup.getQualifiersByName();
}
Also used : UserInGroup(org.openforis.collect.model.UserInGroup) UserGroup(org.openforis.collect.model.UserGroup)

Example 24 with UserGroup

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

the class LocalUserManager method loadAllAvailableUsers.

@Override
public List<User> loadAllAvailableUsers(User availableTo) {
    if (availableTo.getRoles().contains(UserRole.ADMIN)) {
        return loadAll();
    } else {
        Set<User> users = new TreeSet<User>();
        List<UserGroup> userGroups = groupManager.findByUser(availableTo);
        for (UserGroup userGroup : userGroups) {
            List<UserInGroup> groupUsers = groupManager.findUsersInGroup(userGroup);
            for (UserInGroup userInGroup : groupUsers) {
                Integer userId = userInGroup.getUserId();
                User user = loadById(userId);
                users.add(user);
            }
        }
        // sorted by username by default (see User.compareTo)
        return new ArrayList<User>(users);
    }
}
Also used : User(org.openforis.collect.model.User) UserInGroup(org.openforis.collect.model.UserInGroup) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) UserGroup(org.openforis.collect.model.UserGroup)

Example 25 with UserGroup

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

the class ClientUserGroupManager method findByUser.

@SuppressWarnings("rawtypes")
@Override
public List<UserGroup> findByUser(User user) {
    List<Map> userGroupRelations = getList(getUsersRestfulApiUrl() + "/user/" + user.getId() + "/groups", Map.class);
    List<UserGroup> result = new ArrayList<UserGroup>();
    for (Map userGroupRelation : userGroupRelations) {
        Double groupId = (Double) userGroupRelation.get("groupId");
        UserGroup group = loadById(groupId.intValue());
        result.add(group);
    }
    result.add(getDefaultPublicUserGroup());
    return result;
}
Also used : ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) UserGroup(org.openforis.collect.model.UserGroup)

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