Browse Source

token

master
nayelivilchismariscal 6 months ago
parent
commit
00f77c4446
  1. 19
      Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/CategoriaBL.java
  2. 4
      Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/CategoriaBLLocal.java
  3. 13
      Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/dao/CategoriaDAO.java
  4. 158
      Inventario-war/src/java/mx/edu/tjs/servicios/CategoriaEndpoint.java
  5. 4
      Inventario-war/web/resources/css/cssLayout.css
  6. 2
      nbproject/project.properties

19
Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/bl/CategoriaBL.java

@ -56,6 +56,12 @@ public class CategoriaBL implements CategoriaBLLocal {
return m; return m;
} }
public void agregarC (Categoria categoria){
CategoriaDAO categoriaDAO = new CategoriaDAO();
categoriaDAO.agregar(categoria);
}
// Add business logic below. (Right-click in editor and choose // Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method") // "Insert Code > Add Business Method")
@ -124,6 +130,10 @@ public class CategoriaBL implements CategoriaBLLocal {
} }
return m; return m;
} }
public void eliminarC (Categoria categoria){
CategoriaDAO a = new CategoriaDAO();
a.eliminar(categoria);
}
@Override @Override
public Mensaje editar(Categoria categoria) { public Mensaje editar(Categoria categoria) {
@ -152,5 +162,14 @@ public class CategoriaBL implements CategoriaBLLocal {
return p.buscarStatus(true); return p.buscarStatus(true);
} }
public Categoria buscarIdInt(int id) {
CategoriaDAO categoriaDAO = new CategoriaDAO();
if(categoriaDAO==null){
return null;
}else{
return categoriaDAO.buscarIdInt(id);
}
}
} }

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

@ -28,4 +28,8 @@ public interface CategoriaBLLocal {
Mensaje eliminarId(Categoria categoria); Mensaje eliminarId(Categoria categoria);
Mensaje editar(Categoria p); Mensaje editar(Categoria p);
public Categoria buscarIdInt (int id) ;
public void agregarC(Categoria categoria);
public void eliminarC(Categoria categoria);
} }

13
Inventario-ejb/src/java/mx/edu/tjs/chapala/sistemas/dao/CategoriaDAO.java

@ -119,5 +119,18 @@ public class CategoriaDAO {
q.setParameter("status", s); q.setParameter("status", s);
return q.getResultList(); return q.getResultList();
} }
public Categoria buscarIdInt(int id){
if (id == 0 ) {
return null;
}
Query q = em.createNamedQuery("Categoria.findById");
q.setParameter("id", id);
if(q.getResultList().isEmpty()){
return null;
} else {
return (Categoria) q.getResultList().get(0);
}
}
} }

158
Inventario-war/src/java/mx/edu/tjs/servicios/CategoriaEndpoint.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.CategoriaBLLocal;
import mx.edu.tjs.chapala.sistemas.modelo.Categoria;
/**
*
* @author nayelivilchismariscal
*/
@WebServlet(name = "CategoriaEndpoint", urlPatterns = {"/CategoriaEndpoint"})
public class CategoriaEndpoint extends HttpServlet {
@EJB
private CategoriaBLLocal categoriaBL;
Categoria 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 (!"h978HIJG87FD5757huuyujJJKAYtyywedh".equals(token)) {
out.print("Acceso Denegado");
return;
}
switch(opcion){
case "1":
m = categoriaBL.buscarIdInt(Integer.parseInt(request.getParameter("id")));
if(m.getStatus() == 0){
out.print("No existe la categoria");
}else{
out.print("<div style='font-family: Arial, sans-serif; padding: 20px;'>");
out.print("<h1 style='color: purple;'>Categoria </h1>");
out.print("<h2 style='color: blue;'>Nombre: " + m.getNombre() + "</h2>");
out.print("</div>");
}
break;
case "2":
m = categoriaBL.buscarIdInt(Integer.parseInt(request.getParameter("id")));
if(m.getStatus() == 0){
out.print("No existe ese elemento");
}else{
categoriaBL.eliminarC(m);
out.print("Se elimino la categoria");
}
break;
case "3":
Categoria nuevo = new Categoria();
nuevo.setStatus((short) 1);
nuevo.setNombre(request.getParameter("nombre"));
categoriaBL.agregarC(nuevo);
out.print("Se agrego la categoria");
break;
case "4":
try {
int id = Integer.parseInt(request.getParameter("id"));
Categoria categoriaExistente = categoriaBL.buscarIdInt(id);
if (categoriaExistente == null || categoriaExistente.getStatus() == 0) {
out.print("No existe la categoria");
} else {
String nuevoNombre = request.getParameter("nombre");
// Actualizar los campos necesarios
if (nuevoNombre != null && !nuevoNombre.isEmpty()) {
categoriaExistente.setNombre(nuevoNombre);
}
// Aquí puedes agregar más campos si es necesario
// marcaExistente.setOtroCampo(request.getParameter("otroCampo"));
categoriaBL.editar(categoriaExistente);
out.print("Editado con éxito");
}
} catch (NumberFormatException e) {
out.print("ID de marca no válido");
} catch (Exception e) {
out.print("Ocurrió un error al editar la marca");
}
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>
}

4
Inventario-war/web/resources/css/cssLayout.css

@ -136,7 +136,9 @@ th.ui-state-default {
} }
.body1 {
background-image: url('https://img.freepik.com/vector-gratis/fondo-futurista-degradado-geometrico_23-2149116406.jpg?size=626&ext=jpg&ga=GA1.1.117944100.1709510400&semt=ais');
}

2
nbproject/project.properties

@ -13,7 +13,7 @@ j2ee.appclient.mainclass.args=${j2ee.appclient.tool.args}
j2ee.compile.on.save=true j2ee.compile.on.save=true
j2ee.deploy.on.save=true j2ee.deploy.on.save=true
j2ee.platform=1.7 j2ee.platform=1.7
j2ee.platform.classpath= j2ee.platform.classpath=${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar
j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar
j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar
j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar

Loading…
Cancel
Save