This repository has been archived by the owner on Jul 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update versions * update xbuilder version * Add spring boot demo * Add spring boot demo * remove no needed * license
- Loading branch information
1 parent
c6ebc7c
commit 1e4979d
Showing
17 changed files
with
537 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Demo XBuilder and XSender using Spring Boot | ||
|
||
Download this repository and execute | ||
|
||
```shell | ||
mvn spring-boot:run | ||
``` | ||
|
||
### Use the demo | ||
|
||
Open [http://localhost:8080](http://localhost:8080) | ||
|
||
![Screenshot](./screenshot.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2019 Project OpenUBL, Inc. and/or its affiliates | ||
and other contributors as indicated by the @author tags. | ||
Licensed under the Eclipse Public License - v 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.eclipse.org/legal/epl-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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.4.3</version> | ||
<relativePath/> | ||
</parent> | ||
|
||
<groupId>io.github.project-openubl</groupId> | ||
<artifactId>spring-boot-xbuilder-xsender</artifactId> | ||
|
||
<version>0.0.1-SNAPSHOT</version> | ||
<name>Spring Boot - XBuilder, XSender</name> | ||
<description>Demo XBuilder and XSender using Spring Boot</description> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.project-openubl</groupId> | ||
<artifactId>xbuilder</artifactId> | ||
<version>1.1.6.Final</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.project-openubl</groupId> | ||
<artifactId>xsender</artifactId> | ||
<version>3.0.3.Final</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions
49
...t/src/main/java/io/github/project/openubl/quickstart/xbuilder/springboot/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Eclipse Public License - v 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.eclipse.org/legal/epl-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.quickstart.xbuilder.springboot; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
|
||
@Bean | ||
public CommandLineRunner commandLineRunner(ApplicationContext ctx) { | ||
return args -> { | ||
|
||
System.out.println("Let's inspect the beans provided by Spring Boot:"); | ||
|
||
String[] beanNames = ctx.getBeanDefinitionNames(); | ||
Arrays.sort(beanNames); | ||
for (String beanName : beanNames) { | ||
System.out.println(beanName); | ||
} | ||
|
||
}; | ||
} | ||
|
||
} |
102 changes: 102 additions & 0 deletions
102
...ain/java/io/github/project/openubl/quickstart/xbuilder/springboot/XBuilderController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Eclipse Public License - v 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.eclipse.org/legal/epl-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.quickstart.xbuilder.springboot; | ||
|
||
import io.github.project.openubl.quickstart.xbuilder.springboot.xbuilder.XBuilderConfig; | ||
import io.github.project.openubl.quickstart.xbuilder.springboot.xbuilder.XBuilderSystemClock; | ||
import io.github.project.openubl.xmlbuilderlib.facade.DocumentManager; | ||
import io.github.project.openubl.xmlbuilderlib.facade.DocumentWrapper; | ||
import io.github.project.openubl.xmlbuilderlib.models.catalogs.Catalog6; | ||
import io.github.project.openubl.xmlbuilderlib.models.input.common.ClienteInputModel; | ||
import io.github.project.openubl.xmlbuilderlib.models.input.common.ProveedorInputModel; | ||
import io.github.project.openubl.xmlbuilderlib.models.input.standard.DocumentLineInputModel; | ||
import io.github.project.openubl.xmlbuilderlib.models.input.standard.invoice.InvoiceInputModel; | ||
import io.github.project.openubl.xmlbuilderlib.models.output.standard.invoice.InvoiceOutputModel; | ||
import io.github.project.openubl.xmlbuilderlib.utils.CertificateDetails; | ||
import io.github.project.openubl.xmlbuilderlib.utils.CertificateDetailsFactory; | ||
import io.github.project.openubl.xmlbuilderlib.xml.XMLSigner; | ||
import io.github.project.openubl.xmlbuilderlib.xml.XmlSignatureHelper; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.w3c.dom.Document; | ||
|
||
import java.io.InputStream; | ||
import java.math.BigDecimal; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.*; | ||
import java.security.cert.X509Certificate; | ||
import java.util.Arrays; | ||
|
||
@RestController | ||
public class XBuilderController { | ||
|
||
@RequestMapping( | ||
method = RequestMethod.POST, | ||
value = "/api/create-xml", | ||
produces = "text/plain" | ||
) | ||
public String createXML(@RequestBody String clientName) throws Exception { | ||
InvoiceInputModel input = createInvoice(clientName); | ||
DocumentWrapper<InvoiceOutputModel> result = DocumentManager.createXML(input, new XBuilderConfig(), new XBuilderSystemClock()); | ||
String xml = result.getXml(); | ||
|
||
// Sign XML | ||
InputStream ksInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("LLAMA-PE-CERTIFICADO-DEMO-12345678912.pfx"); | ||
CertificateDetails certificate = CertificateDetailsFactory.create(ksInputStream, "password"); | ||
|
||
X509Certificate x509Certificate = certificate.getX509Certificate(); | ||
PrivateKey privateKey = certificate.getPrivateKey(); | ||
Document signedXML = XMLSigner.signXML(xml, "Project OpenUBL", x509Certificate, privateKey); | ||
|
||
// Return | ||
byte[] bytesFromDocument = XmlSignatureHelper.getBytesFromDocument(signedXML); | ||
return new String(bytesFromDocument, StandardCharsets.ISO_8859_1); | ||
} | ||
|
||
private InvoiceInputModel createInvoice(String clientName) { | ||
return InvoiceInputModel.Builder.anInvoiceInputModel() | ||
.withSerie("F001") | ||
.withNumero(1) | ||
.withProveedor(ProveedorInputModel.Builder.aProveedorInputModel() | ||
.withRuc("12345678912") | ||
.withRazonSocial("Los grandes S.A.C.") | ||
.build() | ||
) | ||
.withCliente(ClienteInputModel.Builder.aClienteInputModel() | ||
.withNombre(clientName) | ||
.withNumeroDocumentoIdentidad("12121212121") | ||
.withTipoDocumentoIdentidad(Catalog6.RUC.toString()) | ||
.build() | ||
) | ||
.withDetalle(Arrays.asList( | ||
DocumentLineInputModel.Builder.aDocumentLineInputModel() | ||
.withDescripcion("Item1") | ||
.withCantidad(new BigDecimal(10)) | ||
.withPrecioUnitario(new BigDecimal(100)) | ||
.build(), | ||
DocumentLineInputModel.Builder.aDocumentLineInputModel() | ||
.withDescripcion("Item2") | ||
.withCantidad(new BigDecimal(10)) | ||
.withPrecioUnitario(new BigDecimal(100)) | ||
.build()) | ||
) | ||
.build(); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...main/java/io/github/project/openubl/quickstart/xbuilder/springboot/XSenderController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Eclipse Public License - v 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.eclipse.org/legal/epl-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.quickstart.xbuilder.springboot; | ||
|
||
import io.github.project.openubl.xmlsenderws.webservices.exceptions.InvalidXMLFileException; | ||
import io.github.project.openubl.xmlsenderws.webservices.exceptions.UnsupportedDocumentTypeException; | ||
import io.github.project.openubl.xmlsenderws.webservices.managers.smart.SmartBillServiceConfig; | ||
import io.github.project.openubl.xmlsenderws.webservices.managers.smart.SmartBillServiceManager; | ||
import io.github.project.openubl.xmlsenderws.webservices.managers.smart.SmartBillServiceModel; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
|
||
@RestController | ||
public class XSenderController { | ||
|
||
private final String username = "12345678912MODDATOS"; | ||
private final String password = "MODDATOS"; | ||
|
||
@PostMapping("/api/file/upload") | ||
public String uploadFile(@RequestParam("file") MultipartFile file) throws IOException, InvalidXMLFileException, UnsupportedDocumentTypeException { | ||
SmartBillServiceConfig.getInstance() | ||
.withInvoiceAndNoteDeliveryURL("https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService") | ||
.withPerceptionAndRetentionDeliveryURL("https://e-beta.sunat.gob.pe/ol-ti-itemision-otroscpe-gem-beta/billService") | ||
.withDespatchAdviceDeliveryURL("https://e-beta.sunat.gob.pe/ol-ti-itemision-guia-gem-beta/billService"); | ||
|
||
SmartBillServiceModel result = SmartBillServiceManager.send(file.getBytes(), username, password); | ||
return result.getXmlContentModel().getDocumentType() + " " + result.getBillServiceModel().getStatus(); | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
...ava/io/github/project/openubl/quickstart/xbuilder/springboot/xbuilder/XBuilderConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Eclipse Public License - v 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.eclipse.org/legal/epl-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.quickstart.xbuilder.springboot.xbuilder; | ||
|
||
import io.github.project.openubl.xmlbuilderlib.config.Config; | ||
import io.github.project.openubl.xmlbuilderlib.models.catalogs.Catalog10; | ||
import io.github.project.openubl.xmlbuilderlib.models.catalogs.Catalog7; | ||
import io.github.project.openubl.xmlbuilderlib.models.catalogs.Catalog9; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class XBuilderConfig implements Config { | ||
private BigDecimal igv = new BigDecimal("0.18"); | ||
private BigDecimal ivap = new BigDecimal("0.04"); | ||
private String defaultMoneda = "PEN"; | ||
private String defaultUnidadMedida = "NIU"; | ||
private Catalog9 defaultTipoNotaCredito = Catalog9.ANULACION_DE_LA_OPERACION; | ||
private Catalog10 defaultTipoNotaDebito = Catalog10.AUMENTO_EN_EL_VALOR; | ||
private BigDecimal defaultIcb = new BigDecimal("0.2"); | ||
private Catalog7 defaultTipoIgv = Catalog7.GRAVADO_OPERACION_ONEROSA; | ||
|
||
@Override | ||
public BigDecimal getIgv() { | ||
return igv; | ||
} | ||
|
||
@Override | ||
public BigDecimal getIvap() { | ||
return ivap; | ||
} | ||
|
||
@Override | ||
public String getDefaultMoneda() { | ||
return defaultMoneda; | ||
} | ||
|
||
@Override | ||
public String getDefaultUnidadMedida() { | ||
return defaultUnidadMedida; | ||
} | ||
|
||
@Override | ||
public Catalog9 getDefaultTipoNotaCredito() { | ||
return defaultTipoNotaCredito; | ||
} | ||
|
||
@Override | ||
public Catalog10 getDefaultTipoNotaDebito() { | ||
return defaultTipoNotaDebito; | ||
} | ||
|
||
@Override | ||
public BigDecimal getDefaultIcb() { | ||
return defaultIcb; | ||
} | ||
|
||
@Override | ||
public Catalog7 getDefaultTipoIgv() { | ||
return defaultTipoIgv; | ||
} | ||
} |
Oops, something went wrong.