// Faculty names are not added to the external courses by default
 // this method should fix ssp-3041 - Scody
 private void updateFactultyNames(ExternalStudentRecordsTO recordTO) {
   List<ExternalStudentTranscriptCourseTO> courses = recordTO.getTerms();
   if (courses != null) {
     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.  Faculty School_id: "
                 + course.getFacultySchoolId()
                 + " Student ID: "
                 + course.getSchoolId()
                 + " Course: "
                 + course.getFormattedCourse());
       }
     }
   }
 }
  @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;
  }
 /**
  * Using the Student UUID passed, return the ExternalStudentRecordsLiteTO in its current state,
  * creating it if necessary.
  *
  * @param id Student identifier Any errors will throw this generic exception.
  * @return Service response with success value, in the JSON format.
  * @throws ObjectNotFoundException, IOException If any reference data could not be loaded.
  */
 @RequestMapping(value = "/test/details", method = RequestMethod.GET)
 @PreAuthorize(Permission.SECURITY_PERSON_READ)
 public String getTestProviderDetails(
     final @PathVariable UUID id,
     final @RequestParam(required = true) String testCode,
     final @RequestParam(required = false) String subTestCode,
     HttpServletResponse httpServletResponse)
     throws ObjectNotFoundException, IOException {
   Person person = personService.get(id);
   String url = (String) externalStudentTestService.getTestDetails(testCode, subTestCode, person);
   return "redirect:" + url;
 }
 String getStudentId(UUID personId) throws ObjectNotFoundException {
   return personService.getSchoolIdForPersonId(personId);
 }
  @RequestMapping(value = "/studentactivity", method = RequestMethod.GET)
  @PreAuthorize(Permission.SECURITY_PERSON_READ)
  public @ResponseBody List<RecentActivityTO> loadRecentStudentActivity(final @PathVariable UUID id)
      throws ObjectNotFoundException {
    List<RecentActivityTO> recentActivities = new ArrayList<RecentActivityTO>();
    Person person = personService.get(id);
    SortingAndPaging sAndP =
        SortingAndPaging.createForSingleSortWithPaging(
            ObjectStatus.ACTIVE, 0, 1000, "createdDate", "DESC", "createdDate");

    PagingWrapper<EarlyAlert> earlyAlerts = earlyAlertService.getAllForPerson(person, sAndP);
    SspUser currentUser = securityService.currentUser();
    List<EarlyAlertTO> earlyAlertTOs = earlyAlertTOFactory.asTOList(earlyAlerts.getRows());

    PagingWrapper<JournalEntry> journalEntries =
        journalEntryService.getAllForPerson(person, currentUser, sAndP);

    List<JournalEntryTO> journalEntriesTOs =
        journalEntryTOFactory.asTOList(journalEntries.getRows());

    PagingWrapper<Task> actions = taskService.getAllForPerson(person, currentUser, sAndP);

    List<TaskTO> actionsTOs = taskTOFactory.asTOList(actions.getRows());

    PagingWrapper<Plan> plans =
        planService.getAllForStudent(
            SortingAndPaging.createForSingleSortWithPaging(
                ObjectStatus.ALL, 0, 1000, null, null, null),
            id);

    List<PlanTO> planTOs = planTOFactory.asTOList(plans.getRows());

    for (EarlyAlertTO earlyAlert : earlyAlertTOs) {
      if (earlyAlert.getClosedDate() != null) {
        recentActivities.add(
            new RecentActivityTO(
                earlyAlert.getClosedById(),
                earlyAlert.getClosedByName(),
                "Early Alert Closed",
                earlyAlert.getClosedDate()));
      } else {
        recentActivities.add(
            new RecentActivityTO(
                earlyAlert.getCreatedBy().getId(),
                getPersonLiteName(earlyAlert.getCreatedBy()),
                "Early Alert Created",
                earlyAlert.getCreatedDate()));
      }
    }

    for (JournalEntryTO journalEntry : journalEntriesTOs) {
      recentActivities.add(
          new RecentActivityTO(
              journalEntry.getCreatedBy().getId(),
              getPersonLiteName(journalEntry.getCreatedBy()),
              "Journal Entry",
              journalEntry.getEntryDate()));
    }

    for (TaskTO action : actionsTOs) {
      if (action.isCompleted()) {
        recentActivities.add(
            new RecentActivityTO(
                action.getModifiedBy().getId(),
                getPersonLiteName(action.getModifiedBy()),
                "Action Plan Task Created",
                action.getCompletedDate()));
      } else {
        recentActivities.add(
            new RecentActivityTO(
                action.getCreatedBy().getId(),
                getPersonLiteName(action.getCreatedBy()),
                "Action Plan Task Created",
                action.getCreatedDate()));
      }
    }

    for (PlanTO planTO : planTOs) {
      Date testDate = DateUtils.addDays(planTO.getCreatedDate(), 1);
      String planName = planTO.getName();
      if (planTO.getModifiedDate().before(testDate)) {
        recentActivities.add(
            new RecentActivityTO(
                planTO.getCreatedBy().getId(),
                getPersonLiteName(planTO.getCreatedBy()),
                "Map Plan (" + planName + ") Created",
                planTO.getModifiedDate()));
      } else {
        recentActivities.add(
            new RecentActivityTO(
                planTO.getModifiedBy().getId(),
                getPersonLiteName(planTO.getModifiedBy()),
                "Map Plan (" + planName + ") Updated",
                planTO.getModifiedDate()));
      }
    }

    if (person.getStudentIntakeCompleteDate() != null) {
      recentActivities.add(
          new RecentActivityTO(
              person.getCoach().getId(),
              person.getCoach().getFullName(),
              "Student Intake Completed",
              person.getStudentIntakeCompleteDate()));
    }
    if (person.getStudentIntakeRequestDate() != null) {
      recentActivities.add(
          new RecentActivityTO(
              person.getCoach().getId(),
              person.getCoach().getFullName(),
              "Student Intake Requested",
              person.getStudentIntakeRequestDate()));
    }

    Collections.sort(recentActivities, RecentActivityTO.RECENT_ACTIVITY_TO_DATE_COMPARATOR);
    return recentActivities;
  }