[122] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
[371] | 3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager']) |
---|
[378] | 4 | class MaintenancePolicyDetailedController extends BaseController { |
---|
[371] | 5 | |
---|
| 6 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
[122] | 7 | def index = { redirect(action:list,params:params) } |
---|
| 8 | |
---|
| 9 | // the delete, save and update actions only accept POST requests |
---|
| 10 | static allowedMethods = [delete:'POST', save:'POST', update:'POST'] |
---|
| 11 | |
---|
[371] | 12 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
[122] | 13 | def list = { |
---|
| 14 | params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) |
---|
| 15 | [ maintenancePolicyInstanceList: MaintenancePolicy.list( params ), maintenancePolicyInstanceTotal: MaintenancePolicy.count() ] |
---|
| 16 | } |
---|
| 17 | |
---|
[371] | 18 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_AssetManager', 'ROLE_AssetUser']) |
---|
[122] | 19 | def show = { |
---|
[363] | 20 | |
---|
| 21 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 22 | if(params._action_Show) |
---|
[375] | 23 | params.action='show' |
---|
[363] | 24 | |
---|
[122] | 25 | def maintenancePolicyInstance = MaintenancePolicy.get( params.id ) |
---|
| 26 | |
---|
| 27 | if(!maintenancePolicyInstance) { |
---|
| 28 | flash.message = "MaintenancePolicy not found with id ${params.id}" |
---|
| 29 | redirect(action:list) |
---|
| 30 | } |
---|
| 31 | else { return [ maintenancePolicyInstance : maintenancePolicyInstance ] } |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | def delete = { |
---|
| 35 | def maintenancePolicyInstance = MaintenancePolicy.get( params.id ) |
---|
| 36 | if(maintenancePolicyInstance) { |
---|
| 37 | try { |
---|
[178] | 38 | maintenancePolicyInstance.delete(flush:true) |
---|
[122] | 39 | flash.message = "MaintenancePolicy ${params.id} deleted" |
---|
| 40 | redirect(action:list) |
---|
| 41 | } |
---|
| 42 | catch(org.springframework.dao.DataIntegrityViolationException e) { |
---|
| 43 | flash.message = "MaintenancePolicy ${params.id} could not be deleted" |
---|
| 44 | redirect(action:show,id:params.id) |
---|
| 45 | } |
---|
| 46 | } |
---|
| 47 | else { |
---|
| 48 | flash.message = "MaintenancePolicy not found with id ${params.id}" |
---|
| 49 | redirect(action:list) |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | def edit = { |
---|
[363] | 54 | |
---|
| 55 | // In the case of an actionSubmit button, rewrite action name from 'index'. |
---|
| 56 | if(params._action_Edit) |
---|
[375] | 57 | params.action='edit' |
---|
[363] | 58 | |
---|
[122] | 59 | def maintenancePolicyInstance = MaintenancePolicy.get( params.id ) |
---|
| 60 | |
---|
| 61 | if(!maintenancePolicyInstance) { |
---|
| 62 | flash.message = "MaintenancePolicy not found with id ${params.id}" |
---|
| 63 | redirect(action:list) |
---|
| 64 | } |
---|
| 65 | else { |
---|
| 66 | return [ maintenancePolicyInstance : maintenancePolicyInstance ] |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | def update = { |
---|
| 71 | def maintenancePolicyInstance = MaintenancePolicy.get( params.id ) |
---|
| 72 | if(maintenancePolicyInstance) { |
---|
| 73 | if(params.version) { |
---|
| 74 | def version = params.version.toLong() |
---|
| 75 | if(maintenancePolicyInstance.version > version) { |
---|
| 76 | |
---|
[403] | 77 | maintenancePolicyInstance.errors.rejectValue("version", "default.optimistic.locking.failure") |
---|
[122] | 78 | render(view:'edit',model:[maintenancePolicyInstance:maintenancePolicyInstance]) |
---|
| 79 | return |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | maintenancePolicyInstance.properties = params |
---|
[178] | 83 | if(!maintenancePolicyInstance.hasErrors() && maintenancePolicyInstance.save(flush: true)) { |
---|
[122] | 84 | flash.message = "MaintenancePolicy ${params.id} updated" |
---|
| 85 | redirect(action:show,id:maintenancePolicyInstance.id) |
---|
| 86 | } |
---|
| 87 | else { |
---|
| 88 | render(view:'edit',model:[maintenancePolicyInstance:maintenancePolicyInstance]) |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | else { |
---|
| 92 | flash.message = "MaintenancePolicy not found with id ${params.id}" |
---|
[178] | 93 | redirect(action:list) |
---|
[122] | 94 | } |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | def create = { |
---|
| 98 | def maintenancePolicyInstance = new MaintenancePolicy() |
---|
| 99 | maintenancePolicyInstance.properties = params |
---|
| 100 | return ['maintenancePolicyInstance':maintenancePolicyInstance] |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | def save = { |
---|
| 104 | def maintenancePolicyInstance = new MaintenancePolicy(params) |
---|
[178] | 105 | if(!maintenancePolicyInstance.hasErrors() && maintenancePolicyInstance.save(flush: true)) { |
---|
[122] | 106 | flash.message = "MaintenancePolicy ${maintenancePolicyInstance.id} created" |
---|
| 107 | redirect(action:show,id:maintenancePolicyInstance.id) |
---|
| 108 | } |
---|
| 109 | else { |
---|
| 110 | render(view:'create',model:[maintenancePolicyInstance:maintenancePolicyInstance]) |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | } |
---|