| 1 | package com.popx.presentazione; | |
| 2 | ||
| 3 | import com.popx.modello.ProdottoBean; | |
| 4 | import com.popx.persistenza.ProdottoDAO; | |
| 5 | import com.popx.persistenza.ProdottoDAOImpl; | |
| 6 | ||
| 7 | import javax.servlet.ServletException; | |
| 8 | import javax.servlet.annotation.WebServlet; | |
| 9 | import javax.servlet.http.*; | |
| 10 | import java.io.IOException; | |
| 11 | import java.sql.SQLException; | |
| 12 | import java.util.List; | |
| 13 | ||
| 14 | @WebServlet("/RemoveFromCartServlet") | |
| 15 | public class RemoveFromCartServlet extends HttpServlet { | |
| 16 | ||
| 17 | private final ProdottoDAO prodottoDAO; | |
| 18 | ||
| 19 | // costruttore production | |
| 20 | public RemoveFromCartServlet() { | |
| 21 | this.prodottoDAO = new ProdottoDAOImpl(); | |
| 22 | } | |
| 23 | ||
| 24 | // costruttore test | |
| 25 | public RemoveFromCartServlet(ProdottoDAO prodottoDAO) { | |
| 26 | this.prodottoDAO = prodottoDAO; | |
| 27 | } | |
| 28 | ||
| 29 | @Override | |
| 30 | public void doPost(HttpServletRequest request, HttpServletResponse response) | |
| 31 | throws ServletException, IOException { | |
| 32 | ||
| 33 | String productId = request.getParameter("productId"); | |
| 34 | ||
| 35 | HttpSession session = request.getSession(); | |
| 36 | List<ProdottoBean> cart = (List<ProdottoBean>) session.getAttribute("cart"); | |
| 37 | String userEmail = (String) session.getAttribute("userEmail"); | |
| 38 | ||
| 39 | try { | |
| 40 |
3
1. doPost : negated conditional → KILLED 2. doPost : negated conditional → KILLED 3. doPost : negated conditional → KILLED |
if (productId != null && !productId.isEmpty() && cart != null) { |
| 41 | ||
| 42 |
2
1. lambda$doPost$0 : replaced boolean return with false for com/popx/presentazione/RemoveFromCartServlet::lambda$doPost$0 → KILLED 2. lambda$doPost$0 : replaced boolean return with true for com/popx/presentazione/RemoveFromCartServlet::lambda$doPost$0 → KILLED |
cart.removeIf(product -> product.getId().equals(productId)); |
| 43 |
1
1. doPost : removed call to javax/servlet/http/HttpSession::setAttribute → SURVIVED |
session.setAttribute("cart", cart); |
| 44 | ||
| 45 |
1
1. doPost : negated conditional → KILLED |
if (userEmail != null) { |
| 46 |
1
1. doPost : removed call to com/popx/persistenza/ProdottoDAO::removeProductFromCart → KILLED |
prodottoDAO.removeProductFromCart(userEmail, productId); |
| 47 | } | |
| 48 | ||
| 49 |
1
1. doPost : removed call to javax/servlet/http/HttpServletResponse::setContentType → SURVIVED |
response.setContentType("application/json"); |
| 50 |
1
1. doPost : removed call to java/io/PrintWriter::write → KILLED |
response.getWriter().write("{\"success\": true}"); |
| 51 | ||
| 52 | } else { | |
| 53 |
1
1. doPost : removed call to javax/servlet/http/HttpServletResponse::setContentType → SURVIVED |
response.setContentType("application/json"); |
| 54 |
1
1. doPost : removed call to java/io/PrintWriter::write → KILLED |
response.getWriter().write( |
| 55 | "{\"success\": false, \"message\": \"Invalid product ID.\"}" | |
| 56 | ); | |
| 57 | } | |
| 58 | ||
| 59 | } catch (SQLException e) { | |
| 60 |
1
1. doPost : removed call to javax/servlet/http/HttpServletResponse::setStatus → KILLED |
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); |
| 61 |
1
1. doPost : removed call to java/io/PrintWriter::write → KILLED |
response.getWriter().write( |
| 62 | "{\"success\": false, \"message\": \"Errore nella rimozione del prodotto.\"}" | |
| 63 | ); | |
| 64 | } | |
| 65 | } | |
| 66 | } | |
Mutations | ||
| 40 |
1.1 2.2 3.3 |
|
| 42 |
1.1 2.2 |
|
| 43 |
1.1 |
|
| 45 |
1.1 |
|
| 46 |
1.1 |
|
| 49 |
1.1 |
|
| 50 |
1.1 |
|
| 53 |
1.1 |
|
| 54 |
1.1 |
|
| 60 |
1.1 |
|
| 61 |
1.1 |