Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDEMPIERE-6117 POI: WorkbookFactory.create cannot be used to open XLSX files #2357

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions migration/iD11/oracle/202405131534_IDEMPIERE-6040.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- IDEMPIERE-6040 Improvements for CSV import template
SELECT register_migration_script('202405131534_IDEMPIERE-6040.sql') FROM dual;

SET SQLBLANKLINES ON
SET DEFINE OFF

-- May 13, 2024, 3:34:49 PM CEST
UPDATE AD_Ref_List SET Name='Comma-separated values (CSV)',Updated=TO_TIMESTAMP('2024-05-13 15:34:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Ref_List_ID=200704
;

-- May 13, 2024, 3:35:58 PM CEST
UPDATE AD_Ref_List SET Name='Excel (XLS/XLSX)',Updated=TO_TIMESTAMP('2024-05-13 15:35:58','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Ref_List_ID=200706
;

-- May 13, 2024, 3:36:02 PM CEST
UPDATE AD_Ref_List SET IsActive='N',Updated=TO_TIMESTAMP('2024-05-13 15:36:02','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Ref_List_ID=200705
;

UPDATE AD_ImportTemplate SET ImportTemplateType='XLSX' WHERE ImportTemplateType='XLS'
;

-- May 13, 2024, 3:59:49 PM CEST
UPDATE AD_Field SET SeqNo=120, ColumnSpan=2,Updated=TO_TIMESTAMP('2024-05-13 15:59:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=208476
;

22 changes: 22 additions & 0 deletions migration/iD11/postgresql/202405131534_IDEMPIERE-6040.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- IDEMPIERE-6040 Improvements for CSV import template
SELECT register_migration_script('202405131534_IDEMPIERE-6040.sql') FROM dual;

-- May 13, 2024, 3:34:49 PM CEST
UPDATE AD_Ref_List SET Name='Comma-separated values (CSV)',Updated=TO_TIMESTAMP('2024-05-13 15:34:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Ref_List_ID=200704
;

-- May 13, 2024, 3:35:58 PM CEST
UPDATE AD_Ref_List SET Name='Excel (XLS/XLSX)',Updated=TO_TIMESTAMP('2024-05-13 15:35:58','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Ref_List_ID=200706
;

-- May 13, 2024, 3:36:02 PM CEST
UPDATE AD_Ref_List SET IsActive='N',Updated=TO_TIMESTAMP('2024-05-13 15:36:02','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Ref_List_ID=200705
;

UPDATE AD_ImportTemplate SET ImportTemplateType='XLSX' WHERE ImportTemplateType='XLS'
;

-- May 13, 2024, 3:59:49 PM CEST
UPDATE AD_Field SET SeqNo=120, ColumnSpan=2,Updated=TO_TIMESTAMP('2024-05-13 15:59:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=208476
;

4 changes: 4 additions & 0 deletions org.adempiere.base-feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@
id="org.apache.commons.commons-compress"
version="0.0.0"/>

<plugin
id="org.apache.commons.commons-io"
version="0.0.0"/>

<plugin
id="org.apache.commons.commons-net"
version="0.0.0"/>
Expand Down
1 change: 1 addition & 0 deletions org.adempiere.base-feature/model.generator.launch
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<setEntry value="org.apache.commons.commons-codec@default:default"/>
<setEntry value="org.apache.commons.commons-collections4@default:default"/>
<setEntry value="org.apache.commons.commons-compress@default:default"/>
<setEntry value="org.apache.commons.commons-io@default:default"/>
<setEntry value="org.apache.commons.commons-net@default:default"/>
<setEntry value="org.apache.commons.logging@default:default"/>
<setEntry value="org.apache.felix.gogo.runtime@default:default"/>
Expand Down
1 change: 1 addition & 0 deletions org.adempiere.base-feature/packinfolder.app.launch
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<setEntry value="org.apache.commons.commons-codec@default:default"/>
<setEntry value="org.apache.commons.commons-collections4@default:default"/>
<setEntry value="org.apache.commons.commons-compress@default:default"/>
<setEntry value="org.apache.commons.commons-io@default:default"/>
<setEntry value="org.apache.commons.commons-net@default:default"/>
<setEntry value="org.apache.commons.logging@default:default"/>
<setEntry value="org.apache.felix.gogo.runtime@default:default"/>
Expand Down
1 change: 1 addition & 0 deletions org.adempiere.base-feature/sign.database.build.launch
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<setEntry value="org.apache.commons.commons-codec@default:default"/>
<setEntry value="org.apache.commons.commons-collections4@default:default"/>
<setEntry value="org.apache.commons.commons-compress@default:default"/>
<setEntry value="org.apache.commons.commons-io@default:default"/>
<setEntry value="org.apache.commons.commons-net@default:default"/>
<setEntry value="org.apache.commons.logging@default:default"/>
<setEntry value="org.apache.felix.gogo.runtime@default:default"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<setEntry value="org.apache.commons.commons-codec@default:default"/>
<setEntry value="org.apache.commons.commons-collections4@default:default"/>
<setEntry value="org.apache.commons.commons-compress@default:default"/>
<setEntry value="org.apache.commons.commons-io@default:default"/>
<setEntry value="org.apache.commons.commons-net@default:default"/>
<setEntry value="org.apache.commons.logging@default:default"/>
<setEntry value="org.apache.felix.gogo.runtime@default:default"/>
Expand Down
1 change: 1 addition & 0 deletions org.adempiere.base-feature/translation.app.launch
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<setEntry value="org.apache.commons.commons-codec@default:default"/>
<setEntry value="org.apache.commons.commons-collections4@default:default"/>
<setEntry value="org.apache.commons.commons-compress@default:default"/>
<setEntry value="org.apache.commons.commons-io@default:default"/>
<setEntry value="org.apache.commons.commons-net@default:default"/>
<setEntry value="org.apache.commons.logging@default:default"/>
<setEntry value="org.apache.felix.gogo.runtime@default:default"/>
Expand Down
23 changes: 23 additions & 0 deletions org.adempiere.base/src/org/adempiere/base/BaseActivator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
import java.util.Properties;

import org.adempiere.base.equinox.StackTraceCommand;
import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.extractor.MainExtractorFactory;
import org.apache.poi.hssf.usermodel.HSSFWorkbookFactory;
import org.apache.poi.ooxml.extractor.POIXMLExtractorFactory;
import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFWorkbookFactory;
import org.apache.poi.xslf.usermodel.XSLFSlideShowFactory;
import org.compiere.Adempiere;
import org.eclipse.osgi.framework.console.CommandProvider;
import org.osgi.framework.BundleActivator;
Expand Down Expand Up @@ -61,6 +69,13 @@ public void start(BundleContext context) throws Exception {
context.registerService(CommandProvider.class.getName(), new StackTraceCommand(), null);

blacklistService = new ComponentBlackListService(context);

//setup poi factory
WorkbookFactory.addProvider(new HSSFWorkbookFactory());
WorkbookFactory.addProvider(new XSSFWorkbookFactory());
SlideShowFactory.addProvider(new XSLFSlideShowFactory());
ExtractorFactory.addProvider(new POIXMLExtractorFactory());
ExtractorFactory.addProvider(new MainExtractorFactory());
}

/*
Expand Down Expand Up @@ -120,6 +135,14 @@ public void stop(BundleContext context) throws Exception {
blacklistService.stop(context);
blacklistService = null;
}

//remove poi factory
WorkbookFactory.removeProvider(HSSFWorkbookFactory.class);
WorkbookFactory.removeProvider(XSSFWorkbookFactory.class);
SlideShowFactory.removeProvider(XSLFSlideShowFactory.class);
ExtractorFactory.removeProvider(POIXMLExtractorFactory.class);
ExtractorFactory.removeProvider(MainExtractorFactory.class);

Adempiere.stop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/** Generated Interface for AD_ImportTemplate
* @author iDempiere (generated)
* @version Release 11
* @version Release 12
*/
public interface I_AD_ImportTemplate
{
Expand Down
18 changes: 3 additions & 15 deletions org.adempiere.base/src/org/compiere/model/MImportTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@
import java.util.logging.Level;

import org.adempiere.exceptions.AdempiereException;
import org.apache.poi.hssf.usermodel.HSSFWorkbookFactory;
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;
import org.apache.poi.xssf.usermodel.XSSFWorkbookFactory;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.compiere.util.CCache;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
Expand Down Expand Up @@ -239,8 +238,7 @@ else if ("M".equals(importMode))
*/
public InputStream validateFile(InputStream in) {

if ( MImportTemplate.IMPORTTEMPLATETYPE_XLS.equals(getImportTemplateType())
|| MImportTemplate.IMPORTTEMPLATETYPE_XLSX.equals(getImportTemplateType())) {
if (MImportTemplate.IMPORTTEMPLATETYPE_ExcelXLSXLSX.equals(getImportTemplateType())) {
try {
in = convertExcelToCSV(in);
} catch (Exception e) {
Expand Down Expand Up @@ -309,17 +307,7 @@ public InputStream validateFile(InputStream in) {
*/
public InputStream convertExcelToCSV(InputStream excelIs) throws IOException {

Workbook workbook = null;
if (MImportTemplate.IMPORTTEMPLATETYPE_XLS.equals(getImportTemplateType())) {
HSSFWorkbookFactory xlsWbf = new HSSFWorkbookFactory();
workbook = xlsWbf.create(excelIs);
} else if (MImportTemplate.IMPORTTEMPLATETYPE_XLSX.equals(getImportTemplateType())) {
XSSFWorkbookFactory xlsxWbf = new XSSFWorkbookFactory();
workbook = xlsxWbf.create(excelIs);
} else {
// unexpected error
throw new AdempiereException("Wrong template type -> " + getImportTemplateType());
}
Workbook workbook = WorkbookFactory.create(excelIs);

List<Integer> colTypes = calculateAndValidateColumnTypes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

/** Generated Model for AD_ImportTemplate
* @author iDempiere (generated)
* @version Release 11 - $Id$ */
* @version Release 12 - $Id$ */
@org.adempiere.base.Model(table="AD_ImportTemplate")
public class X_AD_ImportTemplate extends PO implements I_AD_ImportTemplate, I_Persistent
{

/**
*
*/
private static final long serialVersionUID = 20240327L;
private static final long serialVersionUID = 20240513L;

/** Standard Constructor */
public X_AD_ImportTemplate (Properties ctx, int AD_ImportTemplate_ID, String trxName)
Expand Down Expand Up @@ -300,12 +300,12 @@ public String getDescription()

/** ImportTemplateType AD_Reference_ID=200268 */
public static final int IMPORTTEMPLATETYPE_AD_Reference_ID=200268;
/** CSV = CSV */
public static final String IMPORTTEMPLATETYPE_CSV = "CSV";
/** Comma-separated values (CSV) = CSV */
public static final String IMPORTTEMPLATETYPE_Comma_SeparatedValuesCSV = "CSV";
/** XLS = XLS */
public static final String IMPORTTEMPLATETYPE_XLS = "XLS";
/** XLSX = XLSX */
public static final String IMPORTTEMPLATETYPE_XLSX = "XLSX";
/** Excel (XLS/XLSX) = XLSX */
public static final String IMPORTTEMPLATETYPE_ExcelXLSXLSX = "XLSX";
/** Set Import Template Type.
@param ImportTemplateType Import Template Type
*/
Expand Down
1 change: 1 addition & 0 deletions org.adempiere.install/install.app.launch
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<setEntry value="org.apache.commons.commons-codec@default:default"/>
<setEntry value="org.apache.commons.commons-collections4@default:default"/>
<setEntry value="org.apache.commons.commons-compress@default:default"/>
<setEntry value="org.apache.commons.commons-io@default:default"/>
<setEntry value="org.apache.commons.commons-net@default:default"/>
<setEntry value="org.apache.commons.logging@default:default"/>
<setEntry value="org.apache.felix.gogo.runtime@default:default"/>
Expand Down
1 change: 1 addition & 0 deletions org.adempiere.install/install.console.app.launch
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<setEntry value="org.apache.commons.commons-codec@default:default"/>
<setEntry value="org.apache.commons.commons-collections4@default:default"/>
<setEntry value="org.apache.commons.commons-compress@default:default"/>
<setEntry value="org.apache.commons.commons-io@default:default"/>
<setEntry value="org.apache.commons.commons-net@default:default"/>
<setEntry value="org.apache.commons.logging@default:default"/>
<setEntry value="org.apache.felix.scr@1:true"/>
Expand Down
1 change: 1 addition & 0 deletions org.adempiere.install/install.silent.app.launch
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<setEntry value="org.apache.commons.commons-codec@default:default"/>
<setEntry value="org.apache.commons.commons-collections4@default:default"/>
<setEntry value="org.apache.commons.commons-compress@default:default"/>
<setEntry value="org.apache.commons.commons-io@default:default"/>
<setEntry value="org.apache.commons.commons-net@default:default"/>
<setEntry value="org.apache.commons.logging@default:default"/>
<setEntry value="org.apache.felix.scr@1:true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ osgi.bundles=org.apache.felix.scr@1:start,\
wrapped.org.apache.poi.poi-ooxml,\
wrapped.org.apache.poi.poi-ooxml-lite,\
org.apache.commons.commons-compress,\
org.apache.commons.commons-io,\
wrapped.org.apache.xmlbeans.xmlbeans,\
org.eclipse.core.jobs,\
org.eclipse.equinox.preferences,\
Expand Down
11 changes: 8 additions & 3 deletions org.idempiere.test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,14 @@
</requirement>
<requirement>
<type>eclipse-plugin</type>
<id>org.idempiere.tablepartition</id>
<versionRange>0.0.0</versionRange>
</requirement>
<id>org.idempiere.tablepartition</id>
<versionRange>0.0.0</versionRange>
</requirement>
<requirement>
<type>eclipse-plugin</type>
<id>wrapped.org.apache.xmlbeans.xmlbeans</id>
<versionRange>0.0.0</versionRange>
</requirement>
</extraRequirements>
</dependency-resolution>
</configuration>
Expand Down