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