1919import io .github .project .openubl .xsender .company .CompanyURLs ;
2020import io .github .project .openubl .xsender .files .exceptions .UnsupportedXMLFileException ;
2121import io .github .project .openubl .xsender .files .xml .DocumentType ;
22- import io .github .project .openubl .xsender .files .xml .XmlContentModel ;
22+ import io .github .project .openubl .xsender .files .xml .XmlContent ;
2323import io .github .project .openubl .xsender .files .xml .XmlContentProvider ;
24- import io .github .project .openubl .xsender .sunat .catalog .Catalog1 ;
2524import io .github .project .openubl .xsender .sunat .BillServiceDestination ;
25+ import io .github .project .openubl .xsender .sunat .catalog .Catalog1 ;
2626import jodd .io .ZipBuilder ;
2727import org .apache .cxf .helpers .IOUtils ;
2828import org .xml .sax .SAXException ;
@@ -47,6 +47,8 @@ public class BillServiceXMLFileAnalyzer implements BillServiceFileAnalyzer {
4747 private final BillServiceDestination fileDestination ;
4848 private final BillServiceDestination ticketDestination ;
4949
50+ private final XmlContent xmlContent ;
51+
5052 public BillServiceXMLFileAnalyzer (File file , CompanyURLs urLs )
5153 throws IOException , ParserConfigurationException , UnsupportedXMLFileException , SAXException {
5254 this (file .toPath (), urLs );
@@ -64,23 +66,23 @@ public BillServiceXMLFileAnalyzer(InputStream is, CompanyURLs urLs)
6466
6567 public BillServiceXMLFileAnalyzer (byte [] file , CompanyURLs urls )
6668 throws ParserConfigurationException , IOException , SAXException , UnsupportedXMLFileException {
67- XmlContentModel xmlContentModel = XmlContentProvider .getSunatDocument (new ByteArrayInputStream (file ));
69+ this . xmlContent = XmlContentProvider .getSunatDocument (new ByteArrayInputStream (file ));
6870
69- if (xmlContentModel .getDocumentType ().equals (DocumentType .VOIDED_DOCUMENT )) {
70- String voidedLineDocumentTypeCode = xmlContentModel .getVoidedLineDocumentTypeCode ();
71+ if (xmlContent .getDocumentType ().equals (DocumentType .VOIDED_DOCUMENT )) {
72+ String voidedLineDocumentTypeCode = xmlContent .getVoidedLineDocumentTypeCode ();
7173 Optional <Catalog1 > catalog1Optional = Catalog1 .valueOfCode (voidedLineDocumentTypeCode );
7274 if (catalog1Optional .isPresent () && catalog1Optional .get ().equals (Catalog1 .BOLETA )) {
7375 }
7476 }
7577
7678 String fileNameWithoutExtension = BillServiceXMLFileAnalyzer
77- .getFileNameWithoutExtension (xmlContentModel )
79+ .getFileNameWithoutExtension (xmlContent )
7880 .orElseThrow (() -> new UnsupportedXMLFileException ("Couldn't infer the file name" ));
7981 BillServiceDestination fileDestination = BillServiceXMLFileAnalyzer
80- .getFileDeliveryTarget (urls , xmlContentModel )
82+ .getFileDeliveryTarget (urls , xmlContent )
8183 .orElseThrow (() -> new UnsupportedXMLFileException ("Couldn't infer the delivery data" ));
8284 BillServiceDestination ticketDestination = BillServiceXMLFileAnalyzer
83- .getTicketDeliveryTarget (urls , xmlContentModel )
85+ .getTicketDeliveryTarget (urls , xmlContent )
8486 .orElse (null );
8587
8688 String zipFileName = fileNameWithoutExtension + ".zip" ;
@@ -111,10 +113,15 @@ public BillServiceDestination getVerifyTicketDestination() {
111113 return ticketDestination ;
112114 }
113115
114- private static Optional <String > getFileNameWithoutExtension (XmlContentModel xmlContentModel ) {
115- String documentType = xmlContentModel .getDocumentType ();
116- String documentID = xmlContentModel .getDocumentID ();
117- String ruc = xmlContentModel .getRuc ();
116+ @ Override
117+ public XmlContent getXmlContent () {
118+ return xmlContent ;
119+ }
120+
121+ private static Optional <String > getFileNameWithoutExtension (XmlContent xmlContent ) {
122+ String documentType = xmlContent .getDocumentType ();
123+ String documentID = xmlContent .getDocumentID ();
124+ String ruc = xmlContent .getRuc ();
118125
119126 String result = null ;
120127 String codigoDocumento ;
@@ -159,10 +166,10 @@ private static Optional<String> getFileNameWithoutExtension(XmlContentModel xmlC
159166 return Optional .ofNullable (result );
160167 }
161168
162- private static Optional <BillServiceDestination > getFileDeliveryTarget (CompanyURLs urls , XmlContentModel xmlContentModel ) {
169+ private static Optional <BillServiceDestination > getFileDeliveryTarget (CompanyURLs urls , XmlContent xmlContent ) {
163170 BillServiceDestination fileDeliveryTarget = null ;
164171
165- switch (xmlContentModel .getDocumentType ()) {
172+ switch (xmlContent .getDocumentType ()) {
166173 case DocumentType .INVOICE :
167174 case DocumentType .CREDIT_NOTE :
168175 case DocumentType .DEBIT_NOTE :
@@ -172,7 +179,7 @@ private static Optional<BillServiceDestination> getFileDeliveryTarget(CompanyURL
172179 fileDeliveryTarget = new BillServiceDestination (urls .getInvoice (), BillServiceDestination .Operation .SEND_SUMMARY );
173180 break ;
174181 case DocumentType .VOIDED_DOCUMENT :
175- String tipoDocumentoAfectado = xmlContentModel .getVoidedLineDocumentTypeCode ();
182+ String tipoDocumentoAfectado = xmlContent .getVoidedLineDocumentTypeCode ();
176183 Optional <Catalog1 > catalog1Optional = Catalog1 .valueOfCode (tipoDocumentoAfectado );
177184 if (!catalog1Optional .isPresent ()) {
178185 return Optional .empty ();
@@ -205,10 +212,10 @@ private static Optional<BillServiceDestination> getFileDeliveryTarget(CompanyURL
205212
206213 private static Optional <BillServiceDestination > getTicketDeliveryTarget (
207214 CompanyURLs urls ,
208- XmlContentModel xmlContentModel
215+ XmlContent xmlContent
209216 ) {
210217 boolean shouldVerifyTicket = false ;
211- switch (xmlContentModel .getDocumentType ()) {
218+ switch (xmlContent .getDocumentType ()) {
212219 case DocumentType .VOIDED_DOCUMENT :
213220 case DocumentType .SUMMARY_DOCUMENT :
214221 shouldVerifyTicket = true ;
@@ -222,7 +229,7 @@ private static Optional<BillServiceDestination> getTicketDeliveryTarget(
222229 BillServiceDestination ticketDeliveryTarget ;
223230
224231 Catalog1 catalog1 = Catalog1
225- .valueOfCode (xmlContentModel .getVoidedLineDocumentTypeCode ())
232+ .valueOfCode (xmlContent .getVoidedLineDocumentTypeCode ())
226233 .orElse (Catalog1 .FACTURA );
227234 switch (catalog1 ) {
228235 case PERCEPCION :
0 commit comments