Refactroring

This commit is contained in:
dahoud
2025-11-29 04:18:14 +00:00
parent e27a8434e1
commit 5b831086f1
6 changed files with 409 additions and 123 deletions

View File

@@ -2,6 +2,7 @@ package dev.lions.unionflow.client.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;
@@ -9,6 +10,14 @@ import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.UUID;
/**
* DTO client pour les organisations (alias historique Association).
*
* Harmonisé avec le contrat serveur `OrganisationDTO`:
* - `dateCreation`/`dateModification` d'audit (LocalDateTime) alignés sur BaseDTO avec pattern JSON
* - `dateFondation` (LocalDate) pour la date de création fonctionnelle de l'organisation
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class AssociationDTO implements Serializable {
private static final long serialVersionUID = 1L;
@@ -28,9 +37,13 @@ public class AssociationDTO implements Serializable {
@JsonProperty("typeOrganisation")
private String typeAssociation;
// Date de fondation (fonctionnelle), côté serveur: OrganisationDTO.dateFondation
@JsonProperty("dateFondation")
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate dateCreation;
private LocalDate dateFondation;
// Côté serveur: OrganisationDTO.numeroEnregistrement
@JsonProperty("numeroEnregistrement")
private String numeroRegistre;
private String statut;
private Integer nombreMembres;
@@ -40,11 +53,23 @@ public class AssociationDTO implements Serializable {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime dateDerniereActivite;
// Champs d'audit issus de BaseDTO (côté serveur)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime dateCreation;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime dateModification;
private Long version;
private Boolean actif;
private String region;
private String ville;
private String quartier;
private String pays;
// Aligné sur OrganisationDTO.codePostal
private String codePostal;
// Constructeurs
public AssociationDTO() {}
@@ -53,7 +78,7 @@ public class AssociationDTO implements Serializable {
this.nom = nom;
this.typeAssociation = typeAssociation;
this.statut = "ACTIVE";
this.dateCreation = LocalDate.now();
this.dateFondation = LocalDate.now();
this.nombreMembres = 0;
}
@@ -82,8 +107,8 @@ public class AssociationDTO implements Serializable {
public String getTypeAssociation() { return typeAssociation; }
public void setTypeAssociation(String typeAssociation) { this.typeAssociation = typeAssociation; }
public LocalDate getDateCreation() { return dateCreation; }
public void setDateCreation(LocalDate dateCreation) { this.dateCreation = dateCreation; }
public LocalDate getDateFondation() { return dateFondation; }
public void setDateFondation(LocalDate dateFondation) { this.dateFondation = dateFondation; }
public String getNumeroRegistre() { return numeroRegistre; }
public void setNumeroRegistre(String numeroRegistre) { this.numeroRegistre = numeroRegistre; }
@@ -117,6 +142,21 @@ public class AssociationDTO implements Serializable {
public String getPays() { return pays; }
public void setPays(String pays) { this.pays = pays; }
public String getCodePostal() { return codePostal; }
public void setCodePostal(String codePostal) { this.codePostal = codePostal; }
public LocalDateTime getDateCreation() { return dateCreation; }
public void setDateCreation(LocalDateTime dateCreation) { this.dateCreation = dateCreation; }
public LocalDateTime getDateModification() { return dateModification; }
public void setDateModification(LocalDateTime dateModification) { this.dateModification = dateModification; }
public Long getVersion() { return version; }
public void setVersion(Long version) { this.version = version; }
public Boolean getActif() { return actif; }
public void setActif(Boolean actif) { this.actif = actif; }
// Propriétés dérivées
public String getTypeLibelle() {

View File

@@ -54,15 +54,13 @@ public interface AssociationService {
@Path("/{id}")
void supprimer(@PathParam("id") UUID id);
@PUT
// Côté serveur: POST /{id}/activer
@POST
@Path("/{id}/activer")
AssociationDTO activer(@PathParam("id") UUID id);
@PUT
@Path("/{id}/desactiver")
AssociationDTO desactiver(@PathParam("id") UUID id);
@PUT
// Suspension: POST /{id}/suspendre (alias historique "désactiver")
@POST
@Path("/{id}/suspendre")
AssociationDTO suspendre(@PathParam("id") UUID id);

View File

@@ -104,6 +104,18 @@ public class OrganisationsBean implements Serializable {
.count();
organisationsInactives = totalOrganisations - organisationsActives;
}
} catch (dev.lions.unionflow.client.service.RestClientExceptionMapper.UnauthorizedException e) {
// Non bloquant: afficher une info et calculer depuis la liste
LOGGER.warning("Statistiques non autorisées (401): " + e.getMessage());
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO,
"Information",
"Statistiques indisponibles (non autorisé) — affichage des données sans stats."));
totalOrganisations = organisations.size();
organisationsActives = organisations.stream()
.filter(o -> o.getStatut() != null && StatutOrganisationConstants.ACTIVE.equals(o.getStatut()))
.count();
organisationsInactives = totalOrganisations - organisationsActives;
} catch (Exception e) {
LOGGER.warning("Impossible de charger les statistiques: " + e.getMessage());
// Fallback: calculer depuis la liste
@@ -118,8 +130,23 @@ public class OrganisationsBean implements Serializable {
public void preparerNouvelleOrganisation() {
nouvelleOrganisation = new AssociationDTO();
nouvelleOrganisation.setStatut(StatutOrganisationConstants.ACTIVE);
nouvelleOrganisation.setTypeAssociation("ASSOCIATION");
nouvelleOrganisation.setDateCreation(java.time.LocalDate.now());
// S'assurer que le catalogue des types est chargé avant d'initialiser le formulaire
if (typesCatalogue == null || typesCatalogue.isEmpty()) {
chargerTypesOrganisation();
}
// Déterminer un type par défaut dynamique (premier type actif du catalogue)
String typeDefaut = null;
if (typesCatalogue != null) {
typeDefaut = typesCatalogue.stream()
.filter(t -> t.getActif() == null || Boolean.TRUE.equals(t.getActif()))
.map(TypeOrganisationClientDTO::getCode)
.findFirst()
.orElse(null);
}
nouvelleOrganisation.setTypeAssociation(typeDefaut);
nouvelleOrganisation.setDateFondation(java.time.LocalDate.now());
}
public void creerOrganisation() {
@@ -207,7 +234,7 @@ public class OrganisationsBean implements Serializable {
public void desactiverOrganisation(AssociationDTO organisation) {
try {
associationService.desactiver(organisation.getId());
associationService.suspendre(organisation.getId());
organisation.setStatut(StatutOrganisationConstants.INACTIVE);
FacesContext.getCurrentInstance().addMessage(null,
@@ -277,6 +304,14 @@ public class OrganisationsBean implements Serializable {
organisationsFiltrees = organisations;
}
/**
* Recharge la liste et les statistiques (DRY)
*/
public void recharger() {
chargerOrganisations();
chargerStatistiques();
}
// Getters & Setters
public List<AssociationDTO> getOrganisations() { return organisations; }
public void setOrganisations(List<AssociationDTO> organisations) { this.organisations = organisations; }