Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 41 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# Csv codec (3.2.1)
# Csv codec (4.0.0)
## Description
Designed for decode csv raw messages from csv reader to the parsed messages.
It is based on [th2-codec](https://github.com/th2-net/th2-codec).
You can find additional information [here](https://github.com/th2-net/th2-codec/blob/master/README.md)

## Decoding

The codec decodes each raw message in the received batch.
Each raw message might contains several line in CSV format.
Each raw message might contain several line in CSV format.
If the default header parameter is not set the codec trites the first line from the raw message as a header.
Otherwise, the default header will be used for decoding the rest of data.

If no data was decoded from raw message, the message will be skipped, and an error event will be reported.

**NOTE: the encoding is not supported**.

## Decode Example

Simple example:
Expand Down Expand Up @@ -53,7 +57,7 @@ into
```

## Settings
Csv codec has following parameters:
Csv codec has the following parameters:

```yaml
default-header: [A, B, C]
Expand All @@ -73,38 +77,58 @@ The default value for the name is `CodecCsv`.

**validate-length** - check if csv have different count of values against header's count

## Pins

The CSV codec requires at leas one pin with the following attributes:
1. `decode_in` and `subscribe` - to receive raw data.
2. `decode_out` and `publish` - to send decoded data.

The number of pins with each set of attributes is not limited. **Pins can use filters**.

## Full configuration example

```yaml
apiVersion: th2.exactpro.com/v1
kind: Th2GenericBox
kind: Th2Box
metadata:
name: codec-csv
spec:
image-name: ghcr.io/th2-net/th2-codec-csv
image-version: 4.0.0
custom-config:
default-header: [A, B, C]
delimiter: ','
encoding: UTF-8
codecSettings:
default-header: [A, B, C]
delimiter: ','
encoding: UTF-8
pins:
# encoder
- name: in_codec_encode
connection-type: mq
attributes: [ 'encoder_in', 'parsed', 'subscribe' ]
- name: out_codec_encode
connection-type: mq
attributes: [ 'encoder_out', 'raw', 'publish' ]
# decoder
- name: in_codec_decode
connection-type: mq
attributes: ['decode_in', 'subscribe', 'group']
attributes: ['decoder_in', 'raw', 'subscribe']
- name: out_codec_decode
connection-type: mq
attributes: ['decode_out', 'publish', 'parsed']
attributes: ['decoder_out', 'parsed', 'publish']
# encoder general (technical)
- name: in_codec_general_encode
connection-type: mq
attributes: ['general_encoder_in', 'parsed', 'subscribe']
- name: out_codec_general_encode
connection-type: mq
attributes: ['general_encoder_out', 'raw', 'publish']
# decoder general (technical)
- name: in_codec_general_decode
connection-type: mq
attributes: ['general_decoder_in', 'raw', 'subscribe']
- name: out_codec_general_decode
connection-type: mq
attributes: ['general_decoder_out', 'parsed', 'publish']
```

## Release notes

### 4.0.0

+ Migrated to `th2-codec` core part. Uses the standard configuration format and pins for th2-codec

### 3.2.1

+ fixed: last array-field as simple value
Expand Down
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ dependencies {
api platform('com.exactpro.th2:bom:3.1.0')

implementation 'com.exactpro.th2:common:3.37.1'
implementation 'com.exactpro.th2:codec:4.7.0'

implementation "org.slf4j:slf4j-log4j12"
implementation "org.slf4j:slf4j-api"

implementation 'net.sourceforge.javacsv:javacsv:2.0'
implementation 'org.jetbrains:annotations:23.0.0'

compileOnly 'com.google.auto.service:auto-service-annotations:1.0.1'
annotationProcessor 'com.google.auto.service:auto-service:1.0.1'

testImplementation 'org.mockito:mockito-core:3.5.15'
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
Expand All @@ -68,13 +73,13 @@ test {
}

application {
mainClassName 'com.exactpro.th2.codec.csv.Main'
mainClassName 'com.exactpro.th2.codec.MainKt'
}

applicationName = 'service'

distTar {
archiveName "${applicationName}.tar"
archiveFileName.set("${applicationName}.tar")
}

dockerPrepare {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
release_version = 3.2.1
release_version = 4.0.0

docker_image_name=
76 changes: 76 additions & 0 deletions src/main/java/com/exactpro/th2/codec/csv/CodecFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2022 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.exactpro.th2.codec.csv;

import java.io.InputStream;
import java.util.Collections;
import java.util.Set;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.exactpro.th2.codec.api.IPipelineCodec;
import com.exactpro.th2.codec.api.IPipelineCodecContext;
import com.exactpro.th2.codec.api.IPipelineCodecFactory;
import com.exactpro.th2.codec.api.IPipelineCodecSettings;
import com.exactpro.th2.codec.csv.cfg.CsvCodecConfiguration;
import com.google.auto.service.AutoService;

@AutoService(IPipelineCodecFactory.class)
public class CodecFactory implements IPipelineCodecFactory {
public static final String PROTOCOL = "csv";
private static final Set<String> PROTOCOLS = Collections.singleton(PROTOCOL);

@NotNull
@Override
public String getProtocol() {
return PROTOCOL;
}

@NotNull
@Override
public Set<String> getProtocols() {
return PROTOCOLS;
}

@NotNull
@Override
public Class<? extends IPipelineCodecSettings> getSettingsClass() {
return CsvCodecConfiguration.class;
}

@NotNull
@Override
public IPipelineCodec create(@Nullable IPipelineCodecSettings settings) {
if (settings instanceof CsvCodecConfiguration) {
return new CsvCodec((CsvCodecConfiguration)settings);
}
throw new IllegalArgumentException("Unexpected setting type: " + (settings == null ? "null" : settings.getClass()));
}

@Override
public void init(@NotNull IPipelineCodecContext iPipelineCodecContext) {
}

@Override
public void init(@NotNull InputStream inputStream) {
}

@Override
public void close() {
}
}
Loading