Kenmegne
7 days ago 1bc8864f134272c4bf23a9b05831803a423a4771
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
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.megatim.apifdxweb.core.impl.helper;
 
import com.megatim.apifdxweb.core.ifaces.helper.RoutingChecker;
import com.megatim.apifdxweb.core.ifaces.referentiel.ParticipantManager;
import com.megatim.apifdxweb.core.ifaces.referentiel.RoutageManager;
import com.megatim.apifdxweb.core.ifaces.referentiel.natureproduction.NatureProductionFichierManager;
import com.megatim.apifdxweb.tools.exceptions.ApplicationForbidenException;
import com.megatim.fdxcommons.model.integration.ColumnDefinition;
import com.megatim.fdxcommons.model.pojo.DataInMemory;
import com.megatim.fdxcommons.model.referentiel.TypeFichier;
import com.megatim.fdxcommons.model.referentiel.natureproduction.NatureProduction;
import com.megatim.fdxcommons.model.referentiel.natureproduction.NatureProductionFichier;
import com.megatim.fdxcommons.model.referentiel.natureproduction.NatureProductionFichierId;
import com.megatim.fdxcommons.tools.exceptions.CommonRessourceNotFoundException;
import java.util.Map;
import javax.enterprise.context.Dependent;
import javax.inject.Inject;
 
/**
 *
 * @author lenovo
 */
@Dependent
public class RoutingCheckerImpl implements RoutingChecker {
 
    @Inject
    protected ParticipantManager participantManager;
 
    @Inject
    private RoutageManager routageManager;
 
    @Inject
    private NatureProductionFichierManager natureProdFichManager;
 
    @Override
    public void stopIfNatureProductionIsNotCumulative(String codeTypeFichier, String referentielEncours) {
        NatureProductionFichierId id = new NatureProductionFichierId(codeTypeFichier, referentielEncours);
        NatureProductionFichier natureProdFich = natureProdFichManager.getById(id);
 
        if (natureProdFich == null || !natureProdFich.getNatureProduction().equals(NatureProduction.CUMMULATIVE)) {
            throw new ApplicationForbidenException("Cette opération n'est pas accessible pour ce type de fichier");
        }
    }
 
    @Override
    public void stopIfNotProducer(String codeTypeFichier, DataInMemory dataInMemory, String codeParticipant) {
        if (!dataInMemory.getTypeFichierToParticipantsEnvoi().get(codeTypeFichier).contains(codeParticipant)) {
            throw new ApplicationForbidenException("Impossible de continuer la requête car le participant " + codeParticipant + " n'est pas producteur du type de fichier " + codeTypeFichier);
        }
    }
 
    @Override
    public void stopIfNotConsumer(String codeTypeFichier, DataInMemory dataInMemory, String codeParticipant) {
        if (!dataInMemory.getTypeFichierToParticipantsReception().get(codeTypeFichier).contains(codeParticipant)) {
            throw new ApplicationForbidenException("Impossible de continuer la requête car le participant " + codeParticipant + " n'est pas consommateur du type de fichier " + codeTypeFichier);
        }
    }
 
    @Override
    public void stopIfCurrentReferentielNotExists(DataInMemory data) {
        if (data.getReferentielEnCours() == null) {
            throw new CommonRessourceNotFoundException("Aucun référentiel en cours");
        }
    }
 
    /**
     * Check whether there is a current ref in database
     *
     * @param codeTypeFichier
     * @param dataInMemory
     */
    @Override
    public void stopIfTypeFichierNotExists(String codeTypeFichier, DataInMemory dataInMemory) {
        TypeFichier typeFich = dataInMemory.getCodeTypeFichierToTypeFichiers().get(codeTypeFichier);
 
        if (typeFich == null) {
            throw new CommonRessourceNotFoundException("TypeFichier '" + codeTypeFichier + "' inexistant");
        }
 
        Map<String, ColumnDefinition> columnsDefinitionMap = dataInMemory.getTypeFichierToColumnDefinitions().get(codeTypeFichier);
        if (columnsDefinitionMap == null || columnsDefinitionMap.isEmpty()) {
            throw new CommonRessourceNotFoundException("La structure du typeFichier '" + codeTypeFichier + "' est introuvable");
        }
    }
 
}