Rev 414 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 414 | espaco | 1 | package nfe; |
| 2 | |||
| 3 | import br.com.swconsultoria.nfe.dom.ConfiguracoesNfe; |
||
| 4 | import br.com.swconsultoria.nfe.dom.enuns.ConsultaDFeEnum; |
||
| 5 | import br.com.swconsultoria.nfe.dom.enuns.DocumentoEnum; |
||
| 6 | import br.com.swconsultoria.nfe.dom.enuns.PessoaEnum; |
||
| 7 | import br.com.swconsultoria.nfe.dom.enuns.ServicosEnum; |
||
| 8 | import br.com.swconsultoria.nfe.exception.NfeException; |
||
| 9 | import br.com.swconsultoria.nfe.schema.distdfeint.DistDFeInt; |
||
| 10 | import br.com.swconsultoria.nfe.schema.retdistdfeint.RetDistDFeInt; |
||
| 11 | import br.com.swconsultoria.nfe.util.ConstantesUtil; |
||
| 12 | import br.com.swconsultoria.nfe.util.ObjetoUtil; |
||
| 13 | import br.com.swconsultoria.nfe.util.WebServiceUtil; |
||
| 14 | import br.com.swconsultoria.nfe.util.XmlNfeUtil; |
||
| 15 | import br.com.swconsultoria.nfe.wsdl.NFeDistribuicaoDFe.NFeDistribuicaoDFeStub; |
||
| 16 | import lombok.extern.java.Log; |
||
| 17 | import org.apache.axiom.om.OMElement; |
||
| 18 | import org.apache.axiom.om.util.AXIOMUtil; |
||
| 19 | import org.apache.axis2.transport.http.HTTPConstants; |
||
| 20 | |||
| 21 | import javax.xml.bind.JAXBException; |
||
| 22 | import javax.xml.stream.XMLStreamException; |
||
| 23 | import java.rmi.RemoteException; |
||
| 415 | espaco | 24 | import java.util.logging.Logger; |
| 414 | espaco | 25 | |
| 26 | /** |
||
| 27 | * @author Samuel Oliveira - samuel@swconsultoria.com.br - www.swconsultoria.com.br |
||
| 28 | */ |
||
| 29 | @Log |
||
| 30 | class DistribuicaoDFe { |
||
| 31 | |||
| 415 | espaco | 32 | private final static Logger log = Logger.getLogger(WebServiceUtil.class.getName()); |
| 33 | |||
| 414 | espaco | 34 | /** |
| 35 | * Classe Reponsavel Por Consultar as NFE na SEFAZ |
||
| 36 | * |
||
| 37 | * @param config Configuração |
||
| 38 | * @param tipoPessoa Informe {@link PessoaEnum} |
||
| 39 | * @param cpfCnpj Informe o Cpf ou Cnpj |
||
| 40 | * @param tipoConsulta Informe {@link ConsultaDFeEnum} |
||
| 41 | * @param nsuChave Informe a Chave ou o Nsu |
||
| 42 | * @return |
||
| 43 | * @throws NfeException |
||
| 44 | */ |
||
| 45 | static RetDistDFeInt consultaNfe(ConfiguracoesNfe config, PessoaEnum tipoPessoa, String cpfCnpj, ConsultaDFeEnum tipoConsulta, |
||
| 46 | String nsuChave) throws NfeException { |
||
| 47 | |||
| 48 | try { |
||
| 49 | |||
| 50 | DistDFeInt distDFeInt = new DistDFeInt(); |
||
| 51 | distDFeInt.setVersao(ConstantesUtil.VERSAO.DIST_DFE); |
||
| 52 | distDFeInt.setTpAmb(config.getAmbiente().getCodigo()); |
||
| 53 | distDFeInt.setCUFAutor(config.getEstado().getCodigoUF()); |
||
| 54 | |||
| 55 | if (PessoaEnum.JURIDICA.equals(tipoPessoa)) { |
||
| 56 | distDFeInt.setCNPJ(cpfCnpj); |
||
| 57 | } else { |
||
| 58 | distDFeInt.setCPF(cpfCnpj); |
||
| 59 | } |
||
| 60 | |||
| 61 | switch (tipoConsulta) { |
||
| 62 | case NSU: |
||
| 63 | DistDFeInt.DistNSU distNSU = new DistDFeInt.DistNSU(); |
||
| 64 | distNSU.setUltNSU(nsuChave); |
||
| 65 | distDFeInt.setDistNSU(distNSU); |
||
| 66 | break; |
||
| 67 | case NSU_UNICO: |
||
| 68 | DistDFeInt.ConsNSU consNSU = new DistDFeInt.ConsNSU(); |
||
| 69 | consNSU.setNSU(nsuChave); |
||
| 70 | distDFeInt.setConsNSU(consNSU); |
||
| 71 | break; |
||
| 72 | case CHAVE: |
||
| 73 | DistDFeInt.ConsChNFe chNFe = new DistDFeInt.ConsChNFe(); |
||
| 74 | chNFe.setChNFe(nsuChave); |
||
| 75 | distDFeInt.setConsChNFe(chNFe); |
||
| 76 | break; |
||
| 77 | } |
||
| 78 | |||
| 79 | String xml = XmlNfeUtil.objectToXml(distDFeInt, config.getEncode()); |
||
| 80 | |||
| 81 | log.info("[XML-ENVIO]: " + xml); |
||
| 82 | |||
| 83 | OMElement ome = AXIOMUtil.stringToOM(xml); |
||
| 84 | |||
| 85 | NFeDistribuicaoDFeStub.NfeDadosMsg_type0 dadosMsgType0 = new NFeDistribuicaoDFeStub.NfeDadosMsg_type0(); |
||
| 86 | dadosMsgType0.setExtraElement(ome); |
||
| 87 | |||
| 88 | NFeDistribuicaoDFeStub.NfeDistDFeInteresse distDFeInteresse = new NFeDistribuicaoDFeStub.NfeDistDFeInteresse(); |
||
| 89 | distDFeInteresse.setNfeDadosMsg(dadosMsgType0); |
||
| 90 | |||
| 91 | NFeDistribuicaoDFeStub stub = new NFeDistribuicaoDFeStub( |
||
| 92 | WebServiceUtil.getUrl(config, DocumentoEnum.NFE, ServicosEnum.DISTRIBUICAO_DFE)); |
||
| 93 | |||
| 94 | // Timeout |
||
| 95 | if (ObjetoUtil.verifica(config.getTimeout()).isPresent()) { |
||
| 96 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, config.getTimeout()); |
||
| 97 | stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, |
||
| 98 | config.getTimeout()); |
||
| 99 | } |
||
| 100 | NFeDistribuicaoDFeStub.NfeDistDFeInteresseResponse result = stub.nfeDistDFeInteresse(distDFeInteresse); |
||
| 101 | |||
| 102 | log.info("[XML-RETORNO]: " + result.getNfeDistDFeInteresseResult().getExtraElement().toString()); |
||
| 103 | return XmlNfeUtil.xmlToObject(result.getNfeDistDFeInteresseResult().getExtraElement().toString(), |
||
| 104 | RetDistDFeInt.class); |
||
| 105 | |||
| 106 | } catch (RemoteException | XMLStreamException | JAXBException e) { |
||
| 107 | throw new NfeException(e.getMessage(),e); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | } |