Changeset 549 for trunk/grails-app


Ignore:
Timestamp:
May 27, 2010, 9:24:43 PM (15 years ago)
Author:
gav
Message:

Add InventoryItemService savePicture(), part 2.
Add some more comments, another error code and ensure the inputStream gets closed.
Add gnuMims logo as an example picture to the demo inventory items.

Location:
trunk/grails-app
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/i18n/messages.properties

    r548 r549  
    156156inventory.item.already.has.picture=Inventory item already has a picture, please delete the old picture first.
    157157inventory.item.picture.file.unrecognised=Image file [{0}]: type not recognised.
     158inventory.item.picture.source.not.supported=Image source type not supported.
    158159
    159160inventoryMovement.quantity.insufficientItemsInStock=Could not complete operation, insufficient items in stock.
  • trunk/grails-app/services/CreateDataService.groovy

    r534 r549  
    1313    def dateUtilService
    1414    def appConfigService
     15    def inventoryItemService
    1516    def assignedGroupService
    1617    def assignedPersonService
     18
     19    def grailsApplication
    1720
    1821/*******************************************
     
    12031206        def inventoryItemInstance
    12041207
     1208        def pictureResource = grailsApplication.mainContext.getResource('images/logo.png')
     1209
    12051210        //InventoryItem #1
    12061211        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1),
     
    12131218                                                                                    reorderPoint: 0)
    12141219        saveAndTest(inventoryItemInstance)
     1220        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
    12151221
    12161222        //InventoryItem #2
     
    12251231                                                                                    reorderPoint: 0)
    12261232        saveAndTest(inventoryItemInstance)
     1233        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
    12271234
    12281235        //InventoryItem #3
     
    12361243                                                                                    reorderPoint: 2)
    12371244        saveAndTest(inventoryItemInstance)
     1245        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
    12381246
    12391247        //InventoryItem #4
     
    12471255                                                                                    reorderPoint: 0)
    12481256        saveAndTest(inventoryItemInstance)
     1257        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
    12491258
    12501259        //InventoryItem #5
     
    12581267                                                                                    reorderPoint: 2)
    12591268        saveAndTest(inventoryItemInstance)
     1269        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
    12601270    }
    12611271
  • trunk/grails-app/services/InventoryItemService.groovy

    r548 r549  
    261261                return fail(field:"picture", code:"inventory.item.already.has.picture")
    262262
     263            // Declare some more variables, since we appear to have most of what we need.
    263264            def picture = new Picture(inventoryItem: result.inventoryItemInstance)
    264265            def imaging = new Imaging()
     
    268269            def pictureInputStream
    269270
     271            // Check the supplied pictureSource and get the inputStream.
    270272            if(pictureSource instanceof javax.servlet.http.HttpServletRequest) {
    271273                def multiPartFile = pictureSource.getFile('file')
     
    293295            }
    294296            else {
    295                     return fail(code:"default.file.not.supplied")
    296             }
    297 
     297                    return fail(code:"inventory.item.picture.source.not.supported")
     298            }
     299
     300            // Create the Images.
    298301            try {
    299302                images = imaging.createAll(result.inventoryItemInstance, picture, pictureInputStream)
     303                // Ensure the stream is closed.
     304                pictureInputStream.close()
    300305            }
    301306            catch(Exception ex) {
    302307                log.error("picture save", ex)
     308                // Ensure the stream is closed.
     309                pictureInputStream.close()
    303310                return fail(code:"inventory.item.picture.file.unrecognised", args: [pictureFileName])
    304311            }
    305312
     313            // Add images to picture.
    306314            images.each { image ->
    307315                picture.addToImages(image)
    308316            }
    309317
     318            // Save picture.
    310319            if(picture.hasErrors() || !picture.save())
    311320                return fail(code:"default.create.failure", args: ["Picture"])
     
    313322            result.inventoryItemInstance.picture = picture
    314323
     324            // Save inventoryItem.
    315325            if(result.inventoryItemInstance.hasErrors() || !result.inventoryItemInstance.save())
    316326                return fail(code:"default.create.failure")
Note: See TracChangeset for help on using the changeset viewer.