Merge origin/master

Conflicts:
	nbproject/project.properties
	src/java/bean/Pompier.java
	src/java/servlet/PompierServlet.java
	src/java/util/TrmtDate.java
	web/WEB-INF/jspf/formulairePompier.jspf
	web/WEB-INF/jspf/header.jspf
	web/WEB-INF/web.xml
This commit is contained in:
clementine.desrucques 2021-12-13 11:07:06 +01:00
commit 8c53a38e4b
14 changed files with 2048 additions and 2003 deletions

View File

@ -1,8 +1,8 @@
build.xml.data.CRC32=b54f128f
build.xml.script.CRC32=111e10f7
build.xml.stylesheet.CRC32=1707db4f@1.87.0.1
build.xml.stylesheet.CRC32=1707db4f@1.86.0.1
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=b54f128f
nbproject/build-impl.xml.script.CRC32=bc2b5756
nbproject/build-impl.xml.stylesheet.CRC32=334708a0@1.87.0.1
nbproject/build-impl.xml.stylesheet.CRC32=334708a0@1.86.0.1

View File

@ -5,8 +5,9 @@
*/
package bdd;
import bean.Dispo;
import bean.Gardes;
import bean.Pompier;
import util.TrmtDate;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -15,49 +16,46 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import util.TrmtDate;
/**
*
* @author clementine.desrucques
* @author funcha.ahamadi
*/
public class DispoMySql {
public class gardeMySQL {
private final Connection theConnection = Connexion.getConnect("localhost",
"sdis29",
"adminBDsdis",
"mdpBDsdis");
public ArrayList<Dispo> getLesDispo(Calendar[] lesDates, String[] lesPeriodes) {
ArrayList<Dispo> lesP = new ArrayList<>();
Dispo uneDispo;
public ArrayList<Gardes> getLesDisponibilite(Calendar[] lesDates, int[] lesPeriodes) {
ArrayList<Gardes> lesDispo = new ArrayList<>();
Gardes uneDispo;
/* a. Initialisation de la collection lesVentil pour la période,
création d'une ventil par salarié, par date et période
*/
int indiceDateFin = lesDates.length - 1;
Pompier leP;
PompierMySQL sm = new PompierMySQL();
ArrayList<Pompier> lesPom = sm.readAll();
for (Pompier unP : lesPom) {
Pompier lePompier;
PompierMySQL pm = new PompierMySQL();
ArrayList<Pompier> lesPompiers = pm.readLesPompiersCaserne(idCaserne);
for (Pompier unPompier : lesPompiers) {
for (Calendar uneDate : lesDates) {
for (String unePeriode : lesPeriodes) {
uneDispo = new Dispo(uneDate, unePeriode, unP);
lesP.add(uneDispo);
for (int unePeriode : lesPeriodes) {
uneDispo = new Gardes(uneDate, unePeriode, unPompier);
lesDispo.add(uneDispo);
}
}
}
/* b) Maj de la collection lesVentil
*/
readAll(lesPomp, lesDates[0], lesDates[indiceDateFin]);
//System.out.println("lesVentil : " + lesVentil);
return lesPomp;
readAll(lesDispo, lesDates[0], lesDates[indiceDateFin]);
//System.out.println("lesDispo : " + lesDispo);
return lesDispo;
}
public void readAll(ArrayList<Pompier> lesPomp, Calendar d1, Calendar d2) {
Pompier leP;
Dispo uneDispo;
Dispo laDispoTrouvee;
public void readAll(ArrayList<Gardes> lesDispo, Calendar d1, Calendar d2) {
Pompier lePompier;
Gardes uneDispo;
Gardes laDispoTrouvee;
String sql = "SELECT * FROM gardes "
+ "INNER JOIN pompier on idPompier = id "
+ "WHERE jourGarde BETWEEN ? and ?;";
@ -66,35 +64,25 @@ public class DispoMySql {
prepStmt.setDate(1, TrmtDate.getSQLDate(d1));
prepStmt.setDate(2, TrmtDate.getSQLDate(d2));
ResultSet resultat = prepStmt.executeQuery();
while (resultat.next()) {
leP = new Pompier(
while (resultat.next())
// public Pompier(Caserne laCaserne, int id, String nom, String prenom) {
lePompier = new Pompier(
resultat.getCaserne("laCaserne"),
resultat.getInt("id"),
resultat.getString("nom"),
resultat.getString("prenom"),
resultat.getParametre("leStatut"),
resultat.getParametre("leType"),
resultat.getString("mail"),
resultat.getString("login"),
resultat.getString("mdp"),
resultat.getString("adresse"),
resultat.getString("cp"),
resultat.getString("ville"),
resultat.getString("bip"),
resultat.getParametre("leGrade"),
resultat.getString("commentaire")
resultat.getString("prenom")
);
uneDispo = new Dispo(TrmtDate.getCalDate(resultat.getDate("jourVentil")),
resultat.getString("periode"),
leP);
// Recherche si unpompier existe dans les Pompier
uneDispo = new Gardes(TrmtDate.getCalDate(resultat.getDate("jourGarde")),
resultat.getInt("periode"),
lePompier);
// Recherche si uneDispo existe dans les Dispos
int indice = lesDispo.indexOf(uneDispo);
if (indice > -1) {
laDispoTrouvee = lesDispo.get(indice);
laDispoTrouvee.setActivite(resultat.getInt("dispo"));
laDispoTrouvee.setIsInBD(true);
laDispoTrouvee.setDisponibilite(resultat.getInt("disponibilite"));
laDispoTrouvee.setIsInBDD(true);
}
}
prepStmt.close();
resultat.close();
} catch (SQLException ex) {
@ -103,12 +91,12 @@ public class DispoMySql {
System.out.println("Code erreur : " + ex.getErrorCode());
}
}
/**
/**
* Suppression de la ventilation passé en param
* @param v : ventilation
* @return : nb lignes supprimées
*/
public int delete(Dispo p) {
public int delete(Gardes v) {
int nbMaj = -1;
String sql = "DELETE FROM gardes "
+ "WHERE idPompier = ? AND"
@ -116,9 +104,9 @@ public class DispoMySql {
+ "jourGarde = ?;";
try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql);
prepStmt.setInt(1, p.getPompier().getId());
prepStmt.setString(2, p.getPeriode());
prepStmt.setDate(3, TrmtDate.getSQLDate(p.getJourVentil()));
prepStmt.setInt(1, v.getPompier().getId());
prepStmt.setInt(2, v.getPeriode());
prepStmt.setDate(3, TrmtDate.getSQLDate(v.getJourGarde()));
nbMaj= prepStmt.executeUpdate();
} catch (SQLException ex) {
@ -131,24 +119,24 @@ public class DispoMySql {
}
public int update(Dispo v) {
public int update(Gardes v) {
int nbMAJ = -1;
String sql = "UPDATE gardes "
+ "SET ventil = ? "
+ "WHERE idPompier = ? "
+ "WHERE idPompier= ? "
+ "AND jourGarde = ? "
+ "AND periode = ?";
try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql);
prepStmt.setInt(1, v.getActivite());
prepStmt.setInt(1, v.getDisponibilite());
prepStmt.setInt(2, v.getPompier().getId());
prepStmt.setDate(3, TrmtDate.getSQLDate(v.getJourVentil()));
prepStmt.setString(4, v.getPeriode());
prepStmt.setDate(3, TrmtDate.getSQLDate(v.getJourGarde()));
prepStmt.setInt(4, v.getPeriode());
System.out.println("update : " + prepStmt);
nbMAJ = prepStmt.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(DispoMySql.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(gardeMySQL.class.getName()).log(Level.SEVERE, null, ex);
}
return nbMAJ;
}
@ -157,17 +145,17 @@ public class DispoMySql {
* @param v : ventil à créer
* @return : id du ventil
*/
public int create(Dispo v) {
public int create(Gardes v) {
int nbCre = -1;
String sql = "INSERT INTO gardes "
+ "(jourGarde, idPompier, periode, ventil)"
+ "(jourGarde, periode, idPompier, ventil)"
+ "VALUES (?, ?, ?, ?);";
try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql);
prepStmt.setDate(1, TrmtDate.getSQLDate(v.getJourVentil()));
prepStmt.setString(2, v.getPeriode());
prepStmt.setDate(1, TrmtDate.getSQLDate(v.getJourGarde()));
prepStmt.setInt(2, v.getPeriode());
prepStmt.setInt(3, v.getPompier().getId());
prepStmt.setInt(4, v.getActivite());
prepStmt.setInt(4, v.getDisponibilite());
int nbLigne= prepStmt.executeUpdate();
if (nbLigne > 0) {
ResultSet result = prepStmt.getGeneratedKeys();
@ -184,4 +172,12 @@ public class DispoMySql {
return nbCre;
}
}

View File

@ -1,123 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bean;
import java.util.Calendar;
import java.util.Objects;
/**
*
* @author clementine.desrucques
*/
public class Dispo {
Calendar JourVentil;
String periode;
Pompier pompier;
int activite;
boolean isInBD;
public Dispo(Calendar JourVentil, String periode, Pompier pompier, int activite, boolean isInBD) {
this.JourVentil = JourVentil;
this.periode = periode;
this.pompier = pompier;
this.activite = activite;
this.isInBD = isInBD;
}
public Dispo(Calendar JourVentil, String periode, Pompier pompier) {
this.JourVentil = JourVentil;
this.periode = periode;
this.pompier = pompier;
}
public Calendar getJourVentil() {
return JourVentil;
}
public void setJourVentil(Calendar JourVentil) {
this.JourVentil = JourVentil;
}
public String getPeriode() {
return periode;
}
public void setPeriode(String periode) {
this.periode = periode;
}
public Pompier getPompier() {
return pompier;
}
public void setPompier(Pompier pompier) {
this.pompier = pompier;
}
public int getActivite() {
return activite;
}
public void setActivite(int activite) {
this.activite = activite;
}
public boolean isIsInBD() {
return isInBD;
}
public void setIsInBD(boolean isInBD) {
this.isInBD = isInBD;
}
@Override
public int hashCode() {
int hash = 7;
hash = 79 * hash + Objects.hashCode(this.JourVentil);
hash = 79 * hash + Objects.hashCode(this.periode);
hash = 79 * hash + Objects.hashCode(this.pompier);
hash = 79 * hash + this.activite;
hash = 79 * hash + (this.isInBD ? 1 : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Dispo other = (Dispo) obj;
if (this.activite != other.activite) {
return false;
}
if (this.isInBD != other.isInBD) {
return false;
}
if (!Objects.equals(this.periode, other.periode)) {
return false;
}
if (!Objects.equals(this.JourVentil, other.JourVentil)) {
return false;
}
if (!Objects.equals(this.pompier, other.pompier)) {
return false;
}
return true;
}
@Override
public String toString() {
return "Dispo{" + "JourVentil=" + JourVentil + ", periode=" + periode + ", pompier=" + pompier + ", activite=" + activite + ", isInBD=" + isInBD + '}';
}
}

123
src/java/bean/Gardes.java Normal file
View File

@ -0,0 +1,123 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bean;
import java.util.Calendar;
import java.util.Objects;
/**
*
* @author funcha.ahamadi
*/
public class Gardes {
Calendar jourGarde;
int periode;
Pompier pompier;
int disponibilite;
boolean isInBDD;
public Gardes(Calendar jourGarde, int periode, Pompier pompier, int disponibilite, boolean isInBDD) {
this.jourGarde = jourGarde;
this.periode = periode;
this.pompier = pompier;
this.disponibilite = disponibilite;
this.isInBDD = isInBDD;
}
public Gardes(Calendar jourGarde, int periode, Pompier pompier) {
this.jourGarde = jourGarde;
this.periode = periode;
this.pompier = pompier;
}
public Calendar getJourGarde() {
return jourGarde;
}
public void setJourGarde(Calendar jourGarde) {
this.jourGarde = jourGarde;
}
public int getPeriode() {
return periode;
}
public void setPeriode(int periode) {
this.periode = periode;
}
public Pompier getPompier() {
return pompier;
}
public void setPompier(Pompier pompier) {
this.pompier = pompier;
}
public int getDisponibilite() {
return disponibilite;
}
public void setDisponibilite(int disponibilite) {
this.disponibilite = disponibilite;
}
public boolean isIsInBDD() {
return isInBDD;
}
public void setIsInBDD(boolean isInBDD) {
this.isInBDD = isInBDD;
}
@Override
public int hashCode() {
int hash = 7;
hash = 43 * hash + Objects.hashCode(this.jourGarde);
hash = 43 * hash + this.periode;
hash = 43 * hash + Objects.hashCode(this.pompier);
hash = 43 * hash + this.disponibilite;
hash = 43 * hash + (this.isInBDD ? 1 : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Gardes other = (Gardes) obj;
if (this.periode != other.periode) {
return false;
}
if (this.disponibilite != other.disponibilite) {
return false;
}
if (this.isInBDD != other.isInBDD) {
return false;
}
if (!Objects.equals(this.jourGarde, other.jourGarde)) {
return false;
}
if (!Objects.equals(this.pompier, other.pompier)) {
return false;
}
return true;
}
@Override
public String toString() {
return "Gardes{" + "jourGarde=" + jourGarde + ", periode=" + periode + ", pompier=" + pompier + ", disponibilite=" + disponibilite + ", isInBDD=" + isInBDD + '}';
}
}

View File

@ -5,8 +5,8 @@
*/
package form;
import bdd.DispoMySql;
import bean.Dispo;
import bdd.gardeMySQL;
import bean.Gardes;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import java.util.ArrayList;
@ -21,28 +21,28 @@ public class DispoForm {
public void verifDispo(HttpServletRequest request){
HttpSession maS = request.getSession();
ArrayList <Dispo> lesDispo = (ArrayList<Dispo>) maS.getAttribute("lesVentilInit");
ArrayList <Gardes> lesG = (ArrayList<Gardes>) maS.getAttribute("lesVentilInit");
DispoMySql vm = new DispoMySql();
gardeMySQL vm = new gardeMySQL();
Map<String, String[]> map = request.getParameterMap();
String[] lesNvVentil = map.get("lesAct");
int i = 0;
for(Dispo uneDispo : lesDispo){
int oldAct = uneDispo.getActivite();
for(Gardes uneGarde : lesG){
int oldAct = uneGarde.getDisponibilite();
int newAct = Integer.parseInt(lesNvVentil[i]);
if(oldAct != newAct){
if(uneDispo.isIsInBD()){
if(uneGarde.isIsInBDD()){
if(newAct == 0){
vm.delete(uneDispo);
uneDispo.setIsInBD(false);
vm.delete(uneGarde);
uneGarde.setIsInBDD(false);
} else {
uneDispo.setActivite(newAct);
vm.update(uneDispo);
uneGarde.setDisponibilite(newAct);
vm.update(uneGarde);
}
} else {
uneDispo.setActivite(newAct);
vm.create(uneDispo);
uneDispo.setIsInBD(true);
uneGarde.setDisponibilite(newAct);
vm.create(uneGarde);
uneGarde.setIsInBDD(true);
}
}
i++;

View File

@ -5,25 +5,26 @@
*/
package servlet;
import bdd.DispoMySql;
import bean.Dispo;
import bdd.gardeMySQL;
import bean.Gardes;
import bean.Pompier;
import form.DispoForm;
import jakarta.servlet.http.HttpServlet;
import util.TrmtDate;
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Calendar;
import util.TrmtDate;
/**
*
* @author clementine.desrucques
* @author funcha.ahamadi
*/
public class DispoServlet extends HttpServlet {
public class GardesServlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
@ -42,10 +43,10 @@ public class DispoServlet extends HttpServlet {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet DispoServlet</title>");
out.println("<title>Servlet feuilleGardes</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet DispoServlet at " + request.getContextPath() + "</h1>");
out.println("<h1>Servlet feuilleGardes at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
@ -63,40 +64,34 @@ public class DispoServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// processRequest(request, response);
HttpSession maSession = request.getSession();
if (maSession.getAttribute("lesVentilInit") == null) {
//processRequest(request, response);
HttpSession maSession = request.getSession();
ArrayList<Pompier> lesPompiers = (ArrayList<Pompier>) maSession.getAttribute("lesPompiers");
Calendar[] lesDates = new Calendar[7];
String[] lesDatesEnString = new String[7];
lesDates[0] = TrmtDate.getDateDebutSemaine();
lesDatesEnString[0] = TrmtDate.getDateAAfficher(lesDates[0]);
/* Initialisations des dates de la semaine */
Calendar[] lesDates = new Calendar[5];
String[] lesDatesEnString = new String[5];
lesDates[0] = TrmtDate.getDateDebutSemaine();
lesDatesEnString[0] = TrmtDate.getDateAAfficher(lesDates[0]);
for (int i = 1; i < lesDates.length; i++) {
lesDates[i] = TrmtDate.addDays(lesDates[0], i);
lesDatesEnString[i] = TrmtDate.getDateAAfficher(lesDates[i]);
}
maSession.setAttribute("lesDates", lesDates);
maSession.setAttribute("lesDatesEnString", lesDatesEnString);
//System.out.println("lesDates "+ lesDates[4].getTime());
/* Initialisation des périodes */
String[] lesPeriodes = {"AM", "PM"};
maSession.setAttribute("lesPeriodes", lesPeriodes);
/* Recherche des ventilations */
DispoMySql vm = new DispoMySql();
ArrayList<Dispo> lesVentilInit = vm.getLesDispo(lesDates, lesPeriodes);
for (int i = 1; i < lesDates.length; i++) {
lesDates[i] = TrmtDate.addDays(lesDates[0], i);
lesDatesEnString[i] = TrmtDate.getDateAAfficher(lesDates[i]);
}
maSession.setAttribute("lesDates", lesDates);
maSession.setAttribute("lesDatesEnString", lesDatesEnString);
/*Initialisation des periodes */
int[] lesPeriodes = {1,2,3,4};
maSession.setAttribute("lesPeriodes", lesPeriodes);
/* Recherche des ventilations */
gardeMySQL vm = new gardeMySQL();
ArrayList<Gardes> lesVentilInit = vm.getLesDisponibilite(lesDates, lesPeriodes);
//System.out.println("lesVentilInit : " + lesVentilInit);
maSession.setAttribute("lesVentilInit", lesVentilInit);
/* Initialisation des couleurs */
String[] lesCouleurs = {"blanc", "gris", "jaune"};
maSession.setAttribute("lesCouleurs", lesCouleurs);
}
/* Affichage de la page de ventilation */
getServletContext().getRequestDispatcher("/WEB-INF/gardeJSP.jsp").forward(request, response);
/* Affichage de la page de ventilation */
getServletContext().getRequestDispatcher("/WEB-INF/feuilleGardesJSP.jsp").forward(request, response);
}
/**

View File

@ -0,0 +1,54 @@
<%--
Document : feuilleGardes
Created on : 6 déc. 2021, 15:07:45
Author : funcha.ahamadi
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<legend>
Feuille de gardes
</legend>
<form action="gardes" method="POST">
<table class="table">
<thead>
<tr>
<th rowspan="2">N° de BIP</th>
<th rowspan="2">Nom Prenom</th>
<c:forEach items='${sessionScope.lesDatesEnString}' var="uneDate" varStatus="status">
<th colspan="2" class="text-center"> ${uneDate}</th>
</c:forEach>
</tr>
<tr>
<c:forEach var="i" begin="0" end="4" step="1">
<c:forEach items='${sessionScope.lesPeriodes}' var="unePeriode" varStatus="status">
<td class="text-center">${unePeriode}</td>
</c:forEach>
</c:forEach>
</tr>
</thead>
<tbody>
<c:set var="oldId" value="-1" scope="page"/>
<tr>
<c:forEach items='${sessionScope.lesVentilInit}' var="uneVentil" varStatus="status">
<c:set var="newId" value='${uneVentil.getPompier().getId()}' scope="page"/>
<c:if test='${oldId != newId}' var="test" scope="page">
</tr><tr>
<td>${uneVentil.getPompier().getId()}</td>
<td>${uneVentil.getPompier().getNom()} ${uneVentil.getPompier().getPrenom()}</td>
<c:set var="oldId" value='${newId}' scope="page"/>
</c:if>
<c:set var="activite" value='${uneVentil.getActivite()}' scope="page"/>
<td>
<input readonly type="text" value='${activite}' name="lesActivites"class="ztVentil ${sessionScope.lesCouleurs[activite]}"/>
</td>
</c:forEach>
</tr>
</tbody>
</table>
</form><!-- comment -->

View File

@ -17,8 +17,8 @@
<servlet-class>servlet.PompierServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>DispoServlet</servlet-name>
<servlet-class>servlet.DispoServlet</servlet-class>
<servlet-name>feuilleGardes</servlet-name>
<servlet-class>servlet.GardesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AuthentifServlet</servlet-name>
@ -29,8 +29,8 @@
<url-pattern>/pompier</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DispoServlet</servlet-name>
<url-pattern>/DispoServlet</url-pattern>
<servlet-name>feuilleGardes</servlet-name>
<url-pattern>/gardes</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>