Changeset 654 for trunk/grails-app/services
- Timestamp:
- Sep 23, 2010, 5:01:46 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/AssetReportService.groovy
r652 r654 117 117 } // getAssetDetail 118 118 119 /** 120 * Selects and returns level 1 sub items (aka machines or equipment) and their details. 121 * @param params The request params, may contain params to specify the search. 122 * @param locale The locale to use when generating result.message. 123 */ 124 def getEquipmentRegister(params, locale) { 125 def result = [:] 126 127 // Inner join used to return only attribTypes that are used by AssetSubItemExtendedAttributes. 128 // So the result is only assetSubItem extendedAttributeTypes. 129 def attribTypesQ = new HqlBuilder().query { 130 select 'distinct attribT.name' 131 from 'AssetSubItemExtendedAttribute attrib', 132 'join attrib.extendedAttributeType as attribT' 133 order 'by attribT.name asc' 134 } 135 result.attribTypes = Asset.executeQuery(attribTypesQ.query, attribTypesQ.namedParams) 136 137 // Since there will be nothing to show in the report table for assets without level 1 assetSubItems, 138 // a list needs to be given to the user. 139 def assetsWithoutEquipmentQ = new HqlBuilder().query { 140 select 'distinct asset' 141 from 'Asset asset', 142 'left join asset.assetSubItems as assetSubItem' 143 where 'assetSubItem = null' 144 } 145 result.assetsWithoutEquipment = AssetSubItem.executeQuery(assetsWithoutEquipmentQ.query, assetsWithoutEquipmentQ.namedParams) 146 147 // A result is returned for every level 1 assetSubItem and for any extended attributes. 148 def q = new HqlBuilder().query { 149 select 'new map(asset.name as assetName', 150 'assetSubItem.name as name', 151 'assetSubItem.description as description', 152 'assetSubItem.comment as comment', 153 'attribT.name as attribType', 154 'attrib.value as attribValue)' 155 from 'AssetSubItem assetSubItem', 156 'inner join assetSubItem.assets as asset', 157 'left join assetSubItem.assetSubItemExtendedAttributes as attrib', 158 'left join attrib.extendedAttributeType as attribT' 159 where 'asset != null' // ensure that only level 1 assetSubItems are returned. 160 if(params.section instanceof Section) { 161 namedParams.section = params.section 162 and 'asset.section = :section' 163 } 164 order 'by asset.name asc, assetSubItem.name asc, attribT.name asc' 165 } 166 def equipmentResults = AssetSubItem.executeQuery(q.query, q.namedParams) 167 168 // Build the report table rows. 169 // Rows are keyed by equipmentResult.assetName+equipmentResult.name` while the value is a Map of the attributes. 170 // The report table then groups by assetName. 171 def rows = [:] 172 equipmentResults.each { equipmentResult -> 173 // Create row if it does not exist yet. 174 def rowKey = equipmentResult.assetName+equipmentResult.name 175 if(!rows.containsKey(rowKey)) { 176 rows[rowKey] = ['assetName': equipmentResult.assetName, 177 'name':equipmentResult.name, 178 'description':equipmentResult.description, 179 'comment':equipmentResult.comment] 180 181 // Add all attribType columns. 182 result.attribTypes.each { column -> 183 rows[rowKey][column] = null 184 } 185 } 186 187 // Assign value to column. 188 rows[rowKey][equipmentResult.attribType] = equipmentResult.attribValue 189 } 190 191 // The value of each row is the dataList used by the report table. 192 result.dataList = rows.collect {it.value} 193 // Print formatting, since we are done with these as objects. 194 result.attribTypes = result.attribTypes.join(', ') 195 result.assetsWithoutEquipment = result.assetsWithoutEquipment.collect {it.name}.join(', ') 196 197 // Success. 198 return result 199 200 } // getEquipmentRegister 201 119 202 } // end class
Note: See TracChangeset
for help on using the changeset viewer.