From 7d084235dbc38c9f73a39ecfa5e69d389a0021aa Mon Sep 17 00:00:00 2001
From: Martin Weise <martin.weise@tuwien.ac.at>
Date: Sun, 4 Dec 2022 12:22:35 +0100
Subject: [PATCH] More detailed error responses both front- and backend

---
 .../main/java/at/tuwien/mapper/QueryMapper.java   | 15 +++++++--------
 .../at/tuwien/service/impl/QueryServiceImpl.java  |  6 +++---
 .../at/tuwien/service/impl/StoreServiceImpl.java  |  2 +-
 fda-ui/components/TableList.vue                   |  2 +-
 4 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/fda-query-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java b/fda-query-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java
index 71b11475f3..12fb0c95f3 100644
--- a/fda-query-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java
+++ b/fda-query-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java
@@ -450,7 +450,7 @@ public interface QueryMapper {
 
     default PreparedStatement tableCsvDtoToRawDeleteQuery(Connection connection, Table table, TableCsvDeleteDto data)
             throws TableMalformedException, ImageNotSupportedException, QueryMalformedException {
-        log.debug("table csv to delete query, table={}, data={}", table, data);
+        log.trace("table csv to delete query, table={}, data={}", table, data);
         int i = 1;
         if (table.getColumns().size() == 0) {
             log.error("Column size is zero");
@@ -497,7 +497,7 @@ public interface QueryMapper {
 
     default PreparedStatement tableCsvDtoToRawUpdateQuery(Connection connection, Table table, TableCsvUpdateDto data)
             throws TableMalformedException, ImageNotSupportedException, QueryMalformedException {
-        log.debug("mapping table csv to update query, table={}, data={}", table, data);
+        log.trace("mapping table csv to update query, table={}, data={}", table, data);
         int i = 1;
         if (table.getColumns().size() == 0) {
             log.error("Column size is zero");
@@ -570,7 +570,7 @@ public interface QueryMapper {
 
     default PreparedStatement tableToRawCountAllQuery(Connection connection, Table table, Instant timestamp)
             throws ImageNotSupportedException, QueryMalformedException {
-        log.debug("mapping table to raw count query, table={}, timestamp={}", table, timestamp);
+        log.trace("mapping table to raw count query, table={}, timestamp={}", table, timestamp);
         /* check image */
         if (!table.getDatabase().getContainer().getImage().getRepository().equals("mariadb")) {
             log.error("Currently only MariaDB is supported");
@@ -599,7 +599,7 @@ public interface QueryMapper {
                                                          Instant timestamp, Boolean selection, Long page, Long size)
             throws ImageNotSupportedException,
             QueryMalformedException {
-        log.debug("mapping query to timestamped query, query={}, database={}, timestamp={}, selection={}, page={}, size={}",
+        log.trace("mapping query to timestamped query, query={}, database={}, timestamp={}, selection={}, page={}, size={}",
                 query, database, timestamp, selection, page, size);
         /* param check */
         if (!database.getContainer().getImage().getRepository().equals("mariadb")) {
@@ -669,9 +669,8 @@ public interface QueryMapper {
                     + "' ");
         }
         try {
-            final PreparedStatement pstmt = connection.prepareStatement(statement.toString());
-            log.trace("mapped timestamped query {} to prepared statement {}", statement, pstmt);
-            return pstmt;
+            log.debug("mapped timestamped query: {}", statement);
+            return connection.prepareStatement(statement.toString());
         } catch (SQLException e) {
             log.error("Failed to prepare statement {}, reason: {}", statement, e.getMessage());
             throw new QueryMalformedException("Failed to prepare statement", e);
@@ -680,7 +679,7 @@ public interface QueryMapper {
 
     default PreparedStatement tableToRawFindAllQuery(Connection connection, Table table, Instant timestamp, Long size, Long page)
             throws ImageNotSupportedException, QueryMalformedException {
-        log.debug("mapping table to find all query, table={}, timestamp={}, size={}, page={}",
+        log.trace("mapping table to find all query, table={}, timestamp={}, size={}, page={}",
                 table, timestamp, size, page);
         /* param check */
         if (!table.getDatabase().getContainer().getImage().getRepository().equals("mariadb")) {
diff --git a/fda-query-service/services/src/main/java/at/tuwien/service/impl/QueryServiceImpl.java b/fda-query-service/services/src/main/java/at/tuwien/service/impl/QueryServiceImpl.java
index e4a39ad338..2b4ec0f8cb 100644
--- a/fda-query-service/services/src/main/java/at/tuwien/service/impl/QueryServiceImpl.java
+++ b/fda-query-service/services/src/main/java/at/tuwien/service/impl/QueryServiceImpl.java
@@ -99,7 +99,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService
             columns = parseColumns(query.getQuery(), database);
         } catch (JSQLParserException e) {
             log.error("Failed to map/parse columns: {}", e.getMessage());
-            throw new ColumnParseException("Failed to map/parse columns", e);
+            throw new ColumnParseException(e.getMessage(), e);
         }
         final QueryResultDto dto;
         try {
@@ -422,7 +422,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService
                 final String tableName = queryMapper.stringToEscapedString(fromItem.toString());
                 log.error("Table with name {} does not exist, available names: {}", tableName,
                         database.getTables().stream().map(Table::getInternalName).collect(Collectors.toList()));
-                throw new JSQLParserException("Table does not exist");
+                throw new JSQLParserException("Table " + tableName + " does not exist");
             }
         }
 
@@ -445,7 +445,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService
             if (i) {
                 log.error("Column {} does not exist, available columns are {}", item,
                         allColumns.stream().map(TableColumn::getInternalName).collect(Collectors.toList()));
-                throw new JSQLParserException("Column does not exist");
+                throw new JSQLParserException("Column " + item + " does not exist");
             }
         }
         return columns;
diff --git a/fda-query-service/services/src/main/java/at/tuwien/service/impl/StoreServiceImpl.java b/fda-query-service/services/src/main/java/at/tuwien/service/impl/StoreServiceImpl.java
index 205e9d5779..98a558385b 100644
--- a/fda-query-service/services/src/main/java/at/tuwien/service/impl/StoreServiceImpl.java
+++ b/fda-query-service/services/src/main/java/at/tuwien/service/impl/StoreServiceImpl.java
@@ -145,7 +145,7 @@ public class StoreServiceImpl extends HibernateConnector implements StoreService
             final PreparedStatement preparedStatement = storeMapper.queryStoreRawInsertQuery(connection, query);
             final ResultSet resultSet = preparedStatement.executeQuery();
             query.setId(storeMapper.resultSetToId(resultSet));
-            log.error("Inserted query {} into the query store of database with id {}", query.getQuery(), databaseId);
+            log.info("Inserted query {} into the query store of database with id {}", query.getQuery(), databaseId);
             log.trace("inserted query {} into the query store of database {}", query, database);
             return query;
         } catch (SQLException e) {
diff --git a/fda-ui/components/TableList.vue b/fda-ui/components/TableList.vue
index b97fc336d5..c9b0198550 100644
--- a/fda-ui/components/TableList.vue
+++ b/fda-ui/components/TableList.vue
@@ -96,7 +96,7 @@
               disable-sort
               :loading="loadingDetails"
               hide-default-footer
-              items-per-page="-1"
+              :items-per-page="-1"
               :headers="headers"
               :items="tableDetails.columns">
               <template v-slot:item.is_null_allowed="{ item }">
-- 
GitLab