Changeset 548 for trunk/grails-app/services/CreateBulkDataService.groovy
- Timestamp:
- May 27, 2010, 8:47:06 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/CreateBulkDataService.groovy
r418 r548 14 14 def assignedGroupService 15 15 def assignedPersonService 16 def inventoryItemService 16 17 17 18 def sessionFactory 19 def grailsApplication 18 20 def propertyInstanceMap = org.codehaus.groovy.grails.plugins.DomainClassGrailsPlugin.PROPERTY_INSTANCE_MAP 19 21 … … 29 31 * Make a run of data creation. 30 32 */ 31 def create() { 32 if(!GrailsUtil.environment == "development") { 33 log.error "Dev environment not detected, will NOT create bulk data." 34 return false 35 } 33 def createAll() { 34 def result = [:] 35 36 def fail = { Map m -> 37 result.error = [ code: m.code, args: m.args ] 38 return result 39 } 40 41 if(GrailsUtil.environment != "development") 42 return fail(code: 'default.not.development.environment.failure') 36 43 37 44 log.info "Creating BULK data..." … … 40 47 log.info "Creating persons..." 41 48 createBulkTestPersons() 42 43 49 // createBulkTestSites() 44 50 // createBulkTestDepartments() 45 51 // createBulkTestSuppliers() 46 52 // createBulkTestManufacturers() 47 48 // Tasks49 log.info "Creating tasks..."50 createBulkTestTasks()51 52 // createBulkTestEntries()53 // createBulkTestAssignedGroups()54 // createBulkTestAssignedPersons()55 // createBulkTestTaskRecurringSchedules()56 57 // Inventory58 // createBulkTestInventoryStores() /// @todo: Perhaps a 'createQuickStartData' method?59 // createBulkTestInventoryLocations()60 // createBulkTestInventoryGroups() /// @todo: Perhaps a 'createQuickStartData' method?61 // createBulkTestInventoryItems()62 53 63 54 // Assets … … 71 62 // createBulkTestAssetSubItemExtenedAttributes() 72 63 64 // Inventory 65 log.info "Creating inventory..." 66 // createBulkTestInventoryStores() /// @todo: Perhaps a 'createQuickStartData' method? 67 createBulkTestInventoryLocations() 68 // createBulkTestInventoryGroups() /// @todo: Perhaps a 'createQuickStartData' method? 69 createBulkTestInventoryItems() 70 71 // Tasks 72 log.info "Creating tasks..." 73 createBulkTestTasks() 74 // createBulkTestEntries() 75 // createBulkTestAssignedGroups() 76 // createBulkTestAssignedPersons() 77 // createBulkTestTaskRecurringSchedules() 78 73 79 log.info "Creating BULK data...complete." 74 return true 75 76 } 80 return result 81 82 } // create() 83 84 /** 85 * Make a run of inventory data creation. 86 */ 87 def createBulkInventoryTestData() { 88 def result = [:] 89 90 def fail = { Map m -> 91 result.error = [ code: m.code, args: m.args ] 92 return result 93 } 94 95 if(GrailsUtil.environment != "development") 96 return fail(code: 'default.not.development.environment.failure') 97 98 log.info "Creating BULK data..." 99 100 // Inventory 101 log.info "Creating inventory..." 102 // createBulkTestInventoryStores() /// @todo: Perhaps a 'createQuickStartData' method? 103 createBulkTestInventoryLocations() 104 // createBulkTestInventoryGroups() /// @todo: Perhaps a 'createQuickStartData' method? 105 createBulkTestInventoryItems() 106 107 log.info "Creating BULK data...complete." 108 return result 109 110 } // createBulkInventoryTestData() 77 111 78 112 /****************** … … 177 211 } 178 212 179 } 213 } // createBulkTestTasks() 180 214 181 215 def createBulkTestEntries() { … … 202 236 203 237 } // createBulkTestEntries() 238 239 240 /************************** 241 START OF INVENTORY 242 **************************/ 243 244 def createBulkTestInventoryLocations() { 245 246 def inventoryLocationResult 247 def p = [:] 248 249 def start = InventoryLocation.count() + 1 250 def end = start + 50 251 252 def range = start..end 253 254 255 def inventoryStore1 = InventoryStore.read(1) 256 257 def name = "Bulk test location " 258 def btName = '' 259 260 startTime = System.currentTimeMillis() 261 lastBatchStarted = startTime 262 263 range.each() { 264 265 if(it % 100 == 0) { 266 logStatus("Creating inventory location #" + it) 267 cleanUpGorm() 268 } 269 270 btName = name + it 271 272 p = [inventoryStore: inventoryStore1, 273 name: btName] 274 275 inventoryLocationResult = new InventoryLocation(p).save() 276 } // each() 277 278 } // createBulkTestInventoryLocations() 279 280 def createBulkTestInventoryItems() { 281 282 def inventoryItemInstance 283 def p = [:] 284 285 def pictureResource = grailsApplication.mainContext.getResource('images/logo.png') 286 287 def start = InventoryItem.count() + 1 288 def end = start + 250 289 290 def range = start..end 291 292 def inventoryLocation 293 def inventoryLocationIndex = 0 294 def inventoryLocationList = InventoryLocation.findAll() 295 def unitOfMeasure2 = UnitOfMeasure.read(2) 296 def inventoryType1 = InventoryType.read(1) 297 def inventoryGroup1 = InventoryGroup.read(1) 298 299 def name = "Bulk test inventory item " 300 def btName = '' 301 302 startTime = System.currentTimeMillis() 303 lastBatchStarted = startTime 304 305 range.each() { 306 307 if(it % 100 == 0) { 308 logStatus("Creating inventory item #" + it) 309 cleanUpGorm() 310 } 311 312 // Spread the inventoryItems across all available locations. 313 if(inventoryLocationIndex < inventoryLocationList.size()) { 314 inventoryLocation = inventoryLocationList[inventoryLocationIndex] 315 } 316 else { 317 inventoryLocationIndex = 0 318 inventoryLocation = inventoryLocationList[inventoryLocationIndex] 319 } 320 inventoryLocationIndex++ 321 322 // Change the name for each inventoryItem. 323 btName = name + it 324 325 p = [inventoryGroup: inventoryGroup1, 326 inventoryType: inventoryType1, 327 unitOfMeasure: unitOfMeasure2, 328 inventoryLocation: inventoryLocation, 329 name: btName, 330 description: "Bulk test data", 331 unitsInStock: 2, 332 reorderPoint: 0] 333 334 inventoryItemInstance = new InventoryItem(p) 335 saveAndTest(inventoryItemInstance) 336 337 def pictureResult = inventoryItemService.savePicture(inventoryItemInstance, pictureResource) 338 339 if(pictureResult.error) 340 log.error pictureResult.error 341 } // each() 342 343 } // createBulkTestInventoryItems() 204 344 205 345 /**
Note: See TracChangeset
for help on using the changeset viewer.