Ejemplo n.º 1
0
  @Override
  public OperationResult run(Connection conn) throws SQLException {
    // First, find the user
    User user = Queries.getUser(conn, spec.getUsername(), this);
    if (user == null) {
      return new OperationResult(false, "Unknown user " + spec.getUsername());
    }

    // Create the CourseRegistration
    CourseRegistration reg = new CourseRegistration();
    reg.setUserId(user.getId());
    reg.setCourseId(spec.getCourseId());
    reg.setRegistrationType(spec.getRegistrationType());
    reg.setSection(spec.getSection());

    // Insert the CourseRegistration
    DBUtil.storeModelObject(conn, reg);

    Course course = null;
    try {
      course = DBUtil.loadModelObjectForId(conn, Course.SCHEMA, spec.getCourseId());
    } catch (NoSuchUniqueIdException e) {
      logger.error("Could not find course for id={}", spec.getCourseId());
    }

    return new OperationResult(
        true,
        "Added user "
            + spec.getUsername()
            + " to course"
            + (course != null ? " " + course.getNameAndTitle() : ""));
  }
  /* (non-Javadoc)
   * @see org.cloudcoder.app.client.rpc.GetCoursesAndProblemsService#getCourseAndCourseRegistrations()
   */
  @Override
  public CourseAndCourseRegistration[] getCourseAndCourseRegistrations()
      throws CloudCoderAuthenticationException {
    // make sure the client has authenticated
    User user =
        ServletUtil.checkClientIsAuthenticated(
            getThreadLocalRequest(), GetCoursesAndProblemsServiceImpl.class);

    logger.info("Loading courses and registrations for user " + user.getUsername());

    List<? extends Object[]> resultList = Database.getInstance().getCoursesForUser(user);

    CourseAndCourseRegistration[] result = new CourseAndCourseRegistration[resultList.size()];
    int count = 0;
    for (Object[] tuple : resultList) {
      Course course = (Course) tuple[0];
      Term term = (Term) tuple[1];
      course.setTerm(term);
      CourseRegistration reg = (CourseRegistration) tuple[2];

      CourseAndCourseRegistration obj = new CourseAndCourseRegistration();
      obj.setCourse(course);
      obj.setCourseRegistration(reg);

      result[count++] = obj;
    }

    return result;
  }
  /* (non-Javadoc)
   * @see org.cloudcoder.app.client.rpc.GetCoursesAndProblemsService#getProblemAndSubscriptionReceipts(org.cloudcoder.app.shared.model.Course)
   */
  @Override
  public ProblemAndSubmissionReceipt[] getProblemAndSubscriptionReceipts(
      Course course, User forUser, Module module) throws CloudCoderAuthenticationException {
    // Make sure user is authenticated
    User user =
        ServletUtil.checkClientIsAuthenticated(
            getThreadLocalRequest(), GetCoursesAndProblemsServiceImpl.class);

    logger.info(
        "getting problems/submission receipts for authenticated user " + user.getUsername());

    List<ProblemAndSubmissionReceipt> resultList =
        Database.getInstance()
            .getProblemAndSubscriptionReceiptsInCourse(user, course, forUser, module);
    logger.info("Received " + resultList.size() + " problems/submission receipts");
    return resultList.toArray(new ProblemAndSubmissionReceipt[resultList.size()]);
  }
Ejemplo n.º 4
0
    @Override
    public void load(final Runnable onSuccess, final ICallback<Pair<String, Throwable>> onFailure) {
      final Integer userId =
          pageParams.getInt(PageObjectParamNameMap.getInstance().get(UserSelection.class));
      if (userId == null) {
        onFailure.call(new Pair<String, Throwable>("No user id specified", null));
        return;
      }

      // Special case: if the requested user id is the logged-in user's id,
      // then we succeed trivially.  (A user can always access his/her
      // own information, such as a submission history.)
      User loggedInUser = session.get(User.class);
      if (loggedInUser.getId() == userId.intValue()) {
        GWT.log("User self-selection");
        UserSelection userSelection = new UserSelection();
        userSelection.setUser(loggedInUser);
        session.add(userSelection);
        onSuccess.run();
        return;
      }

      // General case: a user is being selected among all users in the course.

      // Users registered in the course should already have been loaded
      User[] regUserList = session.get(User[].class);

      // Check to see if the user is registered in the course
      for (User userInCourse : regUserList) {
        if (userInCourse.getId() == userId.intValue()) {
          // Huzzah!
          UserSelection userSelection = new UserSelection();
          userSelection.setUser(userInCourse);
          session.add(userSelection);
          onSuccess.run();
          return;
        }
      }

      // User is not registered in course
      onFailure.call(
          new Pair<String, Throwable>("User " + userId + " is not registered in the course", null));
    }
Ejemplo n.º 5
0
  @Override
  public void submit(int problemId, String programText)
      throws CloudCoderAuthenticationException, SubmissionException {
    // Make sure that client is authenticated and has permission to edit the given problem
    User user = ServletUtil.checkClientIsAuthenticated(getThreadLocalRequest());

    HttpSession session = getThreadLocalRequest().getSession();

    // The Problem should be stored in the user's session
    Problem problem = (Problem) session.getAttribute(SessionAttributeKeys.PROBLEM_KEY);
    if (problem == null || problem.getProblemId() != problemId) {
      throw new CloudCoderAuthenticationException();
    }

    // Insert a full-text change into the database.
    Change fullTextChange =
        new Change(
            ChangeType.FULL_TEXT,
            0,
            0,
            0,
            0,
            System.currentTimeMillis(),
            user.getId(),
            problem.getProblemId(),
            programText);
    Database.getInstance().storeChanges(new Change[] {fullTextChange});

    // Get test cases.  (TODO: cache them?)
    List<TestCase> testCaseList = Database.getInstance().getTestCasesForProblem(problemId);

    ISubmitService submitService = DefaultSubmitService.getInstance();

    logger.info("Passing submission to submit service...");
    IFutureSubmissionResult future = submitService.submitAsync(problem, testCaseList, programText);

    // Put the full-text Change and IFutureSubmissionResult in the user's session.
    addSessionObjects(session, fullTextChange, future);
  }
Ejemplo n.º 6
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;
  }