Skip to content

Commit 0d00e07

Browse files
Move examples
1 parent 315dcec commit 0d00e07

Some content is hidden

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

47 files changed

+2182
-1
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
java-version: ${{ matrix.java-version }}
3030
cache: maven
3131
- name: Maven tests
32-
run: mvn verify
32+
run: mvn verify -Pexamples
3333
- name: Upload XBuilder e2e Yaml files
3434
uses: actions/upload-artifact@v4
3535
with:

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "interactive"
3+
}

examples/pom.xml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>io.github.project-openubl</groupId>
8+
<artifactId>xhandler-parent</artifactId>
9+
<version>5.0.3-SNAPSHOT</version>
10+
<relativePath>../pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>examples-parent</artifactId>
14+
<name>Examples - Parent</name>
15+
<description>Examples parent</description>
16+
<packaging>pom</packaging>
17+
18+
<modules>
19+
<module>xbuilder</module>
20+
<module>xsender</module>
21+
<module>wildfly</module>
22+
<module>tomcat</module>
23+
<module>springbot</module>
24+
</modules>
25+
</project>

examples/springbot/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Demo XBuilder and XSender using Spring Boot
2+
3+
Download this repository and execute
4+
5+
```shell
6+
mvn spring-boot:run
7+
```
8+
9+
### Use the demo
10+
11+
Open [http://localhost:8080](http://localhost:8080)
12+
13+
![Screenshot](./screenshot.png)

examples/springbot/pom.xml

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
5+
and other contributors as indicated by the @author tags.
6+
7+
Licensed under the Eclipse Public License - v 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
https://www.eclipse.org/legal/epl-2.0/
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<parent>
25+
<groupId>io.github.project-openubl</groupId>
26+
<artifactId>xhandler-parent</artifactId>
27+
<version>5.0.3-SNAPSHOT</version>
28+
<relativePath>../pom.xml</relativePath>
29+
</parent>
30+
31+
<artifactId>examples-springbot</artifactId>
32+
<name>Examples - Springbot</name>
33+
34+
<properties>
35+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
36+
<surefire.plugin.version>3.0.0-M4</surefire.plugin.version>
37+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
38+
<spring.boot-version>2.7.8</spring.boot-version>
39+
</properties>
40+
41+
<dependencyManagement>
42+
<dependencies>
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-dependencies</artifactId>
46+
<version>${spring.boot-version}</version>
47+
<type>pom</type>
48+
<scope>import</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.apache.camel.springboot</groupId>
52+
<artifactId>camel-spring-boot-bom</artifactId>
53+
<version>3.20.3</version>
54+
<type>pom</type>
55+
<scope>import</scope>
56+
</dependency>
57+
</dependencies>
58+
</dependencyManagement>
59+
<dependencies>
60+
<!-- Openubl dependencies -->
61+
<dependency>
62+
<groupId>io.github.project-openubl</groupId>
63+
<artifactId>xbuilder</artifactId>
64+
</dependency>
65+
<dependency>
66+
<groupId>io.github.project-openubl</groupId>
67+
<artifactId>spring-boot-xsender</artifactId>
68+
<version>4.1.4</version>
69+
</dependency>
70+
71+
<!-- Spring minimum libraries -->
72+
<dependency>
73+
<groupId>org.springframework.boot</groupId>
74+
<artifactId>spring-boot-starter-web</artifactId>
75+
</dependency>
76+
77+
<!-- Optional: test dependencies -->
78+
<dependency>
79+
<groupId>org.springframework.boot</groupId>
80+
<artifactId>spring-boot-starter-test</artifactId>
81+
<scope>test</scope>
82+
</dependency>
83+
<dependency>
84+
<groupId>org.apache.camel</groupId>
85+
<artifactId>camel-test-spring-junit5</artifactId>
86+
<scope>test</scope>
87+
</dependency>
88+
</dependencies>
89+
90+
<build>
91+
<plugins>
92+
<plugin>
93+
<groupId>org.springframework.boot</groupId>
94+
<artifactId>spring-boot-maven-plugin</artifactId>
95+
<version>${spring.boot-version}</version>
96+
<executions>
97+
<execution>
98+
<goals>
99+
<goal>repackage</goal>
100+
</goals>
101+
</execution>
102+
</executions>
103+
</plugin>
104+
<plugin>
105+
<artifactId>maven-surefire-plugin</artifactId>
106+
<version>${surefire.plugin.version}</version>
107+
</plugin>
108+
<plugin>
109+
<artifactId>maven-compiler-plugin</artifactId>
110+
<version>3.11.0</version>
111+
<configuration>
112+
<release>11</release>
113+
<source>11</source>
114+
<target>11</target>
115+
</configuration>
116+
</plugin>
117+
</plugins>
118+
</build>
119+
120+
</project>

examples/springbot/screenshot.png

18.4 KB
Loading
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+
* <p>
5+
* Licensed under the Eclipse Public License - v 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+
* <p>
9+
* https://www.eclipse.org/legal/epl-2.0/
10+
* <p>
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.quickstart.xbuilder.springboot;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
import org.springframework.context.annotation.ComponentScan;
22+
23+
@ComponentScan
24+
@ComponentScan("io.github.project.openubl.spring.xsender.runtime")
25+
@SpringBootApplication
26+
public class Application {
27+
28+
public static void main(String[] args) {
29+
SpringApplication.run(Application.class, args);
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 Eclipse Public License - v 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.eclipse.org/legal/epl-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.quickstart.xbuilder.springboot;
18+
19+
import io.github.project.openubl.xbuilder.content.catalogs.Catalog6;
20+
import io.github.project.openubl.xbuilder.content.models.common.Cliente;
21+
import io.github.project.openubl.xbuilder.content.models.common.Proveedor;
22+
import io.github.project.openubl.xbuilder.content.models.standard.general.DocumentoVentaDetalle;
23+
import io.github.project.openubl.xbuilder.content.models.standard.general.Invoice;
24+
import io.github.project.openubl.xbuilder.enricher.ContentEnricher;
25+
import io.github.project.openubl.xbuilder.enricher.config.DateProvider;
26+
import io.github.project.openubl.xbuilder.enricher.config.Defaults;
27+
import io.github.project.openubl.xbuilder.renderer.TemplateProducer;
28+
import io.github.project.openubl.xbuilder.signature.CertificateDetails;
29+
import io.github.project.openubl.xbuilder.signature.CertificateDetailsFactory;
30+
import io.github.project.openubl.xbuilder.signature.XMLSigner;
31+
import io.github.project.openubl.xbuilder.signature.XmlSignatureHelper;
32+
import io.quarkus.qute.Template;
33+
import org.springframework.web.bind.annotation.RequestBody;
34+
import org.springframework.web.bind.annotation.RequestMapping;
35+
import org.springframework.web.bind.annotation.RequestMethod;
36+
import org.springframework.web.bind.annotation.RestController;
37+
import org.w3c.dom.Document;
38+
39+
import java.io.InputStream;
40+
import java.math.BigDecimal;
41+
import java.nio.charset.StandardCharsets;
42+
import java.security.PrivateKey;
43+
import java.security.cert.X509Certificate;
44+
import java.time.LocalDate;
45+
46+
@RestController
47+
public class XBuilderController {
48+
49+
Defaults defaults = Defaults.builder()
50+
.icbTasa(new BigDecimal("0.2"))
51+
.igvTasa(new BigDecimal("0.18"))
52+
.build();
53+
54+
DateProvider dateProvider = LocalDate::now;
55+
56+
@RequestMapping(
57+
method = RequestMethod.POST,
58+
value = "/api/create-xml",
59+
produces = "text/plain"
60+
)
61+
public String createXML(@RequestBody String clientName) throws Exception {
62+
Invoice invoice = createInvoice(clientName);
63+
64+
ContentEnricher enricher = new ContentEnricher(defaults, dateProvider);
65+
enricher.enrich(invoice);
66+
67+
Template template = TemplateProducer.getInstance().getInvoice();
68+
String xml = template.data(invoice).render();
69+
70+
// Sign XML
71+
InputStream ksInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("LLAMA-PE-CERTIFICADO-DEMO-12345678912.pfx");
72+
CertificateDetails certificate = CertificateDetailsFactory.create(ksInputStream, "password");
73+
74+
X509Certificate x509Certificate = certificate.getX509Certificate();
75+
PrivateKey privateKey = certificate.getPrivateKey();
76+
Document signedXML = XMLSigner.signXML(xml, "Project OpenUBL", x509Certificate, privateKey);
77+
78+
// Return
79+
byte[] bytesFromDocument = XmlSignatureHelper.getBytesFromDocument(signedXML);
80+
return new String(bytesFromDocument, StandardCharsets.ISO_8859_1);
81+
}
82+
83+
private Invoice createInvoice(String clientName) {
84+
return Invoice.builder()
85+
.serie("F001")
86+
.numero(1)
87+
.proveedor(Proveedor.builder()
88+
.ruc("12345678912")
89+
.razonSocial("Softgreen S.A.C.")
90+
.build()
91+
)
92+
.cliente(Cliente.builder()
93+
.nombre(clientName)
94+
.numeroDocumentoIdentidad("12121212121")
95+
.tipoDocumentoIdentidad(Catalog6.RUC.toString())
96+
.build()
97+
)
98+
.detalle(DocumentoVentaDetalle.builder()
99+
.descripcion("Item1")
100+
.cantidad(new BigDecimal("10"))
101+
.precio(new BigDecimal("100"))
102+
.unidadMedida("KGM")
103+
.build()
104+
)
105+
.detalle(DocumentoVentaDetalle.builder()
106+
.descripcion("Item2")
107+
.cantidad(new BigDecimal("10"))
108+
.precio(new BigDecimal("100"))
109+
.unidadMedida("KGM")
110+
.build()
111+
)
112+
.build();
113+
}
114+
115+
}

0 commit comments

Comments
 (0)