diff --git a/budgeteer-ubw-importer/src/main/java/org/wickedsource/budgeteer/importer/ubw/UBWWorkRecordsImporter.java b/budgeteer-ubw-importer/src/main/java/org/wickedsource/budgeteer/importer/ubw/UBWWorkRecordsImporter.java index 7099fc5c3..f74af286e 100644 --- a/budgeteer-ubw-importer/src/main/java/org/wickedsource/budgeteer/importer/ubw/UBWWorkRecordsImporter.java +++ b/budgeteer-ubw-importer/src/main/java/org/wickedsource/budgeteer/importer/ubw/UBWWorkRecordsImporter.java @@ -10,14 +10,10 @@ import java.io.IOException; import java.util.*; -import static java.nio.charset.StandardCharsets.UTF_8; - public class UBWWorkRecordsImporter implements WorkRecordsImporter { private int sheetIndex = -1; - private static final String SHEET_NAME = "Aufwände gesamt"; - private static final int COLUMN_INVOICEABLE = 11; private static final int COLUMN_DATE = 3; @@ -41,7 +37,7 @@ public List importFile(ImportFile file) throws ImportExcepti List resultList = new ArrayList<>(); Workbook workbook = new XSSFWorkbook(file.getInputStream()); - if (!checkValidity(workbook)) { + if (!checkValidityAndSetSheetIndex(workbook)) { throw new InvalidFileFormatException("Invalid file", file.getFilename()); } Sheet sheet = workbook.getSheetAt(sheetIndex); @@ -65,10 +61,6 @@ public List importFile(ImportFile file) throws ImportExcepti } } - private int findSheetIndex(Workbook workbook) { - return workbook.getSheetIndex(new String(SHEET_NAME.getBytes(), UTF_8)); - } - private boolean isCompletelyEmpty(Row row) { for (short i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) { Cell cell = row.getCell(i); @@ -104,7 +96,7 @@ public ExampleFile getExampleFile() { Calendar maxCalendar = Calendar.getInstance(); Calendar maxineCalendar = Calendar.getInstance(); XSSFWorkbook workbook = new XSSFWorkbook(getClass().getResourceAsStream("/example_ubw_report.xlsx")); - sheetIndex = findSheetIndex(workbook); + checkValidityAndSetSheetIndex(workbook); XSSFSheet sheet = workbook.getSheetAt(sheetIndex); XSSFRow row; XSSFCell cell; @@ -145,7 +137,6 @@ public ExampleFile getExampleFile() { cell.setCellStyle(style); maxineCalendar.add(Calendar.DATE, -1); } - i--; } @@ -172,11 +163,10 @@ public List> getSkippedRecords() { return skippedRecords; } - boolean checkValidity(Workbook workbook) { - sheetIndex = findSheetIndex(workbook); - boolean isValid = sheetIndex != -1 && workbook.getNumberOfSheets() >= sheetIndex; - if (isValid) { - Sheet sheet = workbook.getSheetAt(sheetIndex); + boolean checkValidityAndSetSheetIndex(Workbook workbook) { + boolean isValid = false; + for(int i = 0; i < workbook.getNumberOfSheets() && !isValid; i++){ + Sheet sheet = workbook.getSheetAt(i); int headerRowIndex = 2; if (sheet.getRow(headerRowIndex) == null) { isValid = false; @@ -188,6 +178,7 @@ boolean checkValidity(Workbook workbook) { r.getCell(COLUMN_BUDGET).getStringCellValue().equals("Subgruppe") && r.getCell(COLUMN_HOURS).getStringCellValue().equals("Aufwand [h]") && r.getCell(COLUMN_INVOICEABLE).getStringCellValue().equals("KV"); + sheetIndex = i; } catch (Exception e) { isValid = false; } diff --git a/budgeteer-ubw-importer/src/test/java/org/wickedsource/budgeteer/importer/ubw/UBWWorkRecordsImporterTest.java b/budgeteer-ubw-importer/src/test/java/org/wickedsource/budgeteer/importer/ubw/UBWWorkRecordsImporterTest.java index 9e99f739c..327e86668 100644 --- a/budgeteer-ubw-importer/src/test/java/org/wickedsource/budgeteer/importer/ubw/UBWWorkRecordsImporterTest.java +++ b/budgeteer-ubw-importer/src/test/java/org/wickedsource/budgeteer/importer/ubw/UBWWorkRecordsImporterTest.java @@ -68,7 +68,7 @@ void testGetExampleFile() { void testValidity() throws IOException { UBWWorkRecordsImporter importer = new UBWWorkRecordsImporter(); Workbook workbook = new XSSFWorkbook(importer.getExampleFile().getInputStream()); - assertTrue(importer.checkValidity(workbook)); + assertTrue(importer.checkValidityAndSetSheetIndex(workbook)); } @Test diff --git a/budgeteer-web-interface/src/main/resources/application.properties b/budgeteer-web-interface/src/main/resources/application.properties index 80196dbdc..a17601fe9 100644 --- a/budgeteer-web-interface/src/main/resources/application.properties +++ b/budgeteer-web-interface/src/main/resources/application.properties @@ -103,7 +103,7 @@ spring.jpa.properties.hibernate.id.new_generator_mappings=false # FLYWAY (FlywayProperties) flyway.baseline-on-migrate=true -flyway.baseline-version=1_1_1 +flyway.baseline-version=1_1_2 flyway.check-location=true flyway.enabled=true flyway.locations=classpath:db/migration diff --git a/build.gradle b/build.gradle index 35b7792d2..122ed8afc 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ file('gradle.d').listFiles().sort().each { } allprojects { - version = '1.1.2.BETA' + version = '1.1.3.BETA' } buildscript {