From 23a46b4be35277e06ec89f48730eeb694e686be8 Mon Sep 17 00:00:00 2001
From: Kenmegne <stephanie.kenmegne@gmail.com>
Date: Thu, 18 Jun 2026 15:40:06 +0000
Subject: [PATCH] add fdx-commons and fdx-consultation
---
fdx-consultation/fdxconsultation-dao-impl/src/main/java/com/megatim/fdxconsultation/dao/searchs/UserParticipantDAOIml.java | 81 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 81 insertions(+), 0 deletions(-)
diff --git a/fdx-consultation/fdxconsultation-dao-impl/src/main/java/com/megatim/fdxconsultation/dao/searchs/UserParticipantDAOIml.java b/fdx-consultation/fdxconsultation-dao-impl/src/main/java/com/megatim/fdxconsultation/dao/searchs/UserParticipantDAOIml.java
new file mode 100644
index 0000000..c5a8e16
--- /dev/null
+++ b/fdx-consultation/fdxconsultation-dao-impl/src/main/java/com/megatim/fdxconsultation/dao/searchs/UserParticipantDAOIml.java
@@ -0,0 +1,81 @@
+package com.megatim.fdxconsultation.dao.searchs;
+
+import com.megatim.fdxcommons.model.referentiel.Participant;
+import com.megatim.fdxconsultation.dao.ifaces.searchs.UserParticipantDAO;
+import com.megatim.fdxconsultation.model.searchentities.ParticipantSearch;
+import java.util.List;
+import javax.enterprise.context.Dependent;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+/**
+ *
+ * @author Gabuntu
+ */
+@Dependent
+public class UserParticipantDAOIml implements UserParticipantDAO {
+
+ @PersistenceContext(unitName = "fdxConsultationPersistenceUnit")
+ protected EntityManager em;
+
+ @Override
+ public List<Participant> findUserParticipantsWithPagination(String userName, ParticipantSearch participantSearch, int pageNumber, int pageSize) {
+ StringBuilder queryString = new StringBuilder("SELECT t from Participant t ")
+ .append(" WHERE ((SELECT COALESCE(COUNT(u), 0) FROM User u JOIN u.participants tf WHERE u.userName = :username AND tf = t) > 0)");
+ extendsQuery(queryString, participantSearch);
+ Query query = em.createQuery(queryString.toString()).setParameter("username", userName);
+ extendsParameter(query, participantSearch);
+ query.setFirstResult((pageNumber - 1) * pageSize).setMaxResults(pageSize);
+ return (List<Participant>) query.getResultList();
+ }
+
+ @Override
+ public List<Participant> findAllUserParticipants(String userName, ParticipantSearch participantSearch) {
+ StringBuilder queryString = new StringBuilder("SELECT t from Participant t ")
+ .append(" WHERE ((SELECT COALESCE(COUNT(u), 0) FROM User u JOIN u.participants tf WHERE u.userName = :username AND tf = t) > 0)");
+ extendsQuery(queryString, participantSearch);
+ Query query = em.createQuery(queryString.toString()).setParameter("username", userName);
+ extendsParameter(query, participantSearch);
+ return (List<Participant>) query.getResultList();
+ }
+
+ @Override
+ public List<Participant> findUserParticipants(String userName) {
+ return (List<Participant>) em.createQuery("SELECT t from Participant t "
+ + " WHERE ((SELECT COALESCE(COUNT(u), 0) FROM User u JOIN u.participants tf WHERE u.userName = :username AND tf = t) > 0)")
+ .setParameter("username", userName)
+ .getResultList();
+ }
+
+ @Override
+ public Long countUserParticipants(String userName, ParticipantSearch participantSearch) {
+ StringBuilder queryString = new StringBuilder("SELECT t from Participant t ")
+ .append(" WHERE ((SELECT COALESCE(COUNT(u), 0) FROM User u JOIN u.participants tf WHERE u.userName = :username AND tf = t) > 0)");
+ extendsQuery(queryString, participantSearch);
+ Query query = em.createQuery(queryString.toString()).setParameter("username", userName);
+ extendsParameter(query, participantSearch);
+ return (long) query.getResultList().size();
+ }
+
+ private void extendsQuery(StringBuilder queryString, ParticipantSearch participantSearch) {
+ if (participantSearch.getCode() != null) {
+ queryString.append(" AND t.code LIKE :code");
+ }
+ if (participantSearch.getLibelle() != null) {
+ queryString.append(" AND t.libelle LIKE :libelle");
+ }
+ }
+
+ private void extendsParameter(Query query, ParticipantSearch participantSearch) {
+ if (participantSearch.getCode() != null) {
+ //System.out.println("typeFichierSearch.getCode() " + "%" + typeFichierSearch.getCode() + "%");
+ query.setParameter("code", "%" + participantSearch.getCode() + "%");
+ }
+ if (participantSearch.getLibelle() != null) {
+ //System.out.println("typeFichierSearch.getCode() " + "%" + typeFichierSearch.getCode() + "%");
+ query.setParameter("libelle", "%" + participantSearch.getLibelle() + "%");
+ }
+ }
+
+}
--
Gitblit v1.10.0