Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.lefp.sgaw
- import org.springframework.dao.DataIntegrityViolationException
- class EmpleadoService {
- static transactional = true
- def empleado
- Empleado obtenerEmpleado(Integer id) {
- def empleado = Empleado.get(id)
- if(!empleado){
- throw new EmpleadoNoExisteException()
- }
- return empleado
- }
- /**
- *
- * @param empleadoMaps list maps
- * @return
- */
- Empleado nuevoEmpleado(empleadoMaps) {
- def empleadoInstance = new Empleado(empleadoMaps)
- if(empleadoInstance.validate()){
- empleadoInstance.save()
- }
- return empleadoInstance;
- }
- def eliminarEmpleado(Integer id) {
- def empleado = Empleado.findByCodFicha(id)
- if (empleado) {
- if(!empleado.cargafamiliares && !empleado.cuentaEmpleado) {
- try {
- empleado.delete(flush: true)
- }
- catch (DataIntegrityViolationException e) {
- }
- } else {
- empleado.emplEsta = "BORRADO"
- empleado.save(flush: true)
- }
- } else {
- throw new EmpleadoNoExisteException()
- }
- }
- }
- class EmpleadoNoExisteException extends Exception{}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement