[122] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
[298] | 3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager']) |
---|
[124] | 4 | class AssetExtendedAttributeDetailedController extends BaseController { |
---|
[122] | 5 | |
---|
| 6 | // the delete, save and update actions only accept POST requests |
---|
| 7 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
| 8 | |
---|
[298] | 9 | def index = { redirect(controller: "assetDetailed", action: "search", params:params) } |
---|
| 10 | |
---|
[122] | 11 | def show = { |
---|
| 12 | def assetExtendedAttributeInstance = AssetExtendedAttribute.get( params.id ) |
---|
| 13 | |
---|
| 14 | if(!assetExtendedAttributeInstance) { |
---|
| 15 | flash.message = "AssetExtendedAttribute not found with id ${params.id}" |
---|
[293] | 16 | redirect(controller: "assetDetailed", action: "search") |
---|
[122] | 17 | } |
---|
| 18 | else { return [ assetExtendedAttributeInstance : assetExtendedAttributeInstance ] } |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | def delete = { |
---|
| 22 | def assetExtendedAttributeInstance = AssetExtendedAttribute.get( params.id ) |
---|
| 23 | if(assetExtendedAttributeInstance) { |
---|
[684] | 24 | def asset = assetExtendedAttributeInstance.asset |
---|
[122] | 25 | try { |
---|
[292] | 26 | assetExtendedAttributeInstance.delete(flush:true) |
---|
[122] | 27 | flash.message = "AssetExtendedAttribute ${params.id} deleted" |
---|
[684] | 28 | redirect(controller: "assetDetailed", action: 'show', id: asset.id) |
---|
[122] | 29 | } |
---|
| 30 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
| 31 | flash.message = "AssetExtendedAttribute ${params.id} could not be deleted" |
---|
| 32 | redirect(action:show,id:params.id) |
---|
| 33 | } |
---|
| 34 | } |
---|
| 35 | else { |
---|
| 36 | flash.message = "AssetExtendedAttribute not found with id ${params.id}" |
---|
[293] | 37 | redirect(controller: "assetDetailed", action: "search") |
---|
[122] | 38 | } |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | def edit = { |
---|
| 42 | def assetExtendedAttributeInstance = AssetExtendedAttribute.get( params.id ) |
---|
| 43 | |
---|
| 44 | if(!assetExtendedAttributeInstance) { |
---|
| 45 | flash.message = "AssetExtendedAttribute not found with id ${params.id}" |
---|
[293] | 46 | redirect(controller: "assetDetailed", action: "search") |
---|
[122] | 47 | } |
---|
| 48 | else { |
---|
| 49 | return [ assetExtendedAttributeInstance : assetExtendedAttributeInstance ] |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | def update = { |
---|
| 54 | def assetExtendedAttributeInstance = AssetExtendedAttribute.get( params.id ) |
---|
| 55 | if(assetExtendedAttributeInstance) { |
---|
| 56 | if(params.version) { |
---|
| 57 | def version = params.version.toLong() |
---|
| 58 | if(assetExtendedAttributeInstance.version > version) { |
---|
| 59 | |
---|
[403] | 60 | assetExtendedAttributeInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
[122] | 61 | render(view:'edit',model:[assetExtendedAttributeInstance:assetExtendedAttributeInstance]) |
---|
| 62 | return |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | assetExtendedAttributeInstance.properties = params |
---|
[178] | 66 | if(!assetExtendedAttributeInstance.hasErrors() && assetExtendedAttributeInstance.save(flush: true)) { |
---|
[122] | 67 | flash.message = "AssetExtendedAttribute ${params.id} updated" |
---|
[684] | 68 | //redirect(action:show,id:assetExtendedAttributeInstance.id) |
---|
| 69 | redirect(controller: 'assetDetailed', action: 'show', id: assetExtendedAttributeInstance.asset.id) |
---|
[122] | 70 | } |
---|
| 71 | else { |
---|
| 72 | render(view:'edit',model:[assetExtendedAttributeInstance:assetExtendedAttributeInstance]) |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | else { |
---|
| 76 | flash.message = "AssetExtendedAttribute not found with id ${params.id}" |
---|
[293] | 77 | redirect(controller: "assetDetailed", action: "search") |
---|
[122] | 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | def create = { |
---|
| 82 | def assetExtendedAttributeInstance = new AssetExtendedAttribute() |
---|
| 83 | assetExtendedAttributeInstance.properties = params |
---|
| 84 | return ['assetExtendedAttributeInstance':assetExtendedAttributeInstance] |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | def save = { |
---|
| 88 | def assetExtendedAttributeInstance = new AssetExtendedAttribute(params) |
---|
[178] | 89 | if(!assetExtendedAttributeInstance.hasErrors() && assetExtendedAttributeInstance.save(flush: true)) { |
---|
[122] | 90 | flash.message = "AssetExtendedAttribute ${assetExtendedAttributeInstance.id} created" |
---|
[656] | 91 | redirect(controller:'assetDetailed', action:'edit',id:assetExtendedAttributeInstance.asset.id) |
---|
[122] | 92 | } |
---|
| 93 | else { |
---|
| 94 | render(view:'create',model:[assetExtendedAttributeInstance:assetExtendedAttributeInstance]) |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | } |
---|