Skip to content

Commit

Permalink
Merge pull request #37 from ismaellawrenz/Cte-simplificado
Browse files Browse the repository at this point in the history
Implementação do CTe simplificado
  • Loading branch information
Samuel-Oliveira authored Dec 11, 2024
2 parents 10f0d3d + ce8a010 commit 7c613db
Show file tree
Hide file tree
Showing 83 changed files with 87,442 additions and 2 deletions.
Binary file modified schemas.zip
Binary file not shown.
28 changes: 28 additions & 0 deletions src/main/java/br/com/swconsultoria/cte/Cte.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import br.com.swconsultoria.cte.schema_400.cte.TCTe;
import br.com.swconsultoria.cte.schema_400.cte.TRetCTe;
import br.com.swconsultoria.cte.schema_400.cteOS.TCTeOS;
import br.com.swconsultoria.cte.schema_400.cteSimp.TCTeSimp;
import br.com.swconsultoria.cte.schema_400.cteSimp.TRetCTeSimp;
import br.com.swconsultoria.cte.schema_400.evEPECCTe.TEvento;
import br.com.swconsultoria.cte.schema_400.evEPECCTe.TRetEvento;
import br.com.swconsultoria.cte.schema_400.retCTeOS.TRetCTeOS;
Expand Down Expand Up @@ -103,6 +105,20 @@ public static TCTeOS montaCteOS(ConfiguracoesCte configuracoesCte,

}

/**
* Metodo para Montar a CTE simplificado.
*
* @param configuracoesCte
* @param enviCTe
* @param valida
* @return
* @throws CteException
*/
public static TCTeSimp montaCteSimp(ConfiguracoesCte configuracoesCte,
TCTeSimp enviCTe, boolean valida) throws CteException {
return EnvioCteSimp.montaCteSimp(ConfiguracoesUtil.iniciaConfiguracoes(configuracoesCte), enviCTe, valida);
}

/**
* Metodo para Enviar a CTE.
*
Expand Down Expand Up @@ -130,6 +146,18 @@ public static TRetCTeOS enviarCteOS(ConfiguracoesCte configuracoesCte, TCTeOS en
return EnvioCteOS.enviaCteOS(ConfiguracoesUtil.iniciaConfiguracoes(configuracoesCte), enviCTe);
}

/**
* Metodo para Enviar a CTE simplificado.
*
* @param configuracoesCte
* @param enviCTe
* @return
* @throws CteException
*/
public static TRetCTeSimp enviarCteSimp(ConfiguracoesCte configuracoesCte, TCTeSimp enviCTe) throws CteException {
return EnvioCteSimp.enviaCteSimp(ConfiguracoesUtil.iniciaConfiguracoes(configuracoesCte), enviCTe);
}

/**
* Metodo para Cancelar a CTE 4.00
*
Expand Down
100 changes: 100 additions & 0 deletions src/main/java/br/com/swconsultoria/cte/EnvioCteSimp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package br.com.swconsultoria.cte;

import br.com.swconsultoria.cte.dom.ConfiguracoesCte;
import br.com.swconsultoria.cte.dom.enuns.AssinaturaEnum;
import br.com.swconsultoria.cte.dom.enuns.ServicosEnum;
import br.com.swconsultoria.cte.exception.CteException;
import br.com.swconsultoria.cte.schema_400.cteSimp.TCTeSimp;
import br.com.swconsultoria.cte.schema_400.cteSimp.TRetCTeSimp;
import br.com.swconsultoria.cte.util.WebServiceCteUtil;
import br.com.swconsultoria.cte.util.XmlCteUtil;
import br.com.swconsultoria.cte.wsdl.cte_recepcao_simp.CTeRecepcaoSimpV4Stub;
import lombok.extern.java.Log;

import javax.xml.bind.JAXBException;
import java.io.IOException;

/**
* Classe Responsavel por Enviar o Cte simplificado.
*
* @author Ismael Luan Lawrenz
*/
@Log
class EnvioCteSimp {

private EnvioCteSimp() {
}

/**
* Metodo para Montar a CTE simplificado
*
* @param config
* @param cte
* @param valida
* @return TCTeSimp
* @throws CteException
*/
static TCTeSimp montaCteSimp(ConfiguracoesCte config, TCTeSimp cte, boolean valida) throws CteException {
try {

/**
* Cria o xml
*/
String xml = XmlCteUtil.objectToXml(cte);

/**
* Assina o Xml
*/
xml = Assinar.assinaCte(config, xml, AssinaturaEnum.CTE_SIMP);
log.info("[XML-ASSINADO]: " + xml);

/**
* Valida o Xml caso sejá selecionado True
*/
if (valida) {
new Validar().validaXml(config, xml, ServicosEnum.ENVIO_CTE_SIMP);
}

return XmlCteUtil.xmlToObject(xml, TCTeSimp.class);

} catch (Exception e) {
throw new CteException(e);
}

}

/**
* Metodo para Enviar a CTE simplificado
*
* @param config
* @param cte
* @return TRetCTeSimp
* @throws CteException
*/
static TRetCTeSimp enviaCteSimp(ConfiguracoesCte config, TCTeSimp cte) throws CteException {

try {

String xml = XmlCteUtil.objectToXml(cte);

log.info("[XML-ENVIO]: " + xml);

CTeRecepcaoSimpV4Stub.CteDadosMsg dadosMsg = new CTeRecepcaoSimpV4Stub.CteDadosMsg();
dadosMsg.setCteDadosMsg(XmlCteUtil.xmlToGZip(xml));

CTeRecepcaoSimpV4Stub stub = new CTeRecepcaoSimpV4Stub(
WebServiceCteUtil.getUrl(config, ServicosEnum.ENVIO_CTE_SIMP));
CTeRecepcaoSimpV4Stub.CteRecepcaoSimpResult result = stub.cteRecepcaoSimp(dadosMsg);

TRetCTeSimp retCte = XmlCteUtil.xmlToObject(result.getExtraElement().toString(),
TRetCTeSimp.class);

log.info("[XML-RETORNO]: " + XmlCteUtil.objectToXml(retCte));
return retCte;

} catch (IOException | JAXBException e) {
throw new CteException("Erro ao enviar CTe", e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum AssinaturaEnum {

CTE("CTe","infCte"),
CTE_OS ("CTeOS","infCte"),
CTE_SIMP("CTeSimp","infCte"),
EVENTO("eventoCTe","infEvento");

private final String tipo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum ServicosEnum {
CANCELAMENTO(Constants.RECEPCAO_EVENTO_4_00, "evCancCTe_v4.00.xsd"),
EVENTO("", "eventoCTe_v4.00.xsd"),
ENVIO_CTE_OS("CTeRecepcaoOS_4.00", "cteOS_v4.00.xsd"),
ENVIO_CTE_SIMP("CTeRecepcaoSimp_4.00", "cteSimp_v4.00.xsd"),
EPEC(Constants.RECEPCAO_EVENTO_4_00, "evEPECCTe_v4.00.xsd"),
MULTIMODAL(Constants.RECEPCAO_EVENTO_4_00, "evRegMultimodal_v4.00.xsd"),
CCE(Constants.RECEPCAO_EVENTO_4_00, "evCCeCTe_v4.00.xsd"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@



package br.com.swconsultoria.cte.schema_400.cteSimp;

import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;


/**
* <p>Java class for KeyInfoType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="KeyInfoType"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="X509Data" type="{http://www.w3.org/2000/09/xmldsig#}X509DataType"/&gt;
* &lt;/sequence&gt;
* &lt;attribute name="Id" type="{http://www.w3.org/2001/XMLSchema}ID" /&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "KeyInfoType", namespace = "http://www.w3.org/2000/09/xmldsig#", propOrder = {
"x509Data"
})
public class KeyInfoType {

@XmlElement(name = "X509Data", required = true)
protected X509DataType x509Data;
@XmlAttribute(name = "Id")
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlID
@XmlSchemaType(name = "ID")
protected String id;

/**
* Gets the value of the x509Data property.
*
* @return
* possible object is
* {@link X509DataType }
*
*/
public X509DataType getX509Data() {
return x509Data;
}

/**
* Sets the value of the x509Data property.
*
* @param value
* allowed object is
* {@link X509DataType }
*
*/
public void setX509Data(X509DataType value) {
this.x509Data = value;
}

/**
* Gets the value of the id property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getId() {
return id;
}

/**
* Sets the value of the id property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setId(String value) {
this.id = value;
}

}
Loading

0 comments on commit 7c613db

Please sign in to comment.