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

Last change on this file since 671 was 633, checked in by gav, 14 years ago

Domain change: Add PurchasingGroup?.
Logic and views to suite.

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