Skip to content

Commit 6d82bdc

Browse files
feat: Map XML back to POJO (#204)
1 parent 371d5fc commit 6d82bdc

File tree

106 files changed

+4991
-709
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+4991
-709
lines changed

core/pom.xml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
<version>${lombok.version}</version>
4242
<scope>provided</scope>
4343
</dependency>
44+
<dependency>
45+
<groupId>org.mapstruct</groupId>
46+
<artifactId>mapstruct</artifactId>
47+
<version>${mapstruct.version}</version>
48+
</dependency>
49+
4450
<dependency>
4551
<groupId>io.quarkus.qute</groupId>
4652
<artifactId>qute-core</artifactId>
@@ -52,12 +58,57 @@
5258
<artifactId>jackson-databind</artifactId>
5359
<version>2.14.2</version>
5460
</dependency>
61+
<dependency>
62+
<groupId>com.fasterxml.jackson.dataformat</groupId>
63+
<artifactId>jackson-dataformat-yaml</artifactId>
64+
<version>2.14.2</version>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>com.fasterxml.jackson.datatype</groupId>
69+
<artifactId>jackson-datatype-jsr310</artifactId>
70+
<version>2.14.2</version>
71+
<scope>test</scope>
72+
</dependency>
73+
5574
<dependency>
5675
<groupId>io.swagger.core.v3</groupId>
5776
<artifactId>swagger-annotations</artifactId>
5877
<version>2.2.8</version>
5978
</dependency>
6079

80+
<dependency>
81+
<groupId>jakarta.xml.bind</groupId>
82+
<artifactId>jakarta.xml.bind-api</artifactId>
83+
<version>2.3.3</version>
84+
</dependency>
85+
<!-- <dependency>-->
86+
<!-- <groupId>org.glassfish.jaxb</groupId>-->
87+
<!-- <artifactId>jaxb-runtime</artifactId>-->
88+
<!-- <version>4.0.2</version>-->
89+
<!-- <exclusions>-->
90+
<!-- <exclusion>-->
91+
<!-- <groupId>jakarta.xml.bind</groupId>-->
92+
<!-- <artifactId>jakarta.xml.bind-api</artifactId>-->
93+
<!-- </exclusion>-->
94+
<!-- </exclusions>-->
95+
<!-- </dependency>-->
96+
<!-- <dependency>-->
97+
<!-- <groupId>org.jboss.spec.javax.xml.bind</groupId>-->
98+
<!-- <artifactId>jboss-jaxb-api_2.3_spec</artifactId>-->
99+
<!-- <version>2.0.1.Final</version>-->
100+
<!-- </dependency>-->
101+
<!-- <dependency>-->
102+
<!-- <groupId>com.sun.xml.bind</groupId>-->
103+
<!-- <artifactId>jaxb-ri</artifactId>-->
104+
<!-- <version>2.3.8</version>-->
105+
<!-- </dependency>-->
106+
<dependency>
107+
<groupId>com.sun.xml.bind</groupId>
108+
<artifactId>jaxb-impl</artifactId>
109+
<version>2.3.8</version>
110+
</dependency>
111+
61112
<dependency>
62113
<groupId>org.junit.jupiter</groupId>
63114
<artifactId>junit-jupiter-engine</artifactId>
@@ -99,6 +150,24 @@
99150
<configuration>
100151
<source>${maven.compiler.source}</source>
101152
<target>${maven.compiler.target}</target>
153+
<parameters>${maven.compiler.parameters}</parameters>
154+
<annotationProcessorPaths>
155+
<path>
156+
<groupId>org.mapstruct</groupId>
157+
<artifactId>mapstruct-processor</artifactId>
158+
<version>${mapstruct.version}</version>
159+
</path>
160+
<path>
161+
<groupId>org.projectlombok</groupId>
162+
<artifactId>lombok</artifactId>
163+
<version>${lombok.version}</version>
164+
</path>
165+
<path>
166+
<groupId>org.projectlombok</groupId>
167+
<artifactId>lombok-mapstruct-binding</artifactId>
168+
<version>0.2.0</version>
169+
</path>
170+
</annotationProcessorPaths>
102171
</configuration>
103172
</plugin>
104173
<plugin>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
3+
* and other contributors as indicated by the @author tags.
4+
*
5+
* Licensed under the Apache License - 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.github.project.openubl.xbuilder.content.jaxb.adapters;
18+
19+
import javax.xml.bind.annotation.adapters.XmlAdapter;
20+
import java.time.LocalDate;
21+
22+
public class LocalDateAdapter extends XmlAdapter<String, LocalDate> {
23+
@Override
24+
public LocalDate unmarshal(String v) throws Exception {
25+
return LocalDate.parse(v);
26+
}
27+
28+
@Override
29+
public String marshal(LocalDate v) throws Exception {
30+
return v.toString();
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
3+
* and other contributors as indicated by the @author tags.
4+
*
5+
* Licensed under the Apache License - 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.github.project.openubl.xbuilder.content.jaxb.adapters;
18+
19+
import javax.xml.bind.annotation.adapters.XmlAdapter;
20+
import java.time.LocalTime;
21+
22+
public class LocalTimeAdapter extends XmlAdapter<String, LocalTime> {
23+
@Override
24+
public LocalTime unmarshal(String v) throws Exception {
25+
return LocalTime.parse(v);
26+
}
27+
28+
@Override
29+
public String marshal(LocalTime v) throws Exception {
30+
return v.toString();
31+
}
32+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
3+
* and other contributors as indicated by the @author tags.
4+
*
5+
* Licensed under the Apache License - 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.github.project.openubl.xbuilder.content.jaxb.mappers;
18+
19+
import io.github.project.openubl.xbuilder.content.jaxb.mappers.common.SalesDocumentHelperMapper;
20+
import io.github.project.openubl.xbuilder.content.jaxb.mappers.common.SalesDocumentMapper;
21+
import io.github.project.openubl.xbuilder.content.jaxb.models.XMLCreditNote;
22+
import io.github.project.openubl.xbuilder.content.jaxb.models.XMLCreditNoteLine;
23+
import io.github.project.openubl.xbuilder.content.jaxb.models.XMLSalesDocument;
24+
import io.github.project.openubl.xbuilder.content.models.standard.general.CreditNote;
25+
import io.github.project.openubl.xbuilder.content.models.standard.general.DocumentoVentaDetalle;
26+
import io.github.project.openubl.xbuilder.content.models.standard.general.TotalImporteNote;
27+
import org.mapstruct.Mapper;
28+
import org.mapstruct.Mapping;
29+
import org.mapstruct.NullValueMappingStrategy;
30+
31+
@Mapper(config = SalesDocumentMapper.class,
32+
nullValueIterableMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT
33+
)
34+
public interface CreditNoteMapper extends SalesDocumentHelperMapper {
35+
36+
@Mapping(target = "comprobanteAfectadoSerieNumero", source = "discrepancyResponse.referenceID")
37+
@Mapping(target = "comprobanteAfectadoTipo", source = "discrepancyResponse.responseCode")
38+
@Mapping(target = "sustentoDescripcion", source = "discrepancyResponse.description")
39+
40+
@Mapping(target = "totalImporte", source = "monetaryTotal")
41+
@Mapping(target = "detalles", source = "lines")
42+
CreditNote map(XMLCreditNote xml);
43+
44+
@Mapping(target = "importe", source = "payableAmount")
45+
@Mapping(target = "importeSinImpuestos", source = "lineExtensionAmount")
46+
@Mapping(target = "importeConImpuestos", source = "taxInclusiveAmount")
47+
TotalImporteNote mapTotalImporteNote(XMLSalesDocument.MonetaryTotal xml);
48+
49+
default DocumentoVentaDetalle mapDocumentoVentaDetalle(XMLCreditNoteLine xml) {
50+
DocumentoVentaDetalle documentoVentaDetalle = mapSalesDocumentDetalle(xml);
51+
documentoVentaDetalle.setCantidad(xml.getQuantity().getValue());
52+
documentoVentaDetalle.setUnidadMedida(xml.getQuantity().getUnitCode());
53+
54+
return documentoVentaDetalle;
55+
}
56+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
3+
* and other contributors as indicated by the @author tags.
4+
*
5+
* Licensed under the Apache License - 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.github.project.openubl.xbuilder.content.jaxb.mappers;
18+
19+
import io.github.project.openubl.xbuilder.content.jaxb.mappers.common.SalesDocumentHelperMapper;
20+
import io.github.project.openubl.xbuilder.content.jaxb.mappers.common.SalesDocumentMapper;
21+
import io.github.project.openubl.xbuilder.content.jaxb.models.XMLDebitNote;
22+
import io.github.project.openubl.xbuilder.content.jaxb.models.XMLDebitNoteLine;
23+
import io.github.project.openubl.xbuilder.content.jaxb.models.XMLSalesDocument;
24+
import io.github.project.openubl.xbuilder.content.models.standard.general.DebitNote;
25+
import io.github.project.openubl.xbuilder.content.models.standard.general.DocumentoVentaDetalle;
26+
import io.github.project.openubl.xbuilder.content.models.standard.general.TotalImporteNote;
27+
import org.mapstruct.Mapper;
28+
import org.mapstruct.Mapping;
29+
import org.mapstruct.NullValueMappingStrategy;
30+
31+
@Mapper(config = SalesDocumentMapper.class,
32+
nullValueIterableMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT
33+
)
34+
public interface DebitNoteMapper extends SalesDocumentHelperMapper {
35+
36+
@Mapping(target = "comprobanteAfectadoSerieNumero", source = "discrepancyResponse.referenceID")
37+
@Mapping(target = "comprobanteAfectadoTipo", source = "discrepancyResponse.responseCode")
38+
@Mapping(target = "sustentoDescripcion", source = "discrepancyResponse.description")
39+
40+
@Mapping(target = "totalImporte", source = "monetaryTotal")
41+
@Mapping(target = "detalles", source = "lines")
42+
DebitNote map(XMLDebitNote xml);
43+
44+
@Mapping(target = "importe", source = "payableAmount")
45+
@Mapping(target = "importeSinImpuestos", source = "lineExtensionAmount")
46+
@Mapping(target = "importeConImpuestos", source = "taxInclusiveAmount")
47+
TotalImporteNote mapTotalImporteNote(XMLSalesDocument.MonetaryTotal xml);
48+
49+
default DocumentoVentaDetalle mapDocumentoVentaDetalle(XMLDebitNoteLine xml) {
50+
DocumentoVentaDetalle documentoVentaDetalle = mapSalesDocumentDetalle(xml);
51+
documentoVentaDetalle.setCantidad(xml.getQuantity().getValue());
52+
documentoVentaDetalle.setUnidadMedida(xml.getQuantity().getUnitCode());
53+
54+
return documentoVentaDetalle;
55+
}
56+
}

0 commit comments

Comments
 (0)