Last change
on this file since 897 was
360,
checked in by gav, 15 years ago
|
Configure cascade deletion of Site -> Section -> Asset -> SubItems.
|
File size:
1.7 KB
|
Rev | Line | |
---|
[360] | 1 | class SectionService { |
---|
| 2 | |
---|
| 3 | boolean transactional = false |
---|
| 4 | |
---|
| 5 | def assetSubItemService |
---|
| 6 | def assetService |
---|
| 7 | |
---|
| 8 | def delete(params) { |
---|
| 9 | Section.withTransaction { status -> |
---|
| 10 | def result = [:] |
---|
| 11 | |
---|
| 12 | def fail = { Map m -> |
---|
| 13 | status.setRollbackOnly() |
---|
| 14 | if(result.sectionInstance && m.field) |
---|
| 15 | result.sectionInstance.errors.rejectValue(m.field, m.code) |
---|
| 16 | result.error = [ code: m.code, args: ["Section", params.id] ] |
---|
| 17 | return result |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | result.sectionInstance = Section.get(params.id) |
---|
| 21 | |
---|
| 22 | if(!result.sectionInstance) |
---|
| 23 | return fail(code:"default.not.found") |
---|
| 24 | |
---|
| 25 | if(result.sectionInstance.maintenanceActions) |
---|
| 26 | return fail(code:"maintenanceActions.still.associated") |
---|
| 27 | |
---|
| 28 | // Delete assets which in turn delete orphan assetSubItems. |
---|
| 29 | def assets = new ArrayList(result.sectionInstance.assets) // avoid ConcurrentModificationException. |
---|
| 30 | def r |
---|
| 31 | for(asset in assets) { |
---|
| 32 | result.sectionInstance.removeFromAssets(asset) |
---|
| 33 | r = assetService.delete(id: asset.id) |
---|
| 34 | if(r.error) { |
---|
| 35 | log.debug r.error |
---|
| 36 | fail(code:"section.asset.delete.failure") |
---|
| 37 | break |
---|
| 38 | } |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | if(result.error) |
---|
| 42 | return result |
---|
| 43 | |
---|
| 44 | try { |
---|
| 45 | result.sectionInstance.delete(flush:true) |
---|
| 46 | return result //Success. |
---|
| 47 | } |
---|
| 48 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
| 49 | return fail(code:"default.delete.failure") |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | } // end withTransaction |
---|
| 53 | } // end delete() |
---|
| 54 | |
---|
| 55 | } // end class |
---|
Note: See
TracBrowser
for help on using the repository browser.