Ignore:
Timestamp:
May 27, 2010, 9:24:43 PM (9 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.