Changeset 426


Ignore:
Timestamp:
Mar 3, 2010, 6:20:20 PM (14 years ago)
Author:
gav
Message:

Small improvements to InventoryCsvService, increase max file size, capitalise and protect parse against nulls.

File:
1 edited

Legend:

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

    r423 r426  
    2727
    2828            def kByteMultiplier = 1000
    29             def fileMaxSize = 500 * kByteMultiplier
     29            def fileMaxSize = 800 * kByteMultiplier
    3030            def logFileLink = g.link(controller: "appCore", action: "appLog") {"log"}
    3131
     
    8282
    8383            def tempSuppliers = []
     84            def tempSupplierItem = ''
     85            def tempSupplierType = ''
    8486            def tempSupplierItemAndType = []
    8587            def tempManufacturers = []
     88            def tempManufacturerItem = ''
     89            def tempManufacturerType = ''
    8690            def tempManufacturerItemAndType = []
    8791
     
    113117
    114118            def parseInputList = {
    115                 if(it.trim() == '') return []
     119                if( (it == null) || (it.trim() == '') ) return []
    116120                return it.split(";").collect{it.trim()}
    117121            }
     
    160164
    161165                // Parse the line into the params map.
    162                 /** TODO: capitalize and capitalizeFully.*/
    163166                inventoryParams = [:]
    164167                line.eachWithIndex { it, j ->
     
    180183
    181184                // Site
     185                inventoryParams.site = WordUtils.capitalize(inventoryParams.site)
    182186                siteInstance = Site.findByName(inventoryParams.site)
    183187                if(!siteInstance) {
     
    190194
    191195                // InventoryStore
     196                inventoryParams.inventoryStore = WordUtils.capitalizeFully(inventoryParams.inventoryStore)
    192197                inventoryStoreInstance = InventoryStore.findByName(inventoryParams.inventoryStore)
    193198                if(!inventoryStoreInstance) {
     
    201206
    202207                // InventoryLocation
     208                inventoryParams.inventoryLocation = WordUtils.capitalize(inventoryParams.inventoryLocation)
    203209                inventoryLocationInstance = InventoryLocation.findByName(inventoryParams.inventoryLocation)
    204210                if(!inventoryLocationInstance) {
     
    212218
    213219                // InventoryGroup
     220                inventoryParams.inventoryLocation = WordUtils.capitalizeFully(inventoryParams.inventoryLocation)
    214221                inventoryGroupInstance = InventoryGroup.findByName(inventoryParams.inventoryGroup)
    215222                if(!inventoryGroupInstance) {
     
    222229
    223230                // InventoryType
     231                inventoryParams.inventoryType = WordUtils.capitalizeFully(inventoryParams.inventoryType)
    224232                inventoryTypeInstance = InventoryType.findByName(inventoryParams.inventoryType)
    225233                if(!inventoryTypeInstance) {
     
    256264                for(tempManufacturer in tempManufacturers) {
    257265                    tempManufacturerItemAndType = parseItemAndType(tempManufacturer)
    258 
    259                     manufacturerInstance = Manufacturer.findByName(tempManufacturerItemAndType[0])
     266                    tempManufacturerItem = WordUtils.capitalizeFully(tempManufacturerItemAndType[0])
     267
     268                    manufacturerInstance = Manufacturer.findByName(tempManufacturerItem)
    260269                    if(!manufacturerInstance) {
    261270
    262271                        // ManufacturerType.
    263                         if(tempManufacturerItemAndType.size == 2)
    264                             manufacturerTypeInstance = ManufacturerType.findByName(tempManufacturerItemAndType[1])
     272                        if(tempManufacturerItemAndType.size == 2) {
     273                            tempManufacturerType = WordUtils.capitalizeFully(tempManufacturerItemAndType[1])
     274                            manufacturerTypeInstance = ManufacturerType.findByName(tempManufacturerType)
     275                        }
    265276                        else
    266277                            manufacturerTypeInstance = manufacturerTypeUnknown
     
    270281                        }
    271282
    272                         manufacturerInstance = new Manufacturer(name: tempManufacturerItemAndType[0],
     283                        manufacturerInstance = new Manufacturer(name: tempManufacturerItem,
    273284                                                                                                manufacturerType: manufacturerTypeInstance)
    274285                        if(!manufacturerInstance.save()) {
     
    287298                for(tempSupplier in tempSuppliers) {
    288299                    tempSupplierItemAndType = parseItemAndType(tempSupplier)
    289 
    290                     supplierInstance = Supplier.findByName(tempSupplierItemAndType[0])
     300                    tempSupplierItem = WordUtils.capitalizeFully(tempSupplierItemAndType[0])
     301
     302                    supplierInstance = Supplier.findByName(tempSupplierItem)
    291303                    if(!supplierInstance) {
    292304
    293305                        // SupplierType.
    294                         if(tempSupplierItemAndType.size == 2)
    295                             supplierTypeInstance = SupplierType.findByName(tempSupplierItemAndType[1])
     306                        if(tempSupplierItemAndType.size == 2) {
     307                            tempSupplierType = WordUtils.capitalizeFully(tempSupplierItemAndType[1])
     308                            supplierTypeInstance = SupplierType.findByName(tempSupplierType)
     309                        }
    296310                        else
    297311                            supplierTypeInstance = supplierTypeUnknown
     
    301315                        }
    302316
    303                         supplierInstance = new Supplier(name: tempSupplierItemAndType[0],
     317                        supplierInstance = new Supplier(name: tempSupplierItem,
    304318                                                                            supplierType: supplierTypeInstance)
    305319                        if(!supplierInstance.save()) {
     
    317331
    318332                for(tempAlternateItem in tempAlternateItems) {
    319 
     333                    tempAlternateItem = WordUtils.capitalize(tempAlternateItem)
    320334                    alternateItemInstance = InventoryItem.findByName(tempAlternateItem)
    321335                    if(!alternateItemInstance) {
     
    342356                for(asset in tempSpareFor) {
    343357
    344                     println ''
    345                     println 'asset: '+asset
    346                     println ''
     358                    asset = WordUtils.capitalize(asset)
    347359
    348360                    spareForInstance = Asset.findByName(asset)
     
    361373                inventoryParams.unitOfMeasure = unitOfMeasureInstance
    362374                inventoryParams.averageDeliveryPeriod = averageDeliveryPeriodInstance
     375
     376                // Format remaining properties.
     377                inventoryParams.name = WordUtils.capitalize(inventoryParams.name)
     378                inventoryParams.description = inventoryParams.description[0].toUpperCase() + inventoryParams.description[1..-1]
    363379
    364380                // Debug
Note: See TracChangeset for help on using the changeset viewer.