From b40af386d5ede4dbb0cd9168fe4da98da7113665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20=C5=A0imandl?= Date: Mon, 11 Feb 2019 10:18:24 +0100 Subject: [PATCH] #24 throws exceptions early, catch them late - minor fix (possibility to work without db) --- .../kiv/offscreen/servlets/UploadFiles.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/sources/imiger-core/src/main/java/cz/zcu/kiv/offscreen/servlets/UploadFiles.java b/sources/imiger-core/src/main/java/cz/zcu/kiv/offscreen/servlets/UploadFiles.java index 5a1bb34a..f311d1ab 100644 --- a/sources/imiger-core/src/main/java/cz/zcu/kiv/offscreen/servlets/UploadFiles.java +++ b/sources/imiger-core/src/main/java/cz/zcu/kiv/offscreen/servlets/UploadFiles.java @@ -3,6 +3,7 @@ import cz.zcu.kiv.offscreen.modularization.ModuleProvider; import cz.zcu.kiv.offscreen.storage.FileLoader; import cz.zcu.kiv.offscreen.user.DB; +import cz.zcu.kiv.offscreen.user.DataAccessException; import cz.zcu.kiv.offscreen.user.Diagram; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; @@ -26,23 +27,31 @@ public class UploadFiles extends BaseServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + logger.debug("Processing request"); - DB db = new DB(getServletContext()); - Diagram diagram = new Diagram(db); List> userDiagramList = new ArrayList<>(); - if (isLoggedIn(request)) { - logger.debug("Logged user"); - int loggedUserId = getUserId(request); + List> publicDiagramList = new ArrayList<>(); + try { + DB db = new DB(getServletContext()); + Diagram diagram = new Diagram(db); + + if (isLoggedIn(request)) { + logger.debug("Logged user"); + int loggedUserId = getUserId(request); + + userDiagramList = diagram.getDiagramListByUserId(loggedUserId); + } + + publicDiagramList = diagram.getDiagramPublicList(); - userDiagramList = diagram.getDiagramListByUserId(loggedUserId); + } catch (DataAccessException e){ + logger.error("Data access exception"); } - request.setAttribute("diagramsPrivate", userDiagramList); - List> publicDiagramList = diagram.getDiagramPublicList(); + request.setAttribute("diagramsPrivate", userDiagramList); request.setAttribute("diagramsPublic", publicDiagramList); request.setAttribute("processingModules", ModuleProvider.getInstance().getModules()); - // render RequestDispatcher rd = getServletContext().getRequestDispatcher("/uploadFiles.jsp"); rd.forward(request, response);