xmlVariable.setAttribute(XML_ATTR_DELIMITER, theFileVariable.getColumnsDelimiter()); xmlVariable.setAttribute(XML_ATTR_USE_FIRST_LINE, Boolean.toString(theFileVariable.getFirstLineIsColumnName())); xmlVariable.setAttribute(XML_ATTR_OFFSET, Integer.toString(theFileVariable.getNumOfFirstRowData())); theFileVariable.getFileName().isPresent() ? theFileVariable.getFileName().get() : dumpDataInFile(new File(outputFolder), theFileVariable.getName(), theFileVariable.getColumnsNames(), theFileVariable.getColumnsDelimiter(), theFileVariable.getData().orElseThrow(IllegalStateException::new) List<String> cols = theFileVariable.getColumnsNames(); if(cols.isEmpty() && theFileVariable.getFirstLineIsColumnName() && theFileVariable.getFileName().isPresent()) { cols = getColumnsFromFile(theFileVariable.getFileName().get(), theFileVariable.getColumnsDelimiter()); }catch(IOException e) { LOGGER.warn("Cannot read columns in file variable "+theFileVariable.getFileName().get());
private void parseTableParameter(final Wini.Section paramSection, final String sectionIdentifier, final String paramName) { if (paramSection.get("SelectNextRow").startsWith("\"Same line as ")) { variablesNotDone.add(sectionIdentifier); return; } FileVariable variable = ParametersReaderUtils.parseTableParameter(leftBrace, rightBrace, paramSection, folder.getAbsolutePath()); if (variable != null) { if ("Local".equals(MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get(ParametersReaderUtils.TABLE_LOCATION)))) { reader.addDataFilesToCopy(new File(variable.getFileName().orElseThrow(IllegalStateException::new))); } nLVarValueFromLRVarName.put(variable.getName(), variable.getName() + "." + variable.getColumnsNames().get(0)); variables.put(paramName, variable); } }
String [][] currentData = refVarFile.getData() .orElseGet(() -> loadColumnOfDataFile(refVarFile.getFileName().orElseThrow(IllegalStateException::new), refVarFile.getColumnsNames(), refVarFile.getColumnsDelimiter())); int minRow = Math.min(newColumnData.length, currentData.length); String [][] newData = new String[maxRow][]; int currentDataColumns = refVarFile.getColumnsNames().size();
private void manageVariable(final String variableName) { final Wini.Section paramSection = fileInfos.get(variableName); //here we don't need to test if it exists because it has been added to this list on these tests String referenceVariableName = MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get("SelectNextRow")).substring( "Same line as ".length()); Variable refVar = variables.get(referenceVariableName); if (refVar == null || !(refVar instanceof FileVariable)) { logger.error("The reference parameter \"" + referenceVariableName + "\" does not exist or is not of the correct type for the parameter \"" + variableName); } else { FileVariable refVarFile = (FileVariable) refVar; nLVarValueFromLRVarName.put(MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get("ParamName")), refVarFile.getName() + "." + MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get("ColumnName"))); FileVariable newVariable = ImmutableFileVariable.copyOf(refVarFile); if (!(refVarFile.getFileName().isPresent() && refVarFile.getFileName().get().equals( //Here we create the dataFile full path to compare with the full path of the dependant variable "Local".equals(MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get(ParametersReaderUtils.TABLE_LOCATION))) ? folder + File.separator + MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get(ParametersReaderUtils.TABLE)) : MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get(ParametersReaderUtils.TABLE_LOCATION)) + File.separator + MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get(ParametersReaderUtils.TABLE))))) { newVariable = ParametersReaderUtils.handleDataForFileVariable(leftBrace, rightBrace, paramSection, refVarFile, folder); reader.removeDataFilesToCopyIf(dataFile -> dataFile.getAbsolutePath().equals(refVarFile.getFileName().orElse(""))); } newVariable = ParametersReaderUtils.handleVariableColumns(leftBrace, rightBrace, paramSection, newVariable); variables.put(referenceVariableName, newVariable); } }
private void changeBaseNameForCopiedVariables() { ImmutableProject tmpProject = (ImmutableProject) project; List<Variable> newVariableList = new ArrayList<>(); List<String> fileLst = new ArrayList<>(); if (fileToCopy == null || fileToCopy.size() == 0) { return; } fileToCopy.get("variables").forEach(var -> fileLst.add(var.getAbsolutePath())); tmpProject.getVariables().forEach(var -> { if (var instanceof FileVariable && ((FileVariable) var).getFileName().isPresent() && fileLst.contains(((FileVariable) var).getFileName().get())) { ImmutableFileVariable fileVar = (ImmutableFileVariable) var; newVariableList.add(fileVar.withFileName( FileVariableWriter.VARIABLE_DIRECTORY + File.separator + new File(fileVar.getFileName().get()).getName())); } else { newVariableList.add(var); } }); project = tmpProject.withVariables(newVariableList); }
public static FileVariable handleVariableColumns(final String leftBrace, final String rightBrace, final Ini.Section paramSection, final FileVariable refVarFile) { String newColName = MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get(COLUMNNAME)); List allColumns = ImmutableList.builder().addAll(refVarFile.getColumnsNames()).add(newColName).build(); return ImmutableFileVariable.builder() .from(refVarFile) .columnsNames(allColumns) .build(); }
addAllColumnsNames(instance.getColumnsNames()); columnsDelimiter(instance.getColumnsDelimiter()); Optional<String> fileNameOptional = instance.getFileName(); if (fileNameOptional.isPresent()) { fileName(fileNameOptional); numOfFirstRowData(instance.getNumOfFirstRowData()); Optional<String[][]> dataOptional = instance.getData(); if (dataOptional.isPresent()) { data(dataOptional); firstLineIsColumnName(instance.getFirstLineIsColumnName());