diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a10825ff..1a482a62 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,8 +39,9 @@ mvn verify -f xsender/spring-boot-extension/integration-tests/ make sync CORE=6.0.0-alpha.1 # el núcleo de una versión de xhandler-rust ``` - `make sync` copia el núcleo, los modelos (`xbuilder/core/.../xbuilder/models/`) y el corpus de - conformidad (`testdata/conformance/`). No los edites a mano. Una versión solo se publica con el + `make sync` copia el núcleo, los modelos (`xbuilder/core/.../xbuilder/models/`), las respuestas + de SUNAT (`xsender/core/.../xsender/models/answers/`) y el corpus de conformidad + (`testdata/conformance/`). No los edites a mano. Una versión solo se publica con el núcleo de la versión igual de xhandler-rust: `make verify-core` lo comprueba. Estos comandos descargan el `core.sh` de xhandler-rust (`xhandler-wasm/core.sh`) del tag del núcleo; `CORE_SH=` usa una copia local, p. ej. al cambiarlo allá. diff --git a/Makefile b/Makefile index 229a1961..15326fdc 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -# The core (xhandler.wasm and its VERSION in xhandler-core, the xbuilder models and -# testdata/conformance) comes from xhandler-rust: +# The core (xhandler.wasm and its VERSION in xhandler-core, the generated xbuilder models and +# xsender answers, and testdata/conformance) comes from xhandler-rust: # # make sync CORE= the xhandler-rust v release # make sync a checkout of xhandler-rust (RUST_REPO), for development @@ -14,7 +14,9 @@ WASM := xhandler-core/src/main/wasm/xhandler.wasm VERSION_FILE := xhandler-core/src/main/resources/io/github/project/openubl/xhandler/core/VERSION MODELS := xbuilder/core/src/main/java/io/github/project/openubl/xbuilder/models -SYNCED := $(WASM) $(VERSION_FILE) $(MODELS) testdata/conformance +ANSWERS := xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers + +SYNCED := $(WASM) $(VERSION_FILE) $(MODELS) $(ANSWERS) testdata/conformance # core.sh syncs and verifies a released core. It lives in xhandler-rust, next to the release # format it reads, and is downloaded from the tag of the core at hand (from main for a core @@ -33,6 +35,7 @@ sync: dist cp $(DIST)/xhandler.wasm $(WASM) cp $(DIST)/VERSION $(VERSION_FILE) rm -rf $(MODELS) && mkdir -p $(MODELS) && cp $(DIST)/models/java/*.java $(MODELS)/ + rm -rf $(ANSWERS) && mkdir -p $(ANSWERS) && cp $(DIST)/models/java/xsender/*.java $(ANSWERS)/ rm -rf testdata/conformance && cp -r $(DIST)/conformance testdata/conformance $(if $(CORE),rm -rf $(DIST)) diff --git a/xsender/core/src/main/java/io/github/project/openubl/xsender/models/SunatResponse.java b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/SunatResponse.java index bd707d58..b084c37c 100644 --- a/xsender/core/src/main/java/io/github/project/openubl/xsender/models/SunatResponse.java +++ b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/SunatResponse.java @@ -1,5 +1,6 @@ package io.github.project.openubl.xsender.models; +import io.github.project.openubl.xsender.models.answers.CDR; import lombok.Builder; import lombok.Data; @@ -9,6 +10,11 @@ public class SunatResponse { private Status status; private Metadata metadata; private Sunat sunat; + /** + * The CDR as the xhandler core read it, with every field it has (e.g. + * {@code documentDescription}); null without CDR + */ + private CDR cdr; public boolean isTicket() { return sunat != null && sunat.getTicket() != null; diff --git a/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/CDR.java b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/CDR.java new file mode 100644 index 00000000..d0e97afd --- /dev/null +++ b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/CDR.java @@ -0,0 +1,53 @@ +// Code generated by xhandler-wasm/codegen.py from xhandler.schema.json. DO NOT EDIT. +package io.github.project.openubl.xsender.models.answers; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The receipt SUNAT gives back (Constancia de Recepción) + */ +@Data +@Builder(toBuilder = true) +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class CDR { + /** + * The CDR zip + */ + @JsonProperty("zip") + private byte[] zip; + + @JsonProperty("response_code") + private String responseCode; + + @JsonProperty("description") + private String description; + + @JsonProperty("notes") + private List notes; + + /** + * For an accepted guía de remisión, the URL its printed copy's QR code + * must encode; null for other documents + */ + @JsonProperty("document_description") + private String documentDescription; + + @JsonProperty("status") + private Status status; + + /** + * The ticket status, only when verifying a ticket + */ + @JsonProperty("status_code") + private String statusCode; +} diff --git a/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/ConsultResult.java b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/ConsultResult.java new file mode 100644 index 00000000..b8efd01d --- /dev/null +++ b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/ConsultResult.java @@ -0,0 +1,27 @@ +// Code generated by xhandler-wasm/codegen.py from xhandler.schema.json. DO NOT EDIT. +package io.github.project.openubl.xsender.models.answers; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The answer of the consult and validation services + */ +@Data +@Builder(toBuilder = true) +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class ConsultResult { + @JsonProperty("status") + private ConsultStatus status; + + @JsonProperty("fault") + private Fault fault; +} diff --git a/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/ConsultStatus.java b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/ConsultStatus.java new file mode 100644 index 00000000..9da1e708 --- /dev/null +++ b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/ConsultStatus.java @@ -0,0 +1,34 @@ +// Code generated by xhandler-wasm/codegen.py from xhandler.schema.json. DO NOT EDIT. +package io.github.project.openubl.xsender.models.answers; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * A status of the consult services: e.g. "0001" (accepted) for getStatus, or + * "0" for validaCDPcriterios + */ +@Data +@Builder(toBuilder = true) +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class ConsultStatus { + @JsonProperty("status_code") + private String statusCode; + + @JsonProperty("status_message") + private String statusMessage; + + /** + * The CDR zip of getStatusCdr + */ + @JsonProperty("cdr_zip") + private byte[] cdrZip; +} diff --git a/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/Fault.java b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/Fault.java new file mode 100644 index 00000000..d12e5417 --- /dev/null +++ b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/Fault.java @@ -0,0 +1,47 @@ +// Code generated by xhandler-wasm/codegen.py from xhandler.schema.json. DO NOT EDIT. +package io.github.project.openubl.xsender.models.answers; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * An error answered by SUNAT + */ +@Data +@Builder(toBuilder = true) +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class Fault { + /** + * SUNAT's code as given: the SOAP faultcode (e.g. "soap-env:Client.0111") + * or the error code of a REST answer (e.g. "1033") + */ + @JsonProperty("code") + private String code; + + /** + * The number in `code` (111), when it has one + */ + @JsonProperty("sunat_code") + private Long sunatCode; + + /** + * The status of the answer, e.g. 500 for SOAP faults or 422 for REST + * errors + */ + @JsonProperty("http_status") + private Integer httpStatus; + + @JsonProperty("message") + private String message; + + @JsonProperty("status") + private Status status; +} diff --git a/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/NoCDR.java b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/NoCDR.java new file mode 100644 index 00000000..eb74afc7 --- /dev/null +++ b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/NoCDR.java @@ -0,0 +1,27 @@ +// Code generated by xhandler-wasm/codegen.py from xhandler.schema.json. DO NOT EDIT. +package io.github.project.openubl.xsender.models.answers; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * A ticket status without CDR, e.g. "98" (in progress) + */ +@Data +@Builder(toBuilder = true) +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class NoCDR { + @JsonProperty("status_code") + private String statusCode; + + @JsonProperty("status") + private Status status; +} diff --git a/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/SendFileAnswer.java b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/SendFileAnswer.java new file mode 100644 index 00000000..af4f121c --- /dev/null +++ b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/SendFileAnswer.java @@ -0,0 +1,31 @@ +// Code generated by xhandler-wasm/codegen.py from xhandler.schema.json. DO NOT EDIT. +package io.github.project.openubl.xsender.models.answers; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The answer to a sent file: a CDR, a ticket to verify later (summaries, + * voided documents, packs, guías) or a fault + */ +@Data +@Builder(toBuilder = true) +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class SendFileAnswer { + @JsonProperty("cdr") + private CDR cdr; + + @JsonProperty("ticket") + private String ticket; + + @JsonProperty("fault") + private Fault fault; +} diff --git a/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/Status.java b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/Status.java new file mode 100644 index 00000000..a58b3393 --- /dev/null +++ b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/Status.java @@ -0,0 +1,20 @@ +// Code generated by xhandler-wasm/codegen.py from xhandler.schema.json. DO NOT EDIT. +package io.github.project.openubl.xsender.models.answers; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The SUNAT verdict of a document, from its response code + */ +public enum Status { + @JsonProperty("ACEPTADO") + ACCEPTED, + @JsonProperty("RECHAZADO") + REJECTED, + @JsonProperty("EXCEPCION") + EXCEPTION, + @JsonProperty("EN_PROCESO") + IN_PROGRESS, + @JsonProperty("UNKNOWN") + UNKNOWN +} diff --git a/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/VerifyResult.java b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/VerifyResult.java new file mode 100644 index 00000000..359bd6a7 --- /dev/null +++ b/xsender/core/src/main/java/io/github/project/openubl/xsender/models/answers/VerifyResult.java @@ -0,0 +1,30 @@ +// Code generated by xhandler-wasm/codegen.py from xhandler.schema.json. DO NOT EDIT. +package io.github.project.openubl.xsender.models.answers; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The answer to a ticket: a CDR, no CDR yet (e.g. in progress) or a fault + */ +@Data +@Builder(toBuilder = true) +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public class VerifyResult { + @JsonProperty("cdr") + private CDR cdr; + + @JsonProperty("no_cdr") + private NoCDR noCdr; + + @JsonProperty("fault") + private Fault fault; +} diff --git a/xsender/core/src/main/java/io/github/project/openubl/xsender/sunat/SunatClient.java b/xsender/core/src/main/java/io/github/project/openubl/xsender/sunat/SunatClient.java index 4bc496d1..c9152845 100644 --- a/xsender/core/src/main/java/io/github/project/openubl/xsender/sunat/SunatClient.java +++ b/xsender/core/src/main/java/io/github/project/openubl/xsender/sunat/SunatClient.java @@ -92,7 +92,7 @@ public SunatResponse sendFile(BillServiceDestination destination, ZipFile zipFil "target", Destinations.target(destination), "file", file(zipFile.getFilename(), zipFile.getFile()) )); - return SunatResponses.of(exchange(call, destination.getRestOperation() != null, credentials)); + return SunatResponses.send(exchange(call, destination.getRestOperation() != null, credentials)); } /** @@ -105,7 +105,7 @@ public SunatResponse verifyTicket(BillServiceDestination destination, String tic "target", Destinations.target(destination), "ticket", ticket )); - return SunatResponses.of(exchange(call, destination.getRestOperation() != null, credentials)); + return SunatResponses.verify(exchange(call, destination.getRestOperation() != null, credentials)); } /** diff --git a/xsender/core/src/main/java/io/github/project/openubl/xsender/sunat/SunatResponses.java b/xsender/core/src/main/java/io/github/project/openubl/xsender/sunat/SunatResponses.java index bb9f8fce..5aa2b3f9 100644 --- a/xsender/core/src/main/java/io/github/project/openubl/xsender/sunat/SunatResponses.java +++ b/xsender/core/src/main/java/io/github/project/openubl/xsender/sunat/SunatResponses.java @@ -1,95 +1,120 @@ package io.github.project.openubl.xsender.sunat; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; +import io.github.project.openubl.xhandler.core.Json; +import io.github.project.openubl.xhandler.core.XhandlerException; import io.github.project.openubl.xsender.models.Metadata; import io.github.project.openubl.xsender.models.Status; import io.github.project.openubl.xsender.models.Sunat; import io.github.project.openubl.xsender.models.SunatResponse; +import io.github.project.openubl.xsender.models.answers.CDR; +import io.github.project.openubl.xsender.models.answers.ConsultResult; +import io.github.project.openubl.xsender.models.answers.ConsultStatus; +import io.github.project.openubl.xsender.models.answers.Fault; +import io.github.project.openubl.xsender.models.answers.NoCDR; +import io.github.project.openubl.xsender.models.answers.SendFileAnswer; +import io.github.project.openubl.xsender.models.answers.VerifyResult; -import java.util.ArrayList; -import java.util.Base64; import java.util.List; /** - * Builds the responses from the answers of the xhandler core: {@code {cdr}}, - * {@code {ticket}}, {@code {no_cdr}}, {@code {fault}} or {@code {status}}. + * Builds the responses from the answers of the xhandler core, read into the + * types generated from its schema (models.answers). */ final class SunatResponses { private SunatResponses() { } - static SunatResponse of(JsonNode answer) { - if (answer.has("cdr")) { - JsonNode cdr = answer.get("cdr"); - return SunatResponse.builder() - .status(Status.valueOf(cdr.get("status").asText())) - .metadata(new Metadata(number(cdr.get("response_code")), cdr.get("description").asText(), notes(cdr), null)) - .sunat(Sunat.builder() - .cdr(Base64.getDecoder().decode(cdr.get("zip").asText())) - .documentDescription(text(cdr.get("document_description"))) - .build()) - .build(); + /** A CDR, a ticket to verify later, or SUNAT's error */ + static SunatResponse send(JsonNode json) { + SendFileAnswer answer = read(json, SendFileAnswer.class); + if (answer.getCdr() != null) { + return of(answer.getCdr()); } - if (answer.has("ticket")) { + if (answer.getTicket() != null) { return SunatResponse.builder() - .sunat(Sunat.builder().ticket(answer.get("ticket").asText()).build()) + .sunat(Sunat.builder().ticket(answer.getTicket()).build()) .build(); } - if (answer.has("no_cdr")) { - JsonNode noCdr = answer.get("no_cdr"); - Integer code = number(noCdr.get("status_code")); + return of(answer.getFault()); + } + + /** A CDR, no CDR yet (e.g. in progress), or SUNAT's error */ + static SunatResponse verify(JsonNode json) { + VerifyResult answer = read(json, VerifyResult.class); + if (answer.getCdr() != null) { + return of(answer.getCdr()); + } + NoCDR noCdr = answer.getNoCdr(); + if (noCdr != null) { + Integer code = number(noCdr.getStatusCode()); return SunatResponse.builder() - .status(Status.valueOf(noCdr.get("status").asText())) + .status(status(noCdr.getStatus())) .metadata(new Metadata(code, Integer.valueOf(98).equals(code) ? "En proceso" : null, List.of(), null)) .build(); } - JsonNode fault = answer.get("fault"); - return SunatResponse.builder() - .status(Status.valueOf(fault.get("status").asText())) - .metadata(new Metadata( - fault.get("sunat_code").isNull() ? null : fault.get("sunat_code").asInt(), - fault.get("message").asText(), - List.of(), - httpStatus(fault) - )) - .build(); + return of(answer.getFault()); } - static ConsultResponse consult(JsonNode answer) { - if (answer.has("fault")) { - JsonNode fault = answer.get("fault"); + static ConsultResponse consult(JsonNode json) { + ConsultResult answer = read(json, ConsultResult.class); + Fault fault = answer.getFault(); + if (fault != null) { // SUNAT's error codes have 4 digits, e.g. "0111" - String code = fault.get("sunat_code").isNull() ? null : "%04d".formatted(fault.get("sunat_code").asInt()); - return new ConsultResponse(code, fault.get("message").asText(), null, httpStatus(fault)); + String code = fault.getSunatCode() == null ? null : "%04d".formatted(fault.getSunatCode()); + return new ConsultResponse(code, fault.getMessage(), null, fault.getHttpStatus()); } - JsonNode status = answer.get("status"); - JsonNode cdr = status.get("cdr_zip"); - return new ConsultResponse( - status.get("status_code").asText(), - text(status.get("status_message")), - cdr.isNull() ? null : Base64.getDecoder().decode(cdr.asText()), - null - ); + ConsultStatus status = answer.getStatus(); + return new ConsultResponse(status.getStatusCode(), status.getStatusMessage(), status.getCdrZip(), null); } - private static Integer httpStatus(JsonNode fault) { - JsonNode status = fault.get("http_status"); - return status == null || status.isNull() ? null : status.asInt(); + private static SunatResponse of(CDR cdr) { + return SunatResponse.builder() + .status(status(cdr.getStatus())) + .metadata(new Metadata(number(cdr.getResponseCode()), cdr.getDescription(), List.copyOf(cdr.getNotes()), null)) + .sunat(Sunat.builder() + .cdr(cdr.getZip()) + .documentDescription(cdr.getDocumentDescription()) + .build()) + .cdr(cdr) + .build(); + } + + private static SunatResponse of(Fault fault) { + Long code = fault.getSunatCode(); + return SunatResponse.builder() + .status(status(fault.getStatus())) + .metadata(new Metadata( + code == null ? null : code.intValue(), + fault.getMessage(), + List.of(), + fault.getHttpStatus() + )) + .build(); } - private static String text(JsonNode value) { - return value == null || value.isNull() ? null : value.asText(); + private static Status status(io.github.project.openubl.xsender.models.answers.Status status) { + return switch (status) { + case ACCEPTED -> Status.ACEPTADO; + case REJECTED -> Status.RECHAZADO; + case EXCEPTION -> Status.EXCEPCION; + case IN_PROGRESS -> Status.EN_PROCESO; + case UNKNOWN -> Status.UNKNOWN; + }; } - private static Integer number(JsonNode code) { - String text = code.asText(); - return text.matches("\\d+") ? Integer.valueOf(text) : null; + /** The generated answers ignore the fields a newer core adds */ + private static T read(JsonNode json, Class type) { + try { + return Json.MAPPER.treeToValue(json, type); + } catch (JsonProcessingException e) { + throw new XhandlerException("xsender: " + e.getMessage(), e); + } } - private static List notes(JsonNode cdr) { - List notes = new ArrayList<>(); - cdr.get("notes").forEach(note -> notes.add(note.asText())); - return notes; + private static Integer number(String code) { + return code.matches("\\d+") ? Integer.valueOf(code) : null; } } diff --git a/xsender/core/src/test/java/io/github/project/openubl/xsender/sunat/SunatResponsesTest.java b/xsender/core/src/test/java/io/github/project/openubl/xsender/sunat/SunatResponsesTest.java index 3a19b990..e38f9c7f 100644 --- a/xsender/core/src/test/java/io/github/project/openubl/xsender/sunat/SunatResponsesTest.java +++ b/xsender/core/src/test/java/io/github/project/openubl/xsender/sunat/SunatResponsesTest.java @@ -16,21 +16,23 @@ private static JsonNode cdr(String documentDescription) throws Exception { String field = documentDescription == null ? "" : ", \"document_description\": \"" + documentDescription + "\""; return new ObjectMapper().readTree(""" {"cdr": {"zip": "", "response_code": "0", "description": "La Guia numero T001-1, ha sido aceptada", - "notes": [], "status": "ACEPTADO"%s}} + "notes": [], "status": "ACEPTADO", "added_by_a_newer_core": true%s}} """.formatted(field)); } @Test void cdr_carriesTheDocumentDescription() throws Exception { - SunatResponse response = SunatResponses.of(cdr(QR)); + SunatResponse response = SunatResponses.send(cdr(QR)); assertEquals(QR, response.getSunat().getDocumentDescription()); + assertEquals(QR, response.getCdr().getDocumentDescription()); } @Test void cdr_withoutDocumentDescription() throws Exception { - SunatResponse response = SunatResponses.of(cdr(null)); + SunatResponse response = SunatResponses.send(cdr(null)); assertNull(response.getSunat().getDocumentDescription()); + assertNull(response.getCdr().getDocumentDescription()); } } diff --git a/xsender/quarkus-extension/deployment/src/main/java/io/github/project/openubl/quarkus/xsender/deployment/QuarkusXsenderProcessor.java b/xsender/quarkus-extension/deployment/src/main/java/io/github/project/openubl/quarkus/xsender/deployment/QuarkusXsenderProcessor.java index dd272388..7a59840d 100644 --- a/xsender/quarkus-extension/deployment/src/main/java/io/github/project/openubl/quarkus/xsender/deployment/QuarkusXsenderProcessor.java +++ b/xsender/quarkus-extension/deployment/src/main/java/io/github/project/openubl/quarkus/xsender/deployment/QuarkusXsenderProcessor.java @@ -1,10 +1,15 @@ package io.github.project.openubl.quarkus.xsender.deployment; import io.github.project.openubl.quarkus.xsender.runtime.XSenderProducer; +import io.github.project.openubl.xsender.models.answers.CDR; import io.quarkus.arc.deployment.AdditionalBeanBuildItem; +import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.IndexDependencyBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; class QuarkusXsenderProcessor { @@ -20,6 +25,22 @@ AdditionalBeanBuildItem producer() { return AdditionalBeanBuildItem.unremovableOf(XSenderProducer.class); } + @BuildStep + IndexDependencyBuildItem indexAnswers() { + return new IndexDependencyBuildItem("io.github.project-openubl", "xsender"); + } + + /** Jackson reads the answers of the xhandler core into the generated types */ + @BuildStep + void registerAnswers(CombinedIndexBuildItem index, BuildProducer reflection) { + String answers = CDR.class.getPackageName(); + String[] classes = index.getIndex().getKnownClasses().stream() + .map(c -> c.name().toString()) + .filter(name -> name.startsWith(answers + ".")) + .toArray(String[]::new); + reflection.produce(ReflectiveClassBuildItem.builder(classes).methods().fields().build()); + } + /** SUNAT is called over HTTPS */ @BuildStep ExtensionSslNativeSupportBuildItem sslNativeSupport() {