[274] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
[298] | 3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager']) |
---|
[274] | 4 | class AssetSubItemExtendedAttributeDetailedController extends BaseController { |
---|
| 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 | |
---|
[274] | 11 | def show = { |
---|
| 12 | def assetSubItemExtendedAttributeInstance = AssetSubItemExtendedAttribute.get( params.id ) |
---|
| 13 | |
---|
| 14 | if(!assetSubItemExtendedAttributeInstance) { |
---|
| 15 | flash.message = "AssetSubItemExtendedAttribute not found with id ${params.id}" |
---|
[293] | 16 | redirect(controller: "assetDetailed", action: "search") |
---|
[274] | 17 | } |
---|
| 18 | else { return [ assetSubItemExtendedAttributeInstance : assetSubItemExtendedAttributeInstance ] } |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | def delete = { |
---|
| 22 | def assetSubItemExtendedAttributeInstance = AssetSubItemExtendedAttribute.get( params.id ) |
---|
| 23 | if(assetSubItemExtendedAttributeInstance) { |
---|
| 24 | try { |
---|
| 25 | assetSubItemExtendedAttributeInstance.delete(flush:true) |
---|
| 26 | flash.message = "AssetSubItemExtendedAttribute ${params.id} deleted" |
---|
[293] | 27 | redirect(controller: "assetDetailed", action: "search") |
---|
[274] | 28 | } |
---|
| 29 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
| 30 | flash.message = "AssetSubItemExtendedAttribute ${params.id} could not be deleted" |
---|
| 31 | redirect(action:show,id:params.id) |
---|
| 32 | } |
---|
| 33 | } |
---|
| 34 | else { |
---|
| 35 | flash.message = "AssetSubItemExtendedAttribute not found with id ${params.id}" |
---|
[293] | 36 | redirect(controller: "assetDetailed", action: "search") |
---|
[274] | 37 | } |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | def edit = { |
---|
| 41 | def assetSubItemExtendedAttributeInstance = AssetSubItemExtendedAttribute.get( params.id ) |
---|
| 42 | |
---|
| 43 | if(!assetSubItemExtendedAttributeInstance) { |
---|
| 44 | flash.message = "AssetSubItemExtendedAttribute not found with id ${params.id}" |
---|
[293] | 45 | redirect(controller: "assetDetailed", action: "search") |
---|
[274] | 46 | } |
---|
| 47 | else { |
---|
| 48 | return [ assetSubItemExtendedAttributeInstance : assetSubItemExtendedAttributeInstance ] |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | def update = { |
---|
| 53 | def assetSubItemExtendedAttributeInstance = AssetSubItemExtendedAttribute.get( params.id ) |
---|
| 54 | if(assetSubItemExtendedAttributeInstance) { |
---|
| 55 | if(params.version) { |
---|
| 56 | def version = params.version.toLong() |
---|
| 57 | if(assetSubItemExtendedAttributeInstance.version > version) { |
---|
| 58 | |
---|
| 59 | assetSubItemExtendedAttributeInstance.errors.rejectValue("version", "assetSubItemExtendedAttribute.optimistic.locking.failure", "Another user has updated this AssetSubItemExtendedAttribute while you were editing.") |
---|
| 60 | render(view:'edit',model:[assetSubItemExtendedAttributeInstance:assetSubItemExtendedAttributeInstance]) |
---|
| 61 | return |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | assetSubItemExtendedAttributeInstance.properties = params |
---|
| 65 | if(!assetSubItemExtendedAttributeInstance.hasErrors() && assetSubItemExtendedAttributeInstance.save(flush: true)) { |
---|
| 66 | flash.message = "AssetSubItemExtendedAttribute ${params.id} updated" |
---|
| 67 | redirect(action:show,id:assetSubItemExtendedAttributeInstance.id) |
---|
| 68 | } |
---|
| 69 | else { |
---|
| 70 | render(view:'edit',model:[assetSubItemExtendedAttributeInstance:assetSubItemExtendedAttributeInstance]) |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | else { |
---|
| 74 | flash.message = "AssetSubItemExtendedAttribute not found with id ${params.id}" |
---|
[293] | 75 | redirect(controller: "assetDetailed", action: "search") |
---|
[274] | 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | def create = { |
---|
| 80 | def assetSubItemExtendedAttributeInstance = new AssetSubItemExtendedAttribute() |
---|
| 81 | assetSubItemExtendedAttributeInstance.properties = params |
---|
| 82 | return ['assetSubItemExtendedAttributeInstance':assetSubItemExtendedAttributeInstance] |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | def save = { |
---|
| 86 | def assetSubItemExtendedAttributeInstance = new AssetSubItemExtendedAttribute(params) |
---|
| 87 | if(!assetSubItemExtendedAttributeInstance.hasErrors() && assetSubItemExtendedAttributeInstance.save(flush: true)) { |
---|
| 88 | flash.message = "AssetSubItemExtendedAttribute ${assetSubItemExtendedAttributeInstance.id} created" |
---|
| 89 | redirect(action:show,id:assetSubItemExtendedAttributeInstance.id) |
---|
| 90 | } |
---|
| 91 | else { |
---|
| 92 | render(view:'create',model:[assetSubItemExtendedAttributeInstance:assetSubItemExtendedAttributeInstance]) |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | } |
---|