| 1 | package control; | |
| 2 | ||
| 3 | import model.CarrelloModel; | |
| 4 | import model.maglietta.MagliettaBean; | |
| 5 | import model.maglietta.MagliettaDAO; | |
| 6 | ||
| 7 | import javax.servlet.ServletException; | |
| 8 | import javax.servlet.annotation.WebServlet; | |
| 9 | import javax.servlet.http.HttpServlet; | |
| 10 | import javax.servlet.http.HttpServletRequest; | |
| 11 | import javax.servlet.http.HttpServletResponse; | |
| 12 | import javax.servlet.http.HttpSession; | |
| 13 | import java.io.IOException; | |
| 14 | import java.sql.SQLException; | |
| 15 | ||
| 16 | @WebServlet("/SaveCustom") | |
| 17 | public class SaveCustom extends HttpServlet { | |
| 18 | @Override | |
| 19 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) | |
| 20 | throws ServletException, IOException { | |
| 21 | ||
| 22 | final String PATH = req.getServletContext().getRealPath("/images/grafiche/"); | |
| 23 | final String ERROR_PAGE = "/pages/errorpage.jsp"; | |
| 24 | String imgData = req.getParameter("imgData"); | |
| 25 | ||
| 26 |
2
1. doPost : negated conditional → KILLED 2. doPost : negated conditional → KILLED |
if (imgData == null || imgData.isEmpty()) { |
| 27 |
1
1. doPost : removed call to javax/servlet/RequestDispatcher::forward → KILLED |
req.getRequestDispatcher(ERROR_PAGE).forward(req, resp); |
| 28 | return; | |
| 29 | } | |
| 30 | ||
| 31 | MagliettaDAO magliettaDAO = new MagliettaDAO(); | |
| 32 | ||
| 33 | try { | |
| 34 |
1
1. doPost : Replaced integer addition with subtraction → KILLED |
String base64Data = imgData.substring(imgData.indexOf(",") + 1); |
| 35 | byte[] imageBytes = java.util.Base64.getDecoder().decode(base64Data); | |
| 36 | ||
| 37 | String nomeFile = magliettaDAO.getMaxID() + "PersonalizzataCustom.png"; | |
| 38 | String relativePath = "images/grafiche/" + nomeFile; | |
| 39 | String filePath = PATH + nomeFile; | |
| 40 | ||
| 41 | java.nio.file.Files.write( | |
| 42 | java.nio.file.Paths.get(filePath), | |
| 43 | imageBytes | |
| 44 | ); | |
| 45 | ||
| 46 | MagliettaBean maglietta = new MagliettaBean(); | |
| 47 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setNome → KILLED |
maglietta.setNome("Custom"); |
| 48 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setColore → KILLED |
maglietta.setColore(req.getParameter("colore")); |
| 49 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setTipo → KILLED |
maglietta.setTipo("Personalizzata"); |
| 50 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setPrezzo → KILLED |
maglietta.setPrezzo(20); |
| 51 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setIVA → KILLED |
maglietta.setIVA(3); |
| 52 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setDescrizione → KILLED |
maglietta.setDescrizione("Maglietta custom"); |
| 53 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setGrafica → KILLED |
maglietta.setGrafica(relativePath); |
| 54 | ||
| 55 |
1
1. doPost : removed call to model/maglietta/MagliettaDAO::doSave → KILLED |
magliettaDAO.doSave(maglietta); |
| 56 | ||
| 57 | HttpSession session = req.getSession(); | |
| 58 | CarrelloModel carrello; | |
| 59 | ||
| 60 | synchronized (session) { | |
| 61 | carrello = (CarrelloModel) session.getAttribute("carrello"); | |
| 62 |
1
1. doPost : negated conditional → KILLED |
if (carrello == null) { |
| 63 | carrello = new CarrelloModel(); | |
| 64 |
1
1. doPost : removed call to javax/servlet/http/HttpSession::setAttribute → KILLED |
session.setAttribute("carrello", carrello); |
| 65 | } | |
| 66 | } | |
| 67 | ||
| 68 |
1
1. doPost : Replaced integer subtraction with addition → KILLED |
int idMaglietta = magliettaDAO.getMaxID() - 1; |
| 69 | String taglia = req.getParameter("taglia"); | |
| 70 | ||
| 71 |
1
1. doPost : removed call to model/CarrelloModel::aggiungi → KILLED |
carrello.aggiungi(idMaglietta, taglia); |
| 72 |
1
1. doPost : removed call to javax/servlet/http/HttpServletResponse::sendRedirect → KILLED |
resp.sendRedirect("pages/carrello.jsp"); |
| 73 | ||
| 74 | } catch (SQLException | IOException e) { | |
| 75 |
1
1. doPost : removed call to javax/servlet/RequestDispatcher::forward → KILLED |
req.getRequestDispatcher(ERROR_PAGE).forward(req, resp); |
| 76 | } | |
| 77 | } | |
| 78 | ||
| 79 | @Override | |
| 80 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) | |
| 81 | throws ServletException, IOException { | |
| 82 |
1
1. doGet : removed call to control/SaveCustom::doPost → KILLED |
doPost(req, resp); |
| 83 | } | |
| 84 | } | |
Mutations | ||
| 26 |
1.1 2.2 |
|
| 27 |
1.1 |
|
| 34 |
1.1 |
|
| 47 |
1.1 |
|
| 48 |
1.1 |
|
| 49 |
1.1 |
|
| 50 |
1.1 |
|
| 51 |
1.1 |
|
| 52 |
1.1 |
|
| 53 |
1.1 |
|
| 55 |
1.1 |
|
| 62 |
1.1 |
|
| 64 |
1.1 |
|
| 68 |
1.1 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |
|
| 75 |
1.1 |
|
| 82 |
1.1 |