source: trunk/grails-app/domain/Asset.groovy @ 933

Last change on this file since 933 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: 1.8 KB
Line 
1import org.codehaus.groovy.grails.commons.ConfigurationHolder
2
3class Asset {
4
5    Section section
6
7    String name
8    String description = ""
9    String comment = ""
10    boolean isActive = true
11
12    static hasMany = [assetSubItems: AssetSubItem,
13                                    maintenanceActions: MaintenanceAction,
14                                    assetExtendedAttributes: AssetExtendedAttribute]
15
16    static belongsTo = [Section]
17
18    static constraints = {
19        name(maxSize:50, unique:true, blank:false)
20        description(maxSize:75)
21        comment(maxSize:500)
22        isActive()
23        section()
24    }
25
26    static mapping = {
27        assetSubItems(batchSize:1000)
28    }
29
30    String toString() {
31        "${this.name}"
32    }
33
34    static searchable = {
35        root false // only index as a component of InventoryItem.
36        only = ['name', 'description', 'comment']
37    }
38
39    def afterUpdate = {
40        // Update the Inventory searchable index, since cascading in searchable-0.5.5 is broken.
41        if(ConfigurationHolder.config.appSearchable.cascadeOnUpdate) {
42            try {
43                InventoryIndexJob.triggerNow(['calledBy':'Asset afterUpdate{}'])
44            }
45            catch(e) {log.error e}
46        } // if
47    } // afterUpdate
48
49    //  This additional setter is used to convert the checkBoxList string or string array
50    //  of ids selected to the corresponding domain objects.
51    public void setAssetSubItemsFromCheckBoxList(ids) {
52        def idList = []
53        if(ids instanceof String) {
54                if(ids.isInteger())
55                    idList << ids.toLong()
56        }
57        else {
58            ids.each() {
59                if(it.isInteger())
60                    idList << it.toLong()
61            }
62        }
63        this.assetSubItems = idList.collect { AssetSubItem.get( it ) }
64    }
65
66}
67
Note: See TracBrowser for help on using the repository browser.