Skip to content

Commit

Permalink
fix: CSV document does not persist with inspection parameters
Browse files Browse the repository at this point in the history
Fixes: #3288
  • Loading branch information
rkorytkowski authored and igarashitm committed Sep 14, 2021
1 parent 42f30ff commit 32e8110
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/itests/reference-mappings/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
<groupId>io.atlasmap</groupId>
<artifactId>atlas-xml-module</artifactId>
</dependency>
<dependency>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-csv-module</artifactId>
</dependency>
<dependency>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-java-test-model</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.reference.csv_to_java;

import io.atlasmap.api.AtlasContext;
import io.atlasmap.api.AtlasSession;
import io.atlasmap.itests.reference.AtlasMappingBaseTest;
import io.atlasmap.itests.reference.AtlasTestUtil;
import io.atlasmap.java.test.TargetFlatPrimitiveClass;
import io.atlasmap.json.test.AtlasJsonTestUnrootedMapper;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.File;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class CsvJavaTest extends AtlasMappingBaseTest {

protected TargetFlatPrimitiveClass executeMapping(String fileName) throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File(fileName).toURI());
AtlasSession session = context.createSession();
String source = AtlasTestUtil.loadFileAsString(
"src/test/resources/csvToJava/atlasmapping-csvWithHeaders.csv");
session.setDefaultSourceDocument(source);
context.process(session);

assertFalse(session.hasErrors(), printAudit(session));
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
return (TargetFlatPrimitiveClass) object;
}

@Test
public void testProcess() throws Exception {
TargetFlatPrimitiveClass object = executeMapping("src/test/resources/csvToJava/atlasmapping-csvWithHeaders.json");
assertEquals("row0", object.getBoxedStringArrayField()[0]);
assertEquals("row1", object.getBoxedStringArrayField()[1]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sourceCsvString,sourceCsvInteger
row0,0
row1,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"AtlasMapping" : {
"jsonType" : "io.atlasmap.v2.AtlasMapping",
"dataSource" : [ {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "sourceCsv-c7982b9e-90b4-44ed-8b52-283e6f1e853c",
"name" : "sourceCsv",
"description" : "Source document sourceCsv type: CSV",
"uri" : "atlas:csv:sourceCsv-c7982b9e-90b4-44ed-8b52-283e6f1e853c?firstRecordAsHeader=true",
"dataSourceType" : "SOURCE"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "io.atlasmap.java.test.TargetFlatPrimitiveClass",
"name" : "io.atlasmap.java.test.TargetFlatPrimitiveClass",
"description" : "Java document class io.atlasmap.java.test.TargetFlatPrimitiveClass",
"uri" : "atlas:java:io.atlasmap.java.test.TargetFlatPrimitiveClass?className=io.atlasmap.java.test.TargetFlatPrimitiveClass",
"dataSourceType" : "TARGET"
} ],
"mappings" : {
"mapping" : [ {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputFieldGroup" : {
"jsonType" : "io.atlasmap.v2.FieldGroup",
"actions" : [ ],
"field" : [ {
"jsonType" : "io.atlasmap.csv.v2.CsvField",
"docId" : "sourceCsv-c7982b9e-90b4-44ed-8b52-283e6f1e853c",
"path" : "/<>/sourceCsvString",
"fieldType" : "STRING",
"name" : "sourceCsvString"
} ]
},
"inputField" : [ ],
"outputField" : [ {
"jsonType" : "io.atlasmap.java.v2.JavaField",
"docId" : "io.atlasmap.java.test.TargetFlatPrimitiveClass",
"path" : "/boxedStringArrayField<>",
"fieldType" : "STRING",
"name" : "boxedStringArrayField"
} ],
"id" : "mapping.50044"
}]
},
"lookupTables" : {
"lookupTable" : [ ]
},
"constants" : {
"constant" : [ ]
},
"properties" : {
"property" : [ ]
},
"name" : "UI.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export class CsvInspectionModel extends DocumentInspectionModel {
if (!this.doc.name) {
this.doc.name = this.doc.id;
}
if (this.doc.inspectionParameters) {
const params = new URLSearchParams(this.doc.inspectionParameters);
this.doc.uri = this.doc.uri + '?' + params;
}

for (const field of csvDocument.fields.field) {
this.parseCSVFieldFromDocument(field as ICsvField, null);
Expand Down

0 comments on commit 32e8110

Please sign in to comment.