1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
2 | |
---|
3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager']) |
---|
4 | class AssetExtendedAttributeDetailedController extends BaseController { |
---|
5 | |
---|
6 | // the delete, save and update actions only accept POST requests |
---|
7 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
8 | |
---|
9 | def index = { redirect(controller: "assetDetailed", action: "search", params:params) } |
---|
10 | |
---|
11 | def show = { |
---|
12 | def assetExtendedAttributeInstance = AssetExtendedAttribute.get( params.id ) |
---|
13 | |
---|
14 | if(!assetExtendedAttributeInstance) { |
---|
15 | flash.message = "AssetExtendedAttribute not found with id ${params.id}" |
---|
16 | redirect(controller: "assetDetailed", action: "search") |
---|
17 | } |
---|
18 | else { return [ assetExtendedAttributeInstance : assetExtendedAttributeInstance ] } |
---|
19 | } |
---|
20 | |
---|
21 | def delete = { |
---|
22 | def assetExtendedAttributeInstance = AssetExtendedAttribute.get( params.id ) |
---|
23 | if(assetExtendedAttributeInstance) { |
---|
24 | def asset = assetExtendedAttributeInstance.asset |
---|
25 | try { |
---|
26 | assetExtendedAttributeInstance.delete(flush:true) |
---|
27 | flash.message = "AssetExtendedAttribute ${params.id} deleted" |
---|
28 | redirect(controller: "assetDetailed", action: 'show', id: asset.id) |
---|
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}" |
---|
37 | redirect(controller: "assetDetailed", action: "search") |
---|
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}" |
---|
46 | redirect(controller: "assetDetailed", action: "search") |
---|
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 | |
---|
60 | assetExtendedAttributeInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
61 | render(view:'edit',model:[assetExtendedAttributeInstance:assetExtendedAttributeInstance]) |
---|
62 | return |
---|
63 | } |
---|
64 | } |
---|
65 | assetExtendedAttributeInstance.properties = params |
---|
66 | if(!assetExtendedAttributeInstance.hasErrors() && assetExtendedAttributeInstance.save(flush: true)) { |
---|
67 | flash.message = "AssetExtendedAttribute ${params.id} updated" |
---|
68 | //redirect(action:show,id:assetExtendedAttributeInstance.id) |
---|
69 | redirect(controller: 'assetDetailed', action: 'show', id: assetExtendedAttributeInstance.asset.id) |
---|
70 | } |
---|
71 | else { |
---|
72 | render(view:'edit',model:[assetExtendedAttributeInstance:assetExtendedAttributeInstance]) |
---|
73 | } |
---|
74 | } |
---|
75 | else { |
---|
76 | flash.message = "AssetExtendedAttribute not found with id ${params.id}" |
---|
77 | redirect(controller: "assetDetailed", action: "search") |
---|
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) |
---|
89 | if(!assetExtendedAttributeInstance.hasErrors() && assetExtendedAttributeInstance.save(flush: true)) { |
---|
90 | flash.message = "AssetExtendedAttribute ${assetExtendedAttributeInstance.id} created" |
---|
91 | redirect(controller:'assetDetailed', action:'edit',id:assetExtendedAttributeInstance.asset.id) |
---|
92 | } |
---|
93 | else { |
---|
94 | render(view:'create',model:[assetExtendedAttributeInstance:assetExtendedAttributeInstance]) |
---|
95 | } |
---|
96 | } |
---|
97 | } |
---|