Advertisement
Guest User

Untitled

a guest
Feb 18th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. Class User {
  2.  
  3. String username
  4. String password
  5.  
  6. String firstName
  7. String lastName
  8. String emailAddress
  9. UserStatus status
  10. UserType type
  11. Date dateCreated
  12.  
  13. List<UserRole> roles
  14.  
  15. static mapping = {
  16. roles(fetch: 'join')
  17. }
  18. }
  19.  
  20. enum RoleType {
  21. SUPER_USER('superuser','Super User'),
  22. SUPPORT_USER('supportuser','Support User'),
  23. STANDARD('standard','Standard')
  24.  
  25. String id
  26. String name
  27.  
  28. RoleType(String id, String name) {
  29. this.id = id
  30. this.name = name
  31. }
  32.  
  33. String toString() {
  34. name
  35. }
  36. }
  37.  
  38. class UserRole {
  39.  
  40. static belongsTo = [user:User]
  41.  
  42. static auditable = true
  43.  
  44. RoleType roleType
  45. String role
  46.  
  47. static constraints = {
  48. role(nullable:false, blank:false)
  49. roleType(nullable:false, inList:RoleType.values().toList())
  50. }
  51.  
  52. static mapping = {
  53. sort(role: "asc")
  54. role(role: IdentityEnumType,sqlType: "varchar(40)")
  55. }
  56. }
  57.  
  58. User user = new User(
  59. username:'support@quirk.biz',
  60. password:'ilovequirk',
  61. status:UserStatus.ACTIVE,
  62. type:UserType.QUIRK,
  63. firstName:'Quirk',
  64. lastName:'Support',
  65. emailAddress:'support@quirk.biz'
  66. )
  67.  
  68. UserRole userRole = new UserRole(roleType:RoleType.SUPER_USER, role:RoleType.SUPER_USER.toString())
  69. user.addToRoles(userRole)
  70.  
  71. user.save(failOnError:true)
  72.  
  73. No signature of method: za.co.hollard.User.addToRoles() is applicable for argument types: (za.co.hollard.UserRole) values: [za.co.hollard.UserRole : null]
  74.  
  75. List<UserRole> roles
  76.  
  77. static hasMany = [ roles:UserRole]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement