[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) { |
---|
| 24 | try { |
---|
[292] | 25 | assetExtendedAttributeInstance.delete(flush:true) |
---|
[122] | 26 | flash.message = "AssetExtendedAttribute ${params.id} deleted" |
---|
[293] | 27 | redirect(controller: "assetDetailed", action: "search") |
---|
[122] | 28 | } |
---|
| 29 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
| 30 | flash.message = "AssetExtendedAttribute ${params.id} could not be deleted" |
---|
| 31 | redirect(action:show,id:params.id) |
---|
| 32 | } |
---|
| 33 | } |
---|
| 34 | else { |
---|
| 35 | flash.message = "AssetExtendedAttribute not found with id ${params.id}" |
---|
[293] | 36 | redirect(controller: "assetDetailed", action: "search") |
---|
[122] | 37 | } |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | def edit = { |
---|
| 41 | def assetExtendedAttributeInstance = AssetExtendedAttribute.get( params.id ) |
---|
| 42 | |
---|
| 43 | if(!assetExtendedAttributeInstance) { |
---|
| 44 | flash.message = "AssetExtendedAttribute not found with id ${params.id}" |
---|
[293] | 45 | redirect(controller: "assetDetailed", action: "search") |
---|
[122] | 46 | } |
---|
| 47 | else { |
---|
| 48 | return [ assetExtendedAttributeInstance : assetExtendedAttributeInstance ] |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | def update = { |
---|
| 53 | def assetExtendedAttributeInstance = AssetExtendedAttribute.get( params.id ) |
---|
| 54 | if(assetExtendedAttributeInstance) { |
---|
| 55 | if(params.version) { |
---|
| 56 | def version = params.version.toLong() |
---|
| 57 | if(assetExtendedAttributeInstance.version > version) { |
---|
| 58 | |
---|
[403] | 59 | assetExtendedAttributeInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
[122] | 60 | render(view:'edit',model:[assetExtendedAttributeInstance:assetExtendedAttributeInstance]) |
---|
| 61 | return |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | assetExtendedAttributeInstance.properties = params |
---|
[178] | 65 | if(!assetExtendedAttributeInstance.hasErrors() && assetExtendedAttributeInstance.save(flush: true)) { |
---|
[122] | 66 | flash.message = "AssetExtendedAttribute ${params.id} updated" |
---|
| 67 | redirect(action:show,id:assetExtendedAttributeInstance.id) |
---|
| 68 | } |
---|
| 69 | else { |
---|
| 70 | render(view:'edit',model:[assetExtendedAttributeInstance:assetExtendedAttributeInstance]) |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | else { |
---|
| 74 | flash.message = "AssetExtendedAttribute not found with id ${params.id}" |
---|
[293] | 75 | redirect(controller: "assetDetailed", action: "search") |
---|
[122] | 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | def create = { |
---|
| 80 | def assetExtendedAttributeInstance = new AssetExtendedAttribute() |
---|
| 81 | assetExtendedAttributeInstance.properties = params |
---|
| 82 | return ['assetExtendedAttributeInstance':assetExtendedAttributeInstance] |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | def save = { |
---|
| 86 | def assetExtendedAttributeInstance = new AssetExtendedAttribute(params) |
---|
[178] | 87 | if(!assetExtendedAttributeInstance.hasErrors() && assetExtendedAttributeInstance.save(flush: true)) { |
---|
[122] | 88 | flash.message = "AssetExtendedAttribute ${assetExtendedAttributeInstance.id} created" |
---|
[656] | 89 | redirect(controller:'assetDetailed', action:'edit',id:assetExtendedAttributeInstance.asset.id) |
---|
[122] | 90 | } |
---|
| 91 | else { |
---|
| 92 | render(view:'create',model:[assetExtendedAttributeInstance:assetExtendedAttributeInstance]) |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | } |
---|