RoleBean.java
2.92 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* 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.AccessRightFacade;
import fi.insomnia.bortal.facade.RoleFacade;
import fi.insomnia.bortal.facade.RoleRightFacade;
import fi.insomnia.bortal.model.AccessRight;
import fi.insomnia.bortal.model.Event;
import fi.insomnia.bortal.model.Role;
import fi.insomnia.bortal.model.RoleRight;
/**
*
* @author tuukka
*/
@Stateless
public class RoleBean implements RoleBeanLocal {
@EJB
private RoleFacade roleFacade;
@EJB
private AccessRightFacade arf;
@EJB
private RoleRightFacade rrfacade;
@EJB
private AccessRightFacade accessrightFacade;
private static final Logger logger = LoggerFactory.getLogger(RoleBean.class);
public List<Role> listRoles() {
return roleFacade.findAll();
}
public Role mergeChanges(Role role) {
return 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 List<RoleRight> getEventRoleRights(Event e, Role r) {
List<AccessRight> rights = arf.findAll();
List<RoleRight> ret = new ArrayList<RoleRight>();
for(AccessRight ar : rights)
{
RoleRight roleright = rrfacade.find(e, ar, r);
if(roleright == null)
{
roleright = new RoleRight(e);
roleright.setAccessRight(ar);
roleright.setRole(r);
rrfacade.create(roleright);
}
ret.add(roleright);
}
return ret;
}
@Override
public RoleRight mergeChanges(RoleRight row) {
return rrfacade.merge(row);
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method")
}