package com.megatim.fdxconsultation.dao.ifaces.referentiel;
|
|
import com.megatim.fdxcommons.model.referentiel.Participant;
|
import com.megatim.fdxcommons.model.referentiel.Routage;
|
import com.megatim.fdxcommons.model.referentiel.RoutageId;
|
import javax.persistence.EntityManager;
|
import com.megatim.fdxconsultation.dao.ifaces.abstracts.CustomDAOWithCriteriaEntityIfaces;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Optional;
|
|
/**
|
*
|
* @author ASUS
|
*/
|
public interface RoutageDAO extends CustomDAOWithCriteriaEntityIfaces<Routage, RoutageId> {
|
|
@Override
|
EntityManager getEntityManager();
|
|
@Override
|
public Routage getById(RoutageId id);
|
|
public default List<Participant> getParticipantsForSend(String versionReferentiel, String codeTypeFichier) {
|
List<Participant> participantsEnvoi = new ArrayList<>();
|
Optional<Routage> optRoutage = getEntityManager().createQuery("SELECT r FROM Routage r "
|
+ "LEFT JOIN r.participantsEnvoi p "
|
+ "LEFT JOIN r.noeudsEnvoi n "
|
+ "LEFT JOIN r.groupeParticipantsEnvoi gp LEFT JOIN gp.participants pa "
|
+ "LEFT JOIN r.groupeNoeudsEnvoi gn LEFT JOIN gn.noeuds no "
|
+ "WHERE r.referentiel.version = :versionReferentiel AND r.typeFichier.code = :codeTypeFichier ")
|
.setParameter("versionReferentiel", versionReferentiel)
|
.setParameter("codeTypeFichier", codeTypeFichier)
|
.getResultList().stream().findFirst();
|
|
if (optRoutage.isPresent()) {
|
Routage routage = optRoutage.get();
|
participantsEnvoi.addAll(routage.getParticipantsEnvoi());
|
routage.getNoeudsEnvoi().stream().forEach(n -> {
|
participantsEnvoi.add(n.getParticipant());
|
});
|
routage.getGroupeNoeudsEnvoi().stream().forEach(gn -> gn.getNoeuds().stream().forEach(n -> participantsEnvoi.add(n.getParticipant())));
|
routage.getGroupeParticipantsEnvoi().stream().forEach(gp -> participantsEnvoi.addAll(gp.getParticipants()));
|
}
|
|
return participantsEnvoi;
|
}
|
|
default List<Participant> getParticipantForReceive(String versionReferentiel, String codeTypeFichier) {
|
List<Participant> participantsReception = new ArrayList<>();
|
Optional<Routage> optRoutage = getEntityManager().createQuery("SELECT r FROM Routage r "
|
+ "LEFT JOIN r.participantsReception p "
|
+ "LEFT JOIN r.noeudsReception n "
|
+ "LEFT JOIN r.groupeParticipantsReception gp LEFT JOIN gp.participants pa "
|
+ "LEFT JOIN r.groupeNoeudsReception gn LEFT JOIN gn.noeuds no "
|
+ "WHERE r.referentiel.version = :versionReferentiel AND r.typeFichier.code = :codeTypeFichier ")
|
.setParameter("versionReferentiel", versionReferentiel)
|
.setParameter("codeTypeFichier", codeTypeFichier)
|
.getResultList().stream().findFirst();
|
|
if (optRoutage.isPresent()) {
|
Routage routage = optRoutage.get();
|
participantsReception.addAll(routage.getParticipantsReception());
|
routage.getNoeudsReception().stream().forEach(n -> {
|
participantsReception.add(n.getParticipant());
|
});
|
routage.getGroupeNoeudsReception().stream().forEach(gn -> gn.getNoeuds().stream().forEach(n -> participantsReception.add(n.getParticipant())));
|
routage.getGroupeParticipantsReception().stream().forEach(gp -> participantsReception.addAll(gp.getParticipants()));
|
}
|
|
return participantsReception;
|
}
|
}
|