Skip to content

Commit f236387

Browse files
add docs (#3)
1 parent 14360c3 commit f236387

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

README.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,68 @@
22
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=project-openubl_xml-builder-lib&metric=alert_status)](https://sonarcloud.io/dashboard?id=project-openubl_xml-builder-lib)
33
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcarlosthe19916%2Fxml-builder-lib.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcarlosthe19916%2Fxml-builder-lib?ref=badge_shield)
44

5-
# xml-builder-lib
5+
# XML Builder Library
6+
7+
Java library for creating XML files based on UBL standards.
8+
9+
## Supported countries
10+
11+
- Perú
12+
13+
> If you want support for your country please create an issue.
14+
15+
## Getting started
16+
17+
XML files can be created from Input Models; for instance:
18+
19+
```java
20+
InvoiceInputModel input = InvoiceInputModel.Builder.anInvoiceInputModel()
21+
.withSerie("F001")
22+
.withNumero(1)
23+
.withProveedor(ProveedorInputModel.Builder.aProveedorInputModel()
24+
.withRuc("12345678912")
25+
.withRazonSocial("Softgreen S.A.C.")
26+
.build()
27+
)
28+
.withCliente(ClienteInputModel.Builder.aClienteInputModel()
29+
.withNombre("Carlos Feria")
30+
.withNumeroDocumentoIdentidad("12121212121")
31+
.withTipoDocumentoIdentidad(Catalog6.RUC.toString())
32+
.build()
33+
)
34+
.withDetalle(Arrays.asList(
35+
DocumentLineInputModel.Builder.aDocumentLineInputModel()
36+
.withDescripcion("Item1")
37+
.withCantidad(new BigDecimal(10))
38+
.withPrecioUnitario(new BigDecimal(100))
39+
.withUnidadMedida("KGM")
40+
.build(),
41+
DocumentLineInputModel.Builder.aDocumentLineInputModel()
42+
.withDescripcion("Item2")
43+
.withCantidad(new BigDecimal(10))
44+
.withPrecioUnitario(new BigDecimal(100))
45+
.withUnidadMedida("KGM")
46+
.build())
47+
)
48+
.build();
49+
50+
// Process Input and get XML
51+
DocumentWrapper<InvoiceOutputModel> result = DocumentFacade.createXML(input, config, systemClock);
52+
InvoiceOutputModel output = result.getOutput();
53+
String xml = result.getXml();
54+
```
55+
56+
## Sign XMLs
57+
58+
After you created the `xml` file you can now sign it:
59+
60+
```java
61+
String xml;
62+
String signID = "mySignID";
63+
64+
// Get your certificate using the method of your preference
65+
X509Certificate certificate;
66+
PrivateKey privateKey;
67+
68+
Document signedXML = XMLSigner.signXML(xml, signID, certificate, privateKey);
69+
```

src/main/java/io/github/project/openubl/xmlbuilderlib/xml/XMLSigner.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@
4343

4444
public class XMLSigner {
4545

46-
public static Document firmarXML(
46+
public static Document signXML(
4747
String text,
4848
String referenceID,
4949
X509Certificate certificate,
5050
PrivateKey privateKey
5151
) throws ParserConfigurationException, NoSuchAlgorithmException, XMLSignatureException, InvalidAlgorithmParameterException, MarshalException, IOException, SAXException {
5252
Document document = XmlSignatureHelper.convertStringToXMLDocument(text);
53-
return firmarXML(document, referenceID, certificate, privateKey);
53+
return signXML(document, referenceID, certificate, privateKey);
5454
}
5555

56-
public static Document firmarXML(
56+
public static Document signXML(
5757
Document copyDocument,
5858
String referenceID,
5959
X509Certificate certificate,

src/test/java/io/github/project/openubl/xmlbuilderlib/integrationtest/AbstractUBLTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void assertSnapshot(String expected, String snapshotFile) {
135135
public void assertSendSunat(String xmlWithoutSignature) throws Exception {
136136
String skipSunat = System.getProperty("skipSunat", "false");
137137
if (skipSunat != null && skipSunat.equals("false")) {
138-
Document signedXML = XMLSigner.firmarXML(xmlWithoutSignature, SIGN_REFERENCE_ID, CERTIFICATE.getX509Certificate(), CERTIFICATE.getPrivateKey());
138+
Document signedXML = XMLSigner.signXML(xmlWithoutSignature, SIGN_REFERENCE_ID, CERTIFICATE.getX509Certificate(), CERTIFICATE.getPrivateKey());
139139
sendFileToSunat(signedXML, xmlWithoutSignature);
140140
}
141141
}

0 commit comments

Comments
 (0)