This has to be something really easy, but am pretty new to Grails & Groovy. I am writing a Grails application in version 2.4.3.
There's a class called UserInfo
class UserInfo extends UserDetails {
String userID = ""
static constraints = {
userID blank:false
}
}
Now the UserDetails class:
class UserDetails {
String userName = ""
String userType = "" // 'Admin' or 'Guest' or 'IT' or 'Supervisor'
...................
//Lot more Informations
....................
static constraints = {
userName blank:false
userType blank:false
}
}
And now in another controller class i want to get the User Type information.
def getUserData = {
def type = []
int count = 0
UserInfo.each {
type [i] = it.userType; // Error: No such property: operator for class: UserInfo
i++;
}
}
The goal here is to get list of UserTypes ('Admin' or 'Guest' or 'IT' or 'Supervisor') and the total numbers of each user type.
For e.g., Admin = 230, Guest = 120, .........
The code above doesn't do that and in fact gives an error. I want to use the data above and plot a X - Y Graph.
Ideally i should have the data in a def in an array model as shown below.
def type = []
type << [totalNum: new Integer("230"), userType: 'Admin']
type << [totalNum: new Integer("120"), userType: 'Guest']
............................................................
............................................................
Once i have populated all the data into a def, then i could use Google Visualization to draw the graph easily.
As of now i still don't know how to extract the data from each instance of UserInfo class and then get it to a def.
Appreciate your help!