Skip to content

Commit

Permalink
Merge pull request #3782 from GDLMadushanka/poi
Browse files Browse the repository at this point in the history
Upgrade apache poi dependency
  • Loading branch information
GDLMadushanka authored Nov 21, 2024
2 parents e9b3ea6 + 39f2f14 commit b9d24d3
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
<groupId>org.apache.poi.wso2</groupId>
<artifactId>poi-ooxml</artifactId>
</exclusion>
<exclusion>
<groupId>commons-io.wso2</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand Down Expand Up @@ -116,6 +120,25 @@
<groupId>org.wso2.orbit.org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<!--Test dependencies-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>5.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.orbit.org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,19 @@ private String[] extractRowData(Row row) {
continue;
}
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
case STRING:
data[i] = cell.getRichStringCellValue().getString();
break;
case HSSFCell.CELL_TYPE_BLANK:
case BLANK:
data[i] = "";
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
case BOOLEAN:
data[i] = String.valueOf(cell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
case FORMULA:
data[i] = "{formula}";
break;
case HSSFCell.CELL_TYPE_NUMERIC:
case NUMERIC:
data[i] = processNumericValue(cell.getNumericCellValue());
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private static ColumnInfo[] getExcelHeaders(Connection connection,
Cell header = cellItr.next();
ColumnInfo column = new ColumnInfo(header.getStringCellValue());
column.setTableName(tableName);
column.setSqlType(header.getCellType());
column.setSqlType(header.getCellType().getCode());
column.setId(header.getColumnIndex());

columns.add(column);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private Workbook createConnectionToExcelDocument(String filePath, boolean releas
} catch (FileNotFoundException e) {
throw new SQLException("Could not locate the EXCEL datasource in the provided " +
"location", e);
} catch (IOException | InvalidFormatException e) {
} catch (IOException e) {
throw new SQLException("Error occurred while initializing the EXCEL datasource", e);
} catch (InterruptedException e) {
throw new SQLException("Error Acquiring the lock for the workbook path - " + filePath, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import java.util.List;
import java.util.Map;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.wso2.micro.integrator.dataservices.sql.driver.processor.reader.DataCell;
import org.wso2.micro.integrator.dataservices.sql.driver.processor.reader.DataRow;
import org.wso2.micro.integrator.dataservices.sql.driver.processor.reader.DataTable;
Expand Down Expand Up @@ -227,7 +227,7 @@ public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLExcepti
if (cell == null) {
throw new SQLException("Error occurred while extracting the value");
}
if (cell.getCellType() != Cell.CELL_TYPE_NUMERIC) {
if (cell.getCellType() != CellType.NUMERIC.getCode()) {
throw new SQLException("Value cannot be cast to a string");
}
return BigDecimal.valueOf(Long.parseLong(cell.getCellValue().toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.List;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
Expand Down Expand Up @@ -58,7 +59,7 @@ public void populateData() throws SQLException {
while (cellItr.hasNext()) {
Cell cell = cellItr.next();
DataCell dataCell =
new DataCell(cellIndex + 1, cell.getCellType(), extractCellValue(cell));
new DataCell(cellIndex + 1, cell.getCellType().getCode(), extractCellValue(cell));
dataRow.addCell(dataCell.getColumnId(), dataCell);
cellIndex++;
}
Expand All @@ -77,13 +78,13 @@ public void populateData() throws SQLException {
*/
private Object extractCellValue(Cell cell) {
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
case NUMERIC:
return cell.getNumericCellValue();
case Cell.CELL_TYPE_BLANK:
case Cell.CELL_TYPE_FORMULA:
case Cell.CELL_TYPE_STRING:
case BLANK:
case FORMULA:
case STRING:
return cell.getStringCellValue();
case Cell.CELL_TYPE_BOOLEAN:
case BOOLEAN:
return cell.getBooleanCellValue();
default:
return cell.getStringCellValue();
Expand Down Expand Up @@ -117,14 +118,14 @@ private ColumnInfo[] extractColumnHeaders(Sheet sheet) throws SQLException {
while (itr.hasNext()) {
Cell cell = itr.next();
if (cell != null) {
int cellType = cell.getCellType();
CellType cellType = cell.getCellType();
switch (cellType) {
case Cell.CELL_TYPE_STRING:
case STRING:
headers.add(new ColumnInfo(cell.getColumnIndex() + 1,
cell.getStringCellValue(), sheet.getSheetName(), Types.VARCHAR,
cell.getColumnIndex() + 1));
break;
case Cell.CELL_TYPE_NUMERIC:
case NUMERIC:
headers.add(new ColumnInfo(cell.getColumnIndex() + 1,
String.valueOf(cell.getNumericCellValue()),
sheet.getSheetName(), Types.INTEGER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.wso2.micro.integrator.dataservices.sql.driver.TExcelConnection;
import org.wso2.micro.integrator.dataservices.sql.driver.processor.reader.DataCell;
import org.wso2.micro.integrator.dataservices.sql.driver.processor.reader.DataRow;
Expand Down Expand Up @@ -62,16 +62,13 @@ public Map<String, DataTable> getData() {
}

private void commitCell(DataCell cell) {
int cellType = cell.getCellType();
CellType cellType = CellType.forInt(cell.getCellType());
switch(cellType) {
case Cell.CELL_TYPE_NUMERIC:

case Cell.CELL_TYPE_BLANK:
case Cell.CELL_TYPE_FORMULA:
case Cell.CELL_TYPE_STRING:

case Cell.CELL_TYPE_BOOLEAN:

case NUMERIC:
case BLANK:
case FORMULA:
case STRING:
case BOOLEAN:
default:

}
Expand Down
8 changes: 8 additions & 0 deletions distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
3 changes: 3 additions & 0 deletions distribution/src/assembly/bin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,9 @@
<include>io.netty:netty-tcnative-boringssl-static</include>
<!-- need to add this to class path for poi -->
<include>org.codehaus.woodstox:stax2-api:jar</include>
<!-- poi jars are needed in classpath form the latest version -->
<include>org.apache.poi:poi:jar</include>
<include>org.apache.poi:poi-ooxml:jar</include>
</includes>
</dependencySet>
<dependencySet>
Expand Down
2 changes: 1 addition & 1 deletion integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@
<postgresql.version>42.2.12</postgresql.version>
<mssql-jdbc.version>8.2.2.jre8</mssql-jdbc.version>
<toml4j.version>0.7.2</toml4j.version>
<commons-io.version>2.6</commons-io.version>
<commons-io.version>2.17.0</commons-io.version>
<neethi.orbit.version>2.0.4.wso2v4</neethi.orbit.version>
<andes.version>3.3.4</andes.version>
<org.apache.geronimo.specs.version>1.0.1</org.apache.geronimo.specs.version>
Expand Down
25 changes: 19 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,16 @@
<artifactId>icu4j</artifactId>
<version>${icu.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi-ooxml.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -1641,7 +1651,7 @@
<jsonassert.version>1.5.1</jsonassert.version>
<saml.common.util.version.range>[1.0.0,2.0.0)</saml.common.util.version.range>
<bouncycastle.orbit.version>1.78.1.wso2v1</bouncycastle.orbit.version>
<orbit.version.poi.ooxml>3.17.0.wso2v1</orbit.version.poi.ooxml>
<orbit.version.poi.ooxml>5.3.0.wso2v1</orbit.version.poi.ooxml>
<org.wso2.json.version>3.0.0.wso2v1</org.wso2.json.version>
<version.equinox.http.servlet>1.1.400.v20130418-1354</version.equinox.http.servlet>
<version.tomcat>9.0.85</version.tomcat>
Expand All @@ -1667,7 +1677,7 @@
<orbit.version.wsdl4j>1.6.2.wso2v4</orbit.version.wsdl4j>
<version.XmlSchema>1.4.7-wso2v8</version.XmlSchema>
<commons-xmlschema.version>1.4.7</commons-xmlschema.version>
<version.commons.codec>1.15</version.commons.codec>
<version.commons.codec>1.17.1</version.commons.codec>
<version.annogen>0.1.0.wso2v1</version.annogen>
<version.backport.util.concurrent>3.1.0.wso2v1</version.backport.util.concurrent>
<version.commons.fileupload>1.5.0.wso2v1</version.commons.fileupload>
Expand All @@ -1677,7 +1687,7 @@
<orbit.version.commons.lang>2.6.0.wso2v1</orbit.version.commons.lang>
<version.geronimo.saaj.spec>1.0.1.wso2v2</version.geronimo.saaj.spec>
<orbit.version.poi>3.17.0.wso2v1</orbit.version.poi>
<orbit.version.poi.scratchpad>3.17.0.wso2v1</orbit.version.poi.scratchpad>
<orbit.version.poi.scratchpad>5.3.0.wso2v1</orbit.version.poi.scratchpad>
<slf4j.version>1.7.36</slf4j.version>
<version.log4j.core>2.17.1</version.log4j.core>
<version.jaxb>2.2.5.wso2v1</version.jaxb>
Expand Down Expand Up @@ -1765,7 +1775,7 @@
<carbon.commons.logging.imp.pkg.version>0.0.0</carbon.commons.logging.imp.pkg.version> <!-- todo org.apache.commons.logging package version changed to this since there are no version in current export, after it was fixed change accordingly (should be able to use carbon.kernel.imp.pkg.version). - rajith-->
<carbon.kernel.imp.pkg.version>[4.4.0,5.0.0)</carbon.kernel.imp.pkg.version>

<commons-io.version>2.11.0</commons-io.version>
<commons-io.version>2.17.0</commons-io.version>
<commons-io.orbit.imp.pkg.version>0.0.0</commons-io.orbit.imp.pkg.version> <!-- todo change this once commons-io is corrected to use correct version exports - rajith -->

<jena-arq.orbit.version>1.0.0.wso2v1</jena-arq.orbit.version>
Expand All @@ -1777,9 +1787,12 @@
<opencsv.orbit.version>1.8.wso2v1</opencsv.orbit.version>
<opencsv.orbit.imp.pkg.version>0.0.0</opencsv.orbit.imp.pkg.version> <!--todo change this to appropriate version range ([1.8.wso2v1,1.9)) after osgi bundle was corrected -->

<poi-ooxml.orbit.version>3.17.0.wso2v1</poi-ooxml.orbit.version>
<poi-ooxml.orbit.version>5.3.0.wso2v1</poi-ooxml.orbit.version>
<poi-ooxml.orbit.imp.pkg.version>0.0.0</poi-ooxml.orbit.imp.pkg.version> <!--todo change this to appropriate version range ([3.9.0.wso2v3,4.0.0)) after osgi bundle is corrected - rajith-->

<poi-ooxml.version>5.3.0</poi-ooxml.version>
<poi.version>5.3.0</poi.version>

<commons-collections4.orbit.version>4.4.wso2v1</commons-collections4.orbit.version>
<commons-collections4.orbit.imp.pkg.version>0.0.0</commons-collections4.orbit.imp.pkg.version>

Expand Down Expand Up @@ -1835,7 +1848,7 @@
<google-oauth-client.orbit.version>1.33.3.wso2v1</google-oauth-client.orbit.version>
<google-oauth-client.orbit.imp.pkg.version>[1.33.1,2.0)</google-oauth-client.orbit.imp.pkg.version>

<poi.orbit.version>3.17.0.wso2v1</poi.orbit.version>
<poi.orbit.version>5.3.0.wso2v1</poi.orbit.version>
<poi.orbit.imp.pkg.version>0.0.0</poi.orbit.imp.pkg.version> <!--todo change this to appropriate version range ([3.9.0,4.0.0)) after osgi bundle is corrected - rajith-->

<google-api-client.orbit.version>1.33.1.wso2v2</google-api-client.orbit.version>
Expand Down

0 comments on commit b9d24d3

Please sign in to comment.