package org.splat.som;
+
/**
*
* @author Daniel Brunier-Coulin
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)));
+ }
+ 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