Search in sources :

Example 1 with Instructor

use of teammates.storage.entity.Instructor in project teammates by TEAMMATES.

the class InstructorsDb method createInstructor.

public InstructorAttributes createInstructor(InstructorAttributes instructorToAdd) throws InvalidParametersException, EntityAlreadyExistsException {
    Instructor instructor = createEntity(instructorToAdd);
    if (instructor == null) {
        throw new InvalidParametersException("Created instructor is null.");
    }
    InstructorAttributes createdInstructor = makeAttributes(instructor);
    putDocument(createdInstructor);
    return createdInstructor;
}
Also used : Instructor(teammates.storage.entity.Instructor) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 2 with Instructor

use of teammates.storage.entity.Instructor in project teammates by TEAMMATES.

the class InstructorsDb method updateInstructorByEmail.

/**
 * Updates the instructor. Cannot modify Course ID or email.
 */
public void updateInstructorByEmail(InstructorAttributes instructorAttributesToUpdate) throws InvalidParametersException, EntityDoesNotExistException {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, instructorAttributesToUpdate);
    if (!instructorAttributesToUpdate.isValid()) {
        throw new InvalidParametersException(instructorAttributesToUpdate.getInvalidityInfo());
    }
    instructorAttributesToUpdate.sanitizeForSaving();
    Instructor instructorToUpdate = getInstructorEntityForEmail(instructorAttributesToUpdate.courseId, instructorAttributesToUpdate.email);
    if (instructorToUpdate == null) {
        throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT_ACCOUNT + instructorAttributesToUpdate.email + ThreadHelper.getCurrentThreadStack());
    }
    instructorToUpdate.setGoogleId(instructorAttributesToUpdate.googleId);
    instructorToUpdate.setName(instructorAttributesToUpdate.name);
    instructorToUpdate.setIsArchived(instructorAttributesToUpdate.isArchived);
    instructorToUpdate.setRole(instructorAttributesToUpdate.role);
    instructorToUpdate.setIsDisplayedToStudents(instructorAttributesToUpdate.isDisplayedToStudents);
    instructorToUpdate.setDisplayedName(instructorAttributesToUpdate.displayedName);
    instructorToUpdate.setInstructorPrivilegeAsText(instructorAttributesToUpdate.getTextFromInstructorPrivileges());
    // TODO: make courseId+email the non-modifiable values
    putDocument(makeAttributes(instructorToUpdate));
    saveEntity(instructorToUpdate, instructorAttributesToUpdate);
}
Also used : Instructor(teammates.storage.entity.Instructor) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 3 with Instructor

use of teammates.storage.entity.Instructor in project teammates by TEAMMATES.

the class InstructorAttributesTest method testValueOf.

@Test
public void testValueOf() {
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    InstructorAttributes instructor = InstructorAttributes.builder("valid.google.id", "valid-course-id", "valid name", "valid@email.com").withDisplayedName(InstructorAttributes.DEFAULT_DISPLAY_NAME).withRole(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER).withPrivileges(privileges).build();
    Instructor entity = instructor.toEntity();
    InstructorAttributes instructor1 = InstructorAttributes.valueOf(entity);
    assertEquals(instructor.googleId, instructor1.googleId);
    assertEquals(instructor.courseId, instructor1.courseId);
    assertEquals(instructor.name, instructor1.name);
    assertEquals(instructor.email, instructor1.email);
    assertEquals(instructor.role, instructor1.role);
    assertEquals(instructor.displayedName, instructor1.displayedName);
    assertEquals(instructor.privileges, instructor1.privileges);
    entity.setRole(null);
    entity.setDisplayedName(null);
    entity.setInstructorPrivilegeAsText(null);
    InstructorAttributes instructor2 = InstructorAttributes.valueOf(entity);
    assertEquals(instructor.googleId, instructor2.googleId);
    assertEquals(instructor.courseId, instructor2.courseId);
    assertEquals(instructor.name, instructor2.name);
    assertEquals(instructor.email, instructor2.email);
    // default values for these
    assertEquals(instructor.role, instructor2.role);
    assertEquals(instructor.displayedName, instructor2.displayedName);
    assertEquals(instructor.privileges, instructor2.privileges);
}
Also used : Instructor(teammates.storage.entity.Instructor) InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 4 with Instructor

use of teammates.storage.entity.Instructor in project teammates by TEAMMATES.

the class InstructorAttributesTest method testToEntity.

@Override
@Test
public void testToEntity() {
    String googleId = "valid.googleId";
    String courseId = "courseId";
    String name = "name";
    String email = "email@google.com";
    String roleName = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER;
    String displayedName = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER;
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    InstructorAttributes instructor = InstructorAttributes.builder(googleId, courseId, name, email).withRole(roleName).withDisplayedName(displayedName).withPrivileges(privileges).build();
    String key = "randomKey";
    instructor.key = key;
    Instructor entity = instructor.toEntity();
    assertEquals(key, entity.getRegistrationKey());
}
Also used : Instructor(teammates.storage.entity.Instructor) InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 5 with Instructor

use of teammates.storage.entity.Instructor in project teammates by TEAMMATES.

the class StatisticsPerInstitute method generateStatsPerInstitute.

private StatsBundle generateStatsPerInstitute(List<CourseStudent> allStudents, List<Instructor> allInstructors, List<Account> allAccounts) {
    Map<String, Map<Integer, Set<String>>> institutes = new HashMap<>();
    Set<String> allInstructorEmailSet = new HashSet<>();
    Set<String> allStudentEmailSet = new HashSet<>();
    int studentEmailCounter = 0;
    int instructorEmailCounter = 0;
    for (Instructor instructor : allInstructors) {
        if (isTestingInstructorData(instructor, allAccounts) || instructor.getEmail() == null) {
            continue;
        }
        String institute = getInstituteForInstructor(instructor, allAccounts);
        if (!institutes.containsKey(institute)) {
            institutes.put(institute, new HashMap<Integer, Set<String>>());
            institutes.get(institute).put(INSTRUCTOR_INDEX, new HashSet<String>());
            institutes.get(institute).put(STUDENT_INDEX, new HashSet<String>());
        }
        institutes.get(institute).get(INSTRUCTOR_INDEX).add(instructor.getEmail().toLowerCase());
        allInstructorEmailSet.add(instructor.getEmail().toLowerCase());
        instructorEmailCounter++;
        updateProgressIndicator();
    }
    for (CourseStudent student : allStudents) {
        if (isTestingStudentData(student, allInstructors, allAccounts) || student.getEmail() == null) {
            continue;
        }
        String institute = getInstituteForStudent(student, allInstructors, allAccounts);
        if (!institutes.containsKey(institute)) {
            institutes.put(institute, new HashMap<Integer, Set<String>>());
            institutes.get(institute).put(INSTRUCTOR_INDEX, new HashSet<String>());
            institutes.get(institute).put(STUDENT_INDEX, new HashSet<String>());
        }
        institutes.get(institute).get(STUDENT_INDEX).add(student.getEmail().toLowerCase());
        allStudentEmailSet.add(student.getEmail().toLowerCase());
        studentEmailCounter++;
        updateProgressIndicator();
    }
    List<InstituteStats> statList = convertToList(institutes);
    sortByTotalStudentsDescending(statList);
    StatsBundle statsBundle = new StatsBundle();
    statsBundle.instituteStatsList = statList;
    statsBundle.numOfAllInstructorEmail = instructorEmailCounter;
    statsBundle.numOfAllStudentEmails = studentEmailCounter;
    statsBundle.numOfUniqueInstructorEmails = allInstructorEmailSet.size();
    statsBundle.numOfUniqueStudentEmails = allStudentEmailSet.size();
    return statsBundle;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Instructor(teammates.storage.entity.Instructor) CourseStudent(teammates.storage.entity.CourseStudent) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

Instructor (teammates.storage.entity.Instructor)7 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)4 InvalidParametersException (teammates.common.exception.InvalidParametersException)3 Test (org.testng.annotations.Test)2 InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)2 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 CourseStudent (teammates.storage.entity.CourseStudent)1