diff --git a/excel-importer-test/src_test/com/axonivy/util/excel/test/ArzneimittelLight.xlsx b/excel-importer-test/src_test/com/axonivy/util/excel/test/ArzneimittelLight.xlsx new file mode 100644 index 0000000..8e2b0f3 Binary files /dev/null and b/excel-importer-test/src_test/com/axonivy/util/excel/test/ArzneimittelLight.xlsx differ diff --git a/excel-importer-test/src_test/com/axonivy/util/excel/test/TestEntityClassCreator.java b/excel-importer-test/src_test/com/axonivy/util/excel/test/TestEntityClassCreator.java index 65212e5..267dac3 100644 --- a/excel-importer-test/src_test/com/axonivy/util/excel/test/TestEntityClassCreator.java +++ b/excel-importer-test/src_test/com/axonivy/util/excel/test/TestEntityClassCreator.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.nio.file.Path; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -12,6 +13,7 @@ import com.axonivy.util.excel.importer.EntityClassReader; import ch.ivyteam.ivy.environment.IvyTest; +import ch.ivyteam.ivy.scripting.dataclass.IEntityClassField; @IvyTest public class TestEntityClassCreator { @@ -26,6 +28,23 @@ void readToEntity(@TempDir Path dir) throws IOException { var entity = reader.getEntity(path); assertThat(entity).isNotNull(); } + + @Test + void readGermanized(@TempDir Path dir) throws Exception { + Path path = dir.resolve("Arzneimittel.xlsx"); + TstRes.loadTo(path, "ArzneimittelLight.xlsx"); + + var entity = reader.getEntity(path); + assertThat(entity).isNotNull(); + List fields = entity.getFields().stream().map(IEntityClassField::getName).toList(); + for(String field : fields) { + assertThat(field) + .as("no whitespaces") + .doesNotContain(" ") + .doesNotContain("(") + .doesNotContain("รค"); + } + } @BeforeEach void setup() { diff --git a/excel-importer-test/src_test/com/axonivy/util/excel/test/TestEntityDataLoader.java b/excel-importer-test/src_test/com/axonivy/util/excel/test/TestEntityDataLoader.java index 3ebef60..fe04c4b 100644 --- a/excel-importer-test/src_test/com/axonivy/util/excel/test/TestEntityDataLoader.java +++ b/excel-importer-test/src_test/com/axonivy/util/excel/test/TestEntityDataLoader.java @@ -51,6 +51,27 @@ void loadDataToEntity(@TempDir Path dir) throws IOException, CoreException { customer.getResource().delete(true, new NullProgressMonitor()); } } + + @Test + void loadArznei(@TempDir Path dir) throws IOException, CoreException { + Path path = dir.resolve("meds.xlsx"); + TstRes.loadTo(path, "ArzneimittelLight.xlsx"); + + Workbook wb = ExcelLoader.load(path); + Sheet customerSheet = wb.getSheetAt(0); + + IEntityClass customer = reader.toEntity(customerSheet, "meds"); + try { + customer.save(new NullProgressMonitor()); + Class entity = loader.createTable(customer); + assertThat(unit.findAll(entity)).isEmpty(); + loader.load(customerSheet, customer); + List records = unit.findAll(entity); + assertThat(records).hasSizeGreaterThanOrEqualTo(2); + } finally { + customer.getResource().delete(true, new NullProgressMonitor()); + } + } @BeforeEach void setup() { diff --git a/excel-importer/src/com/axonivy/util/excel/importer/EntityClassReader.java b/excel-importer/src/com/axonivy/util/excel/importer/EntityClassReader.java index bf8feb5..0286281 100644 --- a/excel-importer/src/com/axonivy/util/excel/importer/EntityClassReader.java +++ b/excel-importer/src/com/axonivy/util/excel/importer/EntityClassReader.java @@ -57,9 +57,12 @@ private void withIdField(IEntityClass entity) { } private String fieldName(String colName) { + colName = colName.replaceAll(" ", ""); if (StringUtils.isAllUpperCase(colName)) { return colName.toLowerCase(); } + colName = colName.replaceAll("\\W", ""); + colName = colName.replaceAll("[^\\p{ASCII}]", ""); return StringUtils.uncapitalize(colName); } diff --git a/excel-importer/src/com/axonivy/util/excel/importer/EntityDataLoader.java b/excel-importer/src/com/axonivy/util/excel/importer/EntityDataLoader.java index 23341b4..6a157db 100644 --- a/excel-importer/src/com/axonivy/util/excel/importer/EntityDataLoader.java +++ b/excel-importer/src/com/axonivy/util/excel/importer/EntityDataLoader.java @@ -56,15 +56,14 @@ public void load(Sheet sheet, IEntityClass entity) { } private void insertCallValuesAsParameter(List fields, Row row, Query insert) { - Iterator cells = row.cellIterator(); - int c = 0; - c++; // consumed by 'id' - while(cells.hasNext()) { - Cell cell = cells.next(); - IEntityClassField field = fields.get(c); - String column = field.getName(); - insert.setParameter(column, getValue(cell)); + int c = -1; + for(var field : fields) { c++; + if (field.getName().equals("id")) { + continue; + } + Cell cell = row.getCell(c); + insert.setParameter(field.getName(), getValue(cell)); } } @@ -93,6 +92,9 @@ public Class createTable(IEntityClass entity) { } private Object getValue(Cell cell) { + if (cell == null) { + return null; + } if (cell.getCellType() == CellType.NUMERIC) { return cell.getNumericCellValue(); } diff --git a/excel-importer/src_hd/com/axonivy/util/excel/importer/EntityManager/EntityManager.xhtml b/excel-importer/src_hd/com/axonivy/util/excel/importer/EntityManager/EntityManager.xhtml index 800699a..1e74384 100644 --- a/excel-importer/src_hd/com/axonivy/util/excel/importer/EntityManager/EntityManager.xhtml +++ b/excel-importer/src_hd/com/axonivy/util/excel/importer/EntityManager/EntityManager.xhtml @@ -15,7 +15,7 @@ - +