METAMODEL-1174: Updated POI dependency (and using code) to latest closes apache/metam...
authorKasper Sørensen <i.am.kasper.sorensen@gmail.com>
Fri, 8 Dec 2017 22:16:38 +0000 (23:16 +0100)
committerDennis Du Krøger <losd@apache.org>
Fri, 8 Dec 2017 22:20:10 +0000 (23:20 +0100)
CHANGES.md
excel/pom.xml
excel/src/main/java/org/apache/metamodel/excel/ExcelDataContext.java
excel/src/main/java/org/apache/metamodel/excel/ExcelInsertBuilder.java
excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java

index f442440..860c0b7 100644 (file)
@@ -1,6 +1,7 @@
  * [METAMODEL-1169] - Fixed issue with SQL Server milliseconds precision in WHERE.
  * [METAMODEL-1173] - Fixed parsing and handling of scalar functions in WHERE clause.
  * [METAMODEL-1171] - Fixed parsing of query operators with DATE, TIME, TIMESTAMP prefix to operand date/time values.
+ * [METAMODEL-1174] - Upgraded Excel module's dependency on Apache POI to latest stable version (3.17).
 
 ### Apache MetaModel 5.0
 
index 6ec11b3..4cea4c9 100644 (file)
@@ -40,7 +40,7 @@ under the License.
                <dependency>
                        <groupId>org.apache.poi</groupId>
                        <artifactId>poi-ooxml</artifactId>
-                       <version>3.13</version>
+                       <version>3.17</version>
                        <exclusions>
                                <exclusion>
                                        <groupId>commons-logging</groupId>
index b5e6fca..b1f8149 100644 (file)
@@ -35,7 +35,7 @@ import org.apache.metamodel.schema.Schema;
 import org.apache.metamodel.schema.Table;
 import org.apache.metamodel.util.FileResource;
 import org.apache.metamodel.util.Resource;
-import org.apache.poi.POIXMLDocument;
+import org.apache.poi.poifs.filesystem.FileMagic;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -189,7 +189,7 @@ public final class ExcelDataContext extends QueryPostprocessDataContext implemen
                 if (_spreadsheetReaderDelegate == null) {
                     _spreadsheetReaderDelegate = _resource.read(in -> {
                         try {
-                            if (POIXMLDocument.hasOOXMLHeader(in)) {
+                            if (FileMagic.valueOf(in) == FileMagic.OOXML) {
                                 return new XlsxSpreadsheetReaderDelegate(_resource, _configuration);
                             } else {
                                 return new DefaultSpreadsheetReaderDelegate(_resource, _configuration);
index dd0d0ea..b584e76 100644 (file)
@@ -22,7 +22,9 @@ import java.util.Date;
 
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.FillPatternType;
 import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.metamodel.data.Style;
 import org.apache.metamodel.data.Style.Color;
@@ -87,7 +89,7 @@ final class ExcelInsertBuilder extends
 
                                        };
                                        if (style.isBold()) {
-                                               font.get().setBoldweight(Font.BOLDWEIGHT_BOLD);
+                                           font.get().setBold(true);
                                        }
                                        if (style.isItalic()) {
                                                font.get().setItalic(true);
@@ -120,7 +122,7 @@ final class ExcelInsertBuilder extends
                                        final Color backgroundColor = style.getBackgroundColor();
                                        if (backgroundColor != null) {
                                                cellStyle.get().setFillPattern(
-                                                               CellStyle.SOLID_FOREGROUND);
+                                                       FillPatternType.SOLID_FOREGROUND);
                                                cellStyle.get().setFillForegroundColor(
                                                                getUpdateCallback().getColorIndex(
                                                                                backgroundColor));
@@ -161,16 +163,16 @@ final class ExcelInsertBuilder extends
                return d.intValue();
        }
 
-       private short getAlignment(TextAlignment alignment) {
+       private HorizontalAlignment getAlignment(TextAlignment alignment) {
                switch (alignment) {
                case LEFT:
-                       return CellStyle.ALIGN_LEFT;
+                       return HorizontalAlignment.LEFT;
                case RIGHT:
-                       return CellStyle.ALIGN_RIGHT;
+                       return HorizontalAlignment.RIGHT;
                case CENTER:
-                       return CellStyle.ALIGN_CENTER;
+                       return HorizontalAlignment.CENTER;
                case JUSTIFY:
-                       return CellStyle.ALIGN_JUSTIFY;
+                       return HorizontalAlignment.JUSTIFY;
                default:
                        throw new IllegalArgumentException("Unknown alignment type: "
                                        + alignment);
index 85cc79b..c7fe930 100644 (file)
@@ -54,6 +54,7 @@ import org.apache.poi.ss.formula.FormulaParseException;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Color;
+import org.apache.poi.ss.usermodel.FillPatternType;
 import org.apache.poi.ss.usermodel.Font;
 import org.apache.poi.ss.usermodel.FontUnderline;
 import org.apache.poi.ss.usermodel.FormulaError;
@@ -142,8 +143,8 @@ final class ExcelUtils {
     }
 
     /**
-     * Writes the {@link Workbook} to a {@link Resource}. The {@link Workbook}
-     * will be closed as a result of this operation!
+     * Writes the {@link Workbook} to a {@link Resource}. The {@link Workbook} will be closed as a result of this
+     * operation!
      * 
      * @param dataContext
      * @param wb
@@ -188,14 +189,15 @@ final class ExcelUtils {
 
         final String result;
 
-        switch (cell.getCellType()) {
-        case Cell.CELL_TYPE_BLANK:
+        switch (cell.getCellTypeEnum()) {
+        case BLANK:
+        case _NONE:
             result = null;
             break;
-        case Cell.CELL_TYPE_BOOLEAN:
+        case BOOLEAN:
             result = Boolean.toString(cell.getBooleanCellValue());
             break;
-        case Cell.CELL_TYPE_ERROR:
+        case ERROR:
             String errorResult;
             try {
                 byte errorCode = cell.getErrorCellValue();
@@ -214,11 +216,11 @@ final class ExcelUtils {
             }
             result = errorResult;
             break;
-        case Cell.CELL_TYPE_FORMULA:
+        case FORMULA:
             // result = cell.getCellFormula();
             result = getFormulaCellValue(wb, cell);
             break;
-        case Cell.CELL_TYPE_NUMERIC:
+        case NUMERIC:
             if (HSSFDateUtil.isCellDateFormatted(cell)) {
                 Date date = cell.getDateCellValue();
                 if (date == null) {
@@ -232,11 +234,11 @@ final class ExcelUtils {
                 result = _numberFormat.format(cell.getNumericCellValue());
             }
             break;
-        case Cell.CELL_TYPE_STRING:
+        case STRING:
             result = cell.getRichStringCellValue().getString();
             break;
         default:
-            throw new IllegalStateException("Unknown cell type: " + cell.getCellType());
+            throw new IllegalStateException("Unknown cell type: " + cell.getCellTypeEnum());
         }
 
         logger.debug("cell {} resolved to value: {}", cellCoordinate, result);
@@ -260,8 +262,8 @@ final class ExcelUtils {
         // evaluate cell first, if possible
         try {
             if (logger.isInfoEnabled()) {
-                logger.info("cell({},{}) is a formula. Attempting to evaluate: {}", new Object[] { cell.getRowIndex(),
-                        cell.getColumnIndex(), cell.getCellFormula() });
+                logger.info("cell({},{}) is a formula. Attempting to evaluate: {}",
+                        new Object[] { cell.getRowIndex(), cell.getColumnIndex(), cell.getCellFormula() });
             }
 
             final FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
@@ -271,8 +273,8 @@ final class ExcelUtils {
 
             return getCellValue(wb, evaluatedCell);
         } catch (RuntimeException e) {
-            logger.warn("Exception occurred while evaluating formula at position ({},{}): {}", new Object[] { cell
-                    .getRowIndex(), cell.getColumnIndex(), e.getMessage() });
+            logger.warn("Exception occurred while evaluating formula at position ({},{}): {}",
+                    new Object[] { cell.getRowIndex(), cell.getColumnIndex(), e.getMessage() });
             // Some exceptions we simply log - result will be then be the
             // actual formula
             if (e instanceof FormulaParseException) {
@@ -299,7 +301,7 @@ final class ExcelUtils {
         final StyleBuilder styleBuilder = new StyleBuilder();
 
         // Font bold, italic, underline
-        if (font.getBoldweight() >= Font.BOLDWEIGHT_BOLD) {
+        if (font.getBold()) {
             styleBuilder.bold();
         }
         if (font.getItalic()) {
@@ -342,7 +344,7 @@ final class ExcelUtils {
         }
 
         // Background color
-        if (cellStyle.getFillPattern() == 1) {
+        if (cellStyle.getFillPatternEnum() == FillPatternType.SOLID_FOREGROUND) {
             Color color = cellStyle.getFillForegroundColorColor();
             if (color instanceof HSSFColor) {
                 short[] triplet = ((HSSFColor) color).getTriplet();
@@ -355,25 +357,28 @@ final class ExcelUtils {
                     styleBuilder.background(argb.substring(2));
                 }
             } else {
-                throw new IllegalStateException("Unexpected color type: " + (color == null ? "null" : color.getClass())
-                        + ")");
+                throw new IllegalStateException(
+                        "Unexpected color type: " + (color == null ? "null" : color.getClass()) + ")");
             }
         }
 
         // alignment
-        switch (cellStyle.getAlignment()) {
-        case CellStyle.ALIGN_LEFT:
+        switch (cellStyle.getAlignmentEnum()) {
+        case LEFT:
             styleBuilder.leftAligned();
             break;
-        case CellStyle.ALIGN_RIGHT:
+        case RIGHT:
             styleBuilder.rightAligned();
             break;
-        case CellStyle.ALIGN_CENTER:
+        case CENTER:
             styleBuilder.centerAligned();
             break;
-        case CellStyle.ALIGN_JUSTIFY:
+        case JUSTIFY:
             styleBuilder.justifyAligned();
             break;
+        default:
+            // we currently don't support other alignment styles
+            break;
         }
 
         return styleBuilder.create();
@@ -413,8 +418,7 @@ final class ExcelUtils {
      * 
      * @param workbook
      * @param row
-     * @param selectItems
-     *            select items of the columns in the table
+     * @param selectItems select items of the columns in the table
      * @return
      */
     public static DefaultRow createRow(Workbook workbook, Row row, DataSetHeader header) {
@@ -436,8 +440,8 @@ final class ExcelUtils {
     }
 
     public static DataSet getDataSet(Workbook workbook, Sheet sheet, Table table, ExcelConfiguration configuration) {
-        final List<SelectItem> selectItems = table.getColumns().stream().map(SelectItem::new).collect(Collectors
-                .toList());
+        final List<SelectItem> selectItems =
+                table.getColumns().stream().map(SelectItem::new).collect(Collectors.toList());
         final Iterator<Row> rowIterator = getRowIterator(sheet, configuration, true);
         if (!rowIterator.hasNext()) {
             // no more rows!