Terms of Service | Privacy Policy | Cookie Policy

...
 
Commits (4)
......@@ -622,7 +622,7 @@
<site>
<id>pages</id>
<url>https://sw4j-org.pages.sw4j.net/random-barcode</url>
<url>https://random-barcode.sw4j.org/</url>
</site>
</distributionManagement>
......@@ -631,4 +631,9 @@
<url>https://git.sw4j.net/sw4j-org/random-barcode/pipelines</url>
</ciManagement>
<issueManagement>
<system>GitLab</system>
<url>https://git.sw4j.net/sw4j-org/random-barcode/issues</url>
</issueManagement>
</project>
\ No newline at end of file
......@@ -90,6 +90,9 @@ public class BarcodeWriter implements Consumer<RandomIdent> {
CodeType codeType = codeConfig.getType();
String codeEncoding = codeConfig.getEncoding();
String codeUrl = codeConfig.getUrl();
if (codeUrl == null) {
codeUrl = "{code}";
}
codeUrl = codeUrl.replace("{code}", randomIdent.getEncoded(codeEncoding));
try {
OutputStream os = codeData.getOutputForIdent(codeType, codeEncoding, randomIdent.getIdent(),
......
......@@ -59,7 +59,7 @@ public class RandomIdent {
/**
* <p>
* Create a new {@code RandomIdent} and the random number for the {@qcode ident}. The random number has a size of
* Create a new {@code RandomIdent} and the random number for the {@code ident}. The random number has a size of
* {@code randomSize} bits (rounded down to the next whole byte). For the generation of the random number the given
* {@code rng} will be used. The generated random number will be encoded in all given {@code encodings}.
* </p>
......
#set($h1 = '#')
#set($h2 = '##')
#set($h3 = '##')
#set($h3 = '###')
#set($h4 = '####')
$h1 User Documentation
<!-- MACRO{toc|fromDepth=1|toDepth=2} -->
$h2 Configuration
The configuration file is a [YAML](https://en.wikipedia.org/wiki/YAML) document.
......@@ -44,6 +47,8 @@ input:
name: data/input.csv
```
The path of the input file is relative to the current working directory.
The input file is a simple csv file in which the identifiers are defined. The only column in this file is a list of
identifiers.
......@@ -59,8 +64,12 @@ This input file defines 3 identifiers.
**Important** The file may not contain any duplicated identifiers.
Currently the input file may not contain a header.
$h3 Output
The `output` section defines the configuration for the output.
```
output:
folder: output/
......@@ -68,8 +77,20 @@ output:
name: output.csv
```
The first item (`folder`) defines where all output files will be placed into. This includes the csv output file and all
barcodes generated.
The folder is relative to the current working directory.
The output file is a csv file with the first column containing the identifiers from the input file and then the random
numbers encoded in the different encodings defined in the [Random](#Random) section.
$h3 Random
$h4 Overview
The `random` section defines the random number generated and how this should be encoded.
```
random:
size: 128
......@@ -84,3 +105,63 @@ random:
encodings:
- base58
```
The `size` defines the size is bits of the random number. This must be a multiple of 8.
The subsection `codes` defines the barcodes to be generated. The subsection `encodings` defines additional encodings
are written into the output file without generating a barcode.
At least one subsection (`codes` or `encodings`) with at least one entry must exists.
$h4 codes
The `codes` subsection defines the barcodes that should be created. Each entry has multiple attributes.
The required attributes are `type` and `encoding`.
The attribute `type` defines the type of the barcode to generate. All supported barcodes are listed in
[Barcodes](#Barcodes).
The attribute `size` defines the size of the barcode. If this attribute is left out then a size of `200x200` is used. To
define a square barcode a single figure (e.g. `150`) can be used.
The attribute `errocorrection` depends on the `type` of the barcode. The possible values and the default value is
defined in the list of supported [barcodes](#Barcodes).
The attribute `filetype` defines the filetype of the barcode output. The currently supported filetypes are listed in
[Filetypes](#Filetypes).
The attribute `encoding` defines the encoding of the random number. The currently supported encodings are listed in
[Encodings](#Encodings).
The attribute `url` defines a free text which is encoded into the barcode. A typical text is an URL that embeds the
generated code. To place the code in the text use the placeholder `{code}`.
$h4 encodings
The `encodings` subsection defines the additional encodings that should be written into the output file. This can be
useful to differentiate between a code in a barcode and a code that is be given to the customer in another way (e.g.
in printed form).
The `encodings` subsection is simply a list of encodings like the encoding in the [`codes`](#codes) subsection.
$h3 Supported Encodings, Barcodes and Filetypes
$h4 Encodings
Currently supported encodings:
* hex
* base58 (with the [bitcoin alphabet](https://en.bitcoin.it/wiki/Base58Check_encoding#Base58_symbol_chart))
$h4 Barcodes
Currently supported barcodes and error corrections (default error correction emphasized):
* QR-Code (L, M, Q, **H**)
$h4 Filetypes
Currently supported filetypes:
* png
......@@ -5,8 +5,8 @@ $h1 User Documentation
$h2 Introduction
This program creates individual codes for a list of input data (e.g. customers identifiers) and writes this codes to
a csv file. Additionally barcodes for the individual codes can be created.
This program creates individual random codes for a list of input data (e.g. customers identifiers) and writes this codes
to a csv file. Additionally barcodes for the individual codes can be created.
$h2 Configuration
......
......@@ -33,7 +33,6 @@ import javax.xml.bind.DatatypeConverter;
import org.sw4j.tool.barcode.random.codedata.CodeData;
import org.sw4j.tool.barcode.random.config.CodeConfig;
import org.sw4j.tool.barcode.random.config.RandomConfig;
import org.sw4j.tool.barcode.random.generator.RandomIdent;
import org.sw4j.tool.barcode.random.support.PredictableRandom;
import org.sw4j.tool.barcode.random.support.TestCodeData;
import static org.testng.Assert.*;
......@@ -223,6 +222,24 @@ public class CodeGeneratorNGTest {
assertEquals(codeData.getOutputs().size(), 1, "Expected 1 barcode to be created.");
}
@Test
public void createCodeOutputWithoutURL() throws IOException {
InputStream is = new ByteArrayInputStream("01\n".getBytes(Charset.forName("UTF-8")));
OutputStream os = new ByteArrayOutputStream();
CodeConfig codeConfig = CodeConfig.builder()
.setType("qrcode")
.setEncoding("hex")
.build();
RandomConfig config = new RandomConfig(128, Arrays.asList(codeConfig), Arrays.asList("base58{10}"));
TestCodeData codeData = new TestCodeData(is, os);
CodeGenerator generator = new CodeGenerator(config, codeData);
generator.createCodes();
assertEquals(codeData.getOutputs().size(), 1, "Expected 1 barcode to be created.");
}
@Test
public void createCodeWithValidErrorCorrection() throws IOException {
InputStream is = new ByteArrayInputStream("01\n".getBytes(Charset.forName("UTF-8")));
......