Skip to content

Commit

Permalink
Cannot view table with special characters #324
Browse files Browse the repository at this point in the history
  • Loading branch information
aeberhart committed Mar 26, 2024
1 parent e6f0d3e commit 04056e6
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions dashjoin-core/src/main/java/org/dashjoin/service/Manage.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ void insert(AbstractDatabase db, List<InputPart> inputParts, boolean clearTable)
Workbook wb = WorkbookFactory.create(inputPart.getBody(InputStream.class, null));
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
for (Sheet sheet : wb) {
Table m = db.tables.get(sheet.getSheetName());
Table m = db.tables.get(getSheetName(sheet));
if (clearTable)
db.delete(m);

Expand Down Expand Up @@ -528,7 +528,7 @@ public DetectResult detect(@Context SecurityContext sc,
Workbook wb = WorkbookFactory.create(inputPart.getBody(InputStream.class, null));
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
for (Sheet sheet : wb) {
Table m = db.tables.get(sheet.getSheetName());
Table m = db.tables.get(getSheetName(sheet));
createMode(res, database, getFileName(header), m);

Iterator<Row> iter = sheet.iterator();
Expand All @@ -537,8 +537,8 @@ public DetectResult detect(@Context SecurityContext sc,
for (int i = 0; i < 10; i++)
_second.add(iter.hasNext() ? new RowWrapper(evaluator, iter.next()) : null);

handleStringTable(res, database, sheet.getSheetName(), m,
new RowWrapper(evaluator, first), _second);
handleStringTable(res, database, getSheetName(sheet), m, new RowWrapper(evaluator, first),
_second);
}
} else if (getFileExt(header).toLowerCase().equals("sqlite")) {
File tmp = File.createTempFile(getFileName(header), "." + getFileExt(header));
Expand Down Expand Up @@ -804,6 +804,10 @@ String cleanColumnName(Object cell) {
return cell.toString().replace('-', '_');
}

String cleanTableName(String res) {
return res.replace(' ', '_');
}

String getFileExt(MultivaluedMap<String, String> header) {
return FilenameUtils.getExtension(getFileNameInternal(header));
}
Expand All @@ -815,7 +819,11 @@ String getFileName(MultivaluedMap<String, String> header) {
// allow RDF uploads where filename must be a URI
res = URLDecoder.decode(res, StandardCharsets.UTF_8);

return res;
return cleanTableName(res);
}

String getSheetName(Sheet sheet) {
return cleanTableName(sheet.getSheetName());
}

String getFileNameInternal(MultivaluedMap<String, String> header) {
Expand Down

0 comments on commit 04056e6

Please sign in to comment.