RoleBean.java
2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fi.insomnia.bortal.beans;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.facade.RoleFacade;
import fi.insomnia.bortal.model.Role;
/**
*
* @author tuukka
*/
@Stateless
public class RoleBean implements RoleBeanLocal {
// public static final String[] DECLARED_ROLES =
// {
// BeanRole.SUPERADMIN.toString(),
// BeanRole.ADMIN_BASE.name(),
// BeanRole.USER_BASE.name()
// };
@EJB
private RoleFacade roleFacade;
private static final Logger logger = LoggerFactory.getLogger(RoleBean.class);
public List<Role> listRoles() {
return roleFacade.findAll();
}
public void mergeChanges(Role role) {
roleFacade.merge(role);
}
public Role create(Role role) {
roleFacade.create(role);
return role;
}
public List<Role> getPossibleParents(Role role) {
List<Role> roleList = listRoles();
if (role == null)
return roleList;
List<Role> children = getAllChilds(role, new HashSet<Role>());
for (Role unit : children) {
if (roleList.contains(unit)) {
roleList.remove(unit);
}
}
return roleList;
}
private static List<Role> getAllChilds(Role role, Set<Role> checkedRoles) {
List<Role> returnList = new ArrayList<Role>();
if (checkedRoles.contains(role) || role == null) {
return returnList;
}
for (Role unit : role.getChildren()) {
List<Role> someList = getAllChilds(unit, checkedRoles);
returnList.addAll(someList);
}
checkedRoles.add(role);
return returnList;
}
// public static String[] getDeclaredRoles() {
// return DECLARED_ROLES;
// }
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method")
}