| 1 | package edu.ucsb.cs156.frontiers.jobs; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.frontiers.entities.Course; | |
| 4 | import edu.ucsb.cs156.frontiers.entities.CourseStaff; | |
| 5 | import edu.ucsb.cs156.frontiers.entities.RosterStudent; | |
| 6 | import edu.ucsb.cs156.frontiers.enums.OrgStatus; | |
| 7 | import edu.ucsb.cs156.frontiers.models.OrgMember; | |
| 8 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
| 9 | import edu.ucsb.cs156.frontiers.repositories.CourseStaffRepository; | |
| 10 | import edu.ucsb.cs156.frontiers.repositories.RosterStudentRepository; | |
| 11 | import edu.ucsb.cs156.frontiers.services.OrganizationMemberService; | |
| 12 | import edu.ucsb.cs156.jobs.services.JobContext; | |
| 13 | import edu.ucsb.cs156.jobs.services.JobContextConsumer; | |
| 14 | import java.util.List; | |
| 15 | import java.util.Optional; | |
| 16 | import java.util.stream.StreamSupport; | |
| 17 | import lombok.Builder; | |
| 18 | ||
| 19 | @Builder | |
| 20 | public class MembershipAuditJob implements JobContextConsumer { | |
| 21 | CourseRepository courseRepository; | |
| 22 | OrganizationMemberService organizationMemberService; | |
| 23 | RosterStudentRepository rosterStudentRepository; | |
| 24 | CourseStaffRepository courseStaffRepository; | |
| 25 | ||
| 26 | // Unscoped: audits every course with a linked GitHub org in one run, not a single course. | |
| 27 | // getScopeType()/getScopeId() default to null (unscoped), same as the old getCourse() did. | |
| 28 | ||
| 29 | @Override | |
| 30 | public void accept(JobContext ctx) throws Exception { | |
| 31 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Auditing membership for each course with an attached GitHub Organization..."); |
| 32 | Iterable<Course> courses = courseRepository.findAll(); | |
| 33 | for (Course course : courses) { | |
| 34 | // Nothing in this method's whole body logs per course -- the only ctx.log() calls are | |
| 35 | // the opening line above and the closing "Done" below. checkCancellation() gives the | |
| 36 | // course loop its own checkpoint independent of course count. | |
| 37 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::checkCancellation → KILLED |
ctx.checkCancellation(); |
| 38 |
2
1. accept : negated conditional → KILLED 2. accept : negated conditional → KILLED |
if (course.getOrgName() != null && course.getInstallationId() != null) { |
| 39 | Iterable<OrgMember> members = organizationMemberService.getOrganizationMembers(course); | |
| 40 | Iterable<OrgMember> admins = organizationMemberService.getOrganizationAdmins(course); | |
| 41 | Iterable<OrgMember> invitees = organizationMemberService.getOrganizationInvitees(course); | |
| 42 | List<RosterStudent> rosterStudents = course.getRosterStudents(); | |
| 43 | List<CourseStaff> courseStaff = course.getCourseStaff(); | |
| 44 |
2
1. accept : negated conditional → KILLED 2. accept : changed conditional boundary → KILLED |
for (int i = 0; i < rosterStudents.size(); i++) { |
| 45 | // Same reasoning as the course loop: this loop never logs per student, so a large | |
| 46 | // roster gives cancellation no other opportunity to fire. | |
| 47 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::checkCancellation → KILLED |
ctx.checkCancellation(); |
| 48 | Integer studentGithubId = rosterStudents.get(i).getGithubId(); | |
| 49 | String studentGithubLogin = rosterStudents.get(i).getGithubLogin(); | |
| 50 |
2
1. accept : negated conditional → KILLED 2. accept : negated conditional → KILLED |
if (studentGithubId != null && studentGithubLogin != null) { |
| 51 | Optional<OrgMember> member = | |
| 52 | StreamSupport.stream(members.spliterator(), false) | |
| 53 |
2
1. lambda$accept$0 : replaced boolean return with false for edu/ucsb/cs156/frontiers/jobs/MembershipAuditJob::lambda$accept$0 → KILLED 2. lambda$accept$0 : replaced boolean return with true for edu/ucsb/cs156/frontiers/jobs/MembershipAuditJob::lambda$accept$0 → KILLED |
.filter(s -> studentGithubId.equals(s.getGithubId())) |
| 54 | .findFirst(); | |
| 55 | Optional<OrgMember> admin = | |
| 56 | StreamSupport.stream(admins.spliterator(), false) | |
| 57 |
2
1. lambda$accept$1 : replaced boolean return with false for edu/ucsb/cs156/frontiers/jobs/MembershipAuditJob::lambda$accept$1 → KILLED 2. lambda$accept$1 : replaced boolean return with true for edu/ucsb/cs156/frontiers/jobs/MembershipAuditJob::lambda$accept$1 → KILLED |
.filter(s -> studentGithubId.equals(s.getGithubId())) |
| 58 | .findFirst(); | |
| 59 | Optional<OrgMember> invitee = | |
| 60 | StreamSupport.stream(invitees.spliterator(), false) | |
| 61 |
2
1. lambda$accept$2 : replaced boolean return with true for edu/ucsb/cs156/frontiers/jobs/MembershipAuditJob::lambda$accept$2 → KILLED 2. lambda$accept$2 : replaced boolean return with false for edu/ucsb/cs156/frontiers/jobs/MembershipAuditJob::lambda$accept$2 → KILLED |
.filter(s -> studentGithubId.equals(s.getGithubId())) |
| 62 | .findFirst(); | |
| 63 | ||
| 64 | OrgStatus updatedStatus = OrgStatus.JOINCOURSE; | |
| 65 | ||
| 66 |
1
1. accept : negated conditional → KILLED |
if (admin.isPresent()) { |
| 67 | updatedStatus = OrgStatus.OWNER; | |
| 68 |
1
1. accept : negated conditional → KILLED |
} else if (member.isPresent()) { |
| 69 | updatedStatus = OrgStatus.MEMBER; | |
| 70 |
1
1. accept : negated conditional → KILLED |
} else if (invitee.isPresent()) { |
| 71 | updatedStatus = OrgStatus.INVITED; | |
| 72 | } | |
| 73 |
1
1. accept : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED |
rosterStudents.get(i).setOrgStatus(updatedStatus); |
| 74 | } | |
| 75 | } | |
| 76 | rosterStudentRepository.saveAll(rosterStudents); | |
| 77 | ||
| 78 |
2
1. accept : negated conditional → KILLED 2. accept : changed conditional boundary → KILLED |
for (int i = 0; i < courseStaff.size(); i++) { |
| 79 | // Same reasoning as the roster-students loop above. | |
| 80 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::checkCancellation → KILLED |
ctx.checkCancellation(); |
| 81 | Integer staffGithubId = courseStaff.get(i).getGithubId(); | |
| 82 | String staffGithubLogin = courseStaff.get(i).getGithubLogin(); | |
| 83 |
2
1. accept : negated conditional → KILLED 2. accept : negated conditional → KILLED |
if (staffGithubId != null && staffGithubLogin != null) { |
| 84 | Optional<OrgMember> member = | |
| 85 | StreamSupport.stream(members.spliterator(), false) | |
| 86 |
2
1. lambda$accept$3 : replaced boolean return with true for edu/ucsb/cs156/frontiers/jobs/MembershipAuditJob::lambda$accept$3 → KILLED 2. lambda$accept$3 : replaced boolean return with false for edu/ucsb/cs156/frontiers/jobs/MembershipAuditJob::lambda$accept$3 → KILLED |
.filter(s -> staffGithubId.equals(s.getGithubId())) |
| 87 | .findFirst(); | |
| 88 | Optional<OrgMember> admin = | |
| 89 | StreamSupport.stream(admins.spliterator(), false) | |
| 90 |
2
1. lambda$accept$4 : replaced boolean return with false for edu/ucsb/cs156/frontiers/jobs/MembershipAuditJob::lambda$accept$4 → KILLED 2. lambda$accept$4 : replaced boolean return with true for edu/ucsb/cs156/frontiers/jobs/MembershipAuditJob::lambda$accept$4 → KILLED |
.filter(s -> staffGithubId.equals(s.getGithubId())) |
| 91 | .findFirst(); | |
| 92 | Optional<OrgMember> invitee = | |
| 93 | StreamSupport.stream(invitees.spliterator(), false) | |
| 94 |
2
1. lambda$accept$5 : replaced boolean return with true for edu/ucsb/cs156/frontiers/jobs/MembershipAuditJob::lambda$accept$5 → KILLED 2. lambda$accept$5 : replaced boolean return with false for edu/ucsb/cs156/frontiers/jobs/MembershipAuditJob::lambda$accept$5 → KILLED |
.filter(s -> staffGithubId.equals(s.getGithubId())) |
| 95 | .findFirst(); | |
| 96 | ||
| 97 | OrgStatus updatedStatus = OrgStatus.JOINCOURSE; | |
| 98 | ||
| 99 |
1
1. accept : negated conditional → KILLED |
if (admin.isPresent()) { |
| 100 | updatedStatus = OrgStatus.OWNER; | |
| 101 |
1
1. accept : negated conditional → KILLED |
} else if (member.isPresent()) { |
| 102 | updatedStatus = OrgStatus.MEMBER; | |
| 103 |
1
1. accept : negated conditional → KILLED |
} else if (invitee.isPresent()) { |
| 104 | updatedStatus = OrgStatus.INVITED; | |
| 105 | } | |
| 106 |
1
1. accept : removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setOrgStatus → KILLED |
courseStaff.get(i).setOrgStatus(updatedStatus); |
| 107 | } | |
| 108 | } | |
| 109 | courseStaffRepository.saveAll(courseStaff); | |
| 110 | } | |
| 111 | } | |
| 112 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Done"); |
| 113 | } | |
| 114 | } | |
Mutations | ||
| 31 |
1.1 |
|
| 37 |
1.1 |
|
| 38 |
1.1 2.2 |
|
| 44 |
1.1 2.2 |
|
| 47 |
1.1 |
|
| 50 |
1.1 2.2 |
|
| 53 |
1.1 2.2 |
|
| 57 |
1.1 2.2 |
|
| 61 |
1.1 2.2 |
|
| 66 |
1.1 |
|
| 68 |
1.1 |
|
| 70 |
1.1 |
|
| 73 |
1.1 |
|
| 78 |
1.1 2.2 |
|
| 80 |
1.1 |
|
| 83 |
1.1 2.2 |
|
| 86 |
1.1 2.2 |
|
| 90 |
1.1 2.2 |
|
| 94 |
1.1 2.2 |
|
| 99 |
1.1 |
|
| 101 |
1.1 |
|
| 103 |
1.1 |
|
| 106 |
1.1 |
|
| 112 |
1.1 |