source: trunk/grails-app/domain/Person.groovy @ 912

Last change on this file since 912 was 723, checked in by gav, 14 years ago

No domain change, avoid possible bug by using toLong() instead of toInteger() in setFromCheckBoxList().

File size: 2.7 KB
RevLine 
[58]1class Person {
[154]2    static transients = ['pass']
[59]3    static hasMany = [authorities: Authority,
[66]4                        personGroups: PersonGroup,
[93]5                        taskModifications: TaskModification,
[66]6                        entries: Entry,
[397]7                        tasks: Task,
[402]8                        contacts: Contact,
[633]9                        addresses: Address,
10                        purchasingGroups: PurchasingGroup]
[58]11
[166]12    static belongsTo = [Authority]
[59]13
[164]14    Department department
15
[154]16    String loginName
17    String firstName
[58]18    String lastName
[402]19    String employeeID = ''
[58]20
[127]21    /* Set after login by 'welcome' action, default to 12 hours, aka "sess.setMaxInactiveInterval(seconds) */
[139]22    Integer sessionTimeout = 43200
[127]23
[154]24    /** MD5 Password */
25    String password
[58]26
[154]27    /** enabled */
28    boolean isActive = true
[58]29
[154]30    /** description */
31    String description = ''
[58]32
[154]33    /** plain password to create a MD5 password */
34    String pass
[58]35
[154]36    static constraints = {
37        loginName(blank: false, unique: true, minSize:4) //minSize:7
38        firstName(blank: false)
[58]39        lastName(blank: false)
[402]40        employeeID()
[73]41        description()
[164]42        department(nullable:true)
[73]43        isActive()
44        //Enforcing minSize on password does not work since "" gets encoded to a string.
[154]45        password(blank: false)
[73]46        //So we need to use pass for validation then encode it for above.
[147]47        pass(blank: false, minSize:4) //minSize:7
[139]48        sessionTimeout(min:60, max:43200)
[154]49    }
[58]50
51    //Overriding the default toString method
52    String toString() {"${this.firstName} ${this.lastName}"}
[294]53
[343]54    //  This additional setter is used to convert the checkBoxList string or string array
[294]55    //  of ids selected to the corresponding domain objects.
56    public void setPersonGroupsFromCheckBoxList(ids) {
57        def idList = []
[343]58        if(ids instanceof String) {
59                if(ids.isInteger())
[723]60                    idList << ids.toLong()
[294]61        }
[343]62        else {
63            ids.each() {
64                if(it.isInteger())
[723]65                    idList << it.toLong()
[343]66            }
67        }
[294]68        this.personGroups = idList.collect { PersonGroup.get( it ) }
69    }
70
[633]71    //  This additional setter is used to convert the checkBoxList string or string array
72    //  of ids selected to the corresponding domain objects.
73    public void setPurchasingGroupsFromCheckBoxList(ids) {
74        def idList = []
75        if(ids instanceof String) {
76                if(ids.isInteger())
[723]77                    idList << ids.toLong()
[633]78        }
79        else {
80            ids.each() {
81                if(it.isInteger())
[723]82                    idList << it.toLong()
[633]83            }
84        }
85        this.purchasingGroups = idList.collect { PurchasingGroup.get( it ) }
86    }
87
[294]88} // end class
Note: See TracBrowser for help on using the repository browser.