[132] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
[298] | 3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager']) |
---|
[133] | 4 | class MaintenanceActionDetailedController extends BaseController { |
---|
[132] | 5 | |
---|
| 6 | // the delete, save and update actions only accept POST requests |
---|
| 7 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
| 8 | |
---|
[298] | 9 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
[132] | 10 | def show = { |
---|
| 11 | def maintenanceActionInstance = MaintenanceAction.get( params.id ) |
---|
| 12 | |
---|
| 13 | if(!maintenanceActionInstance) { |
---|
| 14 | flash.message = "MaintenanceAction not found with id ${params.id}" |
---|
[573] | 15 | redirect(controller: "appCore", action:"start") |
---|
[132] | 16 | } |
---|
| 17 | else { return [ maintenanceActionInstance : maintenanceActionInstance ] } |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | def delete = { |
---|
| 21 | def maintenanceActionInstance = MaintenanceAction.get( params.id ) |
---|
| 22 | if(maintenanceActionInstance) { |
---|
| 23 | try { |
---|
[573] | 24 | def taskProcedure = maintenanceActionInstance.taskProcedure |
---|
[269] | 25 | maintenanceActionInstance.delete(flush:true) |
---|
[132] | 26 | flash.message = "MaintenanceAction ${params.id} deleted" |
---|
[573] | 27 | redirect(controller: "taskProcedureDetailed", action:"show", id:taskProcedure.id) |
---|
[132] | 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}" |
---|
[573] | 36 | redirect(controller: "appCore", action:"start") |
---|
[132] | 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}" |
---|
[573] | 45 | redirect(controller: "appCore", action:"start") |
---|
[132] | 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 | |
---|
[403] | 59 | maintenanceActionInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
[132] | 60 | render(view:'edit',model:[maintenanceActionInstance:maintenanceActionInstance]) |
---|
| 61 | return |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | maintenanceActionInstance.properties = params |
---|
[178] | 65 | if(!maintenanceActionInstance.hasErrors() && maintenanceActionInstance.save(flush: true)) { |
---|
[132] | 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}" |
---|
[573] | 75 | redirect(controller: "appCore", action:"start") |
---|
[132] | 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) |
---|
[178] | 87 | if(!maintenanceActionInstance.hasErrors() && maintenanceActionInstance.save(flush: true)) { |
---|
[132] | 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 | } |
---|