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