Skip to content

Commit

Permalink
Merge pull request #382 from adessoAG/test-encoding-fix
Browse files Browse the repository at this point in the history
UBW Importer fix
  • Loading branch information
maximAtanasov authored Nov 12, 2019
2 parents 67f0323 + 14bf1ea commit ab924b7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +37,7 @@ public List<ImportedWorkRecord> importFile(ImportFile file) throws ImportExcepti

List<ImportedWorkRecord> 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);
Expand All @@ -65,10 +61,6 @@ public List<ImportedWorkRecord> 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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -145,7 +137,6 @@ public ExampleFile getExampleFile() {
cell.setCellStyle(style);
maxineCalendar.add(Calendar.DATE, -1);
}

i--;
}

Expand All @@ -172,11 +163,10 @@ public List<List<String>> 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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ file('gradle.d').listFiles().sort().each {
}

allprojects {
version = '1.1.2.BETA'
version = '1.1.3.BETA'
}

buildscript {
Expand Down

0 comments on commit ab924b7

Please sign in to comment.