Last change
on this file since 826 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 SiteService { |
---|
| 2 | |
---|
| 3 | boolean transactional = false |
---|
| 4 | |
---|
| 5 | def sectionService |
---|
| 6 | |
---|
| 7 | def delete(params) { |
---|
| 8 | Site.withTransaction { status -> |
---|
| 9 | def result = [:] |
---|
| 10 | |
---|
| 11 | def fail = { Map m -> |
---|
| 12 | status.setRollbackOnly() |
---|
| 13 | if(result.siteInstance && m.field) |
---|
| 14 | result.siteInstance.errors.rejectValue(m.field, m.code) |
---|
| 15 | result.error = [ code: m.code, args: ["Site", params.id] ] |
---|
| 16 | return result |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | result.siteInstance = Site.get(params.id) |
---|
| 20 | |
---|
| 21 | if(!result.siteInstance) |
---|
| 22 | return fail(code:"default.not.found") |
---|
| 23 | |
---|
| 24 | if(result.siteInstance.inventoryStores) |
---|
| 25 | return fail(code:"inventoryStores.still.associated") |
---|
| 26 | |
---|
| 27 | // Delete sections which in turn deletes assets etc. |
---|
| 28 | def sections = new ArrayList(result.siteInstance.sections) // avoid ConcurrentModificationException. |
---|
| 29 | def r |
---|
| 30 | for(section in sections) { |
---|
| 31 | result.siteInstance.removeFromSections(section) |
---|
| 32 | r = sectionService.delete(id: section.id) |
---|
| 33 | if(r.error) { |
---|
| 34 | log.debug r.error |
---|
| 35 | fail(code:"site.section.delete.failure") |
---|
| 36 | break |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | if(result.error) |
---|
| 41 | return result |
---|
| 42 | |
---|
| 43 | try { |
---|
| 44 | result.siteInstance.delete(flush:true) |
---|
| 45 | return result //Success. |
---|
| 46 | } |
---|
| 47 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
| 48 | return fail(code:"default.delete.failure") |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | } // end withTransaction |
---|
| 52 | } // end delete() |
---|
| 53 | |
---|
| 54 | } // end class |
---|
Note: See
TracBrowser
for help on using the repository browser.