Commit 686ade38 authored by Matthieu BONNOT's avatar Matthieu BONNOT
Browse files

Tri des ressources avec la date de fin, beautifulling sur la page equipe,...

Tri des ressources avec la date de fin, beautifulling sur la page equipe, profil avec base de dev pour les tests, refacto des methode equipes et gestion des erreurs
parent 09f5b402
Pipeline #56582 failed with stages
in 6 seconds
## 21.9.1 (2021-09-21)
### Evolutions
* Après l'authentification, le collaborateur est redirigé automatiquement vers la page de son agence.
* Améliorations de la page d'erreur.
### Corrections
......@@ -73,6 +73,21 @@
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>
</dependency>
<!-- Environnement de DEV -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Outil de LOG -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.32</version>
</dependency>
</dependencies>
<dependencyManagement>
......
package com.ippon.livretaccueil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication
@EnableAutoConfiguration(exclude={H2ConsoleAutoConfiguration.class})
public class LivretAccueilApplication {
public static void main(String[] args) {
......
......@@ -45,7 +45,7 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.authorizeRequests()
.antMatchers("/", "/ressources*").hasRole("uma_authorization")
.antMatchers("/", "/ressource*").hasRole("uma_authorization")
.anyRequest().authenticated().and().oauth2Login().and().logout().logoutSuccessUrl("/logout-success")
;
http.headers().frameOptions().sameOrigin();
......
......@@ -38,7 +38,12 @@ public class ControllerPageAccueil {
.getIdToken();
Map<String, Object> customClaims = token.getOtherClaims();
model.addAttribute("agence", customClaims.get("agency").toString().toLowerCase().trim());
String agenceUtilisateur = customClaims.get("agency").toString().toLowerCase().trim();
// Hack pour le DEV.
//agenceUtilisateur = "paris";
model.addAttribute("agence", agenceUtilisateur);
}
......@@ -50,6 +55,6 @@ public class ControllerPageAccueil {
model.addAttribute("message", message);
return "userInfo";
return "error";
}
}
package com.ippon.livretaccueil.controller;
import java.security.Principal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.keycloak.KeycloakPrincipal;
import org.keycloak.KeycloakSecurityContext;
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
import org.keycloak.representations.IDToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
......@@ -21,14 +25,16 @@ import com.ippon.livretaccueil.dao.RessourceReadOnlyRepo;
@Controller
public class ControllerPageMonEquipe {
public final static Logger LOGGER = LoggerFactory.getLogger(ControllerPageMonEquipe.class);
@Autowired
private RessourceReadOnlyRepo ressDao;
private RessourceReadOnlyRepo ressDao;
@GetMapping(path = "/ressource")
public String recupererEquipe(Model model) {
public String afficherEquipeCollaborateur(Model model) {
KeycloakAuthenticationToken authentication = (KeycloakAuthenticationToken) SecurityContextHolder.getContext()
.getAuthentication();
.getAuthentication();
final Principal principal = (Principal) authentication.getPrincipal();
......@@ -39,30 +45,75 @@ public class ControllerPageMonEquipe {
KeycloakPrincipal<KeycloakSecurityContext> kPrincipal = (KeycloakPrincipal<KeycloakSecurityContext>) principal;
IDToken token = kPrincipal.getKeycloakSecurityContext()
.getIdToken();
.getIdToken();
Map<String, Object> customClaims = token.getOtherClaims();
System.out.println(customClaims);
}
Collaborateur collaborateur = recupererCollaborateur(user.getUserName());
if (collaborateur != null) {
LOGGER.debug("Collaborateur trouvé : " + collaborateur.getNameres());
Equipe equipe = recupererEquipeCollaborateur(collaborateur);
model.addAttribute("collaborateur", collaborateur);
model.addAttribute("equipeOrganigramme", equipe);
} else {
model.addAttribute("messageErreur", "Collaborateur introuvable.");
}
ressource(model, user.getUserName());
model.addAttribute("username", user.getUserName());
model.addAttribute("user", user);
return "equipeOrganigramme";
}
/**
* Methode pour récuperer le collaborateur à partir de son login.
*
* @param login
* @return
*/
private Collaborateur recupererCollaborateur(String login) {
LOGGER.info("Recuperation des informations du collaborateur : <" + login + ">");
// Surcharge du login pour le DEV
String rechercheParLogin = login;
Collaborateur collab = ressDao.findByLogin(rechercheParLogin);
LOGGER.debug("Recuperation des informations du collaborateur : <" + collab.getFuncres() + "> <" + collab.getDateSRes() + ">");
return collab;
}
/**
* Methode pour recupérer l'équipe d'un collaborateur à partir de son login.
*/
private Equipe recupererEquipeCollaborateur(Collaborateur collaborateur) {
public void ressource(Model model, String login) {
Collaborateur ressource = ressDao.findByLogin(login);
Collaborateur ressourceManager = ressDao.findById(Long.valueOf(ressource.getResmres()));
LOGGER.debug("Recuperation du manager du collabrateur");
Collaborateur managerEquipe = ressDao.findById(Long.valueOf(collaborateur.getResmres()));
List<Collaborateur> membresEquipe = ressDao.findByResmres(managerEquipe.getOid());
Equipe equipe = new Equipe();
equipe.managerEquipe = ressourceManager;
equipe.collaborateursEquipe = ressDao.findByResmres(ressourceManager.getOid());
model.addAttribute("equipeOrganigramme", equipe);
equipe.setManagerEquipe(managerEquipe);
equipe.setCollaborateursEquipe(membresEquipe);
List<Collaborateur> listeTriee = new ArrayList<>();
// Tri de l'équipe :
for(Collaborateur collab : equipe.getCollaborateursEquipe()) {
if(collab.getDateERes() == null) {
//equipe.getCollaborateursEquipe().remove(collab);
listeTriee.add(collab);
}
}
equipe.setCollaborateursEquipe(listeTriee);
return equipe;
}
}
\ No newline at end of file
package com.ippon.livretaccueil.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
//@Controller
public class ControllerTest {
@GetMapping(path = "/helloworld")
public String afficherPageTest(){
return "helloWorld";
}
}
......@@ -5,6 +5,7 @@ import java.util.List;
import com.ippon.livretaccueil.model.staff.Collaborateur;
public interface RessourceReadOnlyRepo extends ReadOnlyRepository<Collaborateur, Long> {
Collaborateur findById(Long id);
List<Collaborateur> findByResmres(Long id);
......
......@@ -5,9 +5,11 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
import java.util.Objects;
@Entity
@Table(name = "rsource", schema="asa")
@Table(name = "rsource", schema = "asa")
public class Collaborateur {
@Id
......@@ -17,37 +19,84 @@ public class Collaborateur {
private String nameres;
private long resmres;
private String login;
private String funcres;
private Date dateSRes;
private Date dateERes;
public long getOid() {
return oid;
}
public void setOid(long oid) {
this.oid = oid;
}
public String getSurnameres() {
return surnameres;
}
public void setSurnameres(String surnameres) {
this.surnameres = surnameres;
}
public String getNameres() {
return nameres;
}
public void setNameres(String nameres) {
this.nameres = nameres;
}
public long getResmres() {
return resmres;
}
public void setResmres(long resmres) {
this.resmres = resmres;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public long getOid() {
return oid;
}
public void setOid(long oid) {
this.oid = oid;
}
public String getSurnameres() {
return surnameres;
}
public void setSurnameres(String surnameres) {
this.surnameres = surnameres;
}
public String getNameres() {
return nameres;
}
public void setNameres(String nameres) {
this.nameres = nameres;
}
public long getResmres() {
return resmres;
}
public void setResmres(long resmres) {
this.resmres = resmres;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getFuncres() {
return funcres;
}
public void setFuncres(String funcres) {
this.funcres = funcres;
}
public Date getDateSRes() {
return dateSRes;
}
public void setDateSRes(Date dateSRes) {
this.dateSRes = dateSRes;
}
public Date getDateERes() {
return dateERes;
}
public void setDateERes(Date dateERes) {
this.dateERes = dateERes;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Collaborateur that = (Collaborateur) o;
return oid == that.oid;
}
@Override
public int hashCode() {
return Objects.hash(oid);
}
}
......@@ -4,12 +4,14 @@ import java.util.List;
public class Equipe {
public Collaborateur managerEquipe;
public List<Collaborateur> collaborateursEquipe;
private Collaborateur managerEquipe;
private Collaborateur collaborateur;
private List<Collaborateur> collaborateursEquipe;
public List<Collaborateur> getCollaborateursEquipe() {
return collaborateursEquipe;
}
public void setCollaborateursEquipe(List<Collaborateur> collaborateursEquipe) {
this.collaborateursEquipe = collaborateursEquipe;
}
......@@ -20,4 +22,11 @@ public class Equipe {
this.managerEquipe = managerEquipe;
}
public Collaborateur getCollaborateur() {
return collaborateur;
}
public void setCollaborateur(Collaborateur collaborateur) {
this.collaborateur = collaborateur;
}
}
#######################################################
# APPLICATION
#######################################################
server.port=8091
# Desactivation de la page d'erreur par default.
server.error.whitelabel.enabled=false
# Propriétés de l'application.
welcome.message=Welcome
error.message=Error Loading
#######################################################
# DATABASE
#######################################################
# Configuration d'une base H2 pour le DEVELOPPEMENT.
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE;INIT=CREATE SCHEMA IF NOT EXISTS asa
spring.datasource.username=sa
spring.datasource.password=password
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.initialize=true
spring.datasource.initialization-mode=always
# Configuration d'Hibernate
spring.jpa.show-sql=true
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=none
#spring.datasource.continue-on-error=true
#spring.h2.console.enabled=true
#log4j.logger.org.hibernate.SQL=DEBUG
#log4j.logger.org.hibernate.type=TRACE
#######################################################
# AUTHENTIFICATION
#######################################################
#Keycloak Configuration
keycloak.auth-server-url=https://auth.ippon.fr/auth/
keycloak.realm=camel-real
keycloak.resource=meltingpoc
keycloak.principal-attribute=preferred_username
keycloak.credentials.secret=e0500553-7334-432d-bac5-99e317c54244
#######################################################
# APPLICATION
#######################################################
server.port=8091
# Desactivation de la page d'erreur par default.
server.error.whitelabel.enabled=false
# Proprits de l'application.
welcome.message=Welcome
error.message=Error Loading
#######################################################
# DATABASE
#######################################################
#Basic Spring Boot Config for Oracle
spring.datasource.url= jdbc:oracle:thin:@//10.0.255.40:1521/SXPREP
spring.datasource.username=everwin_ro
......@@ -6,17 +21,12 @@ spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
#hibernate config
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
server.port=8091
#######################################################
# AUTHENTIFICATION
#######################################################
#Keycloak Configuration
keycloak.auth-server-url=https://auth.ippon.fr/auth/
keycloak.realm=camel-real
keycloak.resource=meltingpoc
keycloak.principal-attribute=preferred_username
welcome.message=Welcome
error.message=Error Loading
keycloak.credentials.secret=e0500553-7334-432d-bac5-99e317c54244
server.error.whitelabel.enabled=false
spring.main.allow-bean-definition-overriding: true
......
INSERT INTO asa.rsource (oid, surnameres, nameres, resmres, login) VALUES (0, 'René', 'Gosciny', 0, 'rgosciny');
INSERT INTO asa.rsource (oid, surnameres, nameres, resmres, login) VALUES (1, 'Asterix', 'LeGaulois', 0, 'alegaulois');
INSERT INTO asa.rsource (oid, surnameres, nameres, resmres, login) VALUES (2, 'Obélix', 'LeGaulois', 0, 'olegaulois');
INSERT INTO asa.rsource (oid, surnameres, nameres, resmres, login, funcres, datesres, dateeres) VALUES (3, 'Matthieu', 'BONNOT', 1, 'mbonnot', 'Dev', '2021-09-06', null);
INSERT INTO asa.rsource (oid, surnameres, nameres, resmres, login, funcres, datesres, dateeres) VALUES (4, 'Michel', 'BLANC', 1, 'mblanc', 'DevOps', '2020-09-06', null);
INSERT INTO asa.rsource (oid, surnameres, nameres, resmres, login, funcres, datesres, dateeres) VALUES (5, 'Michel', 'NOIR', 1, 'mnoir', 'Fou du Code', '2019-09-06', null);
INSERT INTO asa.rsource (oid, surnameres, nameres, resmres, login, funcres, datesres, dateeres) VALUES (6, 'Michelle', 'ROUGE', 1, 'mrouge', 'Cloud', '2021-09-06', '2021-05-01');
INSERT INTO asa.rsource (oid, surnameres, nameres, resmres, login, funcres, datesres, dateeres) VALUES (7, 'Michelle', 'VERTE', 1, 'mverte', 'Commercial', '2021-09-06', null);
\ No newline at end of file
DROP SCHEMA IF EXISTS asa;
CREATE SCHEMA IF NOT EXISTS asa AUTHORIZATION sa;
DROP TABLE IF EXISTS asa.rsource;
CREATE TABLE asa.rsource (
oid INT AUTO_INCREMENT PRIMARY KEY,
surnameres VARCHAR(250) NOT NULL,
nameres VARCHAR(250) NOT NULL,
resmres NUMBER DEFAULT NULL,
login VARCHAR(250) DEFAULT NULL,
funcres VARCHAR(250) DEFAULT NULL,
dateSRes DATE DEFAULT CURRENT_DATE(),
dateERes DATE DEFAULT NULL
);
......@@ -8,6 +8,13 @@ body {
max-width: 80em;
}
#messageErreur{
border: 1px;
border-style: inset;
border-color: red;
width: 80%;
}
.ecranAccueil {
height: 500px;
position: relative;
......@@ -115,4 +122,4 @@ ol.organizational-chart > li > ol > li > div {
}
}
\ No newline at end of file
}
......@@ -3,33 +3,34 @@
<head>
<link href="../static/style.css" th:href="@{/style.css}" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
</head>
<body>
<div id="wrapper">
<div id="wrapper">
<div id="container">
<div id="image" style="text-align: center;">
<div id="image" style="text-align: center; width:100%">
<img src="../images/bandeau.PNG" th:src="@{/images/bandeau.PNG}" />
</div>
<div style="width: 100%;">
<div style="float:left; width: 20%">
<h4>Manager Technique :</h4>
<div>
<p
th:text="${equipeOrganigramme.manager.surnameres} + ' '+ ${equipeOrganigramme.manager.nameres}">
</p>
</div>
</div>
<div style="float:right; width: 80% ">
<h4>Equipe: </h4>
<div style="width:100%">
<div style="padding-top: 30px;">
<h4
th:text="'Manager Technique : '+ ${equipeOrganigramme.managerEquipe.surnameres} + ' '+ ${equipeOrganigramme.managerEquipe.nameres}">
</h4>
<ol class="organizational-chart">
<li>
<ol>
<li th:each="ress : ${equipeOrganigramme.listeEquipe}">
<li th:each="collaborateurE : ${equipeOrganigramme.collaborateursEquipe}">
<div id="listeEquipe">
<p th:text="${ress.surnameres} + ' '+ ${ress.nameres}"></p>
<div th:attr="class=${collaborateur.surnameres == collaborateurE.surnameres ? 'card border-danger' : 'card'}" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title" th:text="${collaborateurE.surnameres} + ' '+ ${collaborateurE.nameres}"></h5>
<h6 class="card-subtitle mb-2 text-muted" th:text="${collaborateurE.funcres}"></h6>
</div>
</div>
</div>
</li>
</ol>
......
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<link href="../static/style.css" th:href="@{/style.css}" rel="stylesheet" />
</head>
<body>
<center><img src="../images/logo_ippon.png">
<center>