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