Salome HOME
Refactoring: kernel and som are moved to Siman-Common.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / som / ApplicationRights.java
1 package org.splat.som;
2 /**
3  * 
4  * @author    Daniel Brunier-Coulin
5  * @copyright OPEN CASCADE 2012
6  */
7
8 import java.util.HashSet;
9 import java.util.Set;
10
11 import org.splat.kernel.Role;
12 import org.splat.kernel.User;
13
14
15 public class ApplicationRights {
16
17     private User        user;
18     private Set<String> roles;
19
20 //  ==============================================================================================================================
21 //  Construction
22 //  ==============================================================================================================================
23
24     public ApplicationRights (User user) {     // Warning: user may be null
25 //  ------------------------------------
26       this.roles = new HashSet<String>();
27       this.user  = user;
28       if  (user != null) {
29         Role[] role = user.getRoles();
30         for (int i=0; i<role.length; i++) {
31           String    iam = role[i].getName();
32           roles.add(iam);
33         }
34       }
35     }
36
37 //  ==============================================================================================================================
38 //  Public member functions
39 //  ==============================================================================================================================
40
41     public boolean canCreateStudy () {
42 //  --------------------------------
43       if (user != null) {
44         String position = user.getOrganizationName();
45         if (position != null && position.equals("Nx2")) return false;
46       }
47       return  roles.contains(Profile.manager.toString());
48     }
49
50     public boolean canContributeToStudy () {
51 //  --------------------------------------
52       if (user != null) {
53         String position = user.getOrganizationName();
54         if (position != null && (position.equals("Nx1") || position.equals("Nx2"))) return false;
55       }
56       return (roles.contains(Profile.manager.toString()) || roles.contains(Profile.studengineer.toString()));
57     }
58
59     public boolean canValidate () {
60 //  -----------------------------
61       return  roles.contains(Profile.manager.toString());
62     }
63
64     public boolean canManageKnowledges () {
65 //  -------------------------------------
66       if (user != null) {
67         String position = user.getOrganizationName();
68         if (position != null && position.equals("Nx2")) return false;
69       }
70       return  roles.contains(Profile.knowledgineer.toString());
71     }
72
73     public boolean canManageDatabase () {
74 //  -----------------------------------
75       if (user != null) {
76         String position = user.getOrganizationName();
77         if (position != null && position.equals("Nx2")) return false;
78       }
79       return  roles.contains(Profile.sysadmin.toString());
80     }
81
82 //  ==============================================================================================================================
83 //  Getters
84 //  ==============================================================================================================================
85
86     public User getUser () {
87 //  ----------------------
88       return user;                             // May be null
89     }
90 }