Skip to content

Commit 10d6661

Browse files
Expose XMLContent while analyzing it in BillService (#35)
1 parent 1301797 commit 10d6661

File tree

9 files changed

+43
-37
lines changed

9 files changed

+43
-37
lines changed

core/src/main/java/io/github/project/openubl/xsender/camel/utils/CamelUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
package io.github.project.openubl.xsender.camel.utils;
1818

1919
import io.github.project.openubl.xsender.company.CompanyCredentials;
20+
import io.github.project.openubl.xsender.files.ZipFile;
2021
import io.github.project.openubl.xsender.sunat.BillConsultServiceDestination;
2122
import io.github.project.openubl.xsender.sunat.BillServiceDestination;
22-
import io.github.project.openubl.xsender.files.ZipFile;
2323
import io.github.project.openubl.xsender.sunat.BillValidServiceDestination;
2424
import org.apache.camel.component.cxf.common.message.CxfConstants;
2525
import org.apache.cxf.attachment.ByteDataSource;

core/src/main/java/io/github/project/openubl/xsender/files/BillServiceFileAnalyzer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package io.github.project.openubl.xsender.files;
1818

19+
import io.github.project.openubl.xsender.files.xml.XmlContent;
1920
import io.github.project.openubl.xsender.sunat.BillServiceDestination;
2021

2122
public interface BillServiceFileAnalyzer {
@@ -24,4 +25,6 @@ public interface BillServiceFileAnalyzer {
2425
BillServiceDestination getSendFileDestination();
2526

2627
BillServiceDestination getVerifyTicketDestination();
28+
29+
XmlContent getXmlContent();
2730
}

core/src/main/java/io/github/project/openubl/xsender/files/BillServiceXMLFileAnalyzer.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import io.github.project.openubl.xsender.company.CompanyURLs;
2020
import io.github.project.openubl.xsender.files.exceptions.UnsupportedXMLFileException;
2121
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;
2323
import io.github.project.openubl.xsender.files.xml.XmlContentProvider;
24-
import io.github.project.openubl.xsender.sunat.catalog.Catalog1;
2524
import io.github.project.openubl.xsender.sunat.BillServiceDestination;
25+
import io.github.project.openubl.xsender.sunat.catalog.Catalog1;
2626
import jodd.io.ZipBuilder;
2727
import org.apache.cxf.helpers.IOUtils;
2828
import 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:

core/src/main/java/io/github/project/openubl/xsender/files/xml/XmlContentModel.java renamed to core/src/main/java/io/github/project/openubl/xsender/files/xml/XmlContent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
@Builder
2626
@NoArgsConstructor
2727
@AllArgsConstructor
28-
public class XmlContentModel {
28+
public class XmlContent {
2929

3030
private String documentType;
3131
private String documentID;

core/src/main/java/io/github/project/openubl/xsender/files/xml/XmlContentProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ private XmlContentProvider() {
3030
// Only static methods
3131
}
3232

33-
public static XmlContentModel getSunatDocument(InputStream is)
34-
throws ParserConfigurationException, SAXException, IOException {
33+
public static XmlContent getSunatDocument(InputStream is) throws ParserConfigurationException, SAXException, IOException {
3534
XmlHandler handler = new XmlHandler();
3635
SAXParserFactory factory = SAXParserFactory.newInstance();
3736
factory.setNamespaceAware(true);

core/src/main/java/io/github/project/openubl/xsender/files/xml/XmlHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ public void characters(char[] ch, int start, int length) throws SAXException {
152152
}
153153
}
154154

155-
public XmlContentModel getModel() {
156-
return XmlContentModel
155+
public XmlContent getModel() {
156+
return XmlContent
157157
.builder()
158158
.documentType(documentType)
159159
.documentID(documentID)

core/src/main/java/io/github/project/openubl/xsender/sunat/BillValidServiceDestination.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import lombok.AllArgsConstructor;
2020
import lombok.Builder;
2121
import lombok.Data;
22-
import lombok.Getter;
2322

2423
@Data
2524
@Builder

core/src/test/java/io/github/project/openubl/xsender/files/xml/XmlContentProviderTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void getSunatDocument_invoice() throws IOException, SAXException, ParserC
3939
assertNotNull(inputStream);
4040

4141
// When
42-
XmlContentModel model = XmlContentProvider.getSunatDocument(inputStream);
42+
XmlContent model = XmlContentProvider.getSunatDocument(inputStream);
4343

4444
// Then
4545
assertNotNull(model);
@@ -60,7 +60,7 @@ public void getSunatDocument_invoice_withExtensionContent()
6060
assertNotNull(inputStream);
6161

6262
// When
63-
XmlContentModel model = XmlContentProvider.getSunatDocument(inputStream);
63+
XmlContent model = XmlContentProvider.getSunatDocument(inputStream);
6464

6565
// Then
6666
assertNotNull(model);
@@ -80,7 +80,7 @@ public void getSunatDocument_creditNote() throws IOException, SAXException, Pars
8080
assertNotNull(inputStream);
8181

8282
// When
83-
XmlContentModel model = XmlContentProvider.getSunatDocument(inputStream);
83+
XmlContent model = XmlContentProvider.getSunatDocument(inputStream);
8484

8585
// Then
8686
assertNotNull(model);
@@ -100,7 +100,7 @@ public void getSunatDocument_debitNote() throws IOException, SAXException, Parse
100100
assertNotNull(inputStream);
101101

102102
// When
103-
XmlContentModel model = XmlContentProvider.getSunatDocument(inputStream);
103+
XmlContent model = XmlContentProvider.getSunatDocument(inputStream);
104104

105105
// Then
106106
assertNotNull(model);
@@ -120,7 +120,7 @@ public void getSunatDocument_voidedDocument() throws IOException, SAXException,
120120
assertNotNull(inputStream);
121121

122122
// When
123-
XmlContentModel model = XmlContentProvider.getSunatDocument(inputStream);
123+
XmlContent model = XmlContentProvider.getSunatDocument(inputStream);
124124

125125
// Then
126126
assertNotNull(model);
@@ -140,7 +140,7 @@ public void getSunatDocument_summaryDocument() throws IOException, SAXException,
140140
assertNotNull(inputStream);
141141

142142
// When
143-
XmlContentModel model = XmlContentProvider.getSunatDocument(inputStream);
143+
XmlContent model = XmlContentProvider.getSunatDocument(inputStream);
144144

145145
// Then
146146
assertNotNull(model);
@@ -160,7 +160,7 @@ public void getSunatDocument_perception() throws IOException, SAXException, Pars
160160
assertNotNull(inputStream);
161161

162162
// When
163-
XmlContentModel model = XmlContentProvider.getSunatDocument(inputStream);
163+
XmlContent model = XmlContentProvider.getSunatDocument(inputStream);
164164

165165
// Then
166166
assertNotNull(model);
@@ -180,7 +180,7 @@ public void getSunatDocument_retention() throws IOException, SAXException, Parse
180180
assertNotNull(inputStream);
181181

182182
// When
183-
XmlContentModel model = XmlContentProvider.getSunatDocument(inputStream);
183+
XmlContent model = XmlContentProvider.getSunatDocument(inputStream);
184184

185185
// Then
186186
assertNotNull(model);
@@ -200,7 +200,7 @@ public void getSunatDocument_despatchAdvice() throws IOException, SAXException,
200200
assertNotNull(inputStream);
201201

202202
// When
203-
XmlContentModel model = XmlContentProvider.getSunatDocument(inputStream);
203+
XmlContent model = XmlContentProvider.getSunatDocument(inputStream);
204204

205205
// Then
206206
assertNotNull(model);

quarkus-extension/deployment/src/main/java/io/github/project/openubl/quarkus/xsender/deployment/QuarkusXsenderProcessor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import io.github.project.openubl.quarkus.xsender.XSender;
2020
import io.github.project.openubl.xsender.camel.routes.CxfRouteBuilder;
21-
import io.github.project.openubl.xsender.files.BillServiceFileAnalyzer;
22-
import io.github.project.openubl.xsender.files.BillServiceXMLFileAnalyzer;
2321
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
2422
import io.quarkus.arc.processor.DotNames;
2523
import io.quarkus.deployment.annotations.BuildProducer;
@@ -84,7 +82,7 @@ ReflectiveClassBuildItem projectReflection() {
8482
io.github.project.openubl.xsender.files.ZipFile.ZipFileBuilder.class,
8583
io.github.project.openubl.xsender.files.exceptions.UnsupportedXMLFileException.class,
8684
io.github.project.openubl.xsender.files.xml.DocumentType.class,
87-
io.github.project.openubl.xsender.files.xml.XmlContentModel.class,
85+
io.github.project.openubl.xsender.files.xml.XmlContent.class,
8886
io.github.project.openubl.xsender.files.xml.XmlContentProvider.class,
8987
io.github.project.openubl.xsender.files.xml.XmlHandler.class,
9088
io.github.project.openubl.xsender.models.Metadata.class,

0 commit comments

Comments
 (0)