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 | try { |
---|
25 | assetExtendedAttributeInstance.delete(flush:true) |
---|
26 | flash.message = "AssetExtendedAttribute ${params.id} deleted" |
---|
27 | redirect(controller: "assetDetailed", action: "search") |
---|
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}" |
---|
36 | redirect(controller: "assetDetailed", action: "search") |
---|
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}" |
---|
45 | redirect(controller: "assetDetailed", action: "search") |
---|
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 | |
---|
59 | assetExtendedAttributeInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
60 | render(view:'edit',model:[assetExtendedAttributeInstance:assetExtendedAttributeInstance]) |
---|
61 | return |
---|
62 | } |
---|
63 | } |
---|
64 | assetExtendedAttributeInstance.properties = params |
---|
65 | if(!assetExtendedAttributeInstance.hasErrors() && assetExtendedAttributeInstance.save(flush: true)) { |
---|
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}" |
---|
75 | redirect(controller: "assetDetailed", action: "search") |
---|
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) |
---|
87 | if(!assetExtendedAttributeInstance.hasErrors() && assetExtendedAttributeInstance.save(flush: true)) { |
---|
88 | flash.message = "AssetExtendedAttribute ${assetExtendedAttributeInstance.id} created" |
---|
89 | redirect(action:show,id:assetExtendedAttributeInstance.id) |
---|
90 | } |
---|
91 | else { |
---|
92 | render(view:'create',model:[assetExtendedAttributeInstance:assetExtendedAttributeInstance]) |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|