Changeset 550 for trunk/grails-app/services/InventoryReportService.groovy
- Timestamp:
- May 28, 2010, 1:29:19 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/InventoryReportService.groovy
r547 r550 13 13 def g = new org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib() 14 14 15 // Protect java heap memory. 16 // Most likely want to set paramsMax and inClauseMax to the same values. 15 17 def paramsMax = 250 18 19 // At least with Oracle and MSSQL db limits are 1000 (in list) and 2000 (nodes) respectively. 20 // But 255 has also been mentioned on the internet as a possible limit for some databases. 21 def inClauseMax = 250 16 22 17 23 /** … … 52 58 def result = [:] 53 59 60 result.inventoryItemList = [] 61 result.inventoryItemCount = 0 62 result.locationCount = 0 63 result.errorMessage = null 54 64 result.summaryOfCalculationMethod = 'This report should be used in conjunction with the `Stock Take (Overview)` Report.' 55 65 56 // Sanitise the locations string and convert to a list. 66 def fail = { Map m -> 67 result.error = [ code: m.code, args: m.args ] 68 result.errorMessage = g.message(result.error) 69 result.locations = '' 70 return result 71 } 72 73 def paginateParams = [:] 74 paginateParams.max = Math.min(params?.max?.toInteger() ?: paramsMax, paramsMax) 75 76 def namedParams = [:] 77 namedParams.locationList = [] 78 79 // Sanitise the user supplied locations string and convert to a list. 57 80 result.locations = params.locationString.trim() 58 81 if(result.locations.startsWith('e.g:')) … … 61 84 result.locations = result.locations.collect {it.trim()} 62 85 63 def paginateParams = [:] 64 paginateParams.max = Math.min(params?.max?.toInteger() ?: paramsMax, paramsMax) 65 66 def namedParams = [:] 67 namedParams.locationList = [null] // null protects against HQL unexpected end of subtree exception with an empty list. 68 69 // Fill namedParams.locationList 70 result.locations.each() { 71 InventoryLocation.findAllByNameIlike(it).each() { 72 namedParams.locationList << it 86 // Fill namedParams.locationList. 87 result.locations.each() { location -> 88 if(namedParams.locationList.size() < paramsMax) { 89 // paramsMax+1 to ensure the too many locations check bellow is triggered. 90 namedParams.locationList += InventoryLocation.findAllByNameIlike(location, [max: paramsMax+1]) 73 91 } 92 namedParams.locationList.unique() 74 93 } 75 94 76 // Return the actual locations as a string. 77 if(namedParams.locationList.size() > 1) 78 result.locations = namedParams.locationList[1..-1].toString()[1..-2] 95 // Return the actual locations as a string, along with a count. 96 result.locationCount = namedParams.locationList.size() 97 if(result.locationCount > 0) { 98 result.locations = namedParams.locationList.toString()[1..-2] 99 } 79 100 else 80 101 result.locations = g.message(code: 'default.none.text') 102 103 // Exit if empty location list. 104 // Protects against HQL unexpected end of subtree exception with an empty list. 105 if(namedParams.locationList.isEmpty()) 106 return fail(code:'report.error.no.locations.found') 107 108 // Exit if IN clause list too big. 109 if(namedParams.locationList.size() > inClauseMax) 110 return fail(code:'report.error.too.many.locations', args: [inClauseMax]) 81 111 82 112 // Inventory List. … … 91 121 92 122 // Exit if too many results. 93 result.countWarning = null 94 if(result.inventoryItemCount > paramsMax) { 95 result.countWarning = g.message(code: 'report.too.many.results.warning', 96 args: [paramsMax], 97 default: "Warning over ${paramsMax} results, please run report again!") 98 result.inventoryItemList = [] 99 return result 100 } 123 if(result.inventoryItemCount > paramsMax) 124 return fail(code:'report.error.too.many.results', args: [paramsMax]) 101 125 102 126 result.inventoryListQuery = "select distinct inventoryItem " + result.inventoryListQuery … … 107 131 namedParams.inventoryList = inventoryList 108 132 109 // Note: HQL docs advise not using fetch aliases in where clause (or any other clause). 133 // Exit if empty inventory list. 134 // Protects against HQL unexpected end of subtree exception with an empty list. 135 if(namedParams.inventoryList.isEmpty()) 136 return fail(code:'report.error.no.inventory.items.found') 137 138 // Exit if inventory list too big. 139 if(namedParams.inventoryList.size() > inClauseMax) 140 return fail(code:'report.error.too.many.inventory.items', args: [inClauseMax]) 141 142 // Note: HQL docs advise 'not using fetch aliases in where clause (or any other clause)'. 110 143 // Access is via the parent object, however that does not work for the order by clause in this case. 111 144 result.query = "from InventoryItem as inventoryItem \ … … 119 152 order by inventoryStore.name, inventoryLocation.name" 120 153 121 result.query = "select inventoryItem " + result.query154 result.query = "select distinct inventoryItem " + result.query 122 155 result.inventoryItemList = InventoryItem.executeQuery(result.query, namedParams, paginateParams) 123 156
Note: See TracChangeset
for help on using the changeset viewer.