com.soento.core.lang.UserInfo Maven / Gradle / Ivy
package com.soento.core.lang;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.soento.core.util.CollectionUtil;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author soento
*/
@Getter
@Setter
public class UserInfo extends BaseObject {
/**
* 用户头像
*/
private String avatar;
/**
* 用户Id
*/
private String id;
/**
* 用户名
*/
private String username;
/**
* 用户昵称
*/
private String nickname;
/**
* 角色集合
*/
private List roles;
public boolean isRoot() {
Set roleIds = getRoleIds();
return roleIds != null && roleIds.size() > 0 && roleIds.contains(RoleInfo.ROOT);
}
@JsonIgnore
public Set getRoleIds() {
Set roleIds = new HashSet<>();
if (roles != null && roles.size() > 0) {
for (RoleInfo role : roles) {
roleIds.add(role.getId());
}
}
return roleIds;
}
@JsonIgnore
public List getRoleNames() {
List roleNames = new ArrayList<>();
if (roles != null && roles.size() > 0) {
for (RoleInfo role : roles) {
roleNames.add(role.getName());
}
}
return roleNames;
}
@JsonIgnore
public Set getPermissionNames() {
Set permissionNames = new HashSet<>();
if (CollectionUtil.isNotEmpty(roles)) {
for (RoleInfo role : roles) {
if (CollectionUtil.isNotEmpty(role.getPermissions())) {
for (PermissionInfo permission : role.getPermissions()) {
permissionNames.add(permission.getName());
}
}
}
}
return permissionNames;
}
@JsonIgnore
public Set getPermissionUris() {
Set permissionUris = new HashSet<>();
if (CollectionUtil.isNotEmpty(roles)) {
for (RoleInfo role : roles) {
if (CollectionUtil.isNotEmpty(role.getPermissions())) {
for (PermissionInfo permission : role.getPermissions()) {
permissionUris.add(permission.getUri());
}
}
}
}
return permissionUris;
}
}