Ignore:
Timestamp:
May 27, 2010, 8:47:06 PM (14 years ago)
Author:
gav
Message:

Add InventoryItemService savePicture().
Add bulk tests for inventory items.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/CreateBulkDataService.groovy

    r418 r548  
    1414    def assignedGroupService
    1515    def assignedPersonService
     16    def inventoryItemService
    1617
    1718    def sessionFactory
     19    def grailsApplication
    1820    def propertyInstanceMap = org.codehaus.groovy.grails.plugins.DomainClassGrailsPlugin.PROPERTY_INSTANCE_MAP
    1921
     
    2931    * Make a run of data creation.
    3032    */
    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')
    3643
    3744        log.info "Creating BULK data..."
     
    4047        log.info "Creating persons..."
    4148        createBulkTestPersons()
    42 
    4349//         createBulkTestSites()
    4450//         createBulkTestDepartments()
    4551//         createBulkTestSuppliers()
    4652//         createBulkTestManufacturers()
    47 
    48         // Tasks
    49         log.info "Creating tasks..."
    50         createBulkTestTasks()
    51 
    52 //         createBulkTestEntries()
    53 //         createBulkTestAssignedGroups()
    54 //         createBulkTestAssignedPersons()
    55 //         createBulkTestTaskRecurringSchedules()
    56 
    57         // Inventory
    58 //         createBulkTestInventoryStores()  /// @todo: Perhaps a 'createQuickStartData' method?
    59 //         createBulkTestInventoryLocations()
    60 //         createBulkTestInventoryGroups() /// @todo: Perhaps a 'createQuickStartData' method?
    61 //         createBulkTestInventoryItems()
    6253
    6354        // Assets
     
    7162//         createBulkTestAssetSubItemExtenedAttributes()
    7263
     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
    7379        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()
    77111
    78112/******************
     
    177211        }
    178212
    179     }
     213    } // createBulkTestTasks()
    180214
    181215    def createBulkTestEntries() {
     
    202236
    203237    } // createBulkTestEntries()
     238
     239
     240/**************************
     241START 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()
    204344
    205345    /**
Note: See TracChangeset for help on using the changeset viewer.