Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CSV document does not persist with inspection parameters #3289

Merged
merged 1 commit into from
Sep 14, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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