| 1 | package control.maglietta; | |
| 2 | ||
| 3 | import model.maglietta.MagliettaBean; | |
| 4 | import model.maglietta.MagliettaDAO; | |
| 5 | import model.misura.MisuraBean; | |
| 6 | import model.misura.MisuraDAO; | |
| 7 | ||
| 8 | import javax.servlet.ServletException; | |
| 9 | import javax.servlet.annotation.MultipartConfig; | |
| 10 | import javax.servlet.annotation.WebServlet; | |
| 11 | import javax.servlet.http.HttpServlet; | |
| 12 | import javax.servlet.http.HttpServletRequest; | |
| 13 | import javax.servlet.http.HttpServletResponse; | |
| 14 | import javax.servlet.http.Part; | |
| 15 | ||
| 16 | import java.io.IOException; | |
| 17 | import java.io.InputStream; | |
| 18 | import java.nio.file.Files; | |
| 19 | import java.nio.file.Path; | |
| 20 | import java.nio.file.Paths; | |
| 21 | import java.sql.SQLException; | |
| 22 | import java.util.stream.Stream; | |
| 23 | ||
| 24 | @WebServlet("/UpdateMaglietta") | |
| 25 | @MultipartConfig | |
| 26 | public class UpdateMaglietta extends HttpServlet { | |
| 27 | @Override | |
| 28 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) | |
| 29 | throws ServletException, IOException { | |
| 30 | final String ERROR_PAGE = "/pages/errorpage.jsp"; | |
| 31 | final String PATH = req.getServletContext().getRealPath("/images/grafiche/"); | |
| 32 | Path uploadDir = Paths.get(PATH).toAbsolutePath().normalize(); | |
| 33 | ||
| 34 | int id; | |
| 35 | int iva; | |
| 36 | int quantita; | |
| 37 | float prezzo; | |
| 38 | ||
| 39 | try { | |
| 40 | id = Integer.parseInt(req.getParameter("id")); | |
| 41 | prezzo = Float.parseFloat(req.getParameter("prezzo")); | |
| 42 | iva = (int) Float.parseFloat(req.getParameter("IVA")); | |
| 43 | quantita = Integer.parseInt(req.getParameter("quantita")); | |
| 44 | } catch (NumberFormatException | NullPointerException e) { | |
| 45 |
1
1. doPost : removed call to javax/servlet/RequestDispatcher::forward → KILLED |
req.getRequestDispatcher(ERROR_PAGE).forward(req, resp); |
| 46 | return; | |
| 47 | } | |
| 48 | ||
| 49 | String nome = req.getParameter("nome"); | |
| 50 | String descrizione = req.getParameter("descrizione"); | |
| 51 | String taglia = req.getParameter("taglia"); | |
| 52 | ||
| 53 | String colore = req.getParameter("colore"); | |
| 54 |
1
1. doPost : negated conditional → KILLED |
colore = (colore != null) ? colore : req.getParameter("coloreVecchio"); |
| 55 | ||
| 56 | String tipo = req.getParameter("tipo"); | |
| 57 |
1
1. doPost : negated conditional → KILLED |
tipo = (tipo != null) ? tipo : req.getParameter("tipoVecchio"); |
| 58 | ||
| 59 | String pathGrafica = req.getParameter("path"); | |
| 60 | ||
| 61 | Part grafica; | |
| 62 | try { | |
| 63 | grafica = req.getPart("grafica"); | |
| 64 |
2
1. doPost : negated conditional → KILLED 2. doPost : negated conditional → KILLED |
if (grafica != null && grafica.getSubmittedFileName().isEmpty()) { |
| 65 | grafica = null; | |
| 66 | } | |
| 67 | } catch (IOException | ServletException e) { | |
| 68 |
1
1. doPost : removed call to javax/servlet/RequestDispatcher::forward → KILLED |
req.getRequestDispatcher(ERROR_PAGE).forward(req, resp); |
| 69 | return; | |
| 70 | } | |
| 71 | ||
| 72 | ||
| 73 |
1
1. doPost : negated conditional → KILLED |
if (grafica != null) { |
| 74 | try { | |
| 75 | pathGrafica = gestisciUploadGrafica(grafica, id, tipo, uploadDir, req, resp); | |
| 76 | } catch (ServletException | IOException e) { | |
| 77 |
1
1. doPost : removed call to javax/servlet/RequestDispatcher::forward → NO_COVERAGE |
req.getRequestDispatcher(ERROR_PAGE).forward(req, resp); |
| 78 | return; | |
| 79 | } | |
| 80 |
1
1. doPost : negated conditional → KILLED |
if (pathGrafica == null) return; |
| 81 | } | |
| 82 | ||
| 83 | MagliettaBean maglietta = new MagliettaBean(); | |
| 84 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setID → KILLED |
maglietta.setID(id); |
| 85 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setNome → KILLED |
maglietta.setNome(nome); |
| 86 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setPrezzo → KILLED |
maglietta.setPrezzo(prezzo); |
| 87 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setIVA → KILLED |
maglietta.setIVA(iva); |
| 88 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setColore → KILLED |
maglietta.setColore(colore); |
| 89 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setTipo → KILLED |
maglietta.setTipo(tipo); |
| 90 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setDescrizione → KILLED |
maglietta.setDescrizione(descrizione); |
| 91 |
1
1. doPost : removed call to model/maglietta/MagliettaBean::setGrafica → KILLED |
maglietta.setGrafica(pathGrafica); |
| 92 | ||
| 93 | MisuraBean misuraBean = new MisuraBean(id, quantita, taglia); | |
| 94 | ||
| 95 | try { | |
| 96 |
1
1. doPost : removed call to model/maglietta/MagliettaDAO::doUpdate → KILLED |
new MagliettaDAO().doUpdate(maglietta); |
| 97 |
1
1. doPost : removed call to model/misura/MisuraDAO::doUpdate → KILLED |
new MisuraDAO().doUpdate(misuraBean); |
| 98 | } catch (SQLException e) { | |
| 99 |
1
1. doPost : removed call to javax/servlet/RequestDispatcher::forward → KILLED |
req.getRequestDispatcher(ERROR_PAGE).forward(req, resp); |
| 100 | return; | |
| 101 | } | |
| 102 | ||
| 103 |
1
1. doPost : removed call to javax/servlet/http/HttpServletResponse::sendRedirect → KILLED |
resp.sendRedirect("Catalogo"); |
| 104 | } | |
| 105 | ||
| 106 | private String gestisciUploadGrafica( | |
| 107 | Part grafica, | |
| 108 | int id, | |
| 109 | String tipo, | |
| 110 | Path uploadDir, | |
| 111 | HttpServletRequest req, | |
| 112 | HttpServletResponse resp) | |
| 113 | throws ServletException, IOException { | |
| 114 | ||
| 115 | final String ERROR_PAGE = "/pages/errorpage.jsp"; | |
| 116 | ||
| 117 | int extensionIndex = grafica.getSubmittedFileName().lastIndexOf("."); | |
| 118 | String estensione = grafica.getSubmittedFileName().substring(extensionIndex); | |
| 119 | String nomeFile = (id + tipo + estensione) | |
| 120 | .replaceAll("[^a-zA-Z0-9._-]", "_"); | |
| 121 | ||
| 122 | String pathGrafica = "images/grafiche/" + nomeFile; | |
| 123 | ||
| 124 | try (Stream<Path> files = Files.list(uploadDir)) { | |
| 125 |
2
1. lambda$gestisciUploadGrafica$0 : replaced boolean return with false for control/maglietta/UpdateMaglietta::lambda$gestisciUploadGrafica$0 → KILLED 2. lambda$gestisciUploadGrafica$0 : replaced boolean return with true for control/maglietta/UpdateMaglietta::lambda$gestisciUploadGrafica$0 → KILLED |
files.filter(p -> p.normalize().startsWith(uploadDir)) |
| 126 |
2
1. lambda$gestisciUploadGrafica$1 : replaced boolean return with true for control/maglietta/UpdateMaglietta::lambda$gestisciUploadGrafica$1 → KILLED 2. lambda$gestisciUploadGrafica$1 : replaced boolean return with false for control/maglietta/UpdateMaglietta::lambda$gestisciUploadGrafica$1 → KILLED |
.filter(p -> p.getFileName().toString().startsWith(id + tipo)) |
| 127 |
1
1. gestisciUploadGrafica : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach(p -> { |
| 128 | try { Files.deleteIfExists(p); } catch (IOException ignored) {/* Ignored*/ } | |
| 129 | }); | |
| 130 | } catch (IOException e) { | |
| 131 |
1
1. gestisciUploadGrafica : removed call to javax/servlet/RequestDispatcher::forward → KILLED |
req.getRequestDispatcher(ERROR_PAGE).forward(req, resp); |
| 132 |
1
1. gestisciUploadGrafica : replaced return value with "" for control/maglietta/UpdateMaglietta::gestisciUploadGrafica → KILLED |
return null; |
| 133 | } | |
| 134 | ||
| 135 | Path destinationFile = uploadDir.resolve(nomeFile).normalize(); | |
| 136 |
1
1. gestisciUploadGrafica : negated conditional → KILLED |
if (!destinationFile.startsWith(uploadDir)) { |
| 137 |
1
1. gestisciUploadGrafica : removed call to javax/servlet/RequestDispatcher::forward → KILLED |
req.getRequestDispatcher(ERROR_PAGE).forward(req, resp); |
| 138 |
1
1. gestisciUploadGrafica : replaced return value with "" for control/maglietta/UpdateMaglietta::gestisciUploadGrafica → KILLED |
return null; |
| 139 | } | |
| 140 | ||
| 141 | try (InputStream inputStream = grafica.getInputStream()) { | |
| 142 | Files.copy(inputStream, destinationFile); | |
| 143 | } catch (IOException e) { | |
| 144 |
1
1. gestisciUploadGrafica : removed call to javax/servlet/RequestDispatcher::forward → KILLED |
req.getRequestDispatcher(ERROR_PAGE).forward(req, resp); |
| 145 |
1
1. gestisciUploadGrafica : replaced return value with "" for control/maglietta/UpdateMaglietta::gestisciUploadGrafica → KILLED |
return null; |
| 146 | } | |
| 147 | ||
| 148 |
1
1. gestisciUploadGrafica : replaced return value with "" for control/maglietta/UpdateMaglietta::gestisciUploadGrafica → KILLED |
return pathGrafica; |
| 149 | } | |
| 150 | } | |
Mutations | ||
| 45 |
1.1 |
|
| 54 |
1.1 |
|
| 57 |
1.1 |
|
| 64 |
1.1 2.2 |
|
| 68 |
1.1 |
|
| 73 |
1.1 |
|
| 77 |
1.1 |
|
| 80 |
1.1 |
|
| 84 |
1.1 |
|
| 85 |
1.1 |
|
| 86 |
1.1 |
|
| 87 |
1.1 |
|
| 88 |
1.1 |
|
| 89 |
1.1 |
|
| 90 |
1.1 |
|
| 91 |
1.1 |
|
| 96 |
1.1 |
|
| 97 |
1.1 |
|
| 99 |
1.1 |
|
| 103 |
1.1 |
|
| 125 |
1.1 2.2 |
|
| 126 |
1.1 2.2 |
|
| 127 |
1.1 |
|
| 131 |
1.1 |
|
| 132 |
1.1 |
|
| 136 |
1.1 |
|
| 137 |
1.1 |
|
| 138 |
1.1 |
|
| 144 |
1.1 |
|
| 145 |
1.1 |
|
| 148 |
1.1 |