From 2d29ea24f9401669c640eb9f4157577f0dc423c1 Mon Sep 17 00:00:00 2001 From: Giao Ho Date: Mon, 5 Oct 2020 10:15:53 +0700 Subject: [PATCH 1/4] Change message --- README.md | 4 ++-- build.gradle | 2 +- .../fixedwidth/parser/convert/validator/NumberValidator.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 890da5d..e80aa9c 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Fixed Width Parser is a small library that purpose is: - If you are using Gradle just add the following dependency to your `build.gradle`. ```groovy -compile "com.github.joutvhu:fixed-width-parser:1.1.0" +compile "com.github.joutvhu:fixed-width-parser:1.1.1" ``` - Or add the following dependency to your `pom.xml` if you are using Maven. @@ -20,7 +20,7 @@ compile "com.github.joutvhu:fixed-width-parser:1.1.0" com.github.joutvhu fixed-width-parser - 1.1.0 + 1.1.1 ``` diff --git a/build.gradle b/build.gradle index b479378..0407e4e 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group = 'com.github.joutvhu' -version '1.1.0' +version '1.1.1' sourceCompatibility = 1.8 targetCompatibility = 1.8 diff --git a/src/main/java/com/joutvhu/fixedwidth/parser/convert/validator/NumberValidator.java b/src/main/java/com/joutvhu/fixedwidth/parser/convert/validator/NumberValidator.java index 89de8c6..38abc1d 100644 --- a/src/main/java/com/joutvhu/fixedwidth/parser/convert/validator/NumberValidator.java +++ b/src/main/java/com/joutvhu/fixedwidth/parser/convert/validator/NumberValidator.java @@ -45,8 +45,8 @@ public void validate(String value, ValidationType type) { } else { String regex = isDecimal ? "^[0-9]+(\\.[0-9]+)?$" : "^[0-9]+$"; if (!Pattern.matches(regex, value)) { - throw new InvalidException(info.formatMessage( - "{title} with value \"{value}\" is not a {number_type}.", + String message = "{title} with value \"{value}\" is not " + (isDecimal ? "a" : "an") + " {number_type}."; + throw new InvalidException(info.formatMessage(message, CommonUtil.putToMap(super.getArguments(value), "{number_type}", () -> isDecimal ? "number" : "integer"))); } From f0dcd60a163de5b3250ddc996c19660af6d16f76 Mon Sep 17 00:00:00 2001 From: f4lco Date: Wed, 16 Jun 2021 10:08:20 +0200 Subject: [PATCH 2/4] Make FixedField#label optional The label of FixedFields should work in the same way as for FixedObject or FixedParam, whose label is optional. If the FixedField label is blank, the parser already assigns the name of the backing field as label, which is a reasonable default. --- .../com/joutvhu/fixedwidth/parser/annotation/FixedField.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/joutvhu/fixedwidth/parser/annotation/FixedField.java b/src/main/java/com/joutvhu/fixedwidth/parser/annotation/FixedField.java index 0900712..6016fce 100644 --- a/src/main/java/com/joutvhu/fixedwidth/parser/annotation/FixedField.java +++ b/src/main/java/com/joutvhu/fixedwidth/parser/annotation/FixedField.java @@ -21,7 +21,7 @@ * * @return label name of the field */ - String label(); + String label() default ""; /** * Setups the start position of the field From 91a945a852ce0ae763af2d05ecee614b060c0f0e Mon Sep 17 00:00:00 2001 From: Giao Ho Date: Wed, 16 Jun 2021 20:52:12 +0700 Subject: [PATCH 3/4] Update test --- .../joutvhu/fixedwidth/parser/DemoTests.java | 66 +++++++++++++++++++ .../com/joutvhu/fixedwidth/parser/ModelG.java | 2 +- .../fixedwidth/parser/ModelGTests.java | 1 + 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/joutvhu/fixedwidth/parser/DemoTests.java diff --git a/src/test/java/com/joutvhu/fixedwidth/parser/DemoTests.java b/src/test/java/com/joutvhu/fixedwidth/parser/DemoTests.java new file mode 100644 index 0000000..ff7e8b3 --- /dev/null +++ b/src/test/java/com/joutvhu/fixedwidth/parser/DemoTests.java @@ -0,0 +1,66 @@ +package com.joutvhu.fixedwidth.parser; + +import com.joutvhu.fixedwidth.parser.annotation.FixedField; +import com.joutvhu.fixedwidth.parser.annotation.FixedObject; +import com.joutvhu.fixedwidth.parser.annotation.FixedParam; +import com.joutvhu.fixedwidth.parser.constraint.FixedFormat; +import com.joutvhu.fixedwidth.parser.constraint.FixedOption; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +import java.time.LocalDate; +import java.util.List; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class DemoTests { + @Test + public void demoTest() { + Food food = (Food) FixedParser + .parser() + .parse("00001Dragon Food 09/30/2020fruit ", Product.class); + + Medicine medicine = (Medicine) FixedParser + .parser() + .parse("60002Golden Star Balm YCamphor Peppermint oil Menthol Tea Tree Oil", Product.class); + + String value = FixedParser + .parser() + .export(food); + + Assertions.assertNotNull(medicine); + Assertions.assertNotNull(value); + } + + @FixedObject(subTypes = { + @FixedObject.Type(value = Food.class, prop = "id", matchWith = "^[0-5].+$") + }, defaultSubType = Medicine.class) + public static class Product { + @FixedField(label = "Product Id", start = 0, length = 5) + private Long id; + + @FixedField(label = "Product Name", start = 5, length = 20) + private String name; + } + + @FixedObject + public static class Food extends Product { + @FixedFormat(format = "MM/dd/yyyy") + @FixedField(label = "Expiry Date", start = 25, length = 10) + private LocalDate expiryDate; + + @FixedOption(options = {"rice ", "breads", "fruit "}) + @FixedField(label = "Type", start = 35, length = 6) + private String type; + } + + @FixedObject + public static class Medicine extends Product { + @FixedFormat(format = "Y|N") + @FixedField(label = "Topical", start = 25, length = 1) + private Boolean topical; + + @FixedField(label = "Ingredients", start = 26, length = 60) + private List<@FixedParam(length = 15) String> ingredients; + } +} diff --git a/src/test/java/com/joutvhu/fixedwidth/parser/ModelG.java b/src/test/java/com/joutvhu/fixedwidth/parser/ModelG.java index 1e9b7ef..92a0eda 100644 --- a/src/test/java/com/joutvhu/fixedwidth/parser/ModelG.java +++ b/src/test/java/com/joutvhu/fixedwidth/parser/ModelG.java @@ -15,7 +15,7 @@ @FixedObject public class ModelG extends ModelD { @FixedRegex(regex = "[a-zA-Z]") - @FixedField(label = "FIELD-D", start = 3, length = 1) + @FixedField(start = 3, length = 1) private Character fieldD; public ModelG(Long fieldA, @FixedRegex(regex = "[a-zA-Z]") Character fieldD) { diff --git a/src/test/java/com/joutvhu/fixedwidth/parser/ModelGTests.java b/src/test/java/com/joutvhu/fixedwidth/parser/ModelGTests.java index 763b6bf..7074051 100644 --- a/src/test/java/com/joutvhu/fixedwidth/parser/ModelGTests.java +++ b/src/test/java/com/joutvhu/fixedwidth/parser/ModelGTests.java @@ -22,6 +22,7 @@ public void read1Test() { Assertions.fail(); } catch (Exception e) { Assertions.assertTrue(e instanceof InvalidException); + Assertions.assertEquals("fieldD field at position 4 and length 1 does not match the /[a-zA-Z]/ regex.", e.getMessage()); } } From 96352a6de0b93d3c6bbeccf5520a3b71419a9864 Mon Sep 17 00:00:00 2001 From: Giao Ho Date: Thu, 17 Jun 2021 01:30:41 +0700 Subject: [PATCH 4/4] Update version --- README.md | 4 ++-- build.gradle | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index e80aa9c..0eeffdd 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Fixed Width Parser is a small library that purpose is: - If you are using Gradle just add the following dependency to your `build.gradle`. ```groovy -compile "com.github.joutvhu:fixed-width-parser:1.1.1" +compile "com.github.joutvhu:fixed-width-parser:1.1.2" ``` - Or add the following dependency to your `pom.xml` if you are using Maven. @@ -20,7 +20,7 @@ compile "com.github.joutvhu:fixed-width-parser:1.1.1" com.github.joutvhu fixed-width-parser - 1.1.1 + 1.1.2 ``` diff --git a/build.gradle b/build.gradle index 0407e4e..6f8ee43 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group = 'com.github.joutvhu' -version '1.1.1' +version '1.1.2' sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -24,26 +24,26 @@ repositories { dependencies { annotationProcessor 'org.projectlombok:lombok:1.18.12' - compile 'org.projectlombok:lombok:1.18.12' + compileOnly 'org.projectlombok:lombok:1.18.12' - compile 'org.apache.commons:commons-lang3:3.11' - compile 'com.google.code.findbugs:jsr305:3.0.2' + implementation 'org.apache.commons:commons-lang3:3.11' + implementation 'com.google.code.findbugs:jsr305:3.0.2' - compile 'org.apache.logging.log4j:log4j-api:2.13.3' - compile 'org.apache.logging.log4j:log4j-core:2.13.3' + implementation 'org.apache.logging.log4j:log4j-api:2.13.3' + implementation 'org.apache.logging.log4j:log4j-core:2.13.3' - compile "com.google.re2j:re2j:1.4" + implementation "com.google.re2j:re2j:1.4" - compile "org.reflections:reflections:0.9.12" + implementation "org.reflections:reflections:0.9.12" - compile "com.fasterxml.jackson.core:jackson-core:2.11.2" - compile "com.fasterxml.jackson.core:jackson-annotations:2.11.2" - compile "com.fasterxml.jackson.core:jackson-databind:2.11.2" - compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.2" - compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.2" + implementation "com.fasterxml.jackson.core:jackson-core:2.11.2" + implementation "com.fasterxml.jackson.core:jackson-annotations:2.11.2" + implementation "com.fasterxml.jackson.core:jackson-databind:2.11.2" + implementation "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.2" + implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.2" - testCompile 'junit:junit:4.13' - testCompile 'org.junit.jupiter:junit-jupiter-api:5.6.2' + testImplementation 'junit:junit:4.13' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.2' testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.6.2' @@ -134,7 +134,7 @@ publishing { withXml { def dependenciesNode = asNode().appendNode('dependencies') - configurations.compile.allDependencies.each { + configurations.implementation.allDependencies.each { def dependencyNode = dependenciesNode.appendNode('dependency') dependencyNode.appendNode('groupId', it.group) dependencyNode.appendNode('artifactId', it.name)