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