Kenmegne
7 days ago 23a46b4be35277e06ec89f48730eeb694e686be8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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;
    }
}