/** GET /users/suggestions -> suggest users to follow */ @RequestMapping( value = "/rest/users/suggestions", method = RequestMethod.GET, produces = "application/json") @ResponseBody public Collection<User> suggestions() { User currentUser = userService.getCurrentUser(); final String login = currentUser.getLogin(); if (log.isDebugEnabled()) { log.debug("REST request to get the last active tweeters list (except " + login + ")."); } Collection<String> exceptions = userService.getFriendsForUser(login); exceptions.add(login); Collection<Tweet> tweets = timelineService.getDayline(""); Map<String, User> users = new HashMap<String, User>(); for (Tweet tweet : tweets) { if (exceptions.contains(tweet.getLogin())) continue; users.put(tweet.getLogin(), userService.getUserProfileByLogin(tweet.getLogin())); if (users.size() == 3) break; // suggestions list limit } return users.values(); }
@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; }
public void serializeHistoryCursor( Collection<TrackHistory> historyCursor, HttpServletResponse httpServletResponse) { try { final ServletOutputStream httpOutputStream = httpServletResponse.getOutputStream(); final BufferedWriter outputStream = new BufferedWriter(new OutputStreamWriter(httpOutputStream)); outputStream.write("{"); outputStream.write("\"count\":"); outputStream.write("" + historyCursor.size()); if (historyCursor.size() > 0) { Gson gson = new Gson(); outputStream.write(","); outputStream.write("\"tracks\":["); for (Iterator<TrackHistory> iterator = historyCursor.iterator(); iterator.hasNext(); ) { TrackHistory next = iterator.next(); outputStream.write(gson.toJson(toWebTrack(next))); if (iterator.hasNext()) { outputStream.write(","); } outputStream.flush(); } /* while (historyCursor.hasNext()) { outputStream.write(gson.toJson(toWebTrack(historyCursor.next()))); if (historyCursor.hasNext()) { outputStream.write(","); } outputStream.flush(); } */ outputStream.write("]"); } outputStream.write("}"); outputStream.flush(); outputStream.close(); httpOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } }