Search in sources :

Example 1 with InstructorSearchResultBundle

use of teammates.common.datatransfer.InstructorSearchResultBundle in project teammates by TEAMMATES.

the class InstructorSearchTest method allTests.

@Test
public void allTests() throws Exception {
    InstructorsDb instructorsDb = new InstructorsDb();
    InstructorAttributes ins1InCourse1 = dataBundle.instructors.get("instructor1OfCourse1");
    InstructorAttributes ins2InCourse1 = dataBundle.instructors.get("instructor2OfCourse1");
    InstructorAttributes helperInCourse1 = dataBundle.instructors.get("helperOfCourse1");
    InstructorAttributes ins1InCourse2 = dataBundle.instructors.get("instructor1OfCourse2");
    InstructorAttributes ins2InCourse2 = dataBundle.instructors.get("instructor2OfCourse2");
    InstructorAttributes ins3InCourse2 = dataBundle.instructors.get("instructor3OfCourse2");
    InstructorAttributes insInArchivedCourse = dataBundle.instructors.get("instructorOfArchivedCourse");
    InstructorAttributes insInUnregCourse = dataBundle.instructors.get("instructor5");
    InstructorAttributes ins1InTestingSanitizationCourse = dataBundle.instructors.get("instructor1OfTestingSanitizationCourse");
    ins1InTestingSanitizationCourse.sanitizeForSaving();
    ______TS("success: search for instructors in whole system; query string does not match anyone");
    InstructorSearchResultBundle results = instructorsDb.searchInstructorsInWholeSystem("non-existent");
    verifySearchResults(results);
    ______TS("success: search for instructors in whole system; empty query string does not match anyone");
    results = instructorsDb.searchInstructorsInWholeSystem("");
    verifySearchResults(results);
    ______TS("success: search for instructors in whole system; query string matches some instructors");
    results = instructorsDb.searchInstructorsInWholeSystem("instructor1");
    verifySearchResults(results, ins1InCourse1, ins1InCourse2, ins1InTestingSanitizationCourse);
    ______TS("success: search for instructors in whole system; query string should be case-insensitive");
    results = instructorsDb.searchInstructorsInWholeSystem("InStRuCtOr2");
    verifySearchResults(results, ins2InCourse1, ins2InCourse2);
    ______TS("success: search for instructors in whole system; instructors in archived courses should be included");
    results = instructorsDb.searchInstructorsInWholeSystem("archived");
    verifySearchResults(results, insInArchivedCourse);
    ______TS("success: search for instructors in whole system; instructors in unregistered course should be included");
    results = instructorsDb.searchInstructorsInWholeSystem("instructor5");
    verifySearchResults(results, insInUnregCourse);
    ______TS("success: search for instructors in whole system; instructors should be searchable by course id");
    results = instructorsDb.searchInstructorsInWholeSystem("idOfUnregisteredCourse");
    verifySearchResults(results, insInUnregCourse);
    ______TS("success: search for instructors in whole system; instructors should be searchable by course name");
    results = instructorsDb.searchInstructorsInWholeSystem("idOfTypicalCourse2");
    verifySearchResults(results, ins1InCourse2, ins2InCourse2, ins3InCourse2);
    ______TS("success: search for instructors in whole system; instructors should be searchable by their name");
    results = instructorsDb.searchInstructorsInWholeSystem("\"Instructor 5 of CourseNoRegister\"");
    verifySearchResults(results, insInUnregCourse);
    ______TS("success: search for instructors in whole system; instructors should be searchable by their email");
    results = instructorsDb.searchInstructorsInWholeSystem("instructor2@course2.tmt");
    verifySearchResults(results, ins2InCourse2);
    ______TS("success: search for instructors in whole system; instructors should be searchable by their google id");
    results = instructorsDb.searchInstructorsInWholeSystem("idOfInstructor5");
    verifySearchResults(results, insInUnregCourse);
    ______TS("success: search for instructors in whole system; instructors should be searchable by their role");
    results = instructorsDb.searchInstructorsInWholeSystem("Custom");
    verifySearchResults(results, helperInCourse1);
    ______TS("success: search for instructors in whole system; instructors should be searchable by displayed name");
    // create a new instructor with unique displayed name to test that field
    // current displayed names in data bundle are either helper or instructor, which matches on many other fields
    InstructorAttributes assistantProf = helperInCourse1.getCopy();
    String displayedName = "Assistant Prof Smith";
    assistantProf.displayedName = displayedName;
    instructorsDb.updateInstructorByEmail(assistantProf);
    results = instructorsDb.searchInstructorsInWholeSystem(displayedName);
    verifySearchResults(results, assistantProf);
    ______TS("success: search for instructors in whole system; deleted instructors no longer searchable");
    instructorsDb.deleteInstructor(ins1InCourse1.courseId, ins1InCourse1.email);
    results = instructorsDb.searchInstructorsInWholeSystem("instructor1");
    verifySearchResults(results, ins1InCourse2, ins1InTestingSanitizationCourse);
    ______TS("success: search for instructors in whole system; instructors created without searchability unsearchable");
    instructorsDb.createEntitiesWithoutExistenceCheck(Arrays.asList(ins1InCourse1));
    results = instructorsDb.searchInstructorsInWholeSystem("instructor1");
    verifySearchResults(results, ins1InCourse2, ins1InTestingSanitizationCourse);
    ______TS("success: search for instructors in whole system; deleting instructor without deleting document:" + "document deleted during search, instructor unsearchable");
    instructorsDb.deleteEntity(ins2InCourse1);
    results = instructorsDb.searchInstructorsInWholeSystem("instructor2");
    verifySearchResults(results, ins2InCourse2);
}
Also used : InstructorsDb(teammates.storage.api.InstructorsDb) InstructorSearchResultBundle(teammates.common.datatransfer.InstructorSearchResultBundle) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 2 with InstructorSearchResultBundle

use of teammates.common.datatransfer.InstructorSearchResultBundle in project teammates by TEAMMATES.

the class InstructorSearchDocument method fromResults.

/**
 * Produces an {@link InstructorSearchResultBundle} from the {@code Results<ScoredDocument>} collection.
 *
 * <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 InstructorSearchResultBundle fromResults(Results<ScoredDocument> results) {
    InstructorSearchResultBundle bundle = new InstructorSearchResultBundle();
    if (results == null) {
        return bundle;
    }
    for (ScoredDocument doc : results) {
        InstructorAttributes instructor = JsonUtils.fromJson(doc.getOnlyField(Const.SearchDocumentField.INSTRUCTOR_ATTRIBUTE).getText(), InstructorAttributes.class);
        if (instructorsDb.getInstructorForRegistrationKey(StringHelper.encrypt(instructor.key)) == null) {
            instructorsDb.deleteDocument(instructor);
            continue;
        }
        bundle.instructorList.add(instructor);
        bundle.numberOfResults++;
    }
    sortInstructorResultList(bundle.instructorList);
    return bundle;
}
Also used : ScoredDocument(com.google.appengine.api.search.ScoredDocument) InstructorSearchResultBundle(teammates.common.datatransfer.InstructorSearchResultBundle) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Aggregations

InstructorSearchResultBundle (teammates.common.datatransfer.InstructorSearchResultBundle)2 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)2 ScoredDocument (com.google.appengine.api.search.ScoredDocument)1 Test (org.testng.annotations.Test)1 InstructorsDb (teammates.storage.api.InstructorsDb)1