diff --git a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/RolBL.java b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/RolBL.java new file mode 100644 index 0000000..8fc928e --- /dev/null +++ b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/RolBL.java @@ -0,0 +1,130 @@ +/* + * 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 mx.edu.tjs.chapala.sistemas.bl; + +import java.util.List; +import java.util.Optional; +import javax.ejb.Stateless; +import javax.faces.application.FacesMessage; +import javax.faces.context.FacesContext; +import mx.edu.tjs.chapala.sistemas.dao.RolDAO; +import mx.edu.tjs.chapala.sistemas.modelo.Rol; +import mx.edu.tjs.chapala.sistemas.msg.Mensaje; + +/** + * + * @author Ely + */ +@Stateless +public class RolBL implements RolBLLocal { + + // Add business logic below. (Right-click in editor and choose + // "Insert Code > Add Business Method") + public void addMessage(FacesMessage.Severity severity, String summary, String detail) { + FacesContext.getCurrentInstance(). + addMessage(null, new FacesMessage(severity, summary, detail)); + } + + + @Override + public Mensaje agregar(Rol rol) { + System.out.println("Llegaste al metodo de agregar rol"); + RolDAO rolDAO = new RolDAO(); + Mensaje m = null; + + //Toda la logica + Optional rolEncontradoOptional =rolDAO.buscarRol(rol); + + if (rolEncontradoOptional.isPresent()) { + rolEncontradoOptional.get(); + m = Mensaje.ELEMENTO_DUPLICADO; + System.out.println("NO SE PUEDE AGREGAR, EL ROL YA EXISTE"); + addMessage(FacesMessage.SEVERITY_ERROR, "", "¡Error! El elemento ya existe"); + + } else { + rolDAO.agregar(rol); + m = Mensaje.SIN_ERROR; + System.out.println("AGREGADO CON EXITO"); + addMessage(FacesMessage.SEVERITY_INFO, "", "¡Elemento agregado con éxito!"); + } + return m; + } + + + @Override + public Rol buscarId(Rol rol) { + System.out.println("Llegaste al metodo de buscar por id"); + RolDAO r = new RolDAO(); + Mensaje m = null; + + Rol rolEncontrado = r.buscarPorId(rol); + + if (rolEncontrado == null) { + m = Mensaje.ELEMENTO_NO_ENCONTRADO; + System.out.println("NO EXISTE EL rol"); + return rolEncontrado; + } else { + m = Mensaje.SIN_ERROR; + System.out.println("ROL ENCONTRADO CON EXITO: " + rolEncontrado.getId()); + return rolEncontrado; + } + } + + + @Override + public Rol buscarNombre(Rol rol) { + System.out.println("Llegaste al metodo de buscar por nombre"); + RolDAO r = new RolDAO(); + Mensaje m = null; + + Rol rolEncontrado = r.buscarPorRol(rol); + + if (rolEncontrado == null) { + m = Mensaje.ELEMENTO_NO_ENCONTRADO; + System.out.println("NO EXISTE EL Usuarios"); + return rolEncontrado; + } else { + m = Mensaje.SIN_ERROR; + System.out.println("Usuarios ENCONTRADO CON EXITO: " + rolEncontrado.getRol()); + return rolEncontrado; + } + } + + + @Override + public List buscarStatus(boolean b) { + RolDAO r = new RolDAO(); + List l = r.buscarStatus(b); + System.out.println(l); + return l; + } + + + @Override + public void eliminarId(Rol r) { + RolDAO rl = new RolDAO(); + Mensaje m = null; + + if (rl.eliminar(r)) { + m = Mensaje.SIN_ERROR; + System.out.println("ELIMINADO CON EXITO"); + addMessage(FacesMessage.SEVERITY_INFO, "", "¡rol eliminado correctamente!"); + + } else { + m = Mensaje.ELEMENTO_NO_ENCONTRADO; + System.out.println("NO SE PUDO ELIMINAR"); + addMessage(FacesMessage.SEVERITY_WARN, "", "¡Error! No se pudo eliminar el rol"); + + } + } + + + @Override + public void editar(Rol rol) { + RolDAO r = new RolDAO(); + Mensaje m = null; + r.editar(rol); + } +} diff --git a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/RolBLLocal.java b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/RolBLLocal.java new file mode 100644 index 0000000..ce1df95 --- /dev/null +++ b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/RolBLLocal.java @@ -0,0 +1,30 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/J2EE/EJB30/SessionLocal.java to edit this template + */ +package mx.edu.tjs.chapala.sistemas.bl; + +import java.util.List; +import javax.ejb.Local; +import mx.edu.tjs.chapala.sistemas.modelo.Rol; +import mx.edu.tjs.chapala.sistemas.msg.Mensaje; + +/** + * + * @author Ely + */ +@Local +public interface RolBLLocal { + public void editar(Rol rol); + + public void eliminarId(Rol r); + + public List buscarStatus(boolean b); + + public Rol buscarNombre(Rol rol); + + public Rol buscarId(Rol rol); + + public Mensaje agregar(Rol rol); + +} diff --git a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/UsuariosBL.java b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/UsuariosBL.java index c8e04ac..786d3aa 100644 --- a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/UsuariosBL.java +++ b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/UsuariosBL.java @@ -124,10 +124,49 @@ public class UsuariosBL implements UsuariosBLLocal { @Override - public void editar(Usuarios usuarios) { - UsuariosDAO u = new UsuariosDAO(); + public Mensaje editar(Usuarios usuarios) { + UsuariosDAO usuariosDAO = new UsuariosDAO(); Mensaje m = null; - u.editar(usuarios); + + //Toda la logica + Optional usuariosEncontradoOptional = usuariosDAO.buscarUsuarios(usuarios); + + if (usuariosEncontradoOptional.isPresent()) { + usuariosEncontradoOptional.get(); + m = Mensaje.ELEMENTO_DUPLICADO; + System.out.println("NO SE PUEDE AGREGAR, EL usuario YA EXISTE"); + addMessage(FacesMessage.SEVERITY_ERROR, "", "¡Error! El elemento ya existe"); + + } else { + usuariosDAO.agregar(usuarios); + m = Mensaje.SIN_ERROR; + System.out.println("AGREGADO CON EXITO"); + addMessage(FacesMessage.SEVERITY_INFO, "", "¡Elemento agregado con éxito!"); + } + return m; + } + + @Override + public Mensaje loginValidar(Usuarios usuarios) { + UsuariosDAO usuariosDAO=new UsuariosDAO(); + Mensaje m = null; + + //Toda la logica + Optional EncontradoOptional = usuariosDAO.validar(usuarios); + + if (EncontradoOptional.isPresent()) { + EncontradoOptional.get(); + usuariosDAO.validar(usuarios); + m = Mensaje.SIN_ERROR; + System.out.println("No Se Inisio Sesion"); + addMessage(FacesMessage.SEVERITY_ERROR, "", "¡Error! algun campo incorecto"); + } else { + usuariosDAO.validar(usuarios); + m = Mensaje.ELEMENTO_DUPLICADO;System.out.println("Inisio Sesion"); + addMessage(FacesMessage.SEVERITY_INFO, "", "¡entrado!"); + } + return m; + } diff --git a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/UsuariosBLLocal.java b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/UsuariosBLLocal.java index 73e8d93..f65ade4 100644 --- a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/UsuariosBLLocal.java +++ b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/UsuariosBLLocal.java @@ -16,7 +16,7 @@ import mx.edu.tjs.chapala.sistemas.msg.Mensaje; @Local public interface UsuariosBLLocal { - public void editar(Usuarios usuarios); + public Mensaje editar(Usuarios usuarios); public void eliminarId(Usuarios usuarios); @@ -28,4 +28,6 @@ public interface UsuariosBLLocal { public Mensaje agregar(Usuarios usuarios); + public Mensaje loginValidar(Usuarios usuarios); + } diff --git a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/dao/RolDAO.java b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/dao/RolDAO.java new file mode 100644 index 0000000..8b9c731 --- /dev/null +++ b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/dao/RolDAO.java @@ -0,0 +1,128 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package mx.edu.tjs.chapala.sistemas.dao; + +import java.util.List; +import java.util.Optional; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import javax.persistence.Query; +import mx.edu.tjs.chapala.sistemas.modelo.Rol; + +/** + * + * @author Ely + */ +public class RolDAO { + private EntityManager em; //Manejador de entidades (entidad=bean del modelo) + + public RolDAO() { + //conexion + EntityManagerFactory emf = Persistence.createEntityManagerFactory("Inventario-ejbPU"); + em = emf.createEntityManager(); + + } + + public void agregar(Rol r) { + em.getTransaction().begin(); + r.setStatus(1); + em.persist(r); //Almacenar en la BD + em.getTransaction().commit(); + } + + public void editar(Rol r) { + buscarPorId(r); + em.getTransaction().begin(); + em.merge(r); //Editar en la BD + em.getTransaction().commit(); + + } + public boolean eliminar(Rol r) { + if (buscarPorId(r) == null) { + return false; + } else { + em.getTransaction().begin(); + + // Obtener usuarios actualizado desde la base de datos + Rol ro = em.find(Rol.class, r.getId()); + + r.setRol(ro.getRol()); + + + // Modificar solo el estado + r.setStatus(0); + + em.merge(r); + em.getTransaction().commit(); + + return true; + } + } + + + + public Optional buscarRol(Rol r) { + Query q1 = em.createNamedQuery("Rol.findByRol"); + q1.setParameter("rol",r.getRol()); + + + + List resultadoRol = q1.getResultList(); + + + // Verifica si hay resultados para todos los campos + if (!resultadoRol.isEmpty()) { + // Compara si el mismo autor está en los tres resultados + Rol rolEncontrado = resultadoRol.stream() + .findFirst() + .orElse(null); + + return Optional.ofNullable(rolEncontrado); + } else { + // Devuelve Optional vacío para indicar ausencia de resultados + return Optional.empty(); + } + } + + public Rol buscarPorId(Rol r) { + Query q = em.createNamedQuery("Rol.findById"); + q.setParameter("id", r.getId()); + if (q.getResultList().isEmpty()) { + return null; + } else { + return (Rol) q.getResultList().get(0); + } + } + + + public Rol buscarPorRol(Rol r) { + Query q = em.createNamedQuery("Rol.findByRol"); + q.setParameter("rol", r.getRol()); + if (q.getResultList().isEmpty()) { + return null; + } else { + return (Rol) q.getResultList().get(0); + } + } + + public List buscarStatus(boolean status) { + Query q = em.createNamedQuery("Rol.findByStatus"); + int s = status ? 1 : 0; + + if(s==1){ + System.out.println("Rol activos"); + } else { + System.out.println("Rol inactivos"); + } + + q.setParameter("status", s); + return q.getResultList(); + } + + + + +} diff --git a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/dao/UsuariosDAO.java b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/dao/UsuariosDAO.java index 58dfe60..c6b6587 100644 --- a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/dao/UsuariosDAO.java +++ b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/dao/UsuariosDAO.java @@ -32,6 +32,32 @@ public class UsuariosDAO { em.persist(u); //Almacenar en la BD em.getTransaction().commit(); } + + public Optional validar(Usuarios u) { + Query q = em.createNamedQuery("Usuarios.findByUsuario"); + q.setParameter("usuario", u.getUsuario()); + Query q1 = em.createNamedQuery("Usuarios.findByContrasenia"); + q1.setParameter("contrasenia", u.getContrasenia()); + List uresultado = q.getResultList(); + List cresultado = q1.getResultList(); + + + if (!uresultado.isEmpty() && !cresultado.isEmpty()) { + + Usuarios Encontrado = uresultado.stream() + .filter(uresultado::contains) + .filter(cresultado::contains) + .findFirst() + .orElse(null); + + return Optional.ofNullable(Encontrado); + } else { + // Devuelve Optional vacío para indicar ausencia de resultados + return Optional.empty(); + } + + + } public void editar(Usuarios u) { buscarPorId(u); @@ -65,18 +91,65 @@ public class UsuariosDAO { } public Optional buscarUsuarios(Usuarios u) { - Query q1 = em.createNamedQuery("Usuarios.findByUsuario"); - q1.setParameter("usuario", u.getUsuario()); + Query q = em.createNamedQuery("Usuarios.findByNombre"); + q.setParameter("nombre", u.getNombre()); - + Query q1 = em.createNamedQuery("Usuarios.findByApellidop"); + q1.setParameter("apellidop", u.getApellidop()); + + Query q2 = em.createNamedQuery("Usuarios.findByApellidom"); + q2.setParameter("apellidom", u.getApellidom()); + + Query q3 = em.createNamedQuery("Usuarios.findByUsuario"); + q3.setParameter("usuario", u.getUsuario()); + + + + Query q5 = em.createNamedQuery("Usuarios.findByPais"); + q5.setParameter("pais", u.getPais()); + + Query q6 = em.createNamedQuery("Usuarios.findByEstado"); + q6.setParameter("estado", u.getEstado()); + + Query q7 = em.createNamedQuery("Usuarios.findByMunicipio"); + q7.setParameter("municipio", u.getMunicipio()); + + Query q8 = em.createNamedQuery("Usuarios.findByLocalidad"); + q8.setParameter("localidad", u.getLocalidad()); + + List resultadoNombre = q.getResultList(); + + List resultadoApellidop = q1.getResultList(); + + List resultadoApellidom = q2.getResultList(); + + List resultadoUsuarios = q3.getResultList(); + + + + List resultadoPais = q5.getResultList(); + + List resultadoEstado = q6.getResultList(); + + List resultadoMunicipio = q7.getResultList(); - List resultadoUsuarios = q1.getResultList(); - + List resultadoLocalidad = q8.getResultList(); // Verifica si hay resultados para todos los campos - if (!resultadoUsuarios.isEmpty()) { + if (!resultadoNombre.isEmpty() && !resultadoApellidop.isEmpty() && !resultadoApellidom.isEmpty() + && !resultadoUsuarios.isEmpty() && !resultadoPais.isEmpty() + && !resultadoEstado.isEmpty() && !resultadoMunicipio.isEmpty() && !resultadoLocalidad.isEmpty()) { // Compara si el mismo autor está en los tres resultados Usuarios usuariosEncontrado = resultadoUsuarios.stream() + .filter(resultadoNombre::contains) + .filter(resultadoApellidop::contains) + .filter(resultadoApellidom::contains) + .filter(resultadoUsuarios::contains) + + .filter(resultadoPais::contains) + .filter(resultadoEstado::contains) + .filter(resultadoMunicipio::contains) + .filter(resultadoLocalidad::contains) .findFirst() .orElse(null); diff --git a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/modelo/Domicilio.java b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/modelo/Domicilio.java deleted file mode 100644 index 14b5492..0000000 --- a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/modelo/Domicilio.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license - * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template - */ -package mx.edu.tjs.chapala.sistemas.modelo; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; - -/** - * - * @author nickdalyrendon - */ -@Entity -@Table(name = "domicilio") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Domicilio.findAll", query = "SELECT d FROM Domicilio d"), - @NamedQuery(name = "Domicilio.findById", query = "SELECT d FROM Domicilio d WHERE d.id = :id"), - @NamedQuery(name = "Domicilio.findByPais", query = "SELECT d FROM Domicilio d WHERE d.pais = :pais"), - @NamedQuery(name = "Domicilio.findByEstado", query = "SELECT d FROM Domicilio d WHERE d.estado = :estado"), - @NamedQuery(name = "Domicilio.findByMunicipio", query = "SELECT d FROM Domicilio d WHERE d.municipio = :municipio"), - @NamedQuery(name = "Domicilio.findByLocalidad", query = "SELECT d FROM Domicilio d WHERE d.localidad = :localidad"), - @NamedQuery(name = "Domicilio.findByCp", query = "SELECT d FROM Domicilio d WHERE d.cp = :cp"), - @NamedQuery(name = "Domicilio.findByCalle", query = "SELECT d FROM Domicilio d WHERE d.calle = :calle"), - @NamedQuery(name = "Domicilio.findByNumero", query = "SELECT d FROM Domicilio d WHERE d.numero = :numero")}) -public class Domicilio implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Basic(optional = false) - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "pais") - private String pais; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "estado") - private String estado; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "municipio") - private String municipio; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "localidad") - private String localidad; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "cp") - private String cp; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "calle") - private String calle; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "numero") - private String numero; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "domicilioId") - private List usuariosList; - - public Domicilio() { - } - - public Domicilio(Integer id) { - this.id = id; - } - - public Domicilio(Integer id, String pais, String estado, String municipio, String localidad, String cp, String calle, String numero) { - this.id = id; - this.pais = pais; - this.estado = estado; - this.municipio = municipio; - this.localidad = localidad; - this.cp = cp; - this.calle = calle; - this.numero = numero; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getPais() { - return pais; - } - - public void setPais(String pais) { - this.pais = pais; - } - - public String getEstado() { - return estado; - } - - public void setEstado(String estado) { - this.estado = estado; - } - - public String getMunicipio() { - return municipio; - } - - public void setMunicipio(String municipio) { - this.municipio = municipio; - } - - public String getLocalidad() { - return localidad; - } - - public void setLocalidad(String localidad) { - this.localidad = localidad; - } - - public String getCp() { - return cp; - } - - public void setCp(String cp) { - this.cp = cp; - } - - public String getCalle() { - return calle; - } - - public void setCalle(String calle) { - this.calle = calle; - } - - public String getNumero() { - return numero; - } - - public void setNumero(String numero) { - this.numero = numero; - } - - @XmlTransient - public List getUsuariosList() { - return usuariosList; - } - - public void setUsuariosList(List usuariosList) { - this.usuariosList = usuariosList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set - if (!(object instanceof Domicilio)) { - return false; - } - Domicilio other = (Domicilio) object; - if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { - return false; - } - return true; - } - - @Override - public String toString() { - return "mx.edu.tjs.chapala.sistemas.modelo.Domicilio[ id=" + id + " ]"; - } - -} diff --git a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/modelo/Rol.java b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/modelo/Rol.java index 0edaf3b..41c8dee 100644 --- a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/modelo/Rol.java +++ b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/modelo/Rol.java @@ -1,114 +1,128 @@ -/* - * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license - * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template - */ -package mx.edu.tjs.chapala.sistemas.modelo; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; - -/** - * - * @author nickdalyrendon - */ -@Entity -@Table(name = "rol") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Rol.findAll", query = "SELECT r FROM Rol r"), - @NamedQuery(name = "Rol.findById", query = "SELECT r FROM Rol r WHERE r.id = :id"), - @NamedQuery(name = "Rol.findByRol", query = "SELECT r FROM Rol r WHERE r.rol = :rol")}) -public class Rol implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Basic(optional = false) - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "rol") - private String rol; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "rolId") - private List usuariosList; - - public Rol() { - } - - public Rol(Integer id) { - this.id = id; - } - - public Rol(Integer id, String rol) { - this.id = id; - this.rol = rol; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getRol() { - return rol; - } - - public void setRol(String rol) { - this.rol = rol; - } - - @XmlTransient - public List getUsuariosList() { - return usuariosList; - } - - public void setUsuariosList(List usuariosList) { - this.usuariosList = usuariosList; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set - if (!(object instanceof Rol)) { - return false; - } - Rol other = (Rol) object; - if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { - return false; - } - return true; - } - - @Override - public String toString() { - return "mx.edu.tjs.chapala.sistemas.modelo.Rol[ id=" + id + " ]"; - } - -} +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package mx.edu.tjs.chapala.sistemas.modelo; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; + +/** + * + * @author Ely + */ +@Entity +@Table(name = "rol") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Rol.findAll", query = "SELECT r FROM Rol r"), + @NamedQuery(name = "Rol.findById", query = "SELECT r FROM Rol r WHERE r.id = :id"), + @NamedQuery(name = "Rol.findByRol", query = "SELECT r FROM Rol r WHERE r.rol = :rol"), + @NamedQuery(name = "Rol.findByStatus", query = "SELECT r FROM Rol r WHERE r.status = :status")}) +public class Rol implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Basic(optional = false) + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "rol") + private String rol; + @Basic(optional = false) + @NotNull + @Column(name = "status") + private int status; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "rolId") + private List usuariosList; + + public Rol() { + } + + public Rol(Integer id) { + this.id = id; + } + + public Rol(Integer id, String rol, int status) { + this.id = id; + this.rol = rol; + this.status = status; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getRol() { + return rol; + } + + public void setRol(String rol) { + this.rol = rol; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + @XmlTransient + public List getUsuariosList() { + return usuariosList; + } + + public void setUsuariosList(List usuariosList) { + this.usuariosList = usuariosList; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof Rol)) { + return false; + } + Rol other = (Rol) object; + if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "mx.edu.tjs.chapala.sistemas.modelo.Rol[ id=" + id + " ]"; + } + +} diff --git a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/modelo/Usuarios.java b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/modelo/Usuarios.java index 15bafd0..e6d82db 100644 --- a/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/modelo/Usuarios.java +++ b/Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/modelo/Usuarios.java @@ -1,259 +1,353 @@ -/* - * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license - * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template - */ -package mx.edu.tjs.chapala.sistemas.modelo; - -import java.io.Serializable; -import java.util.Date; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * - * @author nickdalyrendon - */ -@Entity -@Table(name = "usuarios") -@XmlRootElement -@NamedQueries({ - @NamedQuery(name = "Usuarios.findAll", query = "SELECT u FROM Usuarios u"), - @NamedQuery(name = "Usuarios.findById", query = "SELECT u FROM Usuarios u WHERE u.id = :id"), - @NamedQuery(name = "Usuarios.findByUsuario", query = "SELECT u FROM Usuarios u WHERE u.usuario = :usuario"), - @NamedQuery(name = "Usuarios.findByContrasenia", query = "SELECT u FROM Usuarios u WHERE u.contrasenia = :contrasenia"), - @NamedQuery(name = "Usuarios.findByStatus", query = "SELECT u FROM Usuarios u WHERE u.status = :status"), - @NamedQuery(name = "Usuarios.findByNombre", query = "SELECT u FROM Usuarios u WHERE u.nombre = :nombre"), - @NamedQuery(name = "Usuarios.findByApellidom", query = "SELECT u FROM Usuarios u WHERE u.apellidom = :apellidom"), - @NamedQuery(name = "Usuarios.findByApellidop", query = "SELECT u FROM Usuarios u WHERE u.apellidop = :apellidop"), - @NamedQuery(name = "Usuarios.findByFechanacimiento", query = "SELECT u FROM Usuarios u WHERE u.fechanacimiento = :fechanacimiento"), - @NamedQuery(name = "Usuarios.findByCorreo", query = "SELECT u FROM Usuarios u WHERE u.correo = :correo"), - @NamedQuery(name = "Usuarios.findByGenero", query = "SELECT u FROM Usuarios u WHERE u.genero = :genero"), - @NamedQuery(name = "Usuarios.findByTelefono", query = "SELECT u FROM Usuarios u WHERE u.telefono = :telefono")}) -public class Usuarios implements Serializable { - - private static final long serialVersionUID = 1L; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Basic(optional = false) - @Column(name = "id") - private Integer id; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "usuario") - private String usuario; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "contrasenia") - private String contrasenia; - @Basic(optional = false) - @NotNull - @Column(name = "status") - private int status; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "nombre") - private String nombre; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "apellidom") - private String apellidom; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "apellidop") - private String apellidop; - @Basic(optional = false) - @NotNull - @Column(name = "fechanacimiento") - @Temporal(TemporalType.DATE) - private Date fechanacimiento; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 45) - @Column(name = "correo") - private String correo; - @Basic(optional = false) - @NotNull - @Column(name = "genero") - private Character genero; - @Basic(optional = false) - @NotNull - @Size(min = 1, max = 20) - @Column(name = "telefono") - private String telefono; - @JoinColumn(name = "domicilio_id", referencedColumnName = "id") - @ManyToOne(optional = false) - private Domicilio domicilioId; - @JoinColumn(name = "rol_id", referencedColumnName = "id") - @ManyToOne(optional = false) - private Rol rolId; - - public Usuarios() { - } - - public Usuarios(Integer id) { - this.id = id; - } - - public Usuarios(Integer id, String usuario, String contrasenia, int status, String nombre, String apellidom, String apellidop, Date fechanacimiento, String correo, Character genero, String telefono) { - this.id = id; - this.usuario = usuario; - this.contrasenia = contrasenia; - this.status = status; - this.nombre = nombre; - this.apellidom = apellidom; - this.apellidop = apellidop; - this.fechanacimiento = fechanacimiento; - this.correo = correo; - this.genero = genero; - this.telefono = telefono; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getUsuario() { - return usuario; - } - - public void setUsuario(String usuario) { - this.usuario = usuario; - } - - public String getContrasenia() { - return contrasenia; - } - - public void setContrasenia(String contrasenia) { - this.contrasenia = contrasenia; - } - - public int getStatus() { - return status; - } - - public void setStatus(int status) { - this.status = status; - } - - public String getNombre() { - return nombre; - } - - public void setNombre(String nombre) { - this.nombre = nombre; - } - - public String getApellidom() { - return apellidom; - } - - public void setApellidom(String apellidom) { - this.apellidom = apellidom; - } - - public String getApellidop() { - return apellidop; - } - - public void setApellidop(String apellidop) { - this.apellidop = apellidop; - } - - public Date getFechanacimiento() { - return fechanacimiento; - } - - public void setFechanacimiento(Date fechanacimiento) { - this.fechanacimiento = fechanacimiento; - } - - public String getCorreo() { - return correo; - } - - public void setCorreo(String correo) { - this.correo = correo; - } - - public Character getGenero() { - return genero; - } - - public void setGenero(Character genero) { - this.genero = genero; - } - - public String getTelefono() { - return telefono; - } - - public void setTelefono(String telefono) { - this.telefono = telefono; - } - - public Domicilio getDomicilioId() { - return domicilioId; - } - - public void setDomicilioId(Domicilio domicilioId) { - this.domicilioId = domicilioId; - } - - public Rol getRolId() { - return rolId; - } - - public void setRolId(Rol rolId) { - this.rolId = rolId; - } - - @Override - public int hashCode() { - int hash = 0; - hash += (id != null ? id.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set - if (!(object instanceof Usuarios)) { - return false; - } - Usuarios other = (Usuarios) object; - if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { - return false; - } - return true; - } - - @Override - public String toString() { - return "mx.edu.tjs.chapala.sistemas.modelo.Usuarios[ id=" + id + " ]"; - } - -} +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package mx.edu.tjs.chapala.sistemas.modelo; + +import java.io.Serializable; +import java.util.Date; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author Ely + */ +@Entity +@Table(name = "usuarios") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "Usuarios.findAll", query = "SELECT u FROM Usuarios u"), + @NamedQuery(name = "Usuarios.findById", query = "SELECT u FROM Usuarios u WHERE u.id = :id"), + @NamedQuery(name = "Usuarios.findByNombre", query = "SELECT u FROM Usuarios u WHERE u.nombre = :nombre"), + @NamedQuery(name = "Usuarios.findByApellidop", query = "SELECT u FROM Usuarios u WHERE u.apellidop = :apellidop"), + @NamedQuery(name = "Usuarios.findByApellidom", query = "SELECT u FROM Usuarios u WHERE u.apellidom = :apellidom"), + @NamedQuery(name = "Usuarios.findByGenero", query = "SELECT u FROM Usuarios u WHERE u.genero = :genero"), + @NamedQuery(name = "Usuarios.findByFechanacimiento", query = "SELECT u FROM Usuarios u WHERE u.fechanacimiento = :fechanacimiento"), + @NamedQuery(name = "Usuarios.findByUsuario", query = "SELECT u FROM Usuarios u WHERE u.usuario = :usuario"), + @NamedQuery(name = "Usuarios.findByContrasenia", query = "SELECT u FROM Usuarios u WHERE u.contrasenia = :contrasenia"), + @NamedQuery(name = "Usuarios.findByCorreo", query = "SELECT u FROM Usuarios u WHERE u.correo = :correo"), + @NamedQuery(name = "Usuarios.findByTelefono", query = "SELECT u FROM Usuarios u WHERE u.telefono = :telefono"), + @NamedQuery(name = "Usuarios.findByPais", query = "SELECT u FROM Usuarios u WHERE u.pais = :pais"), + @NamedQuery(name = "Usuarios.findByEstado", query = "SELECT u FROM Usuarios u WHERE u.estado = :estado"), + @NamedQuery(name = "Usuarios.findByMunicipio", query = "SELECT u FROM Usuarios u WHERE u.municipio = :municipio"), + @NamedQuery(name = "Usuarios.findByLocalidad", query = "SELECT u FROM Usuarios u WHERE u.localidad = :localidad"), + @NamedQuery(name = "Usuarios.findByCalle", query = "SELECT u FROM Usuarios u WHERE u.calle = :calle"), + @NamedQuery(name = "Usuarios.findByNumero", query = "SELECT u FROM Usuarios u WHERE u.numero = :numero"), + @NamedQuery(name = "Usuarios.findByCp", query = "SELECT u FROM Usuarios u WHERE u.cp = :cp"), + @NamedQuery(name = "Usuarios.findByStatus", query = "SELECT u FROM Usuarios u WHERE u.status = :status")}) +public class Usuarios implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Basic(optional = false) + @Column(name = "id") + private Integer id; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "nombre") + private String nombre; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "apellidop") + private String apellidop; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "apellidom") + private String apellidom; + @Basic(optional = false) + @NotNull + @Column(name = "genero") + private Character genero; + @Basic(optional = false) + @NotNull + @Column(name = "fechanacimiento") + @Temporal(TemporalType.DATE) + private Date fechanacimiento; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "usuario") + private String usuario; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "contrasenia") + private String contrasenia; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "correo") + private String correo; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 20) + @Column(name = "telefono") + private String telefono; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "pais") + private String pais; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "estado") + private String estado; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "municipio") + private String municipio; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "localidad") + private String localidad; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "calle") + private String calle; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "numero") + private String numero; + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 45) + @Column(name = "cp") + private String cp; + @Basic(optional = false) + @NotNull + @Column(name = "status") + private int status; + @JoinColumn(name = "rol_id", referencedColumnName = "id") + @ManyToOne(optional = false) + private Rol rolId; + + public Usuarios() { + } + + public Usuarios(Integer id) { + this.id = id; + } + + public Usuarios(Integer id, String nombre, String apellidop, String apellidom, Character genero, Date fechanacimiento, String usuario, String contrasenia, String correo, String telefono, String pais, String estado, String municipio, String localidad, String calle, String numero, String cp, int status) { + this.id = id; + this.nombre = nombre; + this.apellidop = apellidop; + this.apellidom = apellidom; + this.genero = genero; + this.fechanacimiento = fechanacimiento; + this.usuario = usuario; + this.contrasenia = contrasenia; + this.correo = correo; + this.telefono = telefono; + this.pais = pais; + this.estado = estado; + this.municipio = municipio; + this.localidad = localidad; + this.calle = calle; + this.numero = numero; + this.cp = cp; + this.status = status; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getNombre() { + return nombre; + } + + public void setNombre(String nombre) { + this.nombre = nombre; + } + + public String getApellidop() { + return apellidop; + } + + public void setApellidop(String apellidop) { + this.apellidop = apellidop; + } + + public String getApellidom() { + return apellidom; + } + + public void setApellidom(String apellidom) { + this.apellidom = apellidom; + } + + public Character getGenero() { + return genero; + } + + public void setGenero(Character genero) { + this.genero = genero; + } + + public Date getFechanacimiento() { + return fechanacimiento; + } + + public void setFechanacimiento(Date fechanacimiento) { + this.fechanacimiento = fechanacimiento; + } + + public String getUsuario() { + return usuario; + } + + public void setUsuario(String usuario) { + this.usuario = usuario; + } + + public String getContrasenia() { + return contrasenia; + } + + public void setContrasenia(String contrasenia) { + this.contrasenia = contrasenia; + } + + public String getCorreo() { + return correo; + } + + public void setCorreo(String correo) { + this.correo = correo; + } + + public String getTelefono() { + return telefono; + } + + public void setTelefono(String telefono) { + this.telefono = telefono; + } + + public String getPais() { + return pais; + } + + public void setPais(String pais) { + this.pais = pais; + } + + public String getEstado() { + return estado; + } + + public void setEstado(String estado) { + this.estado = estado; + } + + public String getMunicipio() { + return municipio; + } + + public void setMunicipio(String municipio) { + this.municipio = municipio; + } + + public String getLocalidad() { + return localidad; + } + + public void setLocalidad(String localidad) { + this.localidad = localidad; + } + + public String getCalle() { + return calle; + } + + public void setCalle(String calle) { + this.calle = calle; + } + + public String getNumero() { + return numero; + } + + public void setNumero(String numero) { + this.numero = numero; + } + + public String getCp() { + return cp; + } + + public void setCp(String cp) { + this.cp = cp; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public Rol getRolId() { + return rolId; + } + + public void setRolId(Rol rolId) { + this.rolId = rolId; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof Usuarios)) { + return false; + } + Usuarios other = (Usuarios) object; + if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "mx.edu.tjs.chapala.sistemas.modelo.Usuarios[ id=" + id + " ]"; + } + +} diff --git a/Inventario-war/src/java/mx/edu/tjs/chapala/sistemas/seguridad/Login.java b/Inventario-war/src/java/mx/edu/tjs/chapala/sistemas/seguridad/Login.java index f9fdff7..d859cb3 100644 --- a/Inventario-war/src/java/mx/edu/tjs/chapala/sistemas/seguridad/Login.java +++ b/Inventario-war/src/java/mx/edu/tjs/chapala/sistemas/seguridad/Login.java @@ -7,8 +7,14 @@ package mx.edu.tjs.chapala.sistemas.seguridad; import javax.inject.Named; import javax.enterprise.context.SessionScoped; import java.io.Serializable; +import javax.ejb.EJB; import javax.faces.context.FacesContext; import javax.servlet.http.HttpSession; +import mx.edu.tjs.chapala.sistemas.bl.UsuariosBLLocal; +import mx.edu.tjs.chapala.sistemas.modelo.Usuarios; +import mx.edu.tjs.chapala.sistemas.msg.Mensaje; +import static mx.edu.tjs.chapala.sistemas.msg.Mensaje.ELEMENTO_DUPLICADO; +import static mx.edu.tjs.chapala.sistemas.msg.Mensaje.SIN_ERROR; /** * @@ -18,6 +24,11 @@ import javax.servlet.http.HttpSession; @SessionScoped public class Login implements Serializable { + + @EJB + private UsuariosBLLocal usuariosBL; + private Usuarios usuarios= new Usuarios(); + private static HttpSession httpSession; @@ -34,22 +45,36 @@ private static HttpSession httpSession; //metodo para salir - public static String logout(){ + public String logout(){ httpSession.removeAttribute("sesionActiva"); httpSession.invalidate(); return "index.xhtml"; } - public static String login(){ + public String login() { //llamar bl para autenticacion que regresa un boolean - //todo:hacer un metodo en el bl que reciba el usuario y pass - boolean login=true; + //todo:hacer un metodo en el bl que reciba el usuario y passMensaje mensaje = usuariosBL.loginValidar(usuarios); + Mensaje mensaje = usuariosBL.loginValidar(usuarios); + boolean login=true; + switch (mensaje) { + case SIN_ERROR: + usuarios = new Usuarios(); + return null; + case ELEMENTO_DUPLICADO: + if(login){ httpSession.setAttribute("sesionActiva","true"); return "ProductoLista.xhtml"; }else{ return "index.xhtml"; } + + default: + return null; + + } + + } diff --git a/Inventario-war/src/java/mx/edu/tjs/chapala/sistemas/vista/DemoBeanUsuarios.java b/Inventario-war/src/java/mx/edu/tjs/chapala/sistemas/vista/DemoBeanUsuarios.java index 59cb326..fd82503 100644 --- a/Inventario-war/src/java/mx/edu/tjs/chapala/sistemas/vista/DemoBeanUsuarios.java +++ b/Inventario-war/src/java/mx/edu/tjs/chapala/sistemas/vista/DemoBeanUsuarios.java @@ -12,6 +12,10 @@ import java.util.Locale; import javax.ejb.EJB; import mx.edu.tjs.chapala.sistemas.bl.UsuariosBLLocal; import mx.edu.tjs.chapala.sistemas.modelo.Usuarios; +import mx.edu.tjs.chapala.sistemas.msg.Mensaje; +import static mx.edu.tjs.chapala.sistemas.msg.Mensaje.ELEMENTO_DUPLICADO; +import static mx.edu.tjs.chapala.sistemas.msg.Mensaje.SIN_ERROR; +import org.primefaces.PrimeFaces; import org.primefaces.util.LangUtils; /** @@ -40,15 +44,39 @@ public class DemoBeanUsuarios implements Serializable { } public String agregar() { - usuarios.setStatus(1); - usuariosBL.agregar(usuarios); - usuarios= new Usuarios(); - return "usuariosLista.xhtml"; + Mensaje mensaje =usuariosBL.agregar(usuarios); + switch(mensaje){ + case SIN_ERROR: + usuarios.setStatus(1); + usuarios = new Usuarios(); + PrimeFaces.current().executeScript("PF('dlg'.hide()"); + PrimeFaces.current().ajax().update("formtabla:growl"); + return "usuariosLista.xhtml"; + case ELEMENTO_DUPLICADO: + return null; + + default: + return null; + + } } public String editar() { - usuariosBL.editar(usuarios); + Mensaje mensaje =usuariosBL.editar(usuarios); + switch(mensaje){ + case SIN_ERROR: + usuarios =new Usuarios(); + PrimeFaces.current().executeScript("PF('dlg'.hide()"); + PrimeFaces.current().ajax().update("formtabla:growl"); return "usuariosLista.xhtml"; + case ELEMENTO_DUPLICADO: + return null; + + default: + return null; + } + + } public String eliminar() { @@ -104,7 +132,7 @@ public class DemoBeanUsuarios implements Serializable { } public void prepararEditar(Usuarios usuarios){ nuevo =false; - titulo="editando Usuario"; + titulo="Editando Usuario"; this.usuarios=usuarios; } @@ -135,7 +163,14 @@ public class DemoBeanUsuarios implements Serializable { Usuarios customer = (Usuarios) value; return customer.getUsuario().toLowerCase().contains(filterText) - || customer.getUsuario().toLowerCase().contains(filterText); + || customer.getNombre().toLowerCase().contains(filterText) + || customer.getApellidop().toLowerCase().contains(filterText) + || customer.getApellidom().toLowerCase().contains(filterText) + || customer.getCp().toLowerCase().contains(filterText) + || customer.getEstado().toLowerCase().contains(filterText) + || customer.getLocalidad().toLowerCase().contains(filterText) + || customer.getMunicipio().toLowerCase().contains(filterText) + || customer.getPais().toLowerCase().contains(filterText); } diff --git a/Inventario-war/web/index.xhtml b/Inventario-war/web/index.xhtml index 42a3a67..a4b5299 100644 --- a/Inventario-war/web/index.xhtml +++ b/Inventario-war/web/index.xhtml @@ -1,23 +1,38 @@ + xmlns:h="http://xmlns.jcp.org/jsf/html" + xmlns:p="http://primefaces.org/ui"> Inventario - - -

login

- - - + +
+
+ +
+ + +
+ + + + + + + + + + + + + +
+
- +
+
- - - - -
+ diff --git a/Inventario-war/web/resources/css/cssLayout.css b/Inventario-war/web/resources/css/cssLayout.css index faa2b12..27cd8f1 100644 --- a/Inventario-war/web/resources/css/cssLayout.css +++ b/Inventario-war/web/resources/css/cssLayout.css @@ -102,7 +102,7 @@ align-items: center; color:black; width: 160px; - height: 98px; + height: 88px; margin-right: 2px; margin-right: -1px; } diff --git a/Inventario-war/web/resources/imagen/usuario.png b/Inventario-war/web/resources/imagen/usuario.png new file mode 100644 index 0000000..a71801a Binary files /dev/null and b/Inventario-war/web/resources/imagen/usuario.png differ diff --git a/Inventario-war/web/rolLista.xhtml b/Inventario-war/web/rolLista.xhtml new file mode 100644 index 0000000..e5bccb2 --- /dev/null +++ b/Inventario-war/web/rolLista.xhtml @@ -0,0 +1,149 @@ + + + + + + + + + +

R O L

+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + +

+

+ + + + + + + + + + + + + + + +
+
+ + + + + +

+

+
+ + + + + + +
+
+ + + +
+
+ + +
+
+ +
+ +
+ + + diff --git a/Inventario-war/web/usuariosLista.xhtml b/Inventario-war/web/usuariosLista.xhtml index 08af381..d6320f5 100644 --- a/Inventario-war/web/usuariosLista.xhtml +++ b/Inventario-war/web/usuariosLista.xhtml @@ -11,37 +11,43 @@ -

U S U A R I O S

+ + + +

U S U A R I O S

- + - + +         - + - - - + +
- + - + - + - + + + + + + + + + + + + + + + + + + - - + - + + + + + + + - + - + - + - - + + + + + + - + + + + + + + +

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +

+

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + + + +

+

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+
+