1 changed files with 110 additions and 0 deletions
			
			
		@ -0,0 +1,110 @@ | 
				
			|||||
 | 
					     /* | 
				
			||||
 | 
					 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 | 
				
			||||
 | 
					 * Click nbfs://nbhost/SystemFileSystem/Templates/J2EE/EJB30/StatelessEjbClass.java to edit this template
 | 
				
			||||
 | 
					 */ | 
				
			||||
 | 
					package hola.BL; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					import hola.dao.DepartamentoDAO; | 
				
			||||
 | 
					import hola.modelo.Departamento; | 
				
			||||
 | 
					import hola.msg.Mensaje; | 
				
			||||
 | 
					import java.util.List; | 
				
			||||
 | 
					import java.util.Optional; | 
				
			||||
 | 
					import javax.ejb.Stateless; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					/** | 
				
			||||
 | 
					 * | 
				
			||||
 | 
					 * @author eduar | 
				
			||||
 | 
					 */ | 
				
			||||
 | 
					@Stateless | 
				
			||||
 | 
					public class DepartamentoBL implements DepartamentoBLLocal { | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    public Mensaje agregar(Departamento departamento) { | 
				
			||||
 | 
					        System.out.println("Llegaste al metodo de agregar Departamento"); | 
				
			||||
 | 
					        DepartamentoDAO departamentoDAO = new DepartamentoDAO(); | 
				
			||||
 | 
					        Mensaje m = null; | 
				
			||||
 | 
					      | 
				
			||||
 | 
					        // Validar que los campos requeridos no estén vacíos
 | 
				
			||||
 | 
					        if (departamento.getNombre().isEmpty() | 
				
			||||
 | 
					                 | 
				
			||||
 | 
					                || departamento.getAnaquel().isEmpty()) { | 
				
			||||
 | 
					            System.out.println(Mensaje.CAMPOS_INCOMPLETOS); | 
				
			||||
 | 
					            // Enviar mensaje de error si algún campo está incompleto
 | 
				
			||||
 | 
					            return Mensaje.CAMPOS_INCOMPLETOS; | 
				
			||||
 | 
					        } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					        // Buscar si el proveedor ya existe en la base de datos
 | 
				
			||||
 | 
					        Optional<Departamento> departamentoEncontradoOptional = departamentoDAO.buscarDepartamento(departamento); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					        if (departamentoEncontradoOptional.isPresent()) { | 
				
			||||
 | 
					            // Manejar el caso en el que se encontró al menos un proveedor duplicado
 | 
				
			||||
 | 
					            departamentoEncontradoOptional.get(); | 
				
			||||
 | 
					            m = Mensaje.ELEMENTO_DUPLICADO; | 
				
			||||
 | 
					        } else { | 
				
			||||
 | 
					            // Agregar el proveedor a la base de datos si no está duplicado
 | 
				
			||||
 | 
					            departamentoDAO.agregar(departamento); | 
				
			||||
 | 
					            //registroDAO.agregar(registro);
 | 
				
			||||
 | 
					            m = Mensaje.SIN_ERROR; | 
				
			||||
 | 
					        } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					        return m; | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    @Override | 
				
			||||
 | 
					    public Departamento buscarId(Departamento departamento) { | 
				
			||||
 | 
					        // Comentario de lógica: Método para buscar un proveedor por ID
 | 
				
			||||
 | 
					        DepartamentoDAO d = new DepartamentoDAO(); | 
				
			||||
 | 
					        return d.buscarPorId(departamento); | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    @Override | 
				
			||||
 | 
					    public void eliminarId(Departamento departamento) { | 
				
			||||
 | 
					        // Comentario de lógica: Método para eliminar un proveedor por ID
 | 
				
			||||
 | 
					        DepartamentoDAO d = new DepartamentoDAO(); | 
				
			||||
 | 
					        if (d.eliminar(departamento)) { | 
				
			||||
 | 
					            System.out.println(Mensaje.SIN_ERROR); | 
				
			||||
 | 
					        } else { | 
				
			||||
 | 
					            System.out.println(Mensaje.NO_EXISTE); | 
				
			||||
 | 
					        } | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    @Override | 
				
			||||
 | 
					    public void editar(Departamento departamento) { | 
				
			||||
 | 
					        // Comentario de lógica: Método para editar un proveedor
 | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					        DepartamentoDAO departamentoDAO = new DepartamentoDAO(); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					        // Validar que los campos requeridos no estén vacíos
 | 
				
			||||
 | 
					        if (departamento.getNombre().isEmpty() | 
				
			||||
 | 
					                || departamento.getNombre().isEmpty() | 
				
			||||
 | 
					                || departamento.getAnaquel().isEmpty() | 
				
			||||
 | 
					                || departamento.getStatus() == null) { | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					            // Enviar mensaje de error si algún campo está incompleto
 | 
				
			||||
 | 
					            System.out.println(Mensaje.CAMPOS_INCOMPLETOS); | 
				
			||||
 | 
					            return; | 
				
			||||
 | 
					        } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					        try { | 
				
			||||
 | 
					            // Editar el proveedor solo si todas las validaciones son exitosas
 | 
				
			||||
 | 
					            if (departamentoDAO.editar(departamento) == true) { | 
				
			||||
 | 
					                System.out.println(Mensaje.SIN_ERROR); | 
				
			||||
 | 
					            } else { | 
				
			||||
 | 
					                System.out.println(Mensaje.NO_EXISTE); | 
				
			||||
 | 
					            } | 
				
			||||
 | 
					        } catch (Exception e) { | 
				
			||||
 | 
					            // Capturar cualquier excepción que ocurra durante la edición del proveedor
 | 
				
			||||
 | 
					            System.out.println(Mensaje.DATOS_INCORRECTOS); | 
				
			||||
 | 
					            e.printStackTrace(); | 
				
			||||
 | 
					        } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    @Override | 
				
			||||
 | 
					    public List<Departamento> buscarValidos(boolean estado) { | 
				
			||||
 | 
					        DepartamentoDAO departamentoDAO = new DepartamentoDAO(); | 
				
			||||
 | 
					        List l = departamentoDAO.buscarValidosD(estado); | 
				
			||||
 | 
					        // Llama al método buscarValidos de ProductoDAO y devuelve la lista resultante
 | 
				
			||||
 | 
					        System.out.println(l); | 
				
			||||
 | 
					        return l; | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue