• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Samuel-Oliveira / Java_NFe / #2

14 Jun 2026 07:31PM UTC coverage: 14.623%. First build
#2

push

Samuel-Oliveira
Merge branch 'develop'

299 of 1379 new or added lines in 130 files covered. (21.68%)

2702 of 18478 relevant lines covered (14.62%)

0.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.02
/src/main/java/br/com/swconsultoria/nfe/util/EpecUtil.java
1
package br.com.swconsultoria.nfe.util;
2

3
import br.com.swconsultoria.nfe.Assinar;
4
import br.com.swconsultoria.nfe.dom.ConfiguracoesNfe;
5
import br.com.swconsultoria.nfe.dom.Evento;
6
import br.com.swconsultoria.nfe.dom.enuns.AssinaturaEnum;
7
import br.com.swconsultoria.nfe.dom.enuns.EventosEnum;
8
import br.com.swconsultoria.nfe.exception.NfeException;
9
import br.com.swconsultoria.nfe.schemas_eventos.TEnvEventoEpec;
10
import br.com.swconsultoria.nfe.schemas_eventos.TEventoEpec;
11
import br.com.swconsultoria.nfe.schemas_eventos.TUf;
12
import br.com.swconsultoria.nfe.schemas_eventos.TProcEventoEpec;
13
import br.com.swconsultoria.nfe.schemas_eventos.TRetEnvEventoEpec;
14

15
import javax.xml.bind.JAXBException;
16
import java.util.Collections;
17
import java.util.List;
18

19
/**
20
 * @author Samuel Oliveira - samuk.exe@hotmail.com
21
 * Data: 02/03/2019 - 22:51
22
 */
23
public class EpecUtil {
24

25
    private EpecUtil() {}
26

27
    /**
28
     * MOnta o Evento de epec Lote
29
     *
30
     * @param epec
31
     * @param configuracao
32
     * @return
33
     * @throws NfeException
34
     */
35
    public static TEnvEventoEpec montaEpec(Evento epec, ConfiguracoesNfe configuracao) throws NfeException {
36
        return montaEpec(Collections.singletonList(epec), configuracao);
1✔
37
    }
38

39
    /**
40
     * MOnta o Evento de epec Lote
41
     *
42
     * @param listaEpec
43
     * @param configuracao
44
     * @return
45
     * @throws NfeException
46
     */
47
    public static TEnvEventoEpec montaEpec(List<Evento> listaEpec, ConfiguracoesNfe configuracao) throws NfeException {
48

49
        if (listaEpec.size() > 20) {
1✔
50
            throw new NfeException("Podem ser enviados no máximo 20 eventos no Lote.");
1✔
51
        }
52

53
        TEnvEventoEpec enviEvento = new TEnvEventoEpec();
1✔
54
        enviEvento.setVersao(ConstantesUtil.VERSAO.EVENTO_EPEC);
1✔
55
        enviEvento.setIdLote("1");
1✔
56

57
        listaEpec.forEach(epec -> {
1✔
58

59
            String id = "ID" + EventosEnum.EPEC.getCodigo() + epec.getChave() + "01";
1✔
60

61
            TEventoEpec eventoEpec = new TEventoEpec();
1✔
62
            eventoEpec.setVersao(ConstantesUtil.VERSAO.EVENTO_EPEC);
1✔
63

64
            TEventoEpec.InfEvento infoEvento = new TEventoEpec.InfEvento();
1✔
65
            infoEvento.setId(id);
1✔
66
            infoEvento.setCOrgao("91");
1✔
67
            infoEvento.setTpAmb(configuracao.getAmbiente().getCodigo());
1✔
68

69
            infoEvento.setCPF(epec.getCpf());
1✔
70
            infoEvento.setCNPJ(epec.getCnpj());
1✔
71

72
            infoEvento.setChNFe(epec.getChave());
1✔
73
            infoEvento.setDhEvento(XmlNfeUtil.dataNfe(epec.getDataEvento(), configuracao.getZoneId()));
1✔
74
            infoEvento.setTpEvento(EventosEnum.EPEC.getCodigo());
1✔
75
            infoEvento.setNSeqEvento("1");
1✔
76
            infoEvento.setVerEvento(ConstantesUtil.VERSAO.EVENTO_EPEC);
1✔
77

78
            TEventoEpec.InfEvento.DetEventoEpec detEvento = new TEventoEpec.InfEvento.DetEventoEpec();
1✔
79
            detEvento.setVersao(ConstantesUtil.VERSAO.EVENTO_EPEC);
1✔
80
            detEvento.setDescEvento("EPEC");
1✔
81
            detEvento.setCOrgaoAutor(configuracao.getEstado().getCodigoUF());
1✔
82
            detEvento.setTpAutor("1");
1✔
83
            detEvento.setVerAplic("1.0.0");
1✔
84
            detEvento.setDhEmi(XmlNfeUtil.dataNfe(epec.getDataEvento(), configuracao.getZoneId()));
1✔
85
            detEvento.setTpNF(epec.getEventoEpec().getTipoNF());
1✔
86
            detEvento.setIE(epec.getEventoEpec().getIeEmitente());
1✔
87

88
            TEventoEpec.InfEvento.DetEventoEpec.Dest dest = new TEventoEpec.InfEvento.DetEventoEpec.Dest();
1✔
89
            dest.setUF(TUf.valueOf(epec.getEventoEpec().getEstadoDestinatario().toString()));
1✔
90
            dest.setCNPJ(epec.getEventoEpec().getCnpjDestinatario());
1✔
91
            dest.setCPF(epec.getEventoEpec().getCpfDestinatario());
1✔
92
            dest.setIE(epec.getEventoEpec().getIeDestinatario());
1✔
93
            dest.setVNF(epec.getEventoEpec().getvNF());
1✔
94
            dest.setVICMS(epec.getEventoEpec().getvICMS());
1✔
95
            dest.setVST(epec.getEventoEpec().getvST());
1✔
96
            detEvento.setDest(dest);
1✔
97

98
            infoEvento.setDetEvento(detEvento);
1✔
99
            eventoEpec.setInfEvento(infoEvento);
1✔
100

101
            enviEvento.getEvento().add(eventoEpec);
1✔
102

103
        });
1✔
104

105
        return enviEvento;
1✔
106
    }
107

108
    /**
109
     * Cria o ProcEvento de CCe
110
     *
111
     * @param config
112
     * @param enviEvento
113
     * @param retorno
114
     * @return
115
     * @throws JAXBException
116
     * @throws NfeException
117
     */
118
    public static String criaProcEventoEpec(ConfiguracoesNfe config, TEnvEventoEpec enviEvento, TRetEnvEventoEpec retorno) throws JAXBException, NfeException {
119

120
        String xml = XmlNfeUtil.objectToXml(enviEvento, config.getEncode());
×
121
        xml = xml.replaceAll(" xmlns:ns2=\"http://www.w3.org/2000/09/xmldsig#\"", "");
×
122
        xml = xml.replace("<evento v", "<evento xmlns=\"http://www.portalfiscal.inf.br/nfe\" v");
×
123

124
        String assinado = Assinar.assinaNfe(ConfiguracoesUtil.iniciaConfiguracoes(config), xml, AssinaturaEnum.EVENTO);
×
125

NEW
126
        TProcEventoEpec procEvento = new TProcEventoEpec();
×
NEW
127
        procEvento.setEvento(XmlNfeUtil.xmlToObject(assinado, TEnvEventoEpec.class).getEvento().get(0));
×
128
        procEvento.setRetEvento(retorno.getRetEvento().get(0));
×
129
        procEvento.setVersao(ConstantesUtil.VERSAO.EVENTO_EPEC);
×
130

131
        return XmlNfeUtil.objectToXml(procEvento, config.getEncode());
×
132
    }
133

134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc