@RequestMapping(value = "/transcript/currentcourses", method = RequestMethod.GET)
  @PreAuthorize(Permission.SECURITY_PERSON_READ)
  public @ResponseBody List<ExternalStudentTranscriptCourseTO> loadCurrentCourses(
      final @PathVariable UUID id) throws ObjectNotFoundException {
    String schoolId = getStudentId(id);

    Term currentTerm;
    try {
      currentTerm = termService.getCurrentTerm();
    } catch (ObjectNotFoundException e) {
      currentTerm = new Term();
      LOGGER.error(
          "CURRENT TERM NOT SET, org.jasig.ssp.web.api.external.ExternalStudentRecordsController.loadCurrentCourses(UUID) is being called but will not function properly");
    }
    List<ExternalStudentTranscriptCourseTO> courses =
        externalStudentTranscriptCourseFactory.asTOList(
            externalStudentTranscriptCourseService.getTranscriptsBySchoolIdAndTermCode(
                schoolId, currentTerm.getCode()));
    Collection<EnrollmentStatus> mappings = statusCodeMappings();

    String defaultStatusCode = getDefaultStatusCode(mappings);

    for (ExternalStudentTranscriptCourseTO course : courses) {
      try {
        Person person =
            !StringUtils.isNotBlank(course.getFacultySchoolId())
                ? null
                : personService.getInternalOrExternalPersonBySchoolId(
                    course.getFacultySchoolId(),
                    false); // TODO: getInternalOrExternalPersonBySchoolId is slow refactor?
        if (person != null) {
          course.setFacultyName(person.getFullName());
        }
      } catch (ObjectNotFoundException e) {
        course.setFacultyName("None Listed");
        LOGGER.debug(
            "FACULTY SCHOOL ID WAS NOT RESOLVED WHILE LOADING TRANSCRIPT RECORD.  Factulty School_id: "
                + course.getFacultySchoolId()
                + " Student ID: "
                + course.getSchoolId()
                + " Course: "
                + course.getFormattedCourse());
      }

      if (StringUtils.isBlank(course.getStatusCode())) {
        course.setStatusCode(defaultStatusCode);
      } else if (mappings != null && !mappings.isEmpty()) {
        for (EnrollmentStatus enrollmentStatus : mappings) {
          if (enrollmentStatus.getCode().equals(course.getStatusCode())) {
            course.setStatusCode(enrollmentStatus.getName());
          }
        }
      }
    }
    return courses;
  }
예제 #2
0
 static void addTermsToMap(final List<Term> terms, final Map<String, Object> parameters)
     throws ObjectNotFoundException {
   final List<String> termCodes = new ArrayList<String>();
   final List<String> termNames = new ArrayList<String>();
   if (terms == null || terms.isEmpty()) {
     parameters.put(TERM_CODES, NOT_USED);
     parameters.put(TERM_NAMES, NOT_USED);
     return;
   }
   for (Term term : terms) {
     if (term == null) continue;
     termCodes.add(term.getCode());
     termNames.add(term.getName());
   }
   parameters.put(TERM_CODES, concatNamesFromStrings(termCodes, NOT_USED));
   parameters.put(TERM_NAMES, concatNamesFromStrings(termNames, NOT_USED));
 }
  @RequestMapping(method = RequestMethod.GET)
  @PreAuthorize(Permission.SECURITY_REPORT_READ)
  public @ResponseBody void getEarlyAlertCaseCountsReport(
      final HttpServletResponse response,
      final @RequestParam(required = false) UUID campusId,
      final @RequestParam(required = false) String rosterStatus,
      final @RequestParam(required = false) List<String> termCodes,
      final @RequestParam(required = false, defaultValue = DEFAULT_REPORT_TYPE) String reportType)
      throws ObjectNotFoundException, IOException {

    Campus campus = SearchParameters.getCampus(campusId, campusService);

    final List<EarlyAlertTermCaseCountsTO> caseLoads = new ArrayList<EarlyAlertTermCaseCountsTO>();
    final List<String> cleanTermCodes = SearchParameters.cleanStringListOfNulls(termCodes);
    final List<Term> terms = SearchParameters.getTerms(cleanTermCodes, termService);
    if (terms.size() > 0) {
      for (Term term : terms) {
        EarlyAlertTermCaseCountsTO caseCounts =
            new EarlyAlertTermCaseCountsTO(
                term.getCode(),
                term.getName(),
                earlyAlertService.getStudentCountForEarlyAlertCreatedDateRange(
                    term.getStartDate(), term.getEndDate(), campus, rosterStatus),
                earlyAlertService.getEarlyAlertCountForCreatedDateRange(
                    term.getStartDate(), term.getEndDate(), campus, rosterStatus),
                earlyAlertResponseService
                    .getRespondedToEarlyAlertCountForEarlyAlertCreatedDateRange(
                        term.getStartDate(), term.getEndDate(), campus, rosterStatus),
                earlyAlertService.getClosedEarlyAlertsCountForEarlyAlertCreatedDateRange(
                    term.getStartDate(), term.getEndDate(), campus, rosterStatus));

        caseLoads.add(caseCounts);
      }

    } else {

      EarlyAlertTermCaseCountsTO caseCounts =
          new EarlyAlertTermCaseCountsTO(
              "All",
              "All",
              earlyAlertService.getStudentCountForEarlyAlertCreatedDateRange(
                  null, null, campus, rosterStatus),
              earlyAlertService.getEarlyAlertCountForCreatedDateRange(
                  null, null, campus, rosterStatus),
              earlyAlertResponseService.getRespondedToEarlyAlertCountForEarlyAlertCreatedDateRange(
                  null, null, campus, rosterStatus),
              earlyAlertService.getClosedEarlyAlertsCountForEarlyAlertCreatedDateRange(
                  null, null, campus, rosterStatus));
      caseLoads.add(caseCounts);
    }

    final Map<String, Object> parameters = Maps.newHashMap();
    SearchParameters.addCampusToParameters(campus, parameters);

    SearchParameters.addTermsToMap(terms, parameters);
    renderReport(
        response,
        parameters,
        caseLoads,
        reportType.equals("csv") ? REPORT_URL_CSV : REPORT_URL,
        reportType,
        REPORT_FILE_TITLE);
  }
예제 #4
0
  @RenderMapping(params = "action=enterAlert")
  public ModelAndView showForm(
      final PortletRequest req,
      @RequestParam(required = false) final String schoolId,
      @RequestParam(required = false) final String formattedCourse,
      @RequestParam(required = false) final String studentUserName,
      @RequestParam(required = false) final String sectionCode,
      @RequestParam(required = false) final String termCode,
      ModelMap model) {
    // Do not use a @ModelAttribute-annotated argument to get the user
    // out of the model b/c Spring will attempt to set properties on it
    // by matching up request param names. This will overwrite user.schoolId
    // with the method param of that name, effectively copying the student's
    // school ID into the faculty user's record.
    if (!StringUtils.isNotBlank(schoolId) && !StringUtils.isNotBlank(studentUserName)) {
      throw new EarlyAlertPortletControllerRuntimeException("Missing student identifier.");
    }

    if (!StringUtils.isNotBlank(formattedCourse) && !StringUtils.isNotBlank(sectionCode)) {
      throw new EarlyAlertPortletControllerRuntimeException("Missing course identifier/s.");
    }
    Person user = (Person) model.get("user");
    if (user == null) {
      throw new EarlyAlertPortletControllerRuntimeException(
          "Missing or deactivated account for current user.");
    }
    FacultyCourse course = null;
    Person student = null;
    ExternalFacultyCourseRoster enrollment = null;
    try {
      // Should really always have a term code (see deprecation notes for
      // getCourseByFacultySchoolIdAndFormattedCourse) but we know at
      // least one real-world deployment (SPC) cannot/does not send term
      // codes when deep linking to the EA form *and* this just happens to
      // work b/c their formattedCourse values are globally unique. So
      // we preserve the option of not filtering by term code.
      course =
          facultyCourseService.getCourseBySearchFacultyCourseTO(
              new SearchFacultyCourseTO(
                  user.getSchoolId(), termCode, sectionCode, formattedCourse));

      if (course == null) {
        throw new EarlyAlertPortletControllerRuntimeException(
            buildErrorMesssage(
                "Course not found or current user is not listed as the instructor of record:",
                user.getSchoolId(),
                schoolId,
                studentUserName,
                formattedCourse,
                termCode,
                sectionCode));
      }

      /*
       * NB:  It's on us to translate from schoolId <-> studentId (SSP
       * UUID) at this point in the Early Alert process.  Previous APIs
       * user the former where following APIs use the later.
       */
      if (StringUtils.isNotBlank(schoolId)) {
        try {
          student = personService.getBySchoolId(schoolId, true); // TODO:  Handle error better??
          if (student == null) {
            throw new EarlyAlertPortletControllerRuntimeException(
                "Student not found by school ID: " + schoolId);
          }
        } catch (ObjectNotFoundException e) {
          throw new EarlyAlertPortletControllerRuntimeException(
              "Student not found by school ID: " + schoolId, e);
        }
      } else {
        try {
          student = personService.getByUsername(studentUserName, true);
          if (student == null) {
            throw new EarlyAlertPortletControllerRuntimeException(
                "Student not found by username: "******"Student not found by username: "******"Selected student has no school ID. Username: "******"Enrollment not found for: ",
                user.getSchoolId(),
                student.getSchoolId(),
                student.getUsername(),
                formattedCourse,
                termCode,
                sectionCode));
      }
    } catch (EarlyAlertPortletControllerRuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new RuntimeException(
          buildErrorMesssage(
              "System error looking up course or enrollment for: ",
              user.getSchoolId(),
              student == null ? schoolId : student.getSchoolId(),
              student == null ? studentUserName : student.getUsername(),
              formattedCourse,
              termCode,
              sectionCode),
          e);
    }
    /*
     *  SANITY CHECK (is this even necessary?  wanted?)
     *    - Confirm that the logged in user is the faculty of record on the
     *      course
     */
    if (!course.getFacultySchoolId().equals(user.getSchoolId())) {
      throw new EarlyAlertPortletControllerRuntimeException(
          buildErrorMesssage(
              "Current user is not listed as the instructor of record on the specified course: ",
              user.getSchoolId(),
              student.getSchoolId(),
              student.getUsername(),
              formattedCourse,
              termCode,
              sectionCode));
    }

    EarlyAlertSearchForm form = new EarlyAlertSearchForm();
    form.setAuthor(user);
    form.setStudent(student);

    form.setSortAndPage(buildSortAndPage(-1, 0));
    PagedResponse<EarlyAlertSearchResultTO> results = earlyAlertService.searchEarlyAlert(form);

    model.put(KEY_STUDENT_ID, student.getId()); // Student UUID
    model.put(KEY_COURSE, course);
    model.put(KEY_ENROLLMENT, enrollment);
    model.put(KEY_EARLY_ALERT_RESULTS, results.getRows());
    try {
      Term term = termService.getByCode(course.getTermCode());
      model.put(KEY_COURSE_TERM_NAME, term.getName());
    } catch (Exception exp) {
      model.put(KEY_COURSE_TERM_NAME, course.getTermCode());
    }

    return new ModelAndView("ea-form", model);
  }