Sync: code local unifié
Synchronisation du code source local (fait foi). Signed-off-by: lions dev Team
This commit is contained in:
@@ -1,8 +1,16 @@
|
||||
package dev.lions.unionflow.server.service;
|
||||
|
||||
import dev.lions.unionflow.server.api.dto.organisation.OrganisationDTO;
|
||||
import dev.lions.unionflow.server.api.enums.organisation.StatutOrganisation;
|
||||
import dev.lions.unionflow.server.api.enums.organisation.TypeOrganisation;
|
||||
import dev.lions.unionflow.server.api.dto.organisation.request.CreateOrganisationRequest;
|
||||
import dev.lions.unionflow.server.api.dto.organisation.request.UpdateOrganisationRequest;
|
||||
import dev.lions.unionflow.server.api.dto.organisation.response.OrganisationResponse;
|
||||
import dev.lions.unionflow.server.api.dto.organisation.response.OrganisationSummaryResponse;
|
||||
import dev.lions.unionflow.server.api.enums.membre.StatutMembre;
|
||||
import dev.lions.unionflow.server.entity.Membre;
|
||||
import dev.lions.unionflow.server.entity.MembreOrganisation;
|
||||
import dev.lions.unionflow.server.repository.EvenementRepository;
|
||||
import dev.lions.unionflow.server.repository.MembreOrganisationRepository;
|
||||
import dev.lions.unionflow.server.repository.MembreRepository;
|
||||
import dev.lions.unionflow.server.repository.TypeReferenceRepository;
|
||||
import dev.lions.unionflow.server.entity.Organisation;
|
||||
import dev.lions.unionflow.server.repository.OrganisationRepository;
|
||||
import io.quarkus.panache.common.Page;
|
||||
@@ -13,10 +21,12 @@ import jakarta.transaction.Transactional;
|
||||
import jakarta.ws.rs.NotFoundException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
@@ -31,21 +41,39 @@ public class OrganisationService {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(OrganisationService.class);
|
||||
|
||||
@Inject OrganisationRepository organisationRepository;
|
||||
@Inject
|
||||
OrganisationRepository organisationRepository;
|
||||
|
||||
@Inject
|
||||
MembreRepository membreRepository;
|
||||
|
||||
@Inject
|
||||
DefaultsService defaultsService;
|
||||
|
||||
@Inject
|
||||
TypeReferenceRepository typeReferenceRepository;
|
||||
|
||||
@Inject
|
||||
MembreOrganisationRepository membreOrganisationRepository;
|
||||
|
||||
@Inject
|
||||
EvenementRepository evenementRepository;
|
||||
|
||||
/**
|
||||
* Crée une nouvelle organisation
|
||||
*
|
||||
* @param organisation l'organisation à créer
|
||||
* @param utilisateur identifiant de l'utilisateur effectuant la création
|
||||
* (email ou "system")
|
||||
* @return l'organisation créée
|
||||
*/
|
||||
@Transactional
|
||||
public Organisation creerOrganisation(Organisation organisation) {
|
||||
public Organisation creerOrganisation(Organisation organisation, String utilisateur) {
|
||||
LOG.infof("Création d'une nouvelle organisation: %s", organisation.getNom());
|
||||
|
||||
// Vérifier l'unicité de l'email
|
||||
if (organisationRepository.findByEmail(organisation.getEmail()).isPresent()) {
|
||||
throw new IllegalArgumentException("Une organisation avec cet email existe déjà");
|
||||
throw new IllegalStateException("Une organisation avec cet email existe déjà");
|
||||
}
|
||||
|
||||
// Vérifier l'unicité du nom
|
||||
@@ -72,6 +100,16 @@ public class OrganisationService {
|
||||
organisation.setTypeOrganisation("ASSOCIATION");
|
||||
}
|
||||
|
||||
// Audit : créé par / modifié par (BaseEntity n'initialise pas creePar dans
|
||||
// @PrePersist)
|
||||
String auditUser = utilisateur != null && !utilisateur.isBlank() ? utilisateur : "system";
|
||||
organisation.setCreePar(auditUser);
|
||||
organisation.setModifiePar(auditUser);
|
||||
if (organisation.getDateCreation() == null) {
|
||||
organisation.setDateCreation(LocalDateTime.now());
|
||||
}
|
||||
organisation.setDateModification(organisation.getDateCreation());
|
||||
|
||||
organisationRepository.persist(organisation);
|
||||
LOG.infof(
|
||||
"Organisation créée avec succès: ID=%s, Nom=%s", organisation.getId(), organisation.getNom());
|
||||
@@ -82,9 +120,9 @@ public class OrganisationService {
|
||||
/**
|
||||
* Met à jour une organisation existante
|
||||
*
|
||||
* @param id l'ID de l'organisation
|
||||
* @param id l'ID de l'organisation
|
||||
* @param organisationMiseAJour les données de mise à jour
|
||||
* @param utilisateur l'utilisateur effectuant la modification
|
||||
* @param utilisateur l'utilisateur effectuant la modification
|
||||
* @return l'organisation mise à jour
|
||||
*/
|
||||
@Transactional
|
||||
@@ -92,15 +130,14 @@ public class OrganisationService {
|
||||
UUID id, Organisation organisationMiseAJour, String utilisateur) {
|
||||
LOG.infof("Mise à jour de l'organisation ID: %s", id);
|
||||
|
||||
Organisation organisation =
|
||||
organisationRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Organisation non trouvée avec l'ID: " + id));
|
||||
Organisation organisation = organisationRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Organisation non trouvée avec l'ID: " + id));
|
||||
|
||||
// Vérifier l'unicité de l'email si modifié
|
||||
if (!organisation.getEmail().equals(organisationMiseAJour.getEmail())) {
|
||||
if (organisationRepository.findByEmail(organisationMiseAJour.getEmail()).isPresent()) {
|
||||
throw new IllegalArgumentException("Une organisation avec cet email existe déjà");
|
||||
throw new IllegalStateException("Une organisation avec cet email existe déjà");
|
||||
}
|
||||
organisation.setEmail(organisationMiseAJour.getEmail());
|
||||
}
|
||||
@@ -113,18 +150,53 @@ public class OrganisationService {
|
||||
organisation.setNom(organisationMiseAJour.getNom());
|
||||
}
|
||||
|
||||
// Mettre à jour les autres champs
|
||||
// Mettre à jour tous les champs métier (alignés sur detail.xhtml et
|
||||
// organisation-form)
|
||||
organisation.setNomCourt(organisationMiseAJour.getNomCourt());
|
||||
organisation.setDescription(organisationMiseAJour.getDescription());
|
||||
organisation.setDateFondation(organisationMiseAJour.getDateFondation());
|
||||
organisation.setNumeroEnregistrement(organisationMiseAJour.getNumeroEnregistrement());
|
||||
organisation.setTelephone(organisationMiseAJour.getTelephone());
|
||||
organisation.setAdresse(organisationMiseAJour.getAdresse());
|
||||
organisation.setVille(organisationMiseAJour.getVille());
|
||||
organisation.setCodePostal(organisationMiseAJour.getCodePostal());
|
||||
organisation.setRegion(organisationMiseAJour.getRegion());
|
||||
organisation.setPays(organisationMiseAJour.getPays());
|
||||
organisation.setTelephoneSecondaire(organisationMiseAJour.getTelephoneSecondaire());
|
||||
organisation.setEmailSecondaire(organisationMiseAJour.getEmailSecondaire());
|
||||
// Adresse gérée via l'entité Adresse (Cat.2)
|
||||
organisation.setLatitude(organisationMiseAJour.getLatitude());
|
||||
organisation.setLongitude(organisationMiseAJour.getLongitude());
|
||||
organisation.setSiteWeb(organisationMiseAJour.getSiteWeb());
|
||||
organisation.setLogo(organisationMiseAJour.getLogo());
|
||||
organisation.setReseauxSociaux(organisationMiseAJour.getReseauxSociaux());
|
||||
organisation.setObjectifs(organisationMiseAJour.getObjectifs());
|
||||
organisation.setActivitesPrincipales(organisationMiseAJour.getActivitesPrincipales());
|
||||
organisation.setCertifications(organisationMiseAJour.getCertifications());
|
||||
organisation.setPartenaires(organisationMiseAJour.getPartenaires());
|
||||
organisation.setNotes(organisationMiseAJour.getNotes());
|
||||
if (organisationMiseAJour.getStatut() != null) {
|
||||
organisation.setStatut(organisationMiseAJour.getStatut());
|
||||
}
|
||||
organisation.setTypeOrganisation(organisationMiseAJour.getTypeOrganisation());
|
||||
organisation.setNiveauHierarchique(
|
||||
organisationMiseAJour.getNiveauHierarchique() != null ? organisationMiseAJour.getNiveauHierarchique() : 0);
|
||||
organisation.setNombreMembres(
|
||||
organisationMiseAJour.getNombreMembres() != null ? organisationMiseAJour.getNombreMembres() : 0);
|
||||
organisation.setNombreAdministrateurs(
|
||||
organisationMiseAJour.getNombreAdministrateurs() != null ? organisationMiseAJour.getNombreAdministrateurs()
|
||||
: 0);
|
||||
// Budget & Finances
|
||||
organisation.setBudgetAnnuel(organisationMiseAJour.getBudgetAnnuel());
|
||||
organisation.setDevise(
|
||||
organisationMiseAJour.getDevise() != null ? organisationMiseAJour.getDevise() : defaultsService.getDevise());
|
||||
organisation.setCotisationObligatoire(
|
||||
organisationMiseAJour.getCotisationObligatoire() != null ? organisationMiseAJour.getCotisationObligatoire()
|
||||
: false);
|
||||
organisation.setMontantCotisationAnnuelle(organisationMiseAJour.getMontantCotisationAnnuelle());
|
||||
organisation.setOrganisationPublique(
|
||||
organisationMiseAJour.getOrganisationPublique() != null ? organisationMiseAJour.getOrganisationPublique()
|
||||
: true);
|
||||
organisation.setAccepteNouveauxMembres(
|
||||
organisationMiseAJour.getAccepteNouveauxMembres() != null ? organisationMiseAJour.getAccepteNouveauxMembres()
|
||||
: true);
|
||||
// Hiérarchie
|
||||
organisation.setOrganisationParente(organisationMiseAJour.getOrganisationParente());
|
||||
|
||||
organisation.marquerCommeModifie(utilisateur);
|
||||
|
||||
@@ -135,17 +207,16 @@ public class OrganisationService {
|
||||
/**
|
||||
* Supprime une organisation
|
||||
*
|
||||
* @param id l'UUID de l'organisation
|
||||
* @param id l'UUID de l'organisation
|
||||
* @param utilisateur l'utilisateur effectuant la suppression
|
||||
*/
|
||||
@Transactional
|
||||
public void supprimerOrganisation(UUID id, String utilisateur) {
|
||||
LOG.infof("Suppression de l'organisation ID: %s", id);
|
||||
|
||||
Organisation organisation =
|
||||
organisationRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Organisation non trouvée avec l'ID: " + id));
|
||||
Organisation organisation = organisationRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Organisation non trouvée avec l'ID: " + id));
|
||||
|
||||
// Vérifier qu'il n'y a pas de membres actifs
|
||||
if (organisation.getNombreMembres() > 0) {
|
||||
@@ -181,6 +252,90 @@ public class OrganisationService {
|
||||
return organisationRepository.findByEmail(email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Liste les organisations auxquelles l'utilisateur connecté (membre) appartient.
|
||||
* Utilisé pour un administrateur d'organisation qui ne doit voir que son/ses organisation(s).
|
||||
*
|
||||
* @param emailUtilisateur email du principal (SecurityIdentity)
|
||||
* @return liste des organisations du membre, ou liste vide si membre non trouvé
|
||||
*/
|
||||
@Transactional
|
||||
public List<Organisation> listerOrganisationsPourUtilisateur(String emailUtilisateur) {
|
||||
if (emailUtilisateur == null || emailUtilisateur.isBlank()) {
|
||||
return List.of();
|
||||
}
|
||||
return membreRepository.findByEmail(emailUtilisateur)
|
||||
.map(m -> m.getMembresOrganisations().stream()
|
||||
.map(mo -> mo.getOrganisation())
|
||||
.distinct()
|
||||
.collect(Collectors.toList()))
|
||||
.orElse(List.of());
|
||||
}
|
||||
|
||||
/**
|
||||
* Associe un utilisateur (par email) à une organisation.
|
||||
* Réservé au SUPER_ADMIN. Crée un Membre minimal si aucun n'existe pour cet email,
|
||||
* puis crée le lien MembreOrganisation (idempotent si déjà associé).
|
||||
*
|
||||
* @param email email de l'utilisateur (doit correspondre à un compte Keycloak / Membre)
|
||||
* @param organisationId UUID de l'organisation
|
||||
* @throws NotFoundException si l'organisation n'existe pas
|
||||
*/
|
||||
@Transactional
|
||||
public void associerUtilisateurAOrganisation(String email, UUID organisationId) {
|
||||
if (email == null || email.isBlank()) {
|
||||
throw new IllegalArgumentException("L'email est obligatoire");
|
||||
}
|
||||
if (organisationId == null) {
|
||||
throw new IllegalArgumentException("L'organisation est obligatoire");
|
||||
}
|
||||
Organisation organisation = organisationRepository.findByIdOptional(organisationId)
|
||||
.orElseThrow(() -> new NotFoundException("Organisation non trouvée: " + organisationId));
|
||||
String emailNorm = email.trim().toLowerCase();
|
||||
Membre membre = membreRepository.findByEmail(emailNorm).orElseGet(() -> {
|
||||
Membre nouveau = creerMembreMinimalPourEmail(emailNorm);
|
||||
membreRepository.persist(nouveau);
|
||||
LOG.infof("Membre minimal créé pour associer l'utilisateur %s à l'organisation %s", emailNorm, organisation.getNom());
|
||||
return nouveau;
|
||||
});
|
||||
if (membreOrganisationRepository.findByMembreIdAndOrganisationId(membre.getId(), organisationId).isPresent()) {
|
||||
LOG.infof("L'utilisateur %s est déjà associé à l'organisation %s", emailNorm, organisation.getNom());
|
||||
return;
|
||||
}
|
||||
MembreOrganisation mo = MembreOrganisation.builder()
|
||||
.membre(membre)
|
||||
.organisation(organisation)
|
||||
.statutMembre(StatutMembre.ACTIF)
|
||||
.dateAdhesion(LocalDate.now())
|
||||
.build();
|
||||
membreOrganisationRepository.persist(mo);
|
||||
LOG.infof("Utilisateur %s associé à l'organisation %s (MembreOrganisation créé)", emailNorm, organisation.getNom());
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée un Membre minimal à partir d'un email (pour associer un compte Keycloak sans fiche membre).
|
||||
*/
|
||||
private Membre creerMembreMinimalPourEmail(String email) {
|
||||
String partieLocale = email.contains("@") ? email.substring(0, email.indexOf('@')) : email;
|
||||
String prenom = partieLocale.contains(".") ? partieLocale.substring(0, partieLocale.indexOf('.')) : "Admin";
|
||||
String nom = partieLocale.contains(".") ? partieLocale.substring(partieLocale.indexOf('.') + 1) : partieLocale;
|
||||
if (nom.isBlank()) nom = "Utilisateur";
|
||||
if (prenom.isBlank()) prenom = "Admin";
|
||||
prenom = prenom.substring(0, 1).toUpperCase() + (prenom.length() > 1 ? prenom.substring(1).toLowerCase() : "");
|
||||
nom = nom.substring(0, 1).toUpperCase() + (nom.length() > 1 ? nom.substring(1).toLowerCase() : "");
|
||||
String numeroMembre = "UF-ADM-" + UUID.randomUUID().toString().substring(0, 8).toUpperCase();
|
||||
Membre m = Membre.builder()
|
||||
.email(email)
|
||||
.numeroMembre(numeroMembre)
|
||||
.prenom(prenom)
|
||||
.nom(nom)
|
||||
.dateNaissance(LocalDate.now().minusYears(25))
|
||||
.statutCompte("ACTIF")
|
||||
.build();
|
||||
m.setActif(Boolean.TRUE); // actif est dans BaseEntity, pas dans MembreBuilder
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liste toutes les organisations actives
|
||||
*
|
||||
@@ -205,8 +360,8 @@ public class OrganisationService {
|
||||
* Recherche d'organisations par nom
|
||||
*
|
||||
* @param recherche terme de recherche
|
||||
* @param page numéro de page
|
||||
* @param size taille de la page
|
||||
* @param page numéro de page
|
||||
* @param size taille de la page
|
||||
* @return liste paginée des organisations correspondantes
|
||||
*/
|
||||
public List<Organisation> rechercherOrganisations(String recherche, int page, int size) {
|
||||
@@ -214,17 +369,30 @@ public class OrganisationService {
|
||||
recherche, Page.of(page, size), Sort.by("nom").ascending());
|
||||
}
|
||||
|
||||
public long rechercherOrganisationsCount(String recherche) {
|
||||
if (recherche == null || recherche.trim().isEmpty()) {
|
||||
return organisationRepository.count();
|
||||
}
|
||||
String pattern = "%" + recherche.trim().toLowerCase() + "%";
|
||||
return organisationRepository.getEntityManager()
|
||||
.createQuery(
|
||||
"SELECT COUNT(o) FROM Organisation o WHERE LOWER(o.nom) LIKE :p OR LOWER(o.description) LIKE :p",
|
||||
Long.class)
|
||||
.setParameter("p", pattern)
|
||||
.getSingleResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Recherche avancée d'organisations
|
||||
*
|
||||
* @param nom nom (optionnel)
|
||||
* @param nom nom (optionnel)
|
||||
* @param typeOrganisation type (optionnel)
|
||||
* @param statut statut (optionnel)
|
||||
* @param ville ville (optionnel)
|
||||
* @param region région (optionnel)
|
||||
* @param pays pays (optionnel)
|
||||
* @param page numéro de page
|
||||
* @param size taille de la page
|
||||
* @param statut statut (optionnel)
|
||||
* @param ville ville (optionnel)
|
||||
* @param region région (optionnel)
|
||||
* @param pays pays (optionnel)
|
||||
* @param page numéro de page
|
||||
* @param size taille de la page
|
||||
* @return liste filtrée des organisations
|
||||
*/
|
||||
public List<Organisation> rechercheAvancee(
|
||||
@@ -243,7 +411,7 @@ public class OrganisationService {
|
||||
/**
|
||||
* Active une organisation
|
||||
*
|
||||
* @param id l'ID de l'organisation
|
||||
* @param id l'ID de l'organisation
|
||||
* @param utilisateur l'utilisateur effectuant l'activation
|
||||
* @return l'organisation activée
|
||||
*/
|
||||
@@ -251,10 +419,9 @@ public class OrganisationService {
|
||||
public Organisation activerOrganisation(UUID id, String utilisateur) {
|
||||
LOG.infof("Activation de l'organisation ID: %s", id);
|
||||
|
||||
Organisation organisation =
|
||||
organisationRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Organisation non trouvée avec l'ID: " + id));
|
||||
Organisation organisation = organisationRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Organisation non trouvée avec l'ID: " + id));
|
||||
|
||||
organisation.activer(utilisateur);
|
||||
|
||||
@@ -265,7 +432,7 @@ public class OrganisationService {
|
||||
/**
|
||||
* Suspend une organisation
|
||||
*
|
||||
* @param id l'UUID de l'organisation
|
||||
* @param id l'UUID de l'organisation
|
||||
* @param utilisateur l'utilisateur effectuant la suspension
|
||||
* @return l'organisation suspendue
|
||||
*/
|
||||
@@ -273,10 +440,9 @@ public class OrganisationService {
|
||||
public Organisation suspendreOrganisation(UUID id, String utilisateur) {
|
||||
LOG.infof("Suspension de l'organisation ID: %s", id);
|
||||
|
||||
Organisation organisation =
|
||||
organisationRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Organisation non trouvée avec l'ID: " + id));
|
||||
Organisation organisation = organisationRepository
|
||||
.findByIdOptional(id)
|
||||
.orElseThrow(() -> new NotFoundException("Organisation non trouvée avec l'ID: " + id));
|
||||
|
||||
organisation.suspendre(utilisateur);
|
||||
|
||||
@@ -285,46 +451,53 @@ public class OrganisationService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtient les statistiques des organisations
|
||||
* Obtient les statistiques des organisations (clés compatibles client DTO
|
||||
* StatistiquesAssociationDTO).
|
||||
*
|
||||
* @return map contenant les statistiques
|
||||
*/
|
||||
public Map<String, Object> obtenirStatistiques() {
|
||||
LOG.info("Calcul des statistiques des organisations");
|
||||
|
||||
long totalOrganisations = organisationRepository.count();
|
||||
long organisationsActives = organisationRepository.countActives();
|
||||
long organisationsInactives = totalOrganisations - organisationsActives;
|
||||
long nouvellesOrganisations30Jours =
|
||||
organisationRepository.countNouvellesOrganisations(LocalDate.now().minusDays(30));
|
||||
long total = organisationRepository.count();
|
||||
long actives = organisationRepository.countActives();
|
||||
long inactives = total - actives;
|
||||
long suspendues = organisationRepository.countByStatut("SUSPENDUE");
|
||||
long dissoutes = organisationRepository.countByStatut("DISSOLUE");
|
||||
long nouvelles30Jours = organisationRepository.countNouvellesOrganisations(LocalDate.now().minusDays(30));
|
||||
double tauxActivite = total > 0 ? (actives * 100.0 / total) : 0.0;
|
||||
|
||||
return Map.of(
|
||||
"totalOrganisations", totalOrganisations,
|
||||
"organisationsActives", organisationsActives,
|
||||
"organisationsInactives", organisationsInactives,
|
||||
"nouvellesOrganisations30Jours", nouvellesOrganisations30Jours,
|
||||
"tauxActivite",
|
||||
totalOrganisations > 0 ? (organisationsActives * 100.0 / totalOrganisations) : 0.0,
|
||||
"timestamp", LocalDateTime.now());
|
||||
List<Organisation> all = organisationRepository.listAll();
|
||||
Map<String, Long> repartitionType = all.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
o -> o.getTypeOrganisation() != null ? o.getTypeOrganisation() : "NON_DEFINI",
|
||||
Collectors.counting()));
|
||||
// TODO Cat.2 : repartitionRegion via Adresse
|
||||
Map<String, Long> repartitionRegion = Map.of();
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("totalAssociations", total);
|
||||
map.put("associationsActives", actives);
|
||||
map.put("associationsInactives", inactives);
|
||||
map.put("associationsSuspendues", suspendues);
|
||||
map.put("associationsDissoutes", dissoutes);
|
||||
map.put("nouvellesAssociations30Jours", nouvelles30Jours);
|
||||
map.put("tauxActivite", tauxActivite);
|
||||
map.put("repartitionParType", repartitionType);
|
||||
map.put("repartitionParRegion", repartitionRegion);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convertit une entité Organisation en DTO
|
||||
*
|
||||
* @param organisation l'entité à convertir
|
||||
* @return le DTO correspondant
|
||||
* Convertit une entité Organisation en DTO complet
|
||||
*/
|
||||
public OrganisationDTO convertToDTO(Organisation organisation) {
|
||||
public OrganisationResponse convertToResponse(Organisation organisation) {
|
||||
if (organisation == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
OrganisationDTO dto = new OrganisationDTO();
|
||||
|
||||
// Conversion de l'ID UUID vers UUID (pas de conversion nécessaire maintenant)
|
||||
OrganisationResponse dto = new OrganisationResponse();
|
||||
dto.setId(organisation.getId());
|
||||
|
||||
// Informations de base
|
||||
dto.setNom(organisation.getNom());
|
||||
dto.setNomCourt(organisation.getNomCourt());
|
||||
dto.setDescription(organisation.getDescription());
|
||||
@@ -332,11 +505,6 @@ public class OrganisationService {
|
||||
dto.setTelephone(organisation.getTelephone());
|
||||
dto.setTelephoneSecondaire(organisation.getTelephoneSecondaire());
|
||||
dto.setEmailSecondaire(organisation.getEmailSecondaire());
|
||||
dto.setAdresse(organisation.getAdresse());
|
||||
dto.setVille(organisation.getVille());
|
||||
dto.setCodePostal(organisation.getCodePostal());
|
||||
dto.setRegion(organisation.getRegion());
|
||||
dto.setPays(organisation.getPays());
|
||||
dto.setLatitude(organisation.getLatitude());
|
||||
dto.setLongitude(organisation.getLongitude());
|
||||
dto.setSiteWeb(organisation.getSiteWeb());
|
||||
@@ -346,98 +514,169 @@ public class OrganisationService {
|
||||
dto.setActivitesPrincipales(organisation.getActivitesPrincipales());
|
||||
dto.setNombreMembres(organisation.getNombreMembres());
|
||||
dto.setNombreAdministrateurs(organisation.getNombreAdministrateurs());
|
||||
if (organisation.getId() != null) {
|
||||
long countEvenements = evenementRepository.countActifsByOrganisationId(organisation.getId());
|
||||
dto.setNombreEvenements((int) countEvenements);
|
||||
} else {
|
||||
dto.setNombreEvenements(0);
|
||||
}
|
||||
dto.setBudgetAnnuel(organisation.getBudgetAnnuel());
|
||||
dto.setDevise(organisation.getDevise());
|
||||
dto.setDateFondation(organisation.getDateFondation());
|
||||
dto.setNumeroEnregistrement(organisation.getNumeroEnregistrement());
|
||||
dto.setNiveauHierarchique(organisation.getNiveauHierarchique());
|
||||
|
||||
// Conversion de l'organisation parente (UUID → UUID, pas de conversion nécessaire)
|
||||
if (organisation.getOrganisationParenteId() != null) {
|
||||
dto.setOrganisationParenteId(organisation.getOrganisationParenteId());
|
||||
if (organisation.getOrganisationParente() != null) {
|
||||
dto.setOrganisationParenteId(organisation.getOrganisationParente().getId());
|
||||
dto.setOrganisationParenteNom(organisation.getOrganisationParente().getNom());
|
||||
}
|
||||
|
||||
// Conversion du type d'organisation (String → Enum)
|
||||
dto.setTypeOrganisation(organisation.getTypeOrganisation());
|
||||
dto.setTypeAssociation(organisation.getTypeOrganisation());
|
||||
dto.setStatut(organisation.getStatut());
|
||||
|
||||
// Résolution des libellés
|
||||
if (organisation.getTypeOrganisation() != null) {
|
||||
try {
|
||||
dto.setTypeOrganisation(
|
||||
TypeOrganisation.valueOf(organisation.getTypeOrganisation().toUpperCase()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Valeur par défaut si la conversion échoue
|
||||
LOG.warnf(
|
||||
"Type d'organisation inconnu: %s, utilisation de ASSOCIATION par défaut",
|
||||
organisation.getTypeOrganisation());
|
||||
dto.setTypeOrganisation(TypeOrganisation.ASSOCIATION);
|
||||
typeReferenceRepository.findByDomaineAndCode("TYPE_ORGANISATION", organisation.getTypeOrganisation())
|
||||
.ifPresent(ref -> {
|
||||
dto.setTypeOrganisationLibelle(ref.getLibelle());
|
||||
dto.setTypeLibelle(ref.getLibelle());
|
||||
});
|
||||
if (dto.getTypeLibelle() == null) {
|
||||
dto.setTypeLibelle(organisation.getTypeOrganisation());
|
||||
}
|
||||
} else {
|
||||
dto.setTypeOrganisation(TypeOrganisation.ASSOCIATION);
|
||||
}
|
||||
|
||||
// Conversion du statut (String → Enum)
|
||||
if (organisation.getStatut() != null) {
|
||||
try {
|
||||
dto.setStatut(
|
||||
StatutOrganisation.valueOf(organisation.getStatut().toUpperCase()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Valeur par défaut si la conversion échoue
|
||||
LOG.warnf(
|
||||
"Statut d'organisation inconnu: %s, utilisation de ACTIVE par défaut",
|
||||
organisation.getStatut());
|
||||
dto.setStatut(StatutOrganisation.ACTIVE);
|
||||
}
|
||||
} else {
|
||||
dto.setStatut(StatutOrganisation.ACTIVE);
|
||||
typeReferenceRepository.findByDomaineAndCode("STATUT_ORGANISATION", organisation.getStatut())
|
||||
.ifPresent(ref -> {
|
||||
dto.setStatutLibelle(ref.getLibelle());
|
||||
dto.setStatutSeverity(ref.getCouleur()); // ou severity si dispo
|
||||
});
|
||||
}
|
||||
|
||||
// Champs de base DTO
|
||||
dto.setDateCreation(organisation.getDateCreation());
|
||||
dto.setDateModification(organisation.getDateModification());
|
||||
dto.setCreePar(organisation.getCreePar());
|
||||
dto.setModifiePar(organisation.getModifiePar());
|
||||
dto.setActif(organisation.getActif());
|
||||
dto.setVersion(organisation.getVersion() != null ? organisation.getVersion() : 0L);
|
||||
|
||||
// Champs par défaut
|
||||
dto.setOrganisationPublique(
|
||||
organisation.getOrganisationPublique() != null
|
||||
? organisation.getOrganisationPublique()
|
||||
: true);
|
||||
organisation.getOrganisationPublique() != null ? organisation.getOrganisationPublique() : true);
|
||||
dto.setAccepteNouveauxMembres(
|
||||
organisation.getAccepteNouveauxMembres() != null
|
||||
? organisation.getAccepteNouveauxMembres()
|
||||
: true);
|
||||
organisation.getAccepteNouveauxMembres() != null ? organisation.getAccepteNouveauxMembres() : true);
|
||||
dto.setCotisationObligatoire(
|
||||
organisation.getCotisationObligatoire() != null
|
||||
? organisation.getCotisationObligatoire()
|
||||
: false);
|
||||
organisation.getCotisationObligatoire() != null ? organisation.getCotisationObligatoire() : false);
|
||||
dto.setMontantCotisationAnnuelle(organisation.getMontantCotisationAnnuelle());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convertit un DTO en entité Organisation
|
||||
*
|
||||
* @param dto le DTO à convertir
|
||||
* @return l'entité correspondante
|
||||
* Convertit une entité Organisation en Summary DTO
|
||||
*/
|
||||
public Organisation convertFromDTO(OrganisationDTO dto) {
|
||||
if (dto == null) {
|
||||
public OrganisationSummaryResponse convertToSummaryResponse(Organisation organisation) {
|
||||
if (organisation == null)
|
||||
return null;
|
||||
|
||||
String typeLibelle = organisation.getTypeOrganisation();
|
||||
if (organisation.getTypeOrganisation() != null) {
|
||||
typeLibelle = typeReferenceRepository
|
||||
.findByDomaineAndCode("TYPE_ORGANISATION", organisation.getTypeOrganisation())
|
||||
.map(dev.lions.unionflow.server.entity.TypeReference::getLibelle)
|
||||
.orElse(organisation.getTypeOrganisation());
|
||||
}
|
||||
|
||||
String statutLibelle = organisation.getStatut();
|
||||
String statutSeverity = null;
|
||||
if (organisation.getStatut() != null) {
|
||||
var refOpt = typeReferenceRepository.findByDomaineAndCode("STATUT_ORGANISATION", organisation.getStatut());
|
||||
if (refOpt.isPresent()) {
|
||||
statutLibelle = refOpt.get().getLibelle();
|
||||
statutSeverity = refOpt.get().getCouleur();
|
||||
}
|
||||
}
|
||||
|
||||
return new OrganisationSummaryResponse(
|
||||
organisation.getId(),
|
||||
organisation.getNom(),
|
||||
organisation.getNomCourt(),
|
||||
organisation.getTypeOrganisation(),
|
||||
typeLibelle,
|
||||
organisation.getStatut(),
|
||||
statutLibelle,
|
||||
statutSeverity,
|
||||
organisation.getNombreMembres(),
|
||||
organisation.getActif());
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée une entité Organisation depuis CreateOrganisationRequest
|
||||
*/
|
||||
public Organisation convertFromCreateRequest(CreateOrganisationRequest req) {
|
||||
if (req == null)
|
||||
return null;
|
||||
return Organisation.builder()
|
||||
.nom(dto.getNom())
|
||||
.nomCourt(dto.getNomCourt())
|
||||
.description(dto.getDescription())
|
||||
.email(dto.getEmail())
|
||||
.telephone(dto.getTelephone())
|
||||
.adresse(dto.getAdresse())
|
||||
.ville(dto.getVille())
|
||||
.codePostal(dto.getCodePostal())
|
||||
.region(dto.getRegion())
|
||||
.pays(dto.getPays())
|
||||
.siteWeb(dto.getSiteWeb())
|
||||
.objectifs(dto.getObjectifs())
|
||||
.activitesPrincipales(dto.getActivitesPrincipales())
|
||||
.nom(req.nom())
|
||||
.nomCourt(req.nomCourt())
|
||||
.description(req.description())
|
||||
.email(req.email())
|
||||
.telephone(req.telephone())
|
||||
.telephoneSecondaire(req.telephoneSecondaire())
|
||||
.emailSecondaire(req.emailSecondaire())
|
||||
.latitude(req.latitude())
|
||||
.longitude(req.longitude())
|
||||
.siteWeb(req.siteWeb())
|
||||
.logo(req.logo())
|
||||
.reseauxSociaux(req.reseauxSociaux())
|
||||
.objectifs(req.objectifs())
|
||||
.activitesPrincipales(req.activitesPrincipales())
|
||||
.certifications(req.certifications())
|
||||
.partenaires(req.partenaires())
|
||||
.notes(req.notes())
|
||||
.dateFondation(req.dateFondation())
|
||||
.numeroEnregistrement(req.numeroEnregistrement())
|
||||
.typeOrganisation(req.typeOrganisation() != null ? req.typeOrganisation() : "ASSOCIATION")
|
||||
.statut(req.statut() != null ? req.statut() : "ACTIVE")
|
||||
.budgetAnnuel(req.budgetAnnuel())
|
||||
.devise(req.devise() != null ? req.devise() : defaultsService.getDevise())
|
||||
.cotisationObligatoire(req.cotisationObligatoire() != null ? req.cotisationObligatoire() : false)
|
||||
.montantCotisationAnnuelle(req.montantCotisationAnnuelle())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée une entité Organisation depuis UpdateOrganisationRequest
|
||||
*/
|
||||
public Organisation convertFromUpdateRequest(UpdateOrganisationRequest req) {
|
||||
if (req == null)
|
||||
return null;
|
||||
return Organisation.builder()
|
||||
.nom(req.nom())
|
||||
.nomCourt(req.nomCourt())
|
||||
.description(req.description())
|
||||
.email(req.email())
|
||||
.telephone(req.telephone())
|
||||
.telephoneSecondaire(req.telephoneSecondaire())
|
||||
.emailSecondaire(req.emailSecondaire())
|
||||
.latitude(req.latitude())
|
||||
.longitude(req.longitude())
|
||||
.siteWeb(req.siteWeb())
|
||||
.logo(req.logo())
|
||||
.reseauxSociaux(req.reseauxSociaux())
|
||||
.objectifs(req.objectifs())
|
||||
.activitesPrincipales(req.activitesPrincipales())
|
||||
.certifications(req.certifications())
|
||||
.partenaires(req.partenaires())
|
||||
.notes(req.notes())
|
||||
.dateFondation(req.dateFondation())
|
||||
.numeroEnregistrement(req.numeroEnregistrement())
|
||||
.typeOrganisation(req.typeOrganisation())
|
||||
.statut(req.statut())
|
||||
.budgetAnnuel(req.budgetAnnuel())
|
||||
.devise(req.devise() != null ? req.devise() : defaultsService.getDevise())
|
||||
.cotisationObligatoire(req.cotisationObligatoire() != null ? req.cotisationObligatoire() : false)
|
||||
.montantCotisationAnnuelle(req.montantCotisationAnnuelle())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user