Skip to content

Commit

Permalink
Merge pull request #25 from gregv12/develop
Browse files Browse the repository at this point in the history
Release 0.2.0
  • Loading branch information
gregv12 authored Apr 18, 2024
2 parents ca1da9e + fe14082 commit 8170974
Show file tree
Hide file tree
Showing 13 changed files with 416 additions and 9 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "maven" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
target-branch: "develop"
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,57 @@ Person problem pushing 'not a number' from row:'4' fieldIndex:'1' targetMethod:'
Max age:43
```

## Single message parse
This example converts a single message into a single bean instance

### StreamBeans code

Mark a java bean with annotation `@CSVMarshaller` use lombok `@Data` to remove the boilerplate getter/setter
methods. The [RowMarshaller](runtime/src/main/java/com/fluxtion/extension/csvcompiler/RowMarshaller.java) is generated
at compile time by the csv-compiler annotation processor.

```java

@Data
@CsvMarshaller
public class Person {
private String name;
private int age;
}
```

The `RowMarshaller.parser(Person.class)` loads a SingleRowMarshaller for the Person javaBean.


A call to `SingleRowMarshaller.parse` will generate a single instance of Person if the message can be parsed. Validation
loggers can inject into the flow if called before the parser method.


```java

public class SingleMessageParse {

public static void main(String[] args) {
SingleRowMarshaller<Person> parser = RowMarshaller.parser(Person.class);
//headers - no output
parser.parse("name,age\n");

System.out.println("parsed:" + parser.parse("Jane,56\n"));
System.out.println("parsed:" + parser.parse("Isiah,12\n"));
System.out.println("parsed:" + parser.parse("Sky,42\n"));
}
}
```


Application execution output:

```text
parsed:SingleMessageParse.Person(name=Jane, age=56)
parsed:SingleMessageParse.Person(name=Isiah, age=12)
parsed:SingleMessageParse.Person(name=Sky, age=42)
```

# Performance

The CSV compiler annotation processor generates a marshaller during compilation. When deployed as a stateless function
Expand Down
4 changes: 2 additions & 2 deletions annotation-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>com.fluxtion.csv-compiler</groupId>
<artifactId>csv-compiler-parentpom</artifactId>
<version>0.1.20-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
<relativePath>../parent-pom/pom.xml</relativePath>
</parent>

<artifactId>csv-compiler-processor</artifactId>
<version>0.1.20-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
<name>csv-compiler :: annotation processor</name>

<description>Build time annotation processor for generating CSV parsers</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.fluxtion.extension.csvcompiler;

import com.fluxtion.extension.csvcompiler.annotations.CsvMarshaller;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class SingleParserTest {


@Data
@AllArgsConstructor
@NoArgsConstructor
@CsvMarshaller
public static class Person {
private String name;
private int age;
}

@Test
public void testSingleParse() {
SingleRowMarshaller<Person> parser = RowMarshaller.parser(Person.class);
//headers - no output
parser.parse("name,age\n");

Assertions.assertEquals(new Person("Jane", 56), parser.parse("Jane,56\n"));
Assertions.assertEquals(new Person("Isiah", 12), parser.parse("Isiah,12\n"));
Assertions.assertEquals(new Person("Sky", 42), parser.parse("Sky,42\n"));
}
}
2 changes: 1 addition & 1 deletion checker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.fluxtion.csv-compiler</groupId>
<artifactId>csv-compiler-parentpom</artifactId>
<version>0.1.20-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
<relativePath>../parent-pom/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
4 changes: 2 additions & 2 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>com.fluxtion.csv-compiler</groupId>
<artifactId>csv-compiler-parentpom</artifactId>
<version>0.1.20-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
<relativePath>../parent-pom/pom.xml</relativePath>
</parent>

<artifactId>csv-compiler-example</artifactId>
<version>0.1.20-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
<name>csv-compiler :: example</name>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.fluxtion.extension.csvcompiler.example2;

import com.fluxtion.extension.csvcompiler.RowMarshaller;
import com.fluxtion.extension.csvcompiler.SingleRowMarshaller;
import com.fluxtion.extension.csvcompiler.annotations.CsvMarshaller;
import lombok.Data;

public class SingleMessageParse {

@Data
@CsvMarshaller
public static class Person {
private String name;
private int age;
}

public static void main(String[] args) {
SingleRowMarshaller<Person> parser = RowMarshaller.parser(Person.class);
//headers - no output
parser.parse("name,age\n");

System.out.println("parsed:" + parser.parse("Jane,56\n"));
System.out.println("parsed:" + parser.parse("Isiah,12\n"));
System.out.println("parsed:" + parser.parse("Sky,42\n"));
}
}
2 changes: 1 addition & 1 deletion parent-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.fluxtion.csv-compiler</groupId>
<artifactId>csv-compiler-parentpom</artifactId>
<version>0.1.20-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>csv-compiler :: parent pom</name>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.fluxtion.extension</groupId>
<artifactId>csv-compiler-master</artifactId>
<version>0.1.20-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>csv-compiler :: master</name>

Expand Down
4 changes: 2 additions & 2 deletions runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>com.fluxtion.csv-compiler</groupId>
<artifactId>csv-compiler-parentpom</artifactId>
<version>0.1.20-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
<relativePath>../parent-pom/pom.xml</relativePath>
</parent>

<artifactId>csv-compiler</artifactId>
<version>0.1.20-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
<name>csv-compiler :: runtime</name>

<description>Runtime library required to use generated CSV parsers</description>
Expand Down
Loading

0 comments on commit 8170974

Please sign in to comment.