Define new Roles and change Role name type to PredefinedRole (#763).

Change-Id: I6e35ab319955c146fe2359440be78bfef382ef99
diff --git a/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java b/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java
index f91e511..4f2dcbc 100644
--- a/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java
+++ b/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java
@@ -7,24 +7,45 @@
  *
  */
 public enum PredefinedRole {
-    USER_GROUP_ADMIN(1), USER_GROUP_MEMBER(2), VC_ACCESS_ADMIN(
-            3), VC_ACCESS_MEMBER(
-                    4), QUERY_ACCESS_ADMIN(5), QUERY_ACCESS_MEMBER(6);
+    USER_GROUP_ADMIN_READ, 
+    USER_GROUP_ADMIN_WRITE, 
+    USER_GROUP_ADMIN_DELETE, 
+    
+    USER_GROUP_MEMBER_DELETE, 
+    
+    QUERY_ADMIN_READ,
+    QUERY_ADMIN_WRITE,
+    QUERY_ADMIN_DELETE,
+    
+    QUERY_MEMBER_READ;
 
-    private int id;
-    private String name;
+//    USER_GROUP_ADMIN(1), USER_GROUP_MEMBER(2), VC_ACCESS_ADMIN(
+//            3), VC_ACCESS_MEMBER(
+//                    4), QUERY_ACCESS_ADMIN(5), QUERY_ACCESS_MEMBER(6);
+//
+//    private int id;
+//    private String name;
+//
+//    PredefinedRole (int i) {
+//        this.id = i;
+//        this.name = name().toLowerCase().replace("_", " ");
+//    }
+//
+//    public int getId () {
+//        return id;
+//    }
 
-    PredefinedRole (int i) {
-        this.id = i;
-        this.name = name().toLowerCase().replace("_", " ");
+    
+    private String value;
+
+    PredefinedRole () {
+        this.value = name().toLowerCase().replace("_", " ");
     }
-
-    public int getId () {
-        return id;
-    }
+    
+    
 
     @Override
     public String toString () {
-        return this.name;
+        return this.value;
     }
 }
diff --git a/src/main/java/de/ids_mannheim/korap/entity/Role.java b/src/main/java/de/ids_mannheim/korap/entity/Role.java
index f096c80..bd247e6 100644
--- a/src/main/java/de/ids_mannheim/korap/entity/Role.java
+++ b/src/main/java/de/ids_mannheim/korap/entity/Role.java
@@ -2,17 +2,20 @@
 
 import java.util.List;
 
-import jakarta.persistence.CascadeType;
+import de.ids_mannheim.korap.constant.PredefinedRole;
+import de.ids_mannheim.korap.constant.PrivilegeType;
 import jakarta.persistence.Column;
 import jakarta.persistence.Entity;
+import jakarta.persistence.EnumType;
+import jakarta.persistence.Enumerated;
 import jakarta.persistence.FetchType;
 import jakarta.persistence.GeneratedValue;
 import jakarta.persistence.GenerationType;
 import jakarta.persistence.Id;
+import jakarta.persistence.JoinColumn;
 import jakarta.persistence.ManyToMany;
-import jakarta.persistence.OneToMany;
+import jakarta.persistence.ManyToOne;
 import jakarta.persistence.Table;
-
 import lombok.Getter;
 import lombok.Setter;
 
@@ -32,13 +35,40 @@
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     private int id;
     @Column(unique = true)
-    private String name;
+    @Enumerated(EnumType.STRING)
+    private PredefinedRole name;
+    @Enumerated(EnumType.STRING)
+    private PrivilegeType privilege;
+    
+    @ManyToOne(fetch = FetchType.LAZY)
+    @JoinColumn(name = "query_id", referencedColumnName = "id")
+    private QueryDO query;
 
+    @ManyToOne(fetch = FetchType.LAZY)
+    @JoinColumn(name = "group_id", referencedColumnName = "id")
+    private UserGroup userGroup;
+    
+//    @ManyToMany(fetch = FetchType.LAZY)
+//    @JoinTable(
+//        name = "role_user_roles",
+//        joinColumns = @JoinColumn(name = "role_id"),
+//        inverseJoinColumns = @JoinColumn(name = "user_role_id")
+//    )
+//    private Set<UserRole> user_roles;
+    
     @ManyToMany(mappedBy = "roles", fetch = FetchType.LAZY)
     private List<UserGroupMember> userGroupMembers;
-
-    @OneToMany(mappedBy = "role", fetch = FetchType.EAGER, cascade = CascadeType.REMOVE)
-    private List<Privilege> privileges;
+//
+//    @OneToMany(mappedBy = "role", fetch = FetchType.EAGER, cascade = CascadeType.REMOVE)
+//    private List<Privilege> privileges;
+    
+    public Role () {}
+    
+    public Role (PredefinedRole name, PrivilegeType privilege, UserGroup group) {
+        setName(name);
+        setPrivilege(privilege);
+        setUserGroup(group);
+    }
 
     public String toString () {
         return "id=" + id + ", name=" + name;