Browse Source

token de proveedor

master
nickdalyrendon 6 months ago
parent
commit
845a7a0cda
  1. 22
      Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/ProveedorBL.java
  2. 4
      Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/ProveedorBLLocal.java
  3. 15
      Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/dao/ProveedorDAO.java
  4. 88
      Inventario-war/src/java/mx/edu/tjs/chapala/sistemas/servicios/ProveedorEndpoint.java
  5. 158
      Inventario-war/src/java/mx/edu/tjs/servicios/ProveedorEndpointt.java
  6. 2
      Inventario-war/web/proveedorLista.xhtml

22
Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/ProveedorBL.java

@ -151,4 +151,26 @@ public class ProveedorBL implements ProveedorBLLocal {
return p.buscarStatus(true); return p.buscarStatus(true);
} }
public void agregarP (Proveedor proveedor){
ProveedorDAO proveedorDAO = new ProveedorDAO();
proveedorDAO.agregar(proveedor);
}
public void eliminarP (Proveedor proveedor){
ProveedorDAO a = new ProveedorDAO();
a.eliminar(proveedor);
}
public Proveedor buscarIdInt(int id) {
ProveedorDAO proveedorDAO = new ProveedorDAO();
if(proveedorDAO==null){
return null;
}else{
return proveedorDAO.buscarIdInt(id);
}
}
} }

4
Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/ProveedorBLLocal.java

@ -29,4 +29,8 @@ public interface ProveedorBLLocal {
Mensaje editar(Proveedor p); Mensaje editar(Proveedor p);
public Proveedor buscarIdInt (int id) ;
public void agregarP(Proveedor proveedor );
public void eliminarP(Proveedor proveedor);
} }

15
Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/dao/ProveedorDAO.java

@ -169,4 +169,19 @@ public class ProveedorDAO {
public Proveedor buscarIdInt(int id){
if (id == 0 ) {
return null;
}
Query q = em.createNamedQuery("Proveedor.findById");
q.setParameter("id", id);
if(q.getResultList().isEmpty()){
return null;
} else {
return (Proveedor) q.getResultList().get(0);
}
}
} }

88
Inventario-war/src/java/mx/edu/tjs/chapala/sistemas/servicios/ProveedorEndpoint.java

@ -0,0 +1,88 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template
*/
package mx.edu.tjs.chapala.sistemas.servicios;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author nickdalyrendon
*/
@WebServlet(name = "ProveedorEndpoint", urlPatterns = {"/ProveedorEndpoint"})
public class ProveedorEndpoint extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet ProveedorEndpoint</title>");
out.println("</head>");
out.println("<body>");
out.println("Parametro"+request.getParameter("test"));
out.println("<h1>Servlet ProveedorEndpoint at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}

158
Inventario-war/src/java/mx/edu/tjs/servicios/ProveedorEndpointt.java

@ -0,0 +1,158 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template
*/
package mx.edu.tjs.servicios;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import mx.edu.tjs.chapala.sistemas.bl.ProveedorBLLocal;
import mx.edu.tjs.chapala.sistemas.modelo.Proveedor;
/**
*
* @author nickdalyrendon
*/
@WebServlet(name = "ProveedorEndpointt", urlPatterns = {"/ProveedorEndpointt"})
public class ProveedorEndpointt extends HttpServlet {
@EJB
private ProveedorBLLocal proveedorBL;
Proveedor m;
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
String opcion = request.getParameter("opcion");
// Verificar el token
String token = request.getParameter("t");
if (!"tokenNickdaly160601".equals(token)) {
out.print("Acceso Denegado");
return;
}
switch (opcion) {
case "1":
m = proveedorBL.buscarIdInt(Integer.parseInt(request.getParameter("id")));
if (m.getStatus() == 0) {
out.print("No existe el proveedor");
} else {
out.print("<div style='font-family: Arial, sans-serif; padding: 20px;'>");
out.print("<h1 style='color: blue;'>Proveedor encontrado</h1>");
out.print("<h2 style='color: green;'>Nombre: " + m.getNombre() + "</h2>");
out.print("</div>");
}
break;
case "2":
m = proveedorBL.buscarIdInt(Integer.parseInt(request.getParameter("id")));
if (m.getStatus() == 0) {
out.print("No existe ese elemento");
} else {
proveedorBL.eliminarP(m);
out.print("Se elimino el proveedor");
}
break;
case "3":
Proveedor nuevo = new Proveedor();
nuevo.setStatus((short) 1);
nuevo.setNombre(request.getParameter("nombre"));
proveedorBL.agregarP(nuevo);
out.print("Se agrego el proveedor");
break;
case "4":
try {
int id = Integer.parseInt(request.getParameter("id"));
Proveedor proveedorExistente = proveedorBL.buscarIdInt(id);
if (proveedorExistente == null || proveedorExistente.getStatus() == 0) {
out.print("No existe el proveedor");
} else {
String nuevoNombre = request.getParameter("nombre");
// Actualizar los campos necesarios
if (nuevoNombre != null && !nuevoNombre.isEmpty()) {
proveedorExistente.setNombre(nuevoNombre);
}
proveedorBL.editar(proveedorExistente);
out.print("Editado con éxito");
}
} catch (NumberFormatException e) {
out.print("ID de proveedor no válido");
} catch (Exception e) {
out.print("Ocurrió un error al editar el proveedor");
}
break;
default:
out.print("<h1> No existe esa opcion </h1>");
break;
}
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}

2
Inventario-war/web/proveedorLista.xhtml

@ -281,6 +281,8 @@
</h:panelGrid> </h:panelGrid>
<p:commandButton action="proveedorLista.xhtml" icon="pi pi-arrow-left" ajax="false" style="right:-600px" />
</div> </div>
<!-- comment <!-- comment

Loading…
Cancel
Save