Changeset 429 for trunk/grails-app


Ignore:
Timestamp:
Mar 5, 2010, 9:20:33 AM (15 years ago)
Author:
gav
Message:

Fix asset copy failure due to to asset sub item non-unique names.

Location:
trunk/grails-app
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/AssetDetailedController.groovy

    r421 r429  
    371371        }
    372372
    373         if(result.error.code != "default.create.failure") {
    374             flash.errorMessage = g.message(code: result.error.code, args: ["Asset"])
    375         }
     373        flash.errorMessage = g.message(code: result.error.code, args: ["Asset"])
    376374
    377375        render(view:'copy', model:[assetInstance: result.assetInstance, assetToCopy: result.assetToCopy])
  • trunk/grails-app/i18n/messages.properties

    r425 r429  
    88inventory.import.failure=Could not create inventory from supplied file, failed on line {0}, see {1}.
    99
     10asset.copy.subItem.create.failure=Could not complete operation, as sub item failed to save.
     11asset.copy.subItem.too.many.failure=Could not complete operation, as there appears to be too many sub items.
    1012asset.copy.method.required=Please select a copy method for sub items.
    1113asset.copy.method=Copy Method
    1214asset.copy.method.help=Link creates a new asset and links it to EXISTING sub items. \
    13     While copy creates a new asset and new sub items.
     15    While copy creates a new asset and new sub items by appending '(id:#)' to create unique sub item names.
    1416asset.copy.asset.required=Please select an asset to copy.
    1517
  • trunk/grails-app/services/AssetService.groovy

    r387 r429  
    159159            // Copy subItems from level 2 and bellow.
    160160            def copyAssetSubItem = { assetSubItemToCopy, parentItem ->
    161                 def assetSubItemInstance = new AssetSubItem(name: assetSubItemToCopy.name,
     161                def nextCount = AssetSubItem.count() + 1
     162                def baseName = assetSubItemToCopy.name.split('\\(id:')[0]
     163                def name = baseName +'(id:'+nextCount+')'
     164                def assetSubItemInstance = new AssetSubItem(name: name,
    162165                                                                                            description: assetSubItemToCopy.description,
    163166                                                                                            parentItem: parentItem)
    164167
    165168                if(assetSubItemInstance.hasErrors() || !assetSubItemInstance.save())
    166                     return fail(field:"subItems", code:"default.create.failure")
     169                    return fail(code:"asset.copy.subItem.create.failure")
    167170
    168171                def i = 0
     
    172175                    i++
    173176                    if(i > 100)
    174                         fail(code:"default.create.failure")
     177                        fail(code:"asset.copy.subItem.too.many.failure")
    175178                    // Stop if an error is flagged.
    176179                    if(result.error)
     
    181184            // Copy the 1st level of subItems.
    182185            def copyAssetSubItem1 = { assetSubItemToCopy ->
    183                 assetSubItemInstance1 = new AssetSubItem(name: assetSubItemToCopy.name,
     186                def nextCount = AssetSubItem.count() + 1
     187                def baseName = assetSubItemToCopy.name.split('\\(id:')[0]
     188                def name = baseName +'(id:'+nextCount+')'
     189                assetSubItemInstance1 = new AssetSubItem(name: name,
    184190                                                                                        description: assetSubItemToCopy.description,
    185191                                                                                        asset: result.assetInstance)
    186192
    187193                if(assetSubItemInstance1.hasErrors() || !assetSubItemInstance1.save())
    188                     return fail(field:"assetSubItems", code:"default.create.failure")
     194                    return fail(code:"asset.copy.subItem.create.failure")
    189195
    190196                result.assetInstance.addToAssetSubItems(assetSubItemInstance1)
     
    196202                    i++
    197203                    if(i > 100)
    198                         fail(code:"default.create.failure")
     204                        fail(code:"asset.copy.subItem.too.many.failure")
    199205                    // Stop if an error is flagged.
    200206                    if(result.error)
     
    217223                i++
    218224                if(i > 100)
    219                     fail(code:"default.create.failure")
     225                    fail(code:"asset.copy.subItem.too.many.failure")
    220226                // Stop if an error is flagged.
    221227                if(result.error)
Note: See TracChangeset for help on using the changeset viewer.