use of teammates.storage.entity.CourseStudent in project teammates by TEAMMATES.
the class StudentsDb method deleteStudent.
public void deleteStudent(String courseId, String email, boolean hasDocument) {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, courseId);
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, email);
if (hasDocument) {
CourseStudent courseStudentToDelete = getCourseStudentEntityForEmail(courseId, email);
if (courseStudentToDelete != null) {
StudentAttributes courseStudentToDeleteAttributes = makeAttributes(courseStudentToDelete);
deleteDocument(courseStudentToDeleteAttributes);
deleteEntityDirect(courseStudentToDelete, courseStudentToDeleteAttributes);
}
} else {
ofy().delete().keys(getCourseStudentForEmailQuery(courseId, email).keys()).now();
}
}
use of teammates.storage.entity.CourseStudent in project teammates by TEAMMATES.
the class StudentsDb method getCourseStudentEntityForRegistrationKey.
private CourseStudent getCourseStudentEntityForRegistrationKey(String registrationKey) {
List<CourseStudent> studentList = load().filter("registrationKey =", registrationKey).list();
// If registration key detected is not unique, something is wrong
if (studentList.size() > 1) {
StringBuilder duplicatedStudentsUniqueIds = new StringBuilder();
for (CourseStudent s : studentList) {
duplicatedStudentsUniqueIds.append(s.getUniqueId() + '\n');
}
log.severe("Duplicate registration keys detected for: \n" + duplicatedStudentsUniqueIds);
}
if (studentList.isEmpty()) {
return null;
}
return studentList.get(0);
}
use of teammates.storage.entity.CourseStudent in project teammates by TEAMMATES.
the class StudentsDb method recreateStudentWithNewEmail.
@SuppressWarnings("PMD.PreserveStackTrace")
private void recreateStudentWithNewEmail(CourseStudent newCourseStudent, String lastName, CourseStudent courseStudent, boolean hasDocument, boolean keepUpdateTimestamp, String courseId, String email) throws InvalidParametersException {
newCourseStudent.setLastName(lastName);
newCourseStudent.setCreatedAt(courseStudent.getCreatedAt());
if (keepUpdateTimestamp) {
newCourseStudent.setLastUpdate(courseStudent.getUpdatedAt());
}
StudentAttributes newCourseStudentAttributes = makeAttributes(newCourseStudent);
try {
createStudent(newCourseStudentAttributes, hasDocument);
} catch (EntityAlreadyExistsException e) {
CourseStudent existingStudent = getEntity(newCourseStudentAttributes);
String error = ERROR_UPDATE_EMAIL_ALREADY_USED + existingStudent.getName() + "/" + existingStudent.getEmail();
throw new InvalidParametersException(error);
}
deleteStudent(courseId, email);
}
use of teammates.storage.entity.CourseStudent in project teammates by TEAMMATES.
the class StudentsDb method updateStudent.
public void updateStudent(String courseId, String email, String newName, String newTeamName, String newSectionName, String newEmail, String newGoogleId, String newComments, boolean hasDocument, boolean keepUpdateTimestamp) throws InvalidParametersException, EntityDoesNotExistException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, courseId);
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, email);
verifyStudentExists(courseId, email);
// Update CourseStudent if it exists.
CourseStudent courseStudent = getCourseStudentEntityForEmail(courseId, email);
if (courseStudent != null) {
boolean isEmailChanged = !email.equals(newEmail);
String lastName = StringHelper.splitName(newName)[1];
if (isEmailChanged) {
CourseStudent newCourseStudent = new CourseStudent(newEmail, newName, newGoogleId, newComments, courseId, newTeamName, newSectionName);
recreateStudentWithNewEmail(newCourseStudent, lastName, courseStudent, hasDocument, keepUpdateTimestamp, courseId, email);
} else {
updateStudentDetails(newName, newTeamName, newSectionName, newGoogleId, newComments, hasDocument, keepUpdateTimestamp, courseStudent, lastName);
}
}
}
Aggregations