Skip to content

Commit

Permalink
Add additional logs
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasCwy committed Apr 23, 2024
1 parent 0b38691 commit 80bcac0
Showing 1 changed file with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,34 @@ public static void main(String[] args) {
public boolean equals(teammates.storage.sqlentity.Course sqlEntity, Course datastoreEntity) {
try {
HibernateUtil.beginTransaction();
boolean result = verifyCourse(sqlEntity, datastoreEntity)
&& verifySectionChain(sqlEntity)
&& verifyFeedbackChain(sqlEntity)
&& verifyInstructors(sqlEntity)
&& verifyDeadlineExtensions(sqlEntity);
boolean isEqual = true;
if (!verifyCourse(sqlEntity, datastoreEntity)) {
log("Failed course verification");
isEqual = false;
}

if (!verifySectionChain(sqlEntity)) {
log("Failed section chain verification");
isEqual = false;
}

if (!verifyFeedbackChain(sqlEntity)) {
log("Failed feedback chain verification");
isEqual = false;
}

if (!verifyInstructors(sqlEntity)) {
log("Failed instructor verification");
isEqual = false;
}

if (!verifyDeadlineExtensions(sqlEntity)) {
log("Failed deadline extension verification");
isEqual = false;
}

HibernateUtil.commitTransaction();
return result;
return isEqual;
} catch (IllegalArgumentException iae) {
return false;
}
Expand Down Expand Up @@ -90,15 +111,18 @@ private boolean verifySectionChain(teammates.storage.sqlentity.Course newCourse)
Map<String, List<Student>> sectionToNewStuMap = newStudents.stream()
.collect(Collectors.groupingBy(Student::getSectionName));

List<Section> newSection = newCourse.getSections();
List<Section> newSections = newCourse.getSections();

boolean isNotSectionsCountEqual = newSection.size() != sectionToOldStuMap.size()
|| newSection.size() != sectionToNewStuMap.size();
boolean isNotSectionsCountEqual = newSections.size() != sectionToOldStuMap.size()
|| newSections.size() != sectionToNewStuMap.size();
if (isNotSectionsCountEqual) {
log(String.format("newSection size: %d, sectionToOldStuMap: %d, sectionToOldStuMap: %d", newSections.size(),
sectionToOldStuMap.size(), sectionToNewStuMap.size()));
log("Section chain - section count not equal");
return false;
}

return newSection.stream().allMatch(section -> {
return newSections.stream().allMatch(section -> {
List<CourseStudent> oldSectionStudents = sectionToOldStuMap.get(section.getName());
List<Student> newSectionStudents = sectionToNewStuMap.get(section.getName());

Expand All @@ -107,6 +131,7 @@ private boolean verifySectionChain(teammates.storage.sqlentity.Course newCourse)
// which means a possible migration error
boolean sectionNameNotPresent = oldSectionStudents == null || newSectionStudents == null;
if (sectionNameNotPresent) {
log("Section chain - section name not present");
return false;
}

Expand All @@ -128,6 +153,7 @@ private boolean verifyTeams(Section newSection,
boolean isNotTeamCountEqual = newTeams.size() != teamNameToNewStuMap.size()
|| newTeams.size() != teamNameToOldStuMap.size();
if (isNotTeamCountEqual) {
log("Section chain - team count not equal");
return false;
}

Expand All @@ -140,6 +166,7 @@ private boolean verifyTeams(Section newSection,
// which means a possible migration error
boolean teamNameNotPresent = oldTeamStudents == null || newTeamStudents == null;
if (teamNameNotPresent) {
log("Section chain - team name not present");
return false;
}
return verifyStudents(oldTeamStudents, newTeamStudents);
Expand All @@ -149,6 +176,7 @@ private boolean verifyTeams(Section newSection,
private boolean verifyStudents(
List<CourseStudent> oldTeamStudents, List<Student> newTeamStudents) {
if (oldTeamStudents.size() != newTeamStudents.size()) {
log("Section chain - number of students not equal");
return false;
}
oldTeamStudents.sort((a, b) -> a.getEmail().compareTo(b.getEmail()));
Expand All @@ -157,6 +185,7 @@ private boolean verifyStudents(
CourseStudent oldStudent = oldTeamStudents.get(i);
Student newStudent = newTeamStudents.get(i);
if (!verifyStudent(oldStudent, newStudent)) {
log("Section chain - student failed attribute comparison");
return false;
}
}
Expand Down Expand Up @@ -348,6 +377,7 @@ private boolean verifyInstructors(teammates.storage.sqlentity.Course newCourse)
.list();

if (oldInstructors.size() != newInstructors.size()) {
log("Feedback chain - Instructor counts not equal");
return false;
}

Expand All @@ -357,6 +387,7 @@ private boolean verifyInstructors(teammates.storage.sqlentity.Course newCourse)
Instructor oldInstructor = oldInstructors.get(i);
teammates.storage.sqlentity.Instructor newInstructor = newInstructors.get(i);
if (!verifyInstructor(oldInstructor, newInstructor)) {
log("Feedback chain - Instructor attributes failed comparison");
return false;
}
}
Expand Down Expand Up @@ -394,6 +425,8 @@ private boolean verifyDeadlineExtensions(teammates.storage.sqlentity.Course newC
.type(DeadlineExtension.class).filter("courseId", newCourse.getId()).list();

if (oldDeadlineExt.size() != newDeadlineExt.size()) {
log("Deadline extension size not equal");

return false;
}

Expand All @@ -404,6 +437,7 @@ private boolean verifyDeadlineExtensions(teammates.storage.sqlentity.Course newC
DeadlineExtension oldDeadline = oldDeadlineExt.get(i);
teammates.storage.sqlentity.DeadlineExtension newDeadline = newDeadlineExt.get(i);
if (!verifyDeadlineExtension(oldDeadline, newDeadline)) {
log("Deadline extension failed comparison");
return false;
}
}
Expand Down

0 comments on commit 80bcac0

Please sign in to comment.