5 * @author Daniel Brunier-Coulin
6 * @copyright OPEN CASCADE 2012-2015
9 import java.util.HashSet;
12 import org.splat.dal.bo.kernel.Role;
13 import org.splat.dal.bo.kernel.User;
15 public class ApplicationRights {
17 private static final String N_1 = "Nx1";
18 private static final String N_2 = "Nx2";
19 private transient final User _user;
20 private transient final Set<String> _roles;
22 // ==============================================================================================================================
24 // ==============================================================================================================================
26 public ApplicationRights(final User user) { // Warning: user may be null
27 this._roles = new HashSet<String>();
30 Role[] role = user.getRoles();
31 for (int i = 0; i < role.length; i++) {
32 String iam = role[i].getName();
38 // ==============================================================================================================================
39 // Public member functions
40 // ==============================================================================================================================
42 public boolean canCreateStudy() {
43 boolean res = (_user == null);
45 res = _roles.contains(Profile.manager.toString());
47 String position = _user.getOrganizationName();
48 res = (position == null || !position.equals(N_2));
53 public boolean canContributeToStudy() {
54 boolean res = (_user == null);
56 res = (_roles.contains(Profile.manager.toString()) || _roles
57 .contains(Profile.studengineer.toString()));
59 String position = _user.getOrganizationName();
60 res = (position == null || ((!position.equals(N_1)) && (!position
66 public boolean canValidate() {
67 return _roles.contains(Profile.manager.toString());
70 public boolean canManageKnowledges() {
71 boolean res = (_user == null);
73 res = _roles.contains(Profile.knowledgineer.toString());
75 String position = _user.getOrganizationName();
76 res = (position == null || (!position.equals(N_2)));
81 public boolean canManageDatabase() {
82 boolean res = (_user == null);
84 res = _roles.contains(Profile.sysadmin.toString());
86 String position = _user.getOrganizationName();
87 res = ((position == null || (!position.equals(N_2))) && _roles.contains(Profile.sysadmin.toString()));
92 // ==============================================================================================================================
94 // ==============================================================================================================================
96 public User getUser() {
97 return _user; // May be null