Search in sources :

Example 1 with StudentSearchResultBundle

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);
}
Also used : StudentSearchResultBundle(teammates.common.datatransfer.StudentSearchResultBundle) StudentsDb(teammates.storage.api.StudentsDb) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 2 with StudentSearchResultBundle

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;
}
Also used : StudentSearchResultBundle(teammates.common.datatransfer.StudentSearchResultBundle) ScoredDocument(com.google.appengine.api.search.ScoredDocument) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 3 with StudentSearchResultBundle

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;
}
Also used : StudentSearchResultBundle(teammates.common.datatransfer.StudentSearchResultBundle) ScoredDocument(com.google.appengine.api.search.ScoredDocument) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 4 with StudentSearchResultBundle

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;
}
Also used : InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Const(teammates.common.util.Const) SearchStudentsTable(teammates.ui.template.SearchStudentsTable) QuestionTable(teammates.ui.template.QuestionTable) HashMap(java.util.HashMap) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FeedbackResponseCommentSearchResultBundle(teammates.common.datatransfer.FeedbackResponseCommentSearchResultBundle) Map(java.util.Map) StudentListSectionData(teammates.ui.template.StudentListSectionData) SectionDetailsBundle(teammates.common.datatransfer.SectionDetailsBundle) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) SearchFeedbackSessionDataTable(teammates.ui.template.SearchFeedbackSessionDataTable) Set(java.util.Set) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) ZoneId(java.time.ZoneId) TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) List(java.util.List) StudentSearchResultBundle(teammates.common.datatransfer.StudentSearchResultBundle) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) FeedbackSessionRow(teammates.ui.template.FeedbackSessionRow) FeedbackResponseCommentRow(teammates.ui.template.FeedbackResponseCommentRow) ResponseRow(teammates.ui.template.ResponseRow) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) SectionDetailsBundle(teammates.common.datatransfer.SectionDetailsBundle) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) StudentListSectionData(teammates.ui.template.StudentListSectionData) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 5 with StudentSearchResultBundle

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);
}
Also used : StudentSearchResultBundle(teammates.common.datatransfer.StudentSearchResultBundle) InstructorSearchPageData(teammates.ui.pagedata.InstructorSearchPageData) FeedbackResponseCommentSearchResultBundle(teammates.common.datatransfer.FeedbackResponseCommentSearchResultBundle) StatusMessage(teammates.common.util.StatusMessage) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) HashSet(java.util.HashSet)

Aggregations

StudentSearchResultBundle (teammates.common.datatransfer.StudentSearchResultBundle)5 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)4 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)4 ScoredDocument (com.google.appengine.api.search.ScoredDocument)2 HashSet (java.util.HashSet)2 FeedbackResponseCommentSearchResultBundle (teammates.common.datatransfer.FeedbackResponseCommentSearchResultBundle)2 ZoneId (java.time.ZoneId)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Test (org.testng.annotations.Test)1 SectionDetailsBundle (teammates.common.datatransfer.SectionDetailsBundle)1 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)1 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)1 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)1 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)1 FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)1 Const (teammates.common.util.Const)1