-2

In my grails app i am using spring security plugin..I have registration form and registered users will be stored in db table.

in bootstrap i have created new role as, def PhysicianRole = new Role(authority: 'ROLE_PHYSICIAN').save(flush: true)

Then i have another form where admin is enabling or disabling users from table.

now i want to assign physician role to all the users who are enabled.so i did as below in bootstrap, def physicians=Physician.findAllWhere(enabled:true) with this i am getting array list as,

physicians-------------->[com.HospitalManagement.User : 1, com.HospitalManagement.User : 2, com.HospitalManagement.User : 4, com.HospitalManagement.User : 5, com.HospitalManagement.User : 6, com.HospitalManagement.User : 7]

now how should i assign physician role to all the objects in this array list?

laxmi
  • 865
  • 6
  • 17
  • 27
  • Please go through the syntax's that are to be followed when asking a question to improve readability. – MAlex Jul 05 '11 at 07:55

1 Answers1

1
def physicianRole = Role.findByAuthority('ROLE_PHYSICIAN')

for (physician in Physician.findAllWhere(enabled:true)) {
   if (!PhysicianRole.findByPhysicianAndRole(physician, physicianRole)) {
      PhysicianRole.create physician, physicianRole 
   }
}
Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
  • With this i am getting error as**ERROR context.GrailsContextLoader - Error executing bootstraps: Cannot invoke method findByPhysicianAndRole() on null object** – laxmi Jul 05 '11 at 04:35
  • 1
    You're missing an import for the PhysicianRole class. – Burt Beckwith Jul 05 '11 at 05:11