4 * @author Daniel Brunier-Coulin
5 * @copyright OPEN CASCADE 2012
8 import java.util.HashSet;
11 import org.splat.kernel.Role;
12 import org.splat.kernel.User;
15 public class ApplicationRights {
18 private Set<String> roles;
20 // ==============================================================================================================================
22 // ==============================================================================================================================
24 public ApplicationRights (User user) { // Warning: user may be null
25 // ------------------------------------
26 this.roles = new HashSet<String>();
29 Role[] role = user.getRoles();
30 for (int i=0; i<role.length; i++) {
31 String iam = role[i].getName();
37 // ==============================================================================================================================
38 // Public member functions
39 // ==============================================================================================================================
41 public boolean canCreateStudy () {
42 // --------------------------------
44 String position = user.getOrganizationName();
45 if (position != null && position.equals("Nx2")) return false;
47 return roles.contains(Profile.manager.toString());
50 public boolean canContributeToStudy () {
51 // --------------------------------------
53 String position = user.getOrganizationName();
54 if (position != null && (position.equals("Nx1") || position.equals("Nx2"))) return false;
56 return (roles.contains(Profile.manager.toString()) || roles.contains(Profile.studengineer.toString()));
59 public boolean canValidate () {
60 // -----------------------------
61 return roles.contains(Profile.manager.toString());
64 public boolean canManageKnowledges () {
65 // -------------------------------------
67 String position = user.getOrganizationName();
68 if (position != null && position.equals("Nx2")) return false;
70 return roles.contains(Profile.knowledgineer.toString());
73 public boolean canManageDatabase () {
74 // -----------------------------------
76 String position = user.getOrganizationName();
77 if (position != null && position.equals("Nx2")) return false;
79 return roles.contains(Profile.sysadmin.toString());
82 // ==============================================================================================================================
84 // ==============================================================================================================================
86 public User getUser () {
87 // ----------------------
88 return user; // May be null