private void prepareColumns(ILogicalTable tableBody) throws SyntaxNodeException { columns = new HashMap<>(); ILogicalTable ids = tableBody.getRow(0); // parse ids, row=0 for (int c = 0; c < ids.getWidth(); c++) { String id = safeId(ids.getColumn(c).getSource().getCell(0, 0).getStringValue()); if (id.length() == 0) { // ignore column with NO ID continue; } if (columns.get(id) != null) { // duplicate ids throw SyntaxNodeExceptionUtils.createError("Duplicate column '" + id + "'!", null, tsn); } columns.put(id, new AlgorithmColumn(id, c)); } }
private IOpenSourceCodeModule getSourceCodeModule(ILogicalTable bodyTable) { int height = bodyTable.getHeight(); IOpenSourceCodeModule[] cellSources = new IOpenSourceCodeModule[height]; for (int i = 0; i < height; i++) { cellSources[i] = new GridCellSourceCodeModule(bodyTable.getRow(i).getSource(), null); } return new CompositeSourceCodeModule(cellSources, "\n"); } }
/** * * @return table with 1 column, if necessary transposed, caller is * responsible to check that table is either 1xN or Nx1 */ public static ILogicalTable make1ColumnTable(ILogicalTable t) { if (t.getWidth() == 1) { return t; } if (t.getHeight() == 1) { return t.transpose(); } // caller is responsible to check that table is either 1xN or Nx1 return t; }
public TableValueFilter(final SpreadsheetResult res) { this.res = res; ILogicalTable table = res.getLogicalTable(); IGridTable t = table.getSource(); this.startX = t.getGridColumn(0, 0) + table.getColumn(0).getSource().getWidth(); this.startY = t.getGridRow(0, 0) + table.getRow(0).getSource().getHeight(); }
public static int countHConditions(ILogicalTable table) { int width = table.getWidth(); int cnt = 0; for (int i = 0; i < width; i++) { String value = table.getColumn(i).getSource().getCell(0, 0).getStringValue(); if (value != null) { value = value.toUpperCase(); if (isValidHConditionHeader(value)) { ++cnt; } } } return cnt; }
protected IOpenSourceCodeModule getExpressionSource(IBindingContext bindingContext, OpenL openl, IOpenClass declaringClass, IMethodSignature signature, IOpenClass methodType) throws Exception { return new GridCellSourceCodeModule(codeTable.getSource(), bindingContext); }
private List<TableRow> buildRows(ILogicalTable tableBody) throws SyntaxNodeException { ILogicalTable leftRows = tableBody.getColumn(0).getRows(2); int dataRowsCount = leftRows.getHeight(); ILogicalTable colTable = tableBody.getSubtable(column.getColumnIndex(), 2, 1, 1); if (colTable.getWidth() != 1) { throw SyntaxNodeExceptionUtils.createError("First column must have width=1!", null, tsn); data = leftRows.getRows(1); } else { data = LogicalTableHelper.mergeBounds(leftRows, colTable); int subColumns = data.getWidth(); IGridTable grid = data.getSource(); for (int r = 0; r < data.getHeight(); r++) { SubValue[] values = createSV(column, grid, r, subColumns); rows.get(r + 1).add(column.getId(), values); grid = colTable.getSource(); SubValue[] values = createSV(column, grid, 0, subColumns); rows.get(0).add(column.getId(), values);
IGridTable leftRowsGrid = leftRows.getSource(); if (!leftRowsGrid.isNormalOrientation()) { throw new RuntimeException("Left Rows must have Normal Orientation"); IGridTable topColumnsGrid = topColumns.getSource(); if (!topColumnsGrid.isNormalOrientation()) { throw new RuntimeException("Top Columns must have Normal Orientation"); int startColumn = 0; if (cLeft < rLeft) { startColumn = topColumns.findColumnStart(rLeft - cLeft); left = rLeft; int startRow = 0; if (rTop < cTop) { startRow = leftRows.findRowStart(cTop - rTop); top = cTop; int nRows = leftRows.getHeight() - startRow; int nColumns = topColumns.getWidth() - startColumn; for (; i < nRows; i++) { rowsOffset[i] = rOffset; rOffset += leftRows.getRowHeight(i + startRow); for (; i < nColumns; i++) { columnsOffset[i] = cOffset; cOffset += topColumns.getColumnWidth(i + startColumn);
/** * Foreign keys row is optional for data table. It consists reference for field value to other table. Foreign keys * always starts from {@value #INDEX_ROW_REFERENCE_START_SYMBOL} symbol. * * @param dataTable data table to check * @return <code>TRUE</code> if second row in data table body (next to the field row) consists even one value, in * any column, starts with {@value #INDEX_ROW_REFERENCE_START_SYMBOL} symbol. */ public static boolean hasForeignKeysRow(ILogicalTable dataTable) { ILogicalTable potentialForeignKeysRow = dataTable.getRows(1, 1); int columnsCount = potentialForeignKeysRow.getWidth(); for (int i = 0; i < columnsCount; i++) { ILogicalTable cell = potentialForeignKeysRow.getColumn(i); String value = cell.getSource().getCell(0, 0).getStringValue(); if (value == null || value.trim().length() == 0) { continue; } return value.charAt(0) == INDEX_ROW_REFERENCE_START_SYMBOL; } return false; }
public SpreadsheetComponentsBuilder(TableSyntaxNode tableSyntaxNode, IBindingContext bindingContext) { this.tableSyntaxNode = tableSyntaxNode; CellsHeaderExtractor extractor = ((SpreadsheetHeaderNode)tableSyntaxNode.getHeader()).getCellHeadersExtractor(); if (extractor == null) { extractor = new CellsHeaderExtractor(getSignature(tableSyntaxNode), tableSyntaxNode.getTableBody().getRow(0).getColumns(1), tableSyntaxNode.getTableBody().getColumn(0).getRows(1)); } this.cellsHeaderExtractor = extractor; this.bindingContext = bindingContext; }
componentsBuilder.getCellsHeadersExtractor().getRowNamesTable().getRow(rowIndex), componentsBuilder.getCellsHeadersExtractor().getColumnNamesTable().getColumn(columnIndex)); IOpenSourceCodeModule source = new GridCellSourceCodeModule(cell.getSource(), spreadsheetBindingContext); String code = StringUtils.trimToNull(source.getCode()); ICell theCellValue = cell.getCell(0, 0); Object result = null; if (String.class.equals(instanceClass)) {
public void finalizeBind(IBindingContext bindingContext) throws Exception { if (!bindingContext.isExecutionMode()) { getTableSyntaxNode().setMetaInfoReader(new MethodTableMetaInfoReader(this)); } super.finalizeBind(bindingContext); TableSyntaxNode tsn = getTableSyntaxNode(); ILogicalTable logicalTable = tsn.getTable(); boolean tableHasProperties = tsn.hasPropertiesDefinedInTable(); ILogicalTable bodyTable = logicalTable.getRows(tableHasProperties ? 2 : 1); if (bodyTable == null) { String errorMessage = "Method table must contain a body section"; SyntaxNodeException error = SyntaxNodeExceptionUtils.createError(errorMessage, tsn); tsn.addError(error); bindingContext.addError(error); } else { int height = bodyTable.getHeight(); IOpenSourceCodeModule[] cellSources = new IOpenSourceCodeModule[height]; for (int i = 0; i < height; i++) { cellSources[i] = new GridCellSourceCodeModule(bodyTable.getRow(i).getSource(), bindingContext); } IOpenSourceCodeModule src = new CompositeSourceCodeModule(cellSources, "\n"); OpenLCellExpressionsCompiler.compileMethod(getOpenl(), src, getTableMethod().getCompositeMethod(), bindingContext); } }
public static ILogicalTable getPropertiesTableSection(ILogicalTable table) { if (table.getHeight() < 2) { return null; } ILogicalTable propTable = table.getRows(1, 1); String header = propTable.getSource().getCell(0, 0).getStringValue(); if (!PROPERTIES_HEADER.equals(header)) { return null; } return propTable.getColumns(1); }
private static void validateSimpleParam(ILogicalTable table, IBindingContext bindingContext) throws SyntaxNodeException { ICell theCell = table.getSource().getCell(0, 0); if (table.getWidth() > 1 || table.getHeight() > 1) { for (int i = 0; i < table.getHeight(); i++) { for (int j = 0; j < table.getWidth(); j++) { if ((!(i == 0 && j == 0))) { ICell cell = table.getCell(j, i); if ((theCell.getAbsoluteRegion().getTop() != cell.getAbsoluteRegion().getTop() || theCell .getAbsoluteRegion() .getLeft() != cell.getAbsoluteRegion().getLeft()) && cell.getStringValue() != null) { if (!cell.getStringValue().startsWith(COMMENTARY)) { IGridTable cellTable = getTopLeftCellFromMergedRegion(table.getSource()); throw SyntaxNodeExceptionUtils.createError( "Table structure is wrong. More than one cell with data found where only one cell is expected.", new GridCellSourceCodeModule(cellTable, bindingContext)); } } } } } } }
public Map<String, Integer> makeUniqueIndex(int colIdx) throws SyntaxNodeException { Map<String, Integer> index = new HashMap<>(); int rows = logicalTable.getHeight(); for (int i = 1; i < rows; i++) { IGridTable gridTable = logicalTable.getSubtable(colIdx, i, 1, 1).getSource(); String key = gridTable.getCell(0, 0).getStringValue(); if (key == null) { throw SyntaxNodeExceptionUtils.createError("Empty key in an unique index", new GridCellSourceCodeModule(gridTable)); } key = key.trim(); if (index.containsKey(key)) { throw SyntaxNodeExceptionUtils.createError("Duplicated key in an unique index: " + key, new GridCellSourceCodeModule(gridTable)); } index.put(key, i - 1); } return index; }
private Object getArrayValues(ILogicalTable valuesTable, OpenlToolAdaptor ota, IOpenClass aggregateType, IOpenClass paramType) throws SyntaxNodeException { if (valuesTable.getHeight() == 1 && valuesTable.getWidth() == 1) { return RuleRowHelper.loadCommaSeparatedParam(aggregateType, paramType, field.getName(), null, valuesTable.getRow(0), ota); } return loadMultiRowArray(valuesTable, ota, paramType, aggregateType); }