Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.22 KB | None | 0 0
  1. package com.lefp.sgaw
  2.  
  3.  
  4. import org.springframework.dao.DataIntegrityViolationException
  5.  
  6. class EmpleadoService {
  7.  
  8.     static transactional = true
  9.     def empleado
  10.  
  11.     Empleado obtenerEmpleado(Integer id) {
  12.         def empleado = Empleado.get(id)
  13.         if(!empleado){
  14.             throw new EmpleadoNoExisteException()
  15.         }
  16.         return empleado
  17.     }
  18.  
  19.     /**
  20.      *
  21.      * @param empleadoMaps list maps
  22.      * @return
  23.      */
  24.     Empleado nuevoEmpleado(empleadoMaps) {
  25.         def empleadoInstance = new Empleado(empleadoMaps)
  26.         if(empleadoInstance.validate()){
  27.             empleadoInstance.save()
  28.         }
  29.        
  30.         return empleadoInstance;
  31.     }
  32.  
  33.     def eliminarEmpleado(Integer id) {
  34.         def empleado = Empleado.findByCodFicha(id)
  35.  
  36.         if (empleado) {
  37.             if(!empleado.cargafamiliares && !empleado.cuentaEmpleado) {
  38.                 try {
  39.                     empleado.delete(flush: true)
  40.                 }
  41.                 catch (DataIntegrityViolationException e) {
  42.                 }
  43.             } else {
  44.                 empleado.emplEsta = "BORRADO"
  45.                 empleado.save(flush: true)
  46.             }
  47.         } else {
  48.             throw new EmpleadoNoExisteException()
  49.         }
  50.     }
  51.    
  52. }
  53. class EmpleadoNoExisteException extends Exception{}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement