use of teammates.common.datatransfer.StudentSearchResultBundle in project teammates by TEAMMATES.
the class StudentSearchTest method allTests.
@Test
public void allTests() {
StudentsDb studentsDb = new StudentsDb();
StudentAttributes stu1InCourse1 = dataBundle.students.get("student1InCourse1");
StudentAttributes stu2InCourse1 = dataBundle.students.get("student2InCourse1");
StudentAttributes stu1InCourse2 = dataBundle.students.get("student1InCourse2");
StudentAttributes stu2InCourse2 = dataBundle.students.get("student2InCourse2");
StudentAttributes stu1InUnregCourse = dataBundle.students.get("student1InUnregisteredCourse");
StudentAttributes stu2InUnregCourse = dataBundle.students.get("student2InUnregisteredCourse");
StudentAttributes stu1InArchCourse = dataBundle.students.get("student1InArchivedCourse");
______TS("success: search for students in whole system; query string does not match any student");
StudentSearchResultBundle bundle = studentsDb.searchStudentsInWholeSystem("non-existent");
assertEquals(0, bundle.numberOfResults);
assertTrue(bundle.studentList.isEmpty());
______TS("success: search for students in whole system; query string matches some students");
bundle = studentsDb.searchStudentsInWholeSystem("student1");
assertEquals(4, bundle.numberOfResults);
AssertHelper.assertSameContentIgnoreOrder(Arrays.asList(stu1InCourse1, stu1InCourse2, stu1InUnregCourse, stu1InArchCourse), bundle.studentList);
______TS("success: search for students in whole system; query string should be case-insensitive");
bundle = studentsDb.searchStudentsInWholeSystem("stUdeNt2");
assertEquals(3, bundle.numberOfResults);
AssertHelper.assertSameContentIgnoreOrder(Arrays.asList(stu2InCourse1, stu2InCourse2, stu2InUnregCourse), bundle.studentList);
______TS("success: search for students; query string matches some students; results restricted " + "based on instructor's privilege");
List<InstructorAttributes> ins1OfCourse1 = Arrays.asList(new InstructorAttributes[] { dataBundle.instructors.get("instructor1OfCourse1") });
List<InstructorAttributes> ins1OfCourse2 = Arrays.asList(new InstructorAttributes[] { dataBundle.instructors.get("instructor1OfCourse2") });
bundle = studentsDb.search("student1", ins1OfCourse1);
assertEquals(1, bundle.numberOfResults);
AssertHelper.assertSameContentIgnoreOrder(Arrays.asList(stu1InCourse1), bundle.studentList);
bundle = studentsDb.search("student1", ins1OfCourse2);
assertEquals(1, bundle.numberOfResults);
AssertHelper.assertSameContentIgnoreOrder(Arrays.asList(stu1InCourse2), bundle.studentList);
______TS("success: search for students; deleted student no longer searchable");
studentsDb.deleteStudent(stu1InCourse1.course, stu1InCourse1.email);
bundle = studentsDb.search("student1", ins1OfCourse1);
assertEquals(0, bundle.numberOfResults);
assertTrue(bundle.studentList.isEmpty());
______TS("success: search for students; deleted student without deleted document: the document " + "will be deleted during the search");
studentsDb.deleteStudentWithoutDocument(stu1InCourse2.course, stu1InCourse2.email);
bundle = studentsDb.search("student1", ins1OfCourse2);
assertEquals(0, bundle.numberOfResults);
assertTrue(bundle.studentList.isEmpty());
studentsDb.deleteStudentWithoutDocument(stu2InCourse1.course, stu2InCourse1.email);
bundle = studentsDb.searchStudentsInWholeSystem("student2");
assertEquals(2, bundle.numberOfResults);
AssertHelper.assertSameContentIgnoreOrder(Arrays.asList(stu2InCourse2, stu2InUnregCourse), bundle.studentList);
}
use of teammates.common.datatransfer.StudentSearchResultBundle in project teammates by TEAMMATES.
the class StudentSearchDocument method fromResults.
/**
* Produces a {@link StudentSearchResultBundle} from the {@code Results<ScoredDocument>} collection.
* The list of {@link InstructorAttributes} is used to filter out the search result.
*/
public static StudentSearchResultBundle fromResults(Results<ScoredDocument> results, List<InstructorAttributes> instructors) {
StudentSearchResultBundle bundle = new StudentSearchResultBundle();
if (results == null) {
return bundle;
}
for (InstructorAttributes ins : instructors) {
bundle.courseIdInstructorMap.put(ins.courseId, ins);
}
List<ScoredDocument> filteredResults = filterOutCourseId(results, instructors);
for (ScoredDocument doc : filteredResults) {
StudentAttributes student = JsonUtils.fromJson(doc.getOnlyField(Const.SearchDocumentField.STUDENT_ATTRIBUTE).getText(), StudentAttributes.class);
if (student.key == null || studentsDb.getStudentForRegistrationKey(StringHelper.encrypt(student.key)) == null) {
studentsDb.deleteDocument(student);
continue;
}
bundle.studentList.add(student);
bundle.numberOfResults++;
}
sortStudentResultList(bundle.studentList);
return bundle;
}
use of teammates.common.datatransfer.StudentSearchResultBundle in project teammates by TEAMMATES.
the class StudentSearchDocument method fromResults.
/**
* Produces a {@link StudentSearchResultBundle} from the {@code Results<ScoredDocument>} collection.
* The list of {@link InstructorAttributes} is used to filter out the search result.
*
* <p>This method should be used by admin only since the searching does not restrict the
* visibility according to the logged-in user's google ID.
*/
public static StudentSearchResultBundle fromResults(Results<ScoredDocument> results) {
StudentSearchResultBundle bundle = new StudentSearchResultBundle();
if (results == null) {
return bundle;
}
for (ScoredDocument doc : results) {
StudentAttributes student = JsonUtils.fromJson(doc.getOnlyField(Const.SearchDocumentField.STUDENT_ATTRIBUTE).getText(), StudentAttributes.class);
if (student.key == null || studentsDb.getStudentForRegistrationKey(StringHelper.encrypt(student.key)) == null) {
studentsDb.deleteDocument(student);
continue;
}
bundle.studentList.add(student);
bundle.numberOfResults++;
}
sortStudentResultList(bundle.studentList);
return bundle;
}
use of teammates.common.datatransfer.StudentSearchResultBundle in project teammates by TEAMMATES.
the class InstructorSearchPageData method createStudentRows.
private List<StudentListSectionData> createStudentRows(String courseId, StudentSearchResultBundle studentSearchResultBundle) {
List<StudentListSectionData> rows = new ArrayList<>();
List<StudentAttributes> studentsInCourse = filterStudentsByCourse(courseId, studentSearchResultBundle);
Map<String, Set<String>> sectionNameToTeamNameMap = new HashMap<>();
Map<String, List<StudentAttributes>> teamNameToStudentsMap = new HashMap<>();
Map<String, String> emailToPhotoUrlMap = new HashMap<>();
for (StudentAttributes student : studentsInCourse) {
String teamName = student.team;
String sectionName = student.section;
String viewPhotoLink = addUserIdToUrl(student.getPublicProfilePictureUrl());
emailToPhotoUrlMap.put(student.email, viewPhotoLink);
teamNameToStudentsMap.computeIfAbsent(teamName, key -> new ArrayList<>()).add(student);
sectionNameToTeamNameMap.computeIfAbsent(sectionName, key -> new HashSet<>()).add(teamName);
}
List<SectionDetailsBundle> sections = new ArrayList<>();
sectionNameToTeamNameMap.forEach((sectionName, teamNameList) -> {
SectionDetailsBundle sdb = new SectionDetailsBundle();
sdb.name = sectionName;
ArrayList<TeamDetailsBundle> teams = new ArrayList<>();
for (String teamName : teamNameList) {
TeamDetailsBundle tdb = new TeamDetailsBundle();
tdb.name = teamName;
tdb.students = teamNameToStudentsMap.get(teamName);
teams.add(tdb);
}
sdb.teams = teams;
sections.add(sdb);
});
for (SectionDetailsBundle section : sections) {
InstructorAttributes instructor = studentSearchResultBundle.courseIdInstructorMap.get(courseId);
boolean isAllowedToViewStudentInSection = instructor.isAllowedForPrivilege(section.name, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS);
boolean isAllowedToModifyStudent = instructor.isAllowedForPrivilege(section.name, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
rows.add(new StudentListSectionData(section, isAllowedToViewStudentInSection, isAllowedToModifyStudent, emailToPhotoUrlMap, account.googleId, getSessionToken()));
}
return rows;
}
use of teammates.common.datatransfer.StudentSearchResultBundle in project teammates by TEAMMATES.
the class InstructorSearchPageAction method execute.
@Override
protected ActionResult execute() {
gateKeeper.verifyInstructorPrivileges(account);
String searchKey = getRequestParamValue(Const.ParamsNames.SEARCH_KEY);
if (searchKey == null) {
searchKey = "";
}
int numberOfSearchOptions = 0;
boolean isSearchForStudents = getRequestParamAsBoolean(Const.ParamsNames.SEARCH_STUDENTS);
if (isSearchForStudents) {
numberOfSearchOptions++;
}
boolean isSearchFeedbackSessionData = getRequestParamAsBoolean(Const.ParamsNames.SEARCH_FEEDBACK_SESSION_DATA);
if (isSearchFeedbackSessionData) {
numberOfSearchOptions++;
}
FeedbackResponseCommentSearchResultBundle frCommentSearchResults = new FeedbackResponseCommentSearchResultBundle();
StudentSearchResultBundle studentSearchResults = new StudentSearchResultBundle();
int totalResultsSize = 0;
if (searchKey.isEmpty() || numberOfSearchOptions == 0) {
// display search tips and tutorials
statusToUser.add(new StatusMessage(Const.StatusMessages.INSTRUCTOR_SEARCH_TIPS, StatusMessageColor.INFO));
} else {
// Start searching
List<InstructorAttributes> instructors = logic.getInstructorsForGoogleId(account.googleId);
if (isSearchFeedbackSessionData) {
frCommentSearchResults = logic.searchFeedbackResponseComments(searchKey, instructors);
}
if (isSearchForStudents) {
studentSearchResults = logic.searchStudents(searchKey, instructors);
}
totalResultsSize = frCommentSearchResults.numberOfResults + studentSearchResults.numberOfResults;
Set<String> instructorEmails = new HashSet<>();
for (InstructorAttributes instructor : instructors) {
instructorEmails.add(instructor.email);
}
if (totalResultsSize == 0) {
statusToUser.add(new StatusMessage(Const.StatusMessages.INSTRUCTOR_SEARCH_NO_RESULTS, StatusMessageColor.WARNING));
}
}
InstructorSearchPageData data = new InstructorSearchPageData(account, sessionToken);
data.init(frCommentSearchResults, studentSearchResults, searchKey, isSearchFeedbackSessionData, isSearchForStudents);
return createShowPageResult(Const.ViewURIs.INSTRUCTOR_SEARCH, data);
}
Aggregations