Commit 40865050 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

issue #12 PrivilegeType in db is mapped by privilege name not id of enum

parent cff9d812
package lcsb.mapviewer.model.user; package lcsb.mapviewer.model.user;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType; import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue; import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.EnumType;
import javax.persistence.GeneratedValue; import javax.persistence.Enumerated;
import javax.persistence.GenerationType; import javax.persistence.FetchType;
import javax.persistence.Id; import javax.persistence.GeneratedValue;
import javax.persistence.Inheritance; import javax.persistence.GenerationType;
import javax.persistence.InheritanceType; import javax.persistence.Id;
import javax.persistence.ManyToOne; import javax.persistence.Inheritance;
import javax.persistence.Table; import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
/** import javax.persistence.Table;
* Class that defines user privilege. Privilege has an access level (typicaly 0,
* 1 value), type of the privilege and user reference. /**
* * Class that defines user privilege. Privilege has an access level (typicaly 0,
* @author Piotr Gawron * 1 value), type of the privilege and user reference.
* *
*/ * @author Piotr Gawron
@Entity *
@Table(name = "privilege_table") */
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @Entity
@DiscriminatorColumn(name = "privilege_class_type_db", discriminatorType = DiscriminatorType.STRING) @Table(name = "privilege_table")
@DiscriminatorValue("BASIC_PRIVILEGE") @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class BasicPrivilege implements Serializable { @DiscriminatorColumn(name = "privilege_class_type_db", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("BASIC_PRIVILEGE")
/** public class BasicPrivilege implements Serializable {
*
*/ /**
private static final long serialVersionUID = 1L; *
*/
/** private static final long serialVersionUID = 1L;
* Unique identifier in the database.
*/ /**
@Id * Unique identifier in the database.
@GeneratedValue(strategy = GenerationType.IDENTITY) */
@Column(name = "idDb", unique = true, nullable = false) @Id
private int id; @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idDb", unique = true, nullable = false)
/** private int id;
* Which user this privilege concerns.
*/ /**
@ManyToOne(fetch = FetchType.LAZY) * Which user this privilege concerns.
private User user; */
@ManyToOne(fetch = FetchType.LAZY)
/** private User user;
* Type of the privilege.
*/ /**
private PrivilegeType type; * Type of the privilege.
*/
/** @Enumerated(EnumType.STRING)
* Access level of the privilege. By default 0 means that user doesn't have private PrivilegeType type;
* privilege and value greater than 0 means that user has privilege. It's
* possible to implement different behaviour for different level values. /**
*/ * Access level of the privilege. By default 0 means that user doesn't have
private int level; * privilege and value greater than 0 means that user has privilege. It's
* possible to implement different behaviour for different level values.
/** */
* Constructor that initialize the privilege with given data. private int level;
*
* @param level /**
* level on which the privilege is set * Constructor that initialize the privilege with given data.
* @param type *
* type of the privilege * @param level
* @param user * level on which the privilege is set
* user for which this privilege is set * @param type
*/ * type of the privilege
public BasicPrivilege(int level, PrivilegeType type, User user) { * @param user
this.level = level; * user for which this privilege is set
this.type = type; */
this.user = user; public BasicPrivilege(int level, PrivilegeType type, User user) {
} this.level = level;
this.type = type;
/** this.user = user;
* Default constructor. }
*/
public BasicPrivilege() { /**
} * Default constructor.
*/
/** public BasicPrivilege() {
* Checks if the privilege is with the same type as privilege given in the }
* parameter.
* /**
* @param privilege * Checks if the privilege is with the same type as privilege given in the
* other privilege to compare * parameter.
* @return <code>true</code> if privilege is of the same type as an argument, *
* <code>false</code> otherwise * @param privilege
*/ * other privilege to compare
public boolean equalsPrivilege(BasicPrivilege privilege) { * @return <code>true</code> if privilege is of the same type as an argument,
if (privilege == null) { * <code>false</code> otherwise
return false; */
} public boolean equalsPrivilege(BasicPrivilege privilege) {
return type.equals(privilege.getType()); if (privilege == null) {
} return false;
}
/** return type.equals(privilege.getType());
* @return the id }
* @see #id
*/ /**
public int getId() { * @return the id
return id; * @see #id
} */
public int getId() {
/** return id;
* @param id }
* the id to set
* @see #id /**
*/ * @param id
public void setId(int id) { * the id to set
this.id = id; * @see #id
} */
public void setId(int id) {
/** this.id = id;
* @return the user }
* @see #user
*/ /**
public User getUser() { * @return the user
return user; * @see #user
} */
public User getUser() {
/** return user;
* @param user }
* the user to set
* @see #user /**
*/ * @param user
public void setUser(User user) { * the user to set
this.user = user; * @see #user
} */
public void setUser(User user) {
/** this.user = user;
* @return the type }
* @see #type
*/ /**
public PrivilegeType getType() { * @return the type
return type; * @see #type
} */
public PrivilegeType getType() {
/** return type;
* @param type }
* the type to set
* @see #type /**
*/ * @param type
public void setType(PrivilegeType type) { * the type to set
this.type = type; * @see #type
} */
public void setType(PrivilegeType type) {
/** this.type = type;
* @return the level }
* @see #level
*/ /**
public int getLevel() { * @return the level
return level; * @see #level
} */
public int getLevel() {
/** return level;
* @param level }
* the level to set
* @see #level /**
*/ * @param level
public void setLevel(int level) { * the level to set
this.level = level; * @see #level
} */
} public void setLevel(int level) {
this.level = level;
}
}
...@@ -3,3 +3,20 @@ alter table project_table add column sbgnformat boolean default false ; ...@@ -3,3 +3,20 @@ alter table project_table add column sbgnformat boolean default false ;
update project_table set sbgnformat = (select sbgnformat from model_table where project_iddb = project_table.iddb); update project_table set sbgnformat = (select sbgnformat from model_table where project_iddb = project_table.iddb);
alter table model_table drop column sbgnformat; alter table model_table drop column sbgnformat;
--PrivilegeType should be mapped in database by name not by index
alter table privilege_table add column type_string character varying;
update privilege_table set type_string = 'VIEW_PROJECT' where type = 0;
update privilege_table set type_string = 'ADD_MAP' where type = 1;
update privilege_table set type_string = 'EDIT_MISSING_CONNECTIONS_PROJECT' where type = 2;
update privilege_table set type_string = 'EDIT_COMMENTS_PROJECT' where type = 3;
update privilege_table set type_string = 'DRUG_TARGETING_ADVANCED_VIEW_PROJECT' where type = 4;
update privilege_table set type_string = 'PROJECT_MANAGEMENT' where type = 5;
update privilege_table set type_string = 'USER_MANAGEMENT' where type = 6;
update privilege_table set type_string = 'CUSTOM_LAYOUTS' where type = 7;
update privilege_table set type_string = 'LAYOUT_VIEW' where type = 8;
update privilege_table set type_string = 'CONFIGURATION_MANAGE' where type = 9;
update privilege_table set type_string = 'LAYOUT_MANAGEMENT' where type = 10;
update privilege_table set type_string = 'MANAGE_GENOMES' where type = 11;
alter table privilege_table drop column type;
alter table privilege_table rename type_string TO type;
...@@ -20,6 +20,8 @@ import org.springframework.security.crypto.password.PasswordEncoder; ...@@ -20,6 +20,8 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.user.BasicPrivilege;
import lcsb.mapviewer.model.user.PrivilegeType;
import lcsb.mapviewer.model.user.User; import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.model.user.UserAnnotationSchema; import lcsb.mapviewer.model.user.UserAnnotationSchema;
import lcsb.mapviewer.model.user.UserClassAnnotators; import lcsb.mapviewer.model.user.UserClassAnnotators;
...@@ -61,6 +63,7 @@ public class UserDaoTest extends PersistTestFunctions { ...@@ -61,6 +63,7 @@ public class UserDaoTest extends PersistTestFunctions {
user = new User(); user = new User();
user.setLogin(testLogin); user.setLogin(testLogin);
user.addPrivilege(new BasicPrivilege(0, PrivilegeType.ADD_MAP, user));
userDao.add(user); userDao.add(user);
long counter2 = userDao.getCount(); long counter2 = userDao.getCount();
...@@ -81,7 +84,7 @@ public class UserDaoTest extends PersistTestFunctions { ...@@ -81,7 +84,7 @@ public class UserDaoTest extends PersistTestFunctions {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
fail("Unexpected exception occured"); throw e;
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment