Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
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 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.AstBody;
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.DecisionProgram;
import io.resys.hdes.client.api.programs.FlowProgram;
import io.resys.hdes.client.api.programs.Program.ProgramResult;
import io.resys.hdes.client.api.programs.ProgramEnvir;
import io.resys.hdes.client.api.programs.ProgramEnvir.ProgramWrapper;
import io.resys.hdes.client.api.programs.ServiceProgram;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
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 = getWrapperInputs(wrapper);
}
public ProgramResult 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 row
final CSVRecord row = iterator.next();
final var result = visitRow(row, headers);
return result;
} catch (IOException e) {
throw new HdesBadRequestException(e.getMessage(), e);
}
}
public String visitMultiple(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