/** @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { log.entry(); if (request instanceof HttpServletRequest) { HttpServletRequest req = ((HttpServletRequest) request); Question question = QuestionManager.getQuestionById(req.getParameter("questionId")); if (question != null) { req.getSession().setAttribute(FilterConstants.ENTITY_ID_FILTER, question.getId()); User u = (User) req.getSession().getAttribute(Constants.CURRENT_USER_ENTITY); req.getSession() .setAttribute( Constants.SHOULD_ALLOW_QUESTION_EDITING, QuestionManager.userCanEditThisQuestion(question, u)); } } // pass the request along the filter chain chain.doFilter(request, response); log.exit(); }
protected Map<String, String> getMapRepresentingASingleIncorrectlyChosenChoice(Question q) { Map<String, String> map = new HashMap<>(); Set<Choice> set = q.getChoices(); for (Choice c : set) { if (map.size() == 0 && c.getIscorrect() == Choice.NOT_CORRECT) { map.put(q.getId() + "," + c.getId(), c.getText()); } } return map; }
protected Map<String, String> getMapRepresentingCorrectChoices(Question q) { Map<String, String> map = new HashMap<>(); Set<Choice> set = q.getChoices(); for (Choice c : set) { if (c.getIscorrect() == Choice.CORRECT) { map.put(q.getId() + "," + c.getId(), c.getText()); } } return map; }
protected Map<String, String> getMapRepresentingACorrectChoiceAndAnIncorrectChoice(Question q) { Map<String, String> map = new HashMap<>(); Set<Choice> set = q.getChoices(); boolean correctAdded = false; boolean incorrectAdded = false; for (Choice c : set) { if (!correctAdded && c.getIscorrect() == Choice.CORRECT) { map.put(q.getId() + "," + c.getId(), c.getText()); correctAdded = true; } if (!incorrectAdded && c.getIscorrect() == Choice.NOT_CORRECT) { map.put(q.getId() + "," + c.getId(), c.getText()); incorrectAdded = true; } } return map; }