io.resys.hdes.client.spi.composer.DebugCSVVisitor Maven / Gradle / Ivy
package io.resys.hdes.client.spi.composer;
/*-
* #%L
* hdes-client-api
* %%
* Copyright (C) 2020 - 2021 Copyright 2020 ReSys OÜ
* %%
* 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.
* #L%
*/
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import io.resys.hdes.client.api.HdesClient;
import io.resys.hdes.client.api.ast.TypeDef;
import io.resys.hdes.client.api.ast.TypeDef.Direction;
import io.resys.hdes.client.api.exceptions.HdesBadRequestException;
import io.resys.hdes.client.api.programs.ProgramEnvir;
import io.resys.hdes.client.api.programs.ProgramEnvir.ProgramWrapper;
public class DebugCSVVisitor {
private final HdesClient client;
private final ProgramEnvir envir;
private final ProgramWrapper, ?> wrapper;
private final Map wrapperInputs;
private final CsvMapper csvMapper = new CsvMapper();
private final Set usedFields = new HashSet<>();
public DebugCSVVisitor(HdesClient client, ProgramWrapper, ?> wrapper, ProgramEnvir envir) {
super();
this.client = client;
this.wrapper = wrapper;
this.envir = envir;
this.wrapperInputs = wrapper.getHeaders().stream()
.filter(h -> h.getDirection() == Direction.IN)
.collect(Collectors.toMap(h -> h.getName(), h -> h));
}
public String visit(String input) {
try {
final CSVParser parser = CSVParser.parse(input, CSVFormat.DEFAULT.withDelimiter(';').withIgnoreEmptyLines());
final List records = parser.getRecords();
if(records.isEmpty()) {
return null;
}
// records
final Iterator iterator = records.iterator();
// header names
final var headers = visitHeaders(iterator);
// data rows
final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy