@Override
  public void startImportAllProblemsFromCourse(Course source, Course dest)
      throws CloudCoderAuthenticationException {
    User authenticatedUser =
        ServletUtil.checkClientIsAuthenticated(
            getThreadLocalRequest(), GetCoursesAndProblemsServiceImpl.class);

    // Make sure that the authenticated user is registered as an instructor for
    // both the source and destination courses.
    boolean sourceInstructor = false, destInstructor = false;
    List<? extends Object[]> courses = Database.getInstance().getCoursesForUser(authenticatedUser);
    for (Object[] triple : courses) {
      CourseRegistration reg = (CourseRegistration) triple[2];
      if (reg.getCourseId() == source.getId() && reg.getRegistrationType().isInstructor()) {
        sourceInstructor = true;
      }
      if (reg.getCourseId() == dest.getId() && reg.getRegistrationType().isInstructor()) {
        destInstructor = true;
      }
    }

    // Create a FutureImportCourseResult
    FutureImportCourseResult result = new FutureImportCourseResult();
    getThreadLocalRequest()
        .getSession()
        .setAttribute(SessionAttributeKeys.FUTURE_IMPORT_COURSE_RESULT_KEY, result);

    if (!sourceInstructor || !destInstructor) {
      result.set(new OperationResult(false, "Permission denied (not an instructor)"));
      return;
    }

    // Start the actual operation
    result.start(source, dest, authenticatedUser);
  }
 @Override
 public OperationResult checkImportAllProblemsFromCourse() {
   FutureImportCourseResult result =
       (FutureImportCourseResult)
           getThreadLocalRequest()
               .getSession()
               .getAttribute(SessionAttributeKeys.FUTURE_IMPORT_COURSE_RESULT_KEY);
   if (result == null) {
     return new OperationResult(
         false, "There doesn't seem to be a pending operation to import exercises?");
   }
   OperationResult poll = result.poll();
   if (poll != null) {
     getThreadLocalRequest()
         .getSession()
         .removeAttribute(SessionAttributeKeys.FUTURE_IMPORT_COURSE_RESULT_KEY);
   }
   return poll;
 }