diff --git a/api/src/main/java/org/openmrs/Role.java b/api/src/main/java/org/openmrs/Role.java index 6158ada4591e..46ddcdbfe92f 100644 --- a/api/src/main/java/org/openmrs/Role.java +++ b/api/src/main/java/org/openmrs/Role.java @@ -9,14 +9,26 @@ */ package org.openmrs; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.search.annotations.Field; import org.openmrs.util.RoleConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.Table; +import javax.persistence.Transient; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + /** * A Role is just an aggregater of {@link Privilege}s. {@link User}s contain a number of roles * (Users DO NOT contain any privileges directly) Roles can be grouped by inheriting other roles. If @@ -25,20 +37,49 @@ * * @see Privilege */ -public class Role extends BaseChangeableOpenmrsMetadata { + +@Entity +@Table(name="role") +@Cache(usage = CacheConcurrencyStrategy.READ_WRITE) +public class Role extends BaseOpenmrsObject { public static final long serialVersionUID = 1234233L; private static final Logger log = LoggerFactory.getLogger(Role.class); - // Fields - + @Id + @Column(name = "role") private String role; + @Transient + @Field + private String name; + + @Column(name = "description", length = 255) + private String description; + + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable( + name = "role_privilege", + joinColumns = @JoinColumn(name = "role"), + inverseJoinColumns = @JoinColumn(name = "privilege") + ) private Set privileges; + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable( + name = "role_role", + joinColumns = @JoinColumn(name = "child_role"), + inverseJoinColumns = @JoinColumn(name = "parent_role") + ) private Set inheritedRoles; + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable( + name = "role_role", + joinColumns = @JoinColumn(name = "parent_role"), + inverseJoinColumns = @JoinColumn(name = "child_role") + ) private Set childRoles; // Constructors @@ -52,6 +93,20 @@ public Role(String role) { this.role = role; } + /** + * @return the description + */ + public String getDescription() { + return this.description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + /** constructor with all database required properties */ public Role(String role, String description) { this.role = role; @@ -72,11 +127,17 @@ public void setPrivileges(Set privileges) { this.privileges = privileges; } - @Override public String getName() { return this.getRole(); } + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + /** * Adds the given Privilege to the list of privileges * diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index df60ab66c34c..18729b68d4c2 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -60,7 +60,6 @@ - diff --git a/api/src/main/resources/org/openmrs/api/db/hibernate/Role.hbm.xml b/api/src/main/resources/org/openmrs/api/db/hibernate/Role.hbm.xml deleted file mode 100644 index 7bcdfe236b79..000000000000 --- a/api/src/main/resources/org/openmrs/api/db/hibernate/Role.hbm.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/api/src/test/java/org/openmrs/api/OrderServiceTest.java b/api/src/test/java/org/openmrs/api/OrderServiceTest.java index f03d13d08311..b3be29516855 100644 --- a/api/src/test/java/org/openmrs/api/OrderServiceTest.java +++ b/api/src/test/java/org/openmrs/api/OrderServiceTest.java @@ -53,6 +53,7 @@ import org.openmrs.PersonAttributeType; import org.openmrs.Provider; import org.openmrs.ProviderAttributeType; +import org.openmrs.Role; import org.openmrs.SimpleDosingInstructions; import org.openmrs.TestOrder; import org.openmrs.Visit; @@ -2654,6 +2655,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th .addAnnotatedClass(Location.class) .addAnnotatedClass(PersonAddress.class) .addAnnotatedClass(PersonAttributeType.class) + .addAnnotatedClass(Role.class) .getMetadataBuilder().build();