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

Last change on this file since 702 was 702, checked in by gav, 13 years ago

Domain change: Add hasRegulatoryRequirements to Asset.

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