-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathRole.java
120 lines (106 loc) · 2.55 KB
/
Role.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.lambdaschool.usermodel.models;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;
/**
* The entity allowing interaction with the roles table.
*/
@Entity
@Table(name = "roles")
public class Role
extends Auditable
{
/**
* The primary key (long) of the roles table.
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long roleid;
/**
* The name (String) of the role. Cannot be null and must be unique.
*/
@Column(nullable = false,
unique = true)
private String name;
/**
* Part of the join relationship between user and role
* connects roles to the user role combination
*/
@OneToMany(mappedBy = "role",
cascade = CascadeType.ALL,
orphanRemoval = true)
@JsonIgnoreProperties(value = "role",
allowSetters = true)
private Set<UserRoles> users = new HashSet<>();
/**
* Default Constructor used primarily by the JPA.
*/
public Role()
{
}
/**
* Given the name, create a new role object. User gets added later
*
* @param name the name of the role in uppercase
*/
public Role(String name)
{
this.name = name.toUpperCase();
}
/**
* Getter for role id
*
* @return the role id, primary key, (long) of this role
*/
public long getRoleid()
{
return roleid;
}
/**
* Setter for role id, used for seeding data
*
* @param roleid the new role id, primary key, (long) for this role
*/
public void setRoleid(long roleid)
{
this.roleid = roleid;
}
/**
* Getter for role name
*
* @return role name (String) in uppercase
*/
public String getName()
{
return name;
}
/**
* Setter for role name
*
* @param name the new role name (String) for this role, in uppercase
*/
public void setName(String name)
{
this.name = name.toUpperCase();
}
/**
* Getter for user role combinations
*
* @return A list of user role combinations associated with this role
*/
public Set<UserRoles> getUsers()
{
return users;
}
/**
* Setter for user role combinations
*
* @param users Change the list of user role combinations associated with this role to this one
*/
public void setUsers(Set<UserRoles> users)
{
this.users = users;
}
}