Changeset 360 for trunk/grails-app
- Timestamp:
- Feb 16, 2010, 10:02:34 AM (15 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/SiteDetailedController.groovy
r298 r360 3 3 @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager']) 4 4 class SiteDetailedController extends BaseController { 5 6 def siteService 5 7 6 8 // the delete, save and update actions only accept POST requests … … 29 31 @Secured(['ROLE_AppAdmin']) 30 32 def delete = { 31 def siteInstance = Site.get( params.id ) 32 if(siteInstance) { 33 try { 34 siteInstance.delete(flush:true) 35 flash.message = "Site ${params.id} deleted" 36 redirect(action:list) 37 } 38 catch(org.springframework.dao.DataIntegrityViolationException e) { 39 flash.message = "Site ${params.id} could not be deleted" 40 redirect(action:show,id:params.id) 41 } 33 def result = siteService.delete(params) 34 35 if(!result.error) { 36 flash.message = g.message(code: "default.delete.success", args: ["Site", params.id]) 37 redirect(action:list) 38 return 42 39 } 43 else { 44 flash.message = "Site not found with id ${params.id}" 40 41 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 42 43 if(result.error.code == "default.not.found") { 45 44 redirect(action:list) 45 return 46 46 } 47 48 redirect(action:show, id: params.id) 47 49 } 48 50 -
trunk/grails-app/i18n/messages.properties
r350 r360 11 11 asset.copy.asset.required=Please select an asset to copy. 12 12 13 maintenanceActions.still.associated=Could not complete operation as maintenance actions are still associated with this item. 14 13 maintenanceActions.still.associated=Could not complete operation as maintenance actions are still associated \ 14 with this item. 15 maintenanceActions.still.associated.subItem=Could not complete operation as maintenance actions are still associated \ 16 with a sub item. 17 inventoryStores.still.associated=Could not complete operation as inventory stores are still associated with this item. 18 19 site.section.delete.failure=Could not complete operation as sections failed to delete. 20 section.asset.delete.failure=Could not complete operation as assets failed to delete. 15 21 asset.subItems.delete.failure=Could not complete operation as orphan sub items failed to delete. 16 22 -
trunk/grails-app/services/AssetService.groovy
r352 r360 47 47 r = assetSubItemService.delete(id: assetSubItem.id) 48 48 if(r.error) { 49 log.debug r.error 49 50 fail(code:"asset.subItems.delete.failure") 50 51 break … … 56 57 return result 57 58 58 try {59 result.assetInstance.delete(flush:true)60 return result //Success.61 }62 catch(org.springframework.dao.DataIntegrityViolationException e) {63 return fail(code:"default.delete.failure")64 }59 // Success. 60 // We have handled all the foreign keys so the delete should go forward. 61 // Can't flush here due to cascading from Section and Site. 62 // And without flush there is no point it trying to catch the dao.DataIntegrityViolationException 63 // since that will only happen after leaving the transaction. 64 result.assetInstance.delete() 65 return result 65 66 66 67 } // end withTransaction -
trunk/grails-app/services/AssetSubItemService.groovy
r352 r360 21 21 22 22 def delete(params) { 23 def result = [:] 24 def fail = { Map m -> 25 result.error = [ code: m.code, args: ["AssetSubItem", params.id] ] 26 return result 27 } 23 AssetSubItem.withTransaction { status -> 24 def result = [:] 28 25 29 result.assetSubItemInstance = AssetSubItem.get(params.id) 26 def fail = { Map m -> 27 status.setRollbackOnly() 28 if(result.assetSubItemInstance && m.field) 29 result.assetSubItemInstance.errors.rejectValue(m.field, m.code) 30 result.error = [ code: m.code, args: ["AssetSubItem", params.id] ] 31 return result 32 } 30 33 31 if(!result.assetSubItemInstance) 32 return fail(code:"default.not.found") 34 result.assetSubItemInstance = AssetSubItem.get(params.id) 33 35 34 if(result.assetSubItemInstance.assets)35 return fail(code:"assetSubItem.assets.associated")36 if(!result.assetSubItemInstance) 37 return fail(code:"default.not.found") 36 38 37 if(result.assetSubItemInstance.maintenanceActions) 38 return fail(code:"maintenanceActions.still.associated") 39 for(subItem in result.assetSubItemInstance.subItems) { 40 if(subItem.maintenanceActions) 41 fail(code:"maintenanceActions.still.associated.subItem") 42 } 39 43 40 try { 41 result.assetSubItemInstance.delete(flush:true) 44 if(result.error) 45 return result 46 47 if(result.assetSubItemInstance.maintenanceActions) 48 return fail(code:"maintenanceActions.still.associated") 49 50 if(result.assetSubItemInstance.assets) 51 return fail(code:"assetSubItem.assets.associated") 52 53 // We have handled all the foreign keys so the delete should go forward. 54 // Can't flush here due to cascading from Section and Site. 55 // And without flush there is no point it trying to catch the dao.DataIntegrityViolationException 56 // since that will only happen after leaving the transaction. 57 result.assetSubItemInstance.delete() 42 58 return result //Success. 43 }44 catch(org.springframework.dao.DataIntegrityViolationException e) {45 return fail(code:"default.delete.failure")46 }47 59 60 } // withTransaction 48 61 } 49 62
Note: See TracChangeset
for help on using the changeset viewer.