Skip to content

Commit

Permalink
#24 throws exceptions early, catch them late
Browse files Browse the repository at this point in the history
- minor fix (possibility to work without db)
  • Loading branch information
tomasSimandl committed Feb 11, 2019
1 parent 092ba8c commit b40af38
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Map<String, String>> userDiagramList = new ArrayList<>();
if (isLoggedIn(request)) {
logger.debug("Logged user");
int loggedUserId = getUserId(request);
List<Map<String, String>> 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<Map<String, String>> 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);
Expand Down

0 comments on commit b40af38

Please sign in to comment.