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