Data transformation language that makes the process of mapping data easier and with a natural syntax. The grammar for this DSL is based on Antlr4.
There is some operations that you are able to use (some variations allowed, please check the grammar file):
- keep only numbers of
field
- trim
field
- remove leading zeros from
field
- remove 3 chars from left of
field
- substring 2 to 3 of
field
- truncate at 20
field
- return
field
source-data.json
{
"it-codigo": " my item ",
"desc-item": " large description that contains more than 20 chars ",
"num-ddd": 47,
"num-telefone": "number 9000-1000"
}
mdmlang-rules.txt
itemCode:
trim it-codigo
return it-codigo
description:
trim desc-item
truncate at 20 desc-item
return desc-item
phoneNumber:
trim num-telefone
keep only numbers of num-telefone
return num-ddd and num-telefone
Java App:
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.brunocvcunha.mdmlang.processor.MDMProcessorContext;
public class MDMLanguageMain {
public static void main(String[] args) throws IOException {
Gson gson = new Gson();
InputStream rules = MDMLanguageMain.class.getResourceAsStream("/mdmlang-rules.txt");
InputStream json = MDMLanguageMain.class.getResourceAsStream("/source-data.json");
MDMProcessorContext ctx = MDMProcessorContext.buildContext(rules);
Type type = new TypeToken<Map<String, Object>>() {}.getType();
Map<String, Object> values = gson.fromJson(new InputStreamReader(json), type);
Map<String, Object> golden = ctx.process(values);
System.out.println(gson.toJson(golden));
}
}
Outputs Transformed Data:
{
"itemCode": "my item",
"description": "large description th",
"phoneNumber": "4790001000"
}
(Release still on process)
Download the latest JAR or grab via Maven:
<dependency>
<groupId>org.brunocvcunha.mdmlang</groupId>
<artifactId>mdmlang</artifactId>
<version>1.0</version>
</dependency>
or Gradle:
compile 'org.brunocvcunha.mdmlang:mdmlang:1.0'
Snapshots of the development version are available in Sonatype's snapshots
repository.
MDM Lang requires at minimum Java 7.