Skip to content

Commit

Permalink
Merge pull request #19 from joutvhu/development
Browse files Browse the repository at this point in the history
1.1.2
  • Loading branch information
joutvhu authored Jun 16, 2021
2 parents 7d16320 + 3cb1d72 commit 610a3b3
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.2"
```

- Or add the following dependency to your `pom.xml` if you are using Maven.
Expand All @@ -20,7 +20,7 @@ compile "com.github.joutvhu:fixed-width-parser:1.1.0"
<dependency>
<groupId>com.github.joutvhu</groupId>
<artifactId>fixed-width-parser</artifactId>
<version>1.1.0</version>
<version>1.1.2</version>
</dependency>
```

Expand Down
32 changes: 16 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = 'com.github.joutvhu'
version '1.1.0'
version '1.1.2'
sourceCompatibility = 1.8
targetCompatibility = 1.8

Expand All @@ -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'

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @return label name of the field
*/
String label();
String label() default "";

/**
* Setups the start position of the field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
}
Expand Down
66 changes: 66 additions & 0 deletions src/test/java/com/joutvhu/fixedwidth/parser/DemoTests.java
Original file line number Diff line number Diff line change
@@ -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 Fruit 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;
}
}
2 changes: 1 addition & 1 deletion src/test/java/com/joutvhu/fixedwidth/parser/ModelG.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down

0 comments on commit 610a3b3

Please sign in to comment.