Mercurial > hg > LGDataverses
comparison src/main/java/edu/harvard/iq/dataverse/RoleAssignment.java @ 10:a50cf11e5178
Rewrite LGDataverse completely upgrading to dataverse4.0
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Tue, 08 Sep 2015 17:00:21 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 9:5926d6419569 | 10:a50cf11e5178 |
|---|---|
| 1 package edu.harvard.iq.dataverse; | |
| 2 | |
| 3 import edu.harvard.iq.dataverse.authorization.DataverseRole; | |
| 4 import edu.harvard.iq.dataverse.authorization.RoleAssignee; | |
| 5 import java.util.Objects; | |
| 6 import javax.persistence.CascadeType; | |
| 7 import javax.persistence.Column; | |
| 8 import javax.persistence.Entity; | |
| 9 import javax.persistence.GeneratedValue; | |
| 10 import javax.persistence.GenerationType; | |
| 11 import javax.persistence.Id; | |
| 12 import javax.persistence.JoinColumn; | |
| 13 import javax.persistence.ManyToOne; | |
| 14 import javax.persistence.NamedQueries; | |
| 15 import javax.persistence.NamedQuery; | |
| 16 import javax.persistence.Table; | |
| 17 import javax.persistence.UniqueConstraint; | |
| 18 | |
| 19 /** | |
| 20 * A role of a user in a Dataverse. A User may have many roles in a given Dataverse. | |
| 21 * This is a realization of a Many-to-Many relationship | |
| 22 * between users and dataverses, with roles as an extra column. | |
| 23 * @author michael | |
| 24 */ | |
| 25 @Entity | |
| 26 @Table( | |
| 27 uniqueConstraints = @UniqueConstraint(columnNames={"assigneeIdentifier","role_id","definitionPoint_id"}) ) | |
| 28 @NamedQueries({ | |
| 29 @NamedQuery( name = "RoleAssignment.listByAssigneeIdentifier_DefinitionPointId", | |
| 30 query = "SELECT r FROM RoleAssignment r WHERE r.assigneeIdentifier=:assigneeIdentifier AND r.definitionPoint.id=:definitionPointId" ), | |
| 31 @NamedQuery( name = "RoleAssignment.listByAssigneeIdentifier", | |
| 32 query = "SELECT r FROM RoleAssignment r WHERE r.assigneeIdentifier=:assigneeIdentifier" ), | |
| 33 @NamedQuery( name = "RoleAssignment.listByDefinitionPointId", | |
| 34 query = "SELECT r FROM RoleAssignment r WHERE r.definitionPoint.id=:definitionPointId" ), | |
| 35 @NamedQuery( name = "RoleAssignment.listByRoleId", | |
| 36 query = "SELECT r FROM RoleAssignment r WHERE r.role=:roleId" ), | |
| 37 @NamedQuery( name = "RoleAssignment.deleteByAssigneeIdentifier_RoleIdDefinition_PointId", | |
| 38 query = "DELETE FROM RoleAssignment r WHERE r.assigneeIdentifier=:userId AND r.role.id=:roleId AND r.definitionPoint.id=:definitionPointId"), | |
| 39 }) | |
| 40 public class RoleAssignment implements java.io.Serializable { | |
| 41 @Id | |
| 42 @GeneratedValue(strategy = GenerationType.IDENTITY) | |
| 43 private Long id; | |
| 44 | |
| 45 @Column( nullable=false ) | |
| 46 private String assigneeIdentifier; | |
| 47 | |
| 48 @ManyToOne( cascade = CascadeType.MERGE ) | |
| 49 @JoinColumn( nullable=false ) | |
| 50 private DataverseRole role; | |
| 51 | |
| 52 @ManyToOne( cascade = CascadeType.MERGE ) | |
| 53 @JoinColumn( nullable=false ) | |
| 54 private DvObject definitionPoint; | |
| 55 | |
| 56 public RoleAssignment() {} | |
| 57 | |
| 58 public RoleAssignment(DataverseRole aRole, RoleAssignee anAssignee, DvObject aDefinitionPoint) { | |
| 59 role = aRole; | |
| 60 assigneeIdentifier = anAssignee.getIdentifier(); | |
| 61 definitionPoint = aDefinitionPoint; | |
| 62 } | |
| 63 | |
| 64 public Long getId() { | |
| 65 return id; | |
| 66 } | |
| 67 | |
| 68 public void setId(Long id) { | |
| 69 this.id = id; | |
| 70 } | |
| 71 | |
| 72 public String getAssigneeIdentifier() { | |
| 73 return assigneeIdentifier; | |
| 74 } | |
| 75 | |
| 76 public void setAssigneeIdentifier(String assigneeIdentifier) { | |
| 77 this.assigneeIdentifier = assigneeIdentifier; | |
| 78 } | |
| 79 | |
| 80 public DataverseRole getRole() { | |
| 81 return role; | |
| 82 } | |
| 83 | |
| 84 public void setRole(DataverseRole role) { | |
| 85 this.role = role; | |
| 86 } | |
| 87 | |
| 88 public DvObject getDefinitionPoint() { | |
| 89 return definitionPoint; | |
| 90 } | |
| 91 | |
| 92 public void setDefinitionPoint(DvObject definitionPoint) { | |
| 93 this.definitionPoint = definitionPoint; | |
| 94 } | |
| 95 | |
| 96 @Override | |
| 97 public int hashCode() { | |
| 98 int hash = 7; | |
| 99 hash = 97 * hash + Objects.hashCode(role); | |
| 100 hash = 97 * hash + Objects.hashCode(assigneeIdentifier); | |
| 101 return hash; | |
| 102 } | |
| 103 | |
| 104 @Override | |
| 105 public boolean equals(Object obj) { | |
| 106 if (obj == null) { | |
| 107 return false; | |
| 108 } | |
| 109 if ( ! (obj instanceof RoleAssignment) ) { | |
| 110 return false; | |
| 111 } | |
| 112 final RoleAssignment other = (RoleAssignment) obj; | |
| 113 | |
| 114 return ( Objects.equals(getRole(), other.getRole() ) | |
| 115 && Objects.equals(getAssigneeIdentifier(), other.getAssigneeIdentifier()) | |
| 116 && Objects.equals(getDefinitionPoint(), other.getDefinitionPoint())); | |
| 117 | |
| 118 } | |
| 119 | |
| 120 @Override | |
| 121 public String toString() { | |
| 122 return "RoleAssignment{" + "id=" + id + ", assignee=" + assigneeIdentifier + ", role=" + role + ", definitionPoint=" + definitionPoint + '}'; | |
| 123 } | |
| 124 | |
| 125 } |
