Skip to content

Commit

Permalink
[KNOWAGE-8399] Fixing NPE into excel exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
leonegiorgia committed Feb 1, 2024
1 parent dc6c35a commit c752f22
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.UUID;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
Expand Down Expand Up @@ -355,7 +356,7 @@ public void adjustColumnWidth(Sheet sheet, String imageB64) {
if(row != null) {
for (int i = 0; i < row.getLastCellNum(); i++) {
sheet.autoSizeColumn(i);
if(!imageB64.isEmpty() && (i == 0 || i == 1)) {
if(StringUtils.isNotEmpty(imageB64) && (i == 0 || i == 1)) {
// first or second column
int colWidth = 25;
if (sheet.getColumnWidthInPixels(i) < (colWidth * 256))
Expand All @@ -371,7 +372,7 @@ public void adjustColumnWidth(Sheet sheet, String imageB64) {
public int createBrandedHeaderSheet(Sheet sheet, String imageB64,
int startRow, float rowHeight, int rowspan, int startCol, int colWidth, int colspan, int namespan, int dataspan,
String documentName, String widgetName) {
if (!imageB64.isEmpty()) {
if (StringUtils.isNotEmpty(imageB64)) {
for (int r = startRow; r < startRow+rowspan; r++) {
sheet.createRow(r).setHeightInPoints(rowHeight);
for (int c = startCol; c < startCol+colspan; c++) {
Expand Down Expand Up @@ -401,7 +402,7 @@ public int createBrandedHeaderSheet(Sheet sheet, String imageB64,
sheet.getRow(startRow+1).getCell(startCol+colspan).setCellStyle(dateCellStyle);
}

int headerIndex = (!imageB64.isEmpty()) ? (startRow+rowspan) : 0;
int headerIndex = (StringUtils.isNotEmpty(imageB64)) ? (startRow+rowspan) : 0;
Row widgetNameRow = sheet.createRow((short) headerIndex);
Cell widgetNameCell = widgetNameRow.createCell(0);
widgetNameCell.setCellValue(widgetName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.apache.commons.lang3.StringUtils;

import it.eng.knowage.commons.multitenant.OrganizationImageManager;
import it.eng.knowage.engine.cockpit.api.export.pdf.CssColorParser;
import it.eng.spagobi.commons.constants.SpagoBIConstants;
import it.eng.spagobi.commons.dao.DAOFactory;
Expand Down Expand Up @@ -1447,7 +1447,7 @@ public void adjustColumnWidth(Sheet sheet, String imageB64) {
if(row != null) {
for (int i = 0; i < row.getLastCellNum(); i++) {
sheet.autoSizeColumn(i);
if(!imageB64.isEmpty() && (i == 0 || i == 1)) {
if(StringUtils.isNotEmpty(imageB64) && (i == 0 || i == 1)) {
// first or second column
int colWidth = 25;
if (sheet.getColumnWidthInPixels(i) < (colWidth * 256))
Expand All @@ -1463,7 +1463,7 @@ public void adjustColumnWidth(Sheet sheet, String imageB64) {
public int createBrandedHeaderSheet(Sheet sheet, String imageB64,
int startRow, float rowHeight, int rowspan, int startCol, int colWidth, int colspan, int namespan, int dataspan,
String documentName, String widgetName) {
if (!imageB64.isEmpty()) {
if (StringUtils.isNotEmpty(imageB64)) {
for (int r = startRow; r < startRow+rowspan; r++) {
sheet.createRow(r).setHeightInPoints(rowHeight);
for (int c = startCol; c < startCol+colspan; c++) {
Expand Down Expand Up @@ -1493,7 +1493,7 @@ public int createBrandedHeaderSheet(Sheet sheet, String imageB64,
sheet.getRow(startRow+1).getCell(startCol+colspan).setCellStyle(dateCellStyle);
}

int headerIndex = (!imageB64.isEmpty()) ? (startRow+rowspan) : 0;
int headerIndex = (StringUtils.isNotEmpty(imageB64)) ? (startRow+rowspan) : 0;
Row widgetNameRow = sheet.createRow((short) headerIndex);
Cell widgetNameCell = widgetNameRow.createCell(0);
widgetNameCell.setCellValue(widgetName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import javax.ws.rs.core.UriBuilder;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.usermodel.Cell;
Expand Down Expand Up @@ -913,9 +914,9 @@ public void fillSheetWithData(JSONObject dataStore, Workbook wb, Sheet sheet, St
// row = sheet.createRow((offset + r + isGroup) + 1); // starting from second row, because the 0th (first) is Header
// else
// row = sheet.createRow((offset + r + isGroup) + 2);
if(!this.imageB64.isEmpty())
row = sheet.createRow((offset + r + isGroup) + (startRow+rowspan) + 2); // starting by Header

if (StringUtils.isNotEmpty(imageB64))
row = sheet.createRow((offset + r + isGroup) + (startRow + rowspan) + 2); // starting by Header
else
row = sheet.createRow((offset + r + isGroup) + 2);

Expand Down

0 comments on commit c752f22

Please sign in to comment.