19
19
import io .github .project .openubl .xsender .company .CompanyURLs ;
20
20
import io .github .project .openubl .xsender .files .exceptions .UnsupportedXMLFileException ;
21
21
import 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 ;
23
23
import io .github .project .openubl .xsender .files .xml .XmlContentProvider ;
24
- import io .github .project .openubl .xsender .sunat .catalog .Catalog1 ;
25
24
import io .github .project .openubl .xsender .sunat .BillServiceDestination ;
25
+ import io .github .project .openubl .xsender .sunat .catalog .Catalog1 ;
26
26
import jodd .io .ZipBuilder ;
27
27
import org .apache .cxf .helpers .IOUtils ;
28
28
import org .xml .sax .SAXException ;
@@ -47,6 +47,8 @@ public class BillServiceXMLFileAnalyzer implements BillServiceFileAnalyzer {
47
47
private final BillServiceDestination fileDestination ;
48
48
private final BillServiceDestination ticketDestination ;
49
49
50
+ private final XmlContent xmlContent ;
51
+
50
52
public BillServiceXMLFileAnalyzer (File file , CompanyURLs urLs )
51
53
throws IOException , ParserConfigurationException , UnsupportedXMLFileException , SAXException {
52
54
this (file .toPath (), urLs );
@@ -64,23 +66,23 @@ public BillServiceXMLFileAnalyzer(InputStream is, CompanyURLs urLs)
64
66
65
67
public BillServiceXMLFileAnalyzer (byte [] file , CompanyURLs urls )
66
68
throws ParserConfigurationException , IOException , SAXException , UnsupportedXMLFileException {
67
- XmlContentModel xmlContentModel = XmlContentProvider .getSunatDocument (new ByteArrayInputStream (file ));
69
+ this . xmlContent = XmlContentProvider .getSunatDocument (new ByteArrayInputStream (file ));
68
70
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 ();
71
73
Optional <Catalog1 > catalog1Optional = Catalog1 .valueOfCode (voidedLineDocumentTypeCode );
72
74
if (catalog1Optional .isPresent () && catalog1Optional .get ().equals (Catalog1 .BOLETA )) {
73
75
}
74
76
}
75
77
76
78
String fileNameWithoutExtension = BillServiceXMLFileAnalyzer
77
- .getFileNameWithoutExtension (xmlContentModel )
79
+ .getFileNameWithoutExtension (xmlContent )
78
80
.orElseThrow (() -> new UnsupportedXMLFileException ("Couldn't infer the file name" ));
79
81
BillServiceDestination fileDestination = BillServiceXMLFileAnalyzer
80
- .getFileDeliveryTarget (urls , xmlContentModel )
82
+ .getFileDeliveryTarget (urls , xmlContent )
81
83
.orElseThrow (() -> new UnsupportedXMLFileException ("Couldn't infer the delivery data" ));
82
84
BillServiceDestination ticketDestination = BillServiceXMLFileAnalyzer
83
- .getTicketDeliveryTarget (urls , xmlContentModel )
85
+ .getTicketDeliveryTarget (urls , xmlContent )
84
86
.orElse (null );
85
87
86
88
String zipFileName = fileNameWithoutExtension + ".zip" ;
@@ -111,10 +113,15 @@ public BillServiceDestination getVerifyTicketDestination() {
111
113
return ticketDestination ;
112
114
}
113
115
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 ();
118
125
119
126
String result = null ;
120
127
String codigoDocumento ;
@@ -159,10 +166,10 @@ private static Optional<String> getFileNameWithoutExtension(XmlContentModel xmlC
159
166
return Optional .ofNullable (result );
160
167
}
161
168
162
- private static Optional <BillServiceDestination > getFileDeliveryTarget (CompanyURLs urls , XmlContentModel xmlContentModel ) {
169
+ private static Optional <BillServiceDestination > getFileDeliveryTarget (CompanyURLs urls , XmlContent xmlContent ) {
163
170
BillServiceDestination fileDeliveryTarget = null ;
164
171
165
- switch (xmlContentModel .getDocumentType ()) {
172
+ switch (xmlContent .getDocumentType ()) {
166
173
case DocumentType .INVOICE :
167
174
case DocumentType .CREDIT_NOTE :
168
175
case DocumentType .DEBIT_NOTE :
@@ -172,7 +179,7 @@ private static Optional<BillServiceDestination> getFileDeliveryTarget(CompanyURL
172
179
fileDeliveryTarget = new BillServiceDestination (urls .getInvoice (), BillServiceDestination .Operation .SEND_SUMMARY );
173
180
break ;
174
181
case DocumentType .VOIDED_DOCUMENT :
175
- String tipoDocumentoAfectado = xmlContentModel .getVoidedLineDocumentTypeCode ();
182
+ String tipoDocumentoAfectado = xmlContent .getVoidedLineDocumentTypeCode ();
176
183
Optional <Catalog1 > catalog1Optional = Catalog1 .valueOfCode (tipoDocumentoAfectado );
177
184
if (!catalog1Optional .isPresent ()) {
178
185
return Optional .empty ();
@@ -205,10 +212,10 @@ private static Optional<BillServiceDestination> getFileDeliveryTarget(CompanyURL
205
212
206
213
private static Optional <BillServiceDestination > getTicketDeliveryTarget (
207
214
CompanyURLs urls ,
208
- XmlContentModel xmlContentModel
215
+ XmlContent xmlContent
209
216
) {
210
217
boolean shouldVerifyTicket = false ;
211
- switch (xmlContentModel .getDocumentType ()) {
218
+ switch (xmlContent .getDocumentType ()) {
212
219
case DocumentType .VOIDED_DOCUMENT :
213
220
case DocumentType .SUMMARY_DOCUMENT :
214
221
shouldVerifyTicket = true ;
@@ -222,7 +229,7 @@ private static Optional<BillServiceDestination> getTicketDeliveryTarget(
222
229
BillServiceDestination ticketDeliveryTarget ;
223
230
224
231
Catalog1 catalog1 = Catalog1
225
- .valueOfCode (xmlContentModel .getVoidedLineDocumentTypeCode ())
232
+ .valueOfCode (xmlContent .getVoidedLineDocumentTypeCode ())
226
233
.orElse (Catalog1 .FACTURA );
227
234
switch (catalog1 ) {
228
235
case PERCEPCION :
0 commit comments