Skip to content

Commit 7c613db

Browse files
Merge pull request #37 from ismaellawrenz/Cte-simplificado
Implementação do CTe simplificado
2 parents 10f0d3d + ce8a010 commit 7c613db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+87442
-2
lines changed

schemas.zip

6.83 KB
Binary file not shown.

src/main/java/br/com/swconsultoria/cte/Cte.java

+28
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import br.com.swconsultoria.cte.schema_400.cte.TCTe;
1010
import br.com.swconsultoria.cte.schema_400.cte.TRetCTe;
1111
import br.com.swconsultoria.cte.schema_400.cteOS.TCTeOS;
12+
import br.com.swconsultoria.cte.schema_400.cteSimp.TCTeSimp;
13+
import br.com.swconsultoria.cte.schema_400.cteSimp.TRetCTeSimp;
1214
import br.com.swconsultoria.cte.schema_400.evEPECCTe.TEvento;
1315
import br.com.swconsultoria.cte.schema_400.evEPECCTe.TRetEvento;
1416
import br.com.swconsultoria.cte.schema_400.retCTeOS.TRetCTeOS;
@@ -103,6 +105,20 @@ public static TCTeOS montaCteOS(ConfiguracoesCte configuracoesCte,
103105

104106
}
105107

108+
/**
109+
* Metodo para Montar a CTE simplificado.
110+
*
111+
* @param configuracoesCte
112+
* @param enviCTe
113+
* @param valida
114+
* @return
115+
* @throws CteException
116+
*/
117+
public static TCTeSimp montaCteSimp(ConfiguracoesCte configuracoesCte,
118+
TCTeSimp enviCTe, boolean valida) throws CteException {
119+
return EnvioCteSimp.montaCteSimp(ConfiguracoesUtil.iniciaConfiguracoes(configuracoesCte), enviCTe, valida);
120+
}
121+
106122
/**
107123
* Metodo para Enviar a CTE.
108124
*
@@ -130,6 +146,18 @@ public static TRetCTeOS enviarCteOS(ConfiguracoesCte configuracoesCte, TCTeOS en
130146
return EnvioCteOS.enviaCteOS(ConfiguracoesUtil.iniciaConfiguracoes(configuracoesCte), enviCTe);
131147
}
132148

149+
/**
150+
* Metodo para Enviar a CTE simplificado.
151+
*
152+
* @param configuracoesCte
153+
* @param enviCTe
154+
* @return
155+
* @throws CteException
156+
*/
157+
public static TRetCTeSimp enviarCteSimp(ConfiguracoesCte configuracoesCte, TCTeSimp enviCTe) throws CteException {
158+
return EnvioCteSimp.enviaCteSimp(ConfiguracoesUtil.iniciaConfiguracoes(configuracoesCte), enviCTe);
159+
}
160+
133161
/**
134162
* Metodo para Cancelar a CTE 4.00
135163
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package br.com.swconsultoria.cte;
2+
3+
import br.com.swconsultoria.cte.dom.ConfiguracoesCte;
4+
import br.com.swconsultoria.cte.dom.enuns.AssinaturaEnum;
5+
import br.com.swconsultoria.cte.dom.enuns.ServicosEnum;
6+
import br.com.swconsultoria.cte.exception.CteException;
7+
import br.com.swconsultoria.cte.schema_400.cteSimp.TCTeSimp;
8+
import br.com.swconsultoria.cte.schema_400.cteSimp.TRetCTeSimp;
9+
import br.com.swconsultoria.cte.util.WebServiceCteUtil;
10+
import br.com.swconsultoria.cte.util.XmlCteUtil;
11+
import br.com.swconsultoria.cte.wsdl.cte_recepcao_simp.CTeRecepcaoSimpV4Stub;
12+
import lombok.extern.java.Log;
13+
14+
import javax.xml.bind.JAXBException;
15+
import java.io.IOException;
16+
17+
/**
18+
* Classe Responsavel por Enviar o Cte simplificado.
19+
*
20+
* @author Ismael Luan Lawrenz
21+
*/
22+
@Log
23+
class EnvioCteSimp {
24+
25+
private EnvioCteSimp() {
26+
}
27+
28+
/**
29+
* Metodo para Montar a CTE simplificado
30+
*
31+
* @param config
32+
* @param cte
33+
* @param valida
34+
* @return TCTeSimp
35+
* @throws CteException
36+
*/
37+
static TCTeSimp montaCteSimp(ConfiguracoesCte config, TCTeSimp cte, boolean valida) throws CteException {
38+
try {
39+
40+
/**
41+
* Cria o xml
42+
*/
43+
String xml = XmlCteUtil.objectToXml(cte);
44+
45+
/**
46+
* Assina o Xml
47+
*/
48+
xml = Assinar.assinaCte(config, xml, AssinaturaEnum.CTE_SIMP);
49+
log.info("[XML-ASSINADO]: " + xml);
50+
51+
/**
52+
* Valida o Xml caso sejá selecionado True
53+
*/
54+
if (valida) {
55+
new Validar().validaXml(config, xml, ServicosEnum.ENVIO_CTE_SIMP);
56+
}
57+
58+
return XmlCteUtil.xmlToObject(xml, TCTeSimp.class);
59+
60+
} catch (Exception e) {
61+
throw new CteException(e);
62+
}
63+
64+
}
65+
66+
/**
67+
* Metodo para Enviar a CTE simplificado
68+
*
69+
* @param config
70+
* @param cte
71+
* @return TRetCTeSimp
72+
* @throws CteException
73+
*/
74+
static TRetCTeSimp enviaCteSimp(ConfiguracoesCte config, TCTeSimp cte) throws CteException {
75+
76+
try {
77+
78+
String xml = XmlCteUtil.objectToXml(cte);
79+
80+
log.info("[XML-ENVIO]: " + xml);
81+
82+
CTeRecepcaoSimpV4Stub.CteDadosMsg dadosMsg = new CTeRecepcaoSimpV4Stub.CteDadosMsg();
83+
dadosMsg.setCteDadosMsg(XmlCteUtil.xmlToGZip(xml));
84+
85+
CTeRecepcaoSimpV4Stub stub = new CTeRecepcaoSimpV4Stub(
86+
WebServiceCteUtil.getUrl(config, ServicosEnum.ENVIO_CTE_SIMP));
87+
CTeRecepcaoSimpV4Stub.CteRecepcaoSimpResult result = stub.cteRecepcaoSimp(dadosMsg);
88+
89+
TRetCTeSimp retCte = XmlCteUtil.xmlToObject(result.getExtraElement().toString(),
90+
TRetCTeSimp.class);
91+
92+
log.info("[XML-RETORNO]: " + XmlCteUtil.objectToXml(retCte));
93+
return retCte;
94+
95+
} catch (IOException | JAXBException e) {
96+
throw new CteException("Erro ao enviar CTe", e);
97+
}
98+
}
99+
100+
}

src/main/java/br/com/swconsultoria/cte/dom/enuns/AssinaturaEnum.java

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public enum AssinaturaEnum {
1111

1212
CTE("CTe","infCte"),
1313
CTE_OS ("CTeOS","infCte"),
14+
CTE_SIMP("CTeSimp","infCte"),
1415
EVENTO("eventoCTe","infEvento");
1516

1617
private final String tipo;

src/main/java/br/com/swconsultoria/cte/dom/enuns/ServicosEnum.java

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public enum ServicosEnum {
1616
CANCELAMENTO(Constants.RECEPCAO_EVENTO_4_00, "evCancCTe_v4.00.xsd"),
1717
EVENTO("", "eventoCTe_v4.00.xsd"),
1818
ENVIO_CTE_OS("CTeRecepcaoOS_4.00", "cteOS_v4.00.xsd"),
19+
ENVIO_CTE_SIMP("CTeRecepcaoSimp_4.00", "cteSimp_v4.00.xsd"),
1920
EPEC(Constants.RECEPCAO_EVENTO_4_00, "evEPECCTe_v4.00.xsd"),
2021
MULTIMODAL(Constants.RECEPCAO_EVENTO_4_00, "evRegMultimodal_v4.00.xsd"),
2122
CCE(Constants.RECEPCAO_EVENTO_4_00, "evCCeCTe_v4.00.xsd"),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
3+
4+
package br.com.swconsultoria.cte.schema_400.cteSimp;
5+
6+
import javax.xml.bind.annotation.*;
7+
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
8+
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
9+
10+
11+
/**
12+
* <p>Java class for KeyInfoType complex type.
13+
*
14+
* <p>The following schema fragment specifies the expected content contained within this class.
15+
*
16+
* <pre>
17+
* &lt;complexType name="KeyInfoType"&gt;
18+
* &lt;complexContent&gt;
19+
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
20+
* &lt;sequence&gt;
21+
* &lt;element name="X509Data" type="{http://www.w3.org/2000/09/xmldsig#}X509DataType"/&gt;
22+
* &lt;/sequence&gt;
23+
* &lt;attribute name="Id" type="{http://www.w3.org/2001/XMLSchema}ID" /&gt;
24+
* &lt;/restriction&gt;
25+
* &lt;/complexContent&gt;
26+
* &lt;/complexType&gt;
27+
* </pre>
28+
*
29+
*
30+
*/
31+
@XmlAccessorType(XmlAccessType.FIELD)
32+
@XmlType(name = "KeyInfoType", namespace = "http://www.w3.org/2000/09/xmldsig#", propOrder = {
33+
"x509Data"
34+
})
35+
public class KeyInfoType {
36+
37+
@XmlElement(name = "X509Data", required = true)
38+
protected X509DataType x509Data;
39+
@XmlAttribute(name = "Id")
40+
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
41+
@XmlID
42+
@XmlSchemaType(name = "ID")
43+
protected String id;
44+
45+
/**
46+
* Gets the value of the x509Data property.
47+
*
48+
* @return
49+
* possible object is
50+
* {@link X509DataType }
51+
*
52+
*/
53+
public X509DataType getX509Data() {
54+
return x509Data;
55+
}
56+
57+
/**
58+
* Sets the value of the x509Data property.
59+
*
60+
* @param value
61+
* allowed object is
62+
* {@link X509DataType }
63+
*
64+
*/
65+
public void setX509Data(X509DataType value) {
66+
this.x509Data = value;
67+
}
68+
69+
/**
70+
* Gets the value of the id property.
71+
*
72+
* @return
73+
* possible object is
74+
* {@link String }
75+
*
76+
*/
77+
public String getId() {
78+
return id;
79+
}
80+
81+
/**
82+
* Sets the value of the id property.
83+
*
84+
* @param value
85+
* allowed object is
86+
* {@link String }
87+
*
88+
*/
89+
public void setId(String value) {
90+
this.id = value;
91+
}
92+
93+
}

0 commit comments

Comments
 (0)