Skip to content

Commit

Permalink
feat: Add CSV module
Browse files Browse the repository at this point in the history
Fixes: #2018
  • Loading branch information
rkorytkowski authored and igarashitm committed May 8, 2020
1 parent 10bc69f commit f13fead
Show file tree
Hide file tree
Showing 43 changed files with 2,356 additions and 168 deletions.
4 changes: 4 additions & 0 deletions camel/pom.xml
Expand Up @@ -64,6 +64,10 @@
<groupId>io.atlasmap</groupId>
<artifactId>atlas-xml-module</artifactId>
</dependency>
<dependency>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-csv-module</artifactId>
</dependency>
<!-- for testing -->
<dependency>
<groupId>io.atlasmap</groupId>
Expand Down
Expand Up @@ -26,9 +26,6 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
Expand Down
4 changes: 4 additions & 0 deletions camel3/pom.xml
Expand Up @@ -70,6 +70,10 @@
<groupId>io.atlasmap</groupId>
<artifactId>atlas-xml-module</artifactId>
</dependency>
<dependency>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-csv-module</artifactId>
</dependency>
<!-- for testing -->
<dependency>
<groupId>io.atlasmap</groupId>
Expand Down
18 changes: 18 additions & 0 deletions coverage-report/pom.xml
Expand Up @@ -132,6 +132,24 @@
<artifactId>atlas-xml-service</artifactId>
</dependency>

<!-- AtlasMap CSV -->
<dependency>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-csv-core</artifactId>
</dependency>
<dependency>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-csv-model</artifactId>
</dependency>
<dependency>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-csv-module</artifactId>
</dependency>
<dependency>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-csv-service</artifactId>
</dependency>

<!-- Others -->
<dependency>
<groupId>io.atlasmap</groupId>
Expand Down
12 changes: 12 additions & 0 deletions docs/src/main/asciidoc/developer-guide/openapi/core/index.adoc
Expand Up @@ -2234,6 +2234,12 @@ endif::internal-generation[]
|
|

| name
|
| String
|
|

| jsonType
| X
| String
Expand Down Expand Up @@ -2325,6 +2331,12 @@ endif::internal-generation[]
|
|

| name
|
| String
|
|

| field
|
| List of <<Field>>
Expand Down
Expand Up @@ -402,6 +402,12 @@ endif::internal-generation[]
|
|

| name
|
| String
|
|

| jsonType
| X
| String
Expand Down
24 changes: 12 additions & 12 deletions docs/src/main/asciidoc/developer-guide/openapi/java/index.adoc
Expand Up @@ -462,6 +462,12 @@ endif::internal-generation[]
|
|

| name
|
| String
|
|

| annotations
|
| StringList
Expand All @@ -480,12 +486,6 @@ endif::internal-generation[]
|
|

| name
|
| String
|
|

| className
|
| String
Expand Down Expand Up @@ -807,6 +807,12 @@ endif::internal-generation[]
|
|

| name
|
| String
|
|

| annotations
|
| StringList
Expand All @@ -825,12 +831,6 @@ endif::internal-generation[]
|
|

| name
|
| String
|
|

| className
|
| String
Expand Down
Expand Up @@ -399,6 +399,12 @@ endif::internal-generation[]
|
|

| name
|
| String
|
|

| jsonType
| X
| String
Expand Down
6 changes: 6 additions & 0 deletions docs/src/main/asciidoc/developer-guide/openapi/xml/index.adoc
Expand Up @@ -399,6 +399,12 @@ endif::internal-generation[]
|
|

| name
|
| String
|
|

| jsonType
| X
| String
Expand Down
3 changes: 3 additions & 0 deletions lib/dist/assembly-aggregate.xml
Expand Up @@ -24,6 +24,9 @@
<include>io.atlasmap:atlas-xml-core</include>
<include>io.atlasmap:atlas-xml-model</include>
<include>io.atlasmap:atlas-xml-module</include>
<include>io.atlasmap:atlas-csv-core</include>
<include>io.atlasmap:atlas-csv-model</include>
<include>io.atlasmap:atlas-csv-module</include>
</includes>
<binaries>
<outputDirectory>.</outputDirectory>
Expand Down
4 changes: 4 additions & 0 deletions lib/itests/core/pom.xml
Expand Up @@ -61,6 +61,10 @@
<groupId>io.atlasmap</groupId>
<artifactId>atlas-dfdl-module</artifactId>
</dependency>
<dependency>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-csv-module</artifactId>
</dependency>
<dependency>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-dfdl-test-model</artifactId>
Expand Down
@@ -0,0 +1,101 @@
/**
* Copyright (C) 2017 Red Hat, Inc.
*
* 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 io.atlasmap.itests.core;

import io.atlasmap.api.AtlasContext;
import io.atlasmap.api.AtlasSession;
import io.atlasmap.core.AtlasMappingService;
import io.atlasmap.core.DefaultAtlasContextFactory;
import io.atlasmap.v2.AtlasMapping;
import io.atlasmap.v2.Collection;
import io.atlasmap.v2.Mapping;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;

import java.net.URL;
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;

public class CsvMappingTest {

public static final String MAPPINGS_JSON = "mappings/atlasmapping-csv.json";
private AtlasMappingService mappingService;

@Before
public void before() {
mappingService = DefaultAtlasContextFactory.getInstance().getMappingService();
}

@Test
public void testMapAllFields() throws Exception {
AtlasContext context = createContext(MAPPINGS_JSON, "1", "2");
AtlasSession session = context.createSession();
session.setSourceDocument("source", "first_name,last_name\r\nBob,Johnson\r\nAndrew,Smith\r\n");
context.process(session);

assertFalse(session.hasErrors());
Object csv = session.getTargetDocument("target-csv");
assertThat(csv, CoreMatchers.is("first,last\r\nBob,Johnson\r\nAndrew,Smith\r\n"));
}

@Test
public void testMapOneOfTwoFields() throws Exception {
AtlasContext context = createContext(MAPPINGS_JSON, "3");
AtlasSession session = context.createSession();
session.setSourceDocument("source", "first_name,last_name\r\nBob,Johnson\r\nAndrew,Smith\r\n");
context.process(session);

assertFalse(session.hasErrors());
Object csv = session.getTargetDocument("target-csv");
assertThat(csv, CoreMatchers.is("last\r\nJohnson\r\nSmith\r\n"));
}

@Test
public void testCapitalize() throws Exception {
AtlasContext context = createContext(MAPPINGS_JSON, "4");
AtlasSession session = context.createSession();
session.setSourceDocument("source", "first_name,last_name\r\nbob,johnson\r\nandrew,smith\r\n");
context.process(session);

assertFalse(session.hasErrors());
Object csv = session.getTargetDocument("target-csv");
assertThat(csv, CoreMatchers.is("first\r\nBob\r\nAndrew\r\n"));
}

public AtlasContext createContext(String file, String... mappingIds) throws Exception {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/atlasmapping-csv.json");
AtlasMapping mapping = mappingService.loadMapping(url);
List<String> ids = Arrays.asList(mappingIds);
mapping.getMappings().getMapping().removeIf(m -> {
if (m instanceof Mapping) {
return !ids.contains(((Mapping) m).getId());
} else if (m instanceof Collection) {
Collection col = (Collection) m;
col.getMappings().getMapping().removeIf(map -> !ids.contains(((Mapping) map).getId()));
return col.getMappings().getMapping().isEmpty();
} else {
return false;
}
});
AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
return context;
}

}
Expand Up @@ -28,7 +28,7 @@ public class DefaultAtlasContextTest {
public void testModuleInit() {
DefaultAtlasContextFactory factory = DefaultAtlasContextFactory.getInstance();
assertNotNull(factory.getModuleInfoRegistry());
assertEquals(new Integer(4), new Integer(factory.getModuleInfoRegistry().size()));
assertEquals(new Integer(5), new Integer(factory.getModuleInfoRegistry().size()));
}

}

0 comments on commit f13fead

Please sign in to comment.