Skip to content

feat: Map XML back to POJO #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>

<dependency>
<groupId>io.quarkus.qute</groupId>
<artifactId>qute-core</artifactId>
Expand All @@ -52,12 +58,57 @@
<artifactId>jackson-databind</artifactId>
<version>2.14.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.14.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.14.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.8</version>
</dependency>

<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.glassfish.jaxb</groupId>-->
<!-- <artifactId>jaxb-runtime</artifactId>-->
<!-- <version>4.0.2</version>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>jakarta.xml.bind</groupId>-->
<!-- <artifactId>jakarta.xml.bind-api</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.jboss.spec.javax.xml.bind</groupId>-->
<!-- <artifactId>jboss-jaxb-api_2.3_spec</artifactId>-->
<!-- <version>2.0.1.Final</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.sun.xml.bind</groupId>-->
<!-- <artifactId>jaxb-ri</artifactId>-->
<!-- <version>2.3.8</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.8</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down Expand Up @@ -99,6 +150,24 @@
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<parameters>${maven.compiler.parameters}</parameters>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License - 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.project.openubl.xbuilder.content.jaxb.adapters;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.time.LocalDate;

public class LocalDateAdapter extends XmlAdapter<String, LocalDate> {
@Override
public LocalDate unmarshal(String v) throws Exception {
return LocalDate.parse(v);
}

@Override
public String marshal(LocalDate v) throws Exception {
return v.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License - 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.project.openubl.xbuilder.content.jaxb.adapters;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.time.LocalTime;

public class LocalTimeAdapter extends XmlAdapter<String, LocalTime> {
@Override
public LocalTime unmarshal(String v) throws Exception {
return LocalTime.parse(v);
}

@Override
public String marshal(LocalTime v) throws Exception {
return v.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License - 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.project.openubl.xbuilder.content.jaxb.mappers;

import io.github.project.openubl.xbuilder.content.jaxb.mappers.common.SalesDocumentHelperMapper;
import io.github.project.openubl.xbuilder.content.jaxb.mappers.common.SalesDocumentMapper;
import io.github.project.openubl.xbuilder.content.jaxb.models.XMLCreditNote;
import io.github.project.openubl.xbuilder.content.jaxb.models.XMLCreditNoteLine;
import io.github.project.openubl.xbuilder.content.jaxb.models.XMLSalesDocument;
import io.github.project.openubl.xbuilder.content.models.standard.general.CreditNote;
import io.github.project.openubl.xbuilder.content.models.standard.general.DocumentoVentaDetalle;
import io.github.project.openubl.xbuilder.content.models.standard.general.TotalImporteNote;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueMappingStrategy;

@Mapper(config = SalesDocumentMapper.class,
nullValueIterableMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT
)
public interface CreditNoteMapper extends SalesDocumentHelperMapper {

@Mapping(target = "comprobanteAfectadoSerieNumero", source = "discrepancyResponse.referenceID")
@Mapping(target = "comprobanteAfectadoTipo", source = "discrepancyResponse.responseCode")
@Mapping(target = "sustentoDescripcion", source = "discrepancyResponse.description")

@Mapping(target = "totalImporte", source = "monetaryTotal")
@Mapping(target = "detalles", source = "lines")
CreditNote map(XMLCreditNote xml);

@Mapping(target = "importe", source = "payableAmount")
@Mapping(target = "importeSinImpuestos", source = "lineExtensionAmount")
@Mapping(target = "importeConImpuestos", source = "taxInclusiveAmount")
TotalImporteNote mapTotalImporteNote(XMLSalesDocument.MonetaryTotal xml);

default DocumentoVentaDetalle mapDocumentoVentaDetalle(XMLCreditNoteLine xml) {
DocumentoVentaDetalle documentoVentaDetalle = mapSalesDocumentDetalle(xml);
documentoVentaDetalle.setCantidad(xml.getQuantity().getValue());
documentoVentaDetalle.setUnidadMedida(xml.getQuantity().getUnitCode());

return documentoVentaDetalle;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License - 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.project.openubl.xbuilder.content.jaxb.mappers;

import io.github.project.openubl.xbuilder.content.jaxb.mappers.common.SalesDocumentHelperMapper;
import io.github.project.openubl.xbuilder.content.jaxb.mappers.common.SalesDocumentMapper;
import io.github.project.openubl.xbuilder.content.jaxb.models.XMLDebitNote;
import io.github.project.openubl.xbuilder.content.jaxb.models.XMLDebitNoteLine;
import io.github.project.openubl.xbuilder.content.jaxb.models.XMLSalesDocument;
import io.github.project.openubl.xbuilder.content.models.standard.general.DebitNote;
import io.github.project.openubl.xbuilder.content.models.standard.general.DocumentoVentaDetalle;
import io.github.project.openubl.xbuilder.content.models.standard.general.TotalImporteNote;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueMappingStrategy;

@Mapper(config = SalesDocumentMapper.class,
nullValueIterableMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT
)
public interface DebitNoteMapper extends SalesDocumentHelperMapper {

@Mapping(target = "comprobanteAfectadoSerieNumero", source = "discrepancyResponse.referenceID")
@Mapping(target = "comprobanteAfectadoTipo", source = "discrepancyResponse.responseCode")
@Mapping(target = "sustentoDescripcion", source = "discrepancyResponse.description")

@Mapping(target = "totalImporte", source = "monetaryTotal")
@Mapping(target = "detalles", source = "lines")
DebitNote map(XMLDebitNote xml);

@Mapping(target = "importe", source = "payableAmount")
@Mapping(target = "importeSinImpuestos", source = "lineExtensionAmount")
@Mapping(target = "importeConImpuestos", source = "taxInclusiveAmount")
TotalImporteNote mapTotalImporteNote(XMLSalesDocument.MonetaryTotal xml);

default DocumentoVentaDetalle mapDocumentoVentaDetalle(XMLDebitNoteLine xml) {
DocumentoVentaDetalle documentoVentaDetalle = mapSalesDocumentDetalle(xml);
documentoVentaDetalle.setCantidad(xml.getQuantity().getValue());
documentoVentaDetalle.setUnidadMedida(xml.getQuantity().getUnitCode());

return documentoVentaDetalle;
}
}
Loading