Ignore:
Timestamp:
Feb 10, 2010, 3:52:30 AM (15 years ago)
Author:
gav
Message:

Move AssetSubItem delete to a service method and configure cascade deletion checks.

File:
1 edited

Legend:

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

    r290 r347  
    22
    33    boolean transactional = false
     4
     5    def delete(params) {
     6        def result = [:]
     7        def fail = { Map m ->
     8            result.error = [ code: m.code, args: ["AssetSubItem", params.id] ]
     9            return result
     10        }
     11
     12        result.assetSubItemInstance = AssetSubItem.get(params.id)
     13
     14        if(!result.assetSubItemInstance)
     15            return fail(code:"default.not.found")
     16
     17        if(result.assetSubItemInstance.assets)
     18            return fail(code:"assetSubItem.assets.associated")
     19
     20        if(result.assetSubItemInstance.maintenanceActions)
     21            return fail(code:"assetSubItem.maintenanceActions.associated")
     22
     23        try {
     24            result.assetSubItemInstance.delete(flush:true)
     25            return result //Success.
     26        }
     27        catch(org.springframework.dao.DataIntegrityViolationException e) {
     28            return fail(code:"default.delete.failure")
     29        }
     30
     31    }
    432
    533    def create(params) {
Note: See TracChangeset for help on using the changeset viewer.