Salome HOME
Copyrights update 2015.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / som / ApplicationRights.java
index 2bde8cd209e296ce4d65f8e05308ad60e65b1c06..8a18cb90938ec5a4ab82c96834462e5d09ee9772 100644 (file)
@@ -1,90 +1,99 @@
 package org.splat.som;
+
 /**
  * 
  * @author    Daniel Brunier-Coulin
- * @copyright OPEN CASCADE 2012
+ * @copyright OPEN CASCADE 2012-2015
  */
 
 import java.util.HashSet;
 import java.util.Set;
 
-import org.splat.kernel.Role;
-import org.splat.kernel.User;
-
+import org.splat.dal.bo.kernel.Role;
+import org.splat.dal.bo.kernel.User;
 
 public class ApplicationRights {
 
-    private User        user;
-    private Set<String> roles;
+       private static final String N_1 = "Nx1";
+       private static final String N_2 = "Nx2";
+       private transient final User _user;
+       private transient final Set<String> _roles;
 
-//  ==============================================================================================================================
-//  Construction
-//  ==============================================================================================================================
+       // ==============================================================================================================================
+       // Construction
+       // ==============================================================================================================================
 
-    public ApplicationRights (User user) {     // Warning: user may be null
-//  ------------------------------------
-      this.roles = new HashSet<String>();
-      this.user  = user;
-      if  (user != null) {
-       Role[] role = user.getRoles();
-       for (int i=0; i<role.length; i++) {
-          String    iam = role[i].getName();
-          roles.add(iam);
-       }
-      }
-    }
+       public ApplicationRights(final User user) { // Warning: user may be null
+               this._roles = new HashSet<String>();
+               this._user = user;
+               if (user != null) {
+                       Role[] role = user.getRoles();
+                       for (int i = 0; i < role.length; i++) {
+                               String iam = role[i].getName();
+                               _roles.add(iam);
+                       }
+               }
+       }
 
-//  ==============================================================================================================================
-//  Public member functions
-//  ==============================================================================================================================
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
 
-    public boolean canCreateStudy () {
-//  --------------------------------
-      if (user != null) {
-        String position = user.getOrganizationName();
-        if (position != null && position.equals("Nx2")) return false;
-      }
-      return  roles.contains(Profile.manager.toString());
-    }
+       public boolean canCreateStudy() {
+               boolean res = (_user == null);
+               if (res) {
+                       res = _roles.contains(Profile.manager.toString());
+               } else {
+                       String position = _user.getOrganizationName();
+                       res = (position == null || !position.equals(N_2));
+               }
+               return res;
+       }
 
-    public boolean canContributeToStudy () {
-//  --------------------------------------
-      if (user != null) {
-        String position = user.getOrganizationName();
-        if (position != null && (position.equals("Nx1") || position.equals("Nx2"))) return false;
-      }
-      return (roles.contains(Profile.manager.toString()) || roles.contains(Profile.studengineer.toString()));
-    }
+       public boolean canContributeToStudy() {
+               boolean res = (_user == null);
+               if (res) {
+                       res = (_roles.contains(Profile.manager.toString()) || _roles
+                                       .contains(Profile.studengineer.toString()));
+               } else {
+                       String position = _user.getOrganizationName();
+                       res = (position == null || ((!position.equals(N_1)) && (!position
+                                       .equals(N_2))));
+               }
+               return res;
+       }
 
-    public boolean canValidate () {
-//  -----------------------------
-      return  roles.contains(Profile.manager.toString());
-    }
+       public boolean canValidate() {
+               return _roles.contains(Profile.manager.toString());
+       }
 
-    public boolean canManageKnowledges () {
-//  -------------------------------------
-      if (user != null) {
-        String position = user.getOrganizationName();
-        if (position != null && position.equals("Nx2")) return false;
-      }
-      return  roles.contains(Profile.knowledgineer.toString());
-    }
+       public boolean canManageKnowledges() {
+               boolean res = (_user == null); 
+               if (res) {
+                       res = _roles.contains(Profile.knowledgineer.toString());
+               } else {
+                       String position = _user.getOrganizationName();
+                       res = (position == null || (!position.equals(N_2)));
+               }
+               return res;
+       }
 
-    public boolean canManageDatabase () {
-//  -----------------------------------
-      if (user != null) {
-        String position = user.getOrganizationName();
-        if (position != null && position.equals("Nx2")) return false;
-      }
-      return  roles.contains(Profile.sysadmin.toString());
-    }
+       public boolean canManageDatabase() {
+               boolean res = (_user == null); 
+               if (res) {
+                       res = _roles.contains(Profile.sysadmin.toString());
+               } else {
+                       String position = _user.getOrganizationName();
+                       res = ((position == null || (!position.equals(N_2))) && _roles.contains(Profile.sysadmin.toString()));
+               }
+               return res;
+       }
 
-//  ==============================================================================================================================
-//  Getters
-//  ==============================================================================================================================
+       // ==============================================================================================================================
+       // Getters
+       // ==============================================================================================================================
 
-    public User getUser () {
-//  ----------------------
-      return user;                             // May be null
-    }
+       public User getUser() {
+               return _user; // May be null
+       }
 }
\ No newline at end of file