Advertisement
Guest User

Untitled

a guest
Mar 14th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 3.06 KB | None | 0 0
  1. package br.ufscar.sead.loa.labteca.remar
  2.  
  3. import org.springframework.security.access.annotation.Secured
  4.  
  5. import static org.springframework.http.HttpStatus.*
  6. import grails.transaction.Transactional
  7.  
  8. @Transactional(readOnly = true)
  9. @Secured('ROLE_ADMIN')
  10.  
  11. class AnotacaoController {
  12.  
  13.     static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]
  14.  
  15.     def index(Integer max) {
  16.         redirect(action: 'create')
  17.     }
  18.  
  19.     def show(Anotacao anotacaoInstance) {
  20.         respond anotacaoInstance
  21.     }
  22.  
  23.     def create() {
  24.         respond new Anotacao(params)
  25.     }
  26.  
  27.     @Transactional
  28.     def save(Anotacao anotacaoInstance) {
  29.  
  30.         anotacaoInstance = new Anotacao(params);
  31.         println anotacaoInstance
  32.  
  33.         if (anotacaoInstance == null) {
  34.             notFound()
  35.             return
  36.         }
  37.  
  38.         if (anotacaoInstance.hasErrors()) {
  39.             respond anotacaoInstance.errors, view:'create'
  40.             return
  41.         }
  42.  
  43.         anotacaoInstance.save flush:true
  44.  
  45.         request.withFormat {
  46.             form multipartForm {
  47.                 flash.message = message(code: 'default.created.message', args: [message(code: 'anotacao.label', default: 'Anotacao'), anotacaoInstance.id])
  48.                 redirect anotacaoInstance
  49.             }
  50.             '*' { respond anotacaoInstance, [status: CREATED] }
  51.         }
  52.     }
  53.  
  54.     def edit(Anotacao anotacaoInstance) {
  55.         respond anotacaoInstance
  56.     }
  57.  
  58.     @Transactional
  59.     def update(Anotacao anotacaoInstance) {
  60.         if (anotacaoInstance == null) {
  61.             notFound()
  62.             return
  63.         }
  64.  
  65.         if (anotacaoInstance.hasErrors()) {
  66.             respond anotacaoInstance.errors, view:'edit'
  67.             return
  68.         }
  69.  
  70.         anotacaoInstance.save flush:true
  71.  
  72.         request.withFormat {
  73.             form multipartForm {
  74.                 flash.message = message(code: 'default.updated.message', args: [message(code: 'Anotacao.label', default: 'Anotacao'), anotacaoInstance.id])
  75.                 redirect anotacaoInstance
  76.             }
  77.             '*'{ respond anotacaoInstance, [status: OK] }
  78.         }
  79.     }
  80.  
  81.     @Transactional
  82.     def delete(Anotacao anotacaoInstance) {
  83.  
  84.         if (anotacaoInstance == null) {
  85.             notFound()
  86.             return
  87.         }
  88.  
  89.         anotacaoInstance.delete flush:true
  90.  
  91.         request.withFormat {
  92.             form multipartForm {
  93.                 flash.message = message(code: 'default.deleted.message', args: [message(code: 'Anotacao.label', default: 'Anotacao'), anotacaoInstance.id])
  94.                 redirect action:"index", method:"GET"
  95.             }
  96.             '*'{ render status: NO_CONTENT }
  97.         }
  98.     }
  99.  
  100.     protected void notFound() {
  101.         request.withFormat {
  102.             form multipartForm {
  103.                 flash.message = message(code: 'default.not.found.message', args: [message(code: 'anotacao.label', default: 'Anotacao'), params.id])
  104.                 redirect action: "index", method: "GET"
  105.             }
  106.             '*'{ render status: NOT_FOUND }
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement