/* (non-Javadoc)
   * @see org.cloudcoder.app.client.rpc.GetCoursesAndProblemsService#findCurrentQuiz(org.cloudcoder.app.shared.model.Problem)
   */
  @Override
  public Quiz findCurrentQuiz(Problem problem) throws CloudCoderAuthenticationException {
    // Make sure user is authenticated
    User user =
        ServletUtil.checkClientIsAuthenticated(
            getThreadLocalRequest(), GetCoursesAndProblemsServiceImpl.class);

    // Find current quiz (if any)
    Quiz quiz = Database.getInstance().findCurrentQuiz(user, problem);

    if (quiz != null) {
      // Set the end time to the current time: this allows the client
      // to compute how long the quiz has been active
      quiz.setEndTime(System.currentTimeMillis());
    }

    return quiz;
  }
Exemple #2
0
  @Override
  public Boolean run(Connection conn) throws SQLException {
    PreparedStatement stmt =
        prepareStatement(
            conn,
            "update cc_quizzes as q"
                + "  join cc_course_registrations as cr on  cr.course_id = q.course_id"
                + "                                     and cr.section = q.section"
                + "                                     and cr.user_id = ?"
                + "                                     and q.problem_id = ?"
                + "                                     and q.section = ?"
                + "                                     and q.course_id = ?"
                + " set end_time = ?");
    stmt.setInt(1, user.getId());
    stmt.setInt(2, quiz.getProblemId());
    stmt.setInt(3, quiz.getSection());
    stmt.setInt(4, quiz.getCourseId());
    long currentTime = System.currentTimeMillis();
    stmt.setLong(5, currentTime);

    int updateCount = stmt.executeUpdate();
    return updateCount > 0;
  }