org.openforis.collect.manager.ClientUserGroupManager Maven / Gradle / Ivy
package org.openforis.collect.manager;
import static org.openforis.collect.config.CollectConfiguration.getUsersRestfulApiUrl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.openforis.collect.client.AbstractClient;
import org.openforis.collect.model.User;
import org.openforis.collect.model.UserGroup;
import org.openforis.collect.model.UserInGroup;
import org.openforis.collect.model.UserInGroup.UserGroupJoinRequestStatus;
import org.openforis.collect.model.UserInGroup.UserGroupRole;
public class ClientUserGroupManager extends AbstractClient implements UserGroupManager {
/**
* Cached default public user group
*/
private UserGroup defaultPublicUserGroup;
@Override
public UserGroup getDefaultPublicUserGroup() {
if (defaultPublicUserGroup == null) {
defaultPublicUserGroup = findByName(DEFAULT_PUBLIC_USER_GROUP_NAME);
}
return defaultPublicUserGroup;
}
@Override
public String getDefaultPrivateUserGroupName(User user) {
return user.getUsername() + DEFAULT_PRIVATE_USER_GROUP_NAME_SUFFIX;
}
@Override
public UserGroup loadById(Integer id) {
return getOne(getUsersRestfulApiUrl() + "/group/" + id, UserGroup.class);
}
@Override
public List loadAll() {
return getList(getUsersRestfulApiUrl() + "/group", UserGroup.class);
}
@Override
public UserInGroup findUserInGroup(int userGroupId, final int userId) {
List userInGroups = findUsersInGroup(userGroupId);
return (UserInGroup) CollectionUtils.find(userInGroups, new Predicate() {
public boolean evaluate(Object userInGroup) {
return ((UserInGroup) userInGroup).getUserId().equals(userId);
}
});
}
@SuppressWarnings("rawtypes")
@Override
public List findUsersInGroup(int userGroupId) {
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy