| 1 | package com.popx.presentazione; | |
| 2 | ||
| 3 | import com.popx.persistenza.ProdottoDAO; | |
| 4 | import com.popx.persistenza.ProdottoDAOImpl; | |
| 5 | ||
| 6 | import javax.servlet.ServletException; | |
| 7 | import javax.servlet.annotation.WebServlet; | |
| 8 | import javax.servlet.http.*; | |
| 9 | import java.io.IOException; | |
| 10 | ||
| 11 | @WebServlet("/UpdateCartServlet") | |
| 12 | public class UpdateCartServlet extends HttpServlet { | |
| 13 | ||
| 14 | private final ProdottoDAO prodottoDAO; | |
| 15 | ||
| 16 | // costruttore production | |
| 17 | public UpdateCartServlet() { | |
| 18 | this.prodottoDAO = new ProdottoDAOImpl(); | |
| 19 | } | |
| 20 | ||
| 21 | // costruttore test | |
| 22 | public UpdateCartServlet(ProdottoDAO prodottoDAO) { | |
| 23 | this.prodottoDAO = prodottoDAO; | |
| 24 | } | |
| 25 | ||
| 26 | @Override | |
| 27 | public void doPost(HttpServletRequest request, HttpServletResponse response) | |
| 28 | throws ServletException, IOException { | |
| 29 | ||
| 30 | String productId = request.getParameter("productId"); | |
| 31 | int qty; | |
| 32 | ||
| 33 | try { | |
| 34 | qty = Integer.parseInt(request.getParameter("qty")); | |
| 35 | } catch (NumberFormatException e) { | |
| 36 | qty = 1; | |
| 37 | } | |
| 38 | ||
| 39 | HttpSession session = request.getSession(); | |
| 40 | String userEmail = (String) session.getAttribute("userEmail"); | |
| 41 | ||
| 42 | try { | |
| 43 |
1
1. doPost : removed call to com/popx/persistenza/ProdottoDAO::updateProductQtyInCart → KILLED |
prodottoDAO.updateProductQtyInCart(session, productId, qty); |
| 44 | ||
| 45 |
1
1. doPost : negated conditional → KILLED |
if (userEmail != null) { |
| 46 |
1
1. doPost : removed call to com/popx/persistenza/ProdottoDAO::updateCartProductQuantityInDatabase → KILLED |
prodottoDAO.updateCartProductQuantityInDatabase(userEmail, productId, qty); |
| 47 | } | |
| 48 | ||
| 49 |
1
1. doPost : removed call to javax/servlet/http/HttpServletResponse::setStatus → SURVIVED |
response.setStatus(HttpServletResponse.SC_OK); |
| 50 |
1
1. doPost : removed call to java/io/PrintWriter::write → KILLED |
response.getWriter().write("{\"success\": true}"); |
| 51 | ||
| 52 | } catch (Exception e) { | |
| 53 |
1
1. doPost : removed call to javax/servlet/http/HttpServletResponse::setStatus → KILLED |
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); |
| 54 |
1
1. doPost : removed call to java/io/PrintWriter::write → KILLED |
response.getWriter().write( |
| 55 | "{\"success\": false, \"message\": \"Errore nell'aggiornamento del carrello.\"}" | |
| 56 | ); | |
| 57 | } | |
| 58 | } | |
| 59 | } | |
Mutations | ||
| 43 |
1.1 |
|
| 45 |
1.1 |
|
| 46 |
1.1 |
|
| 49 |
1.1 |
|
| 50 |
1.1 |
|
| 53 |
1.1 |
|
| 54 |
1.1 |