CreateTeamsFromCATMEJob.java

1
package edu.ucsb.cs156.frontiers.jobs;
2
3
import edu.ucsb.cs156.frontiers.entities.Course;
4
import edu.ucsb.cs156.frontiers.entities.RosterStudent;
5
import edu.ucsb.cs156.frontiers.entities.Team;
6
import edu.ucsb.cs156.frontiers.entities.TeamMember;
7
import edu.ucsb.cs156.frontiers.enums.RosterStatus;
8
import edu.ucsb.cs156.frontiers.models.CATMETeamAssignment;
9
import edu.ucsb.cs156.frontiers.repositories.CourseRepository;
10
import edu.ucsb.cs156.frontiers.repositories.RosterStudentRepository;
11
import edu.ucsb.cs156.frontiers.repositories.TeamMemberRepository;
12
import edu.ucsb.cs156.frontiers.repositories.TeamRepository;
13
import edu.ucsb.cs156.jobs.services.JobContext;
14
import edu.ucsb.cs156.jobs.services.JobContextConsumer;
15
import java.util.ArrayList;
16
import java.util.HashMap;
17
import java.util.LinkedHashMap;
18
import java.util.List;
19
import java.util.Map;
20
import lombok.Builder;
21
22
/**
23
 * Creates teams in Frontiers from the team assignments of a CATME TeamMaker CSV export, and adds
24
 * each student to their team. Teams that already exist are reused; students already on their team
25
 * are left alone. Nothing is pushed to GitHub: that is a separate step (Push Teams to GitHub, on
26
 * the Teams tab).
27
 *
28
 * <p>The assignments are expected to have passed the CATME audit first, so every student in them
29
 * should be an enrolled student of the course; any that is not is logged and skipped.
30
 */
31
@Builder
32
public class CreateTeamsFromCATMEJob implements JobContextConsumer {
33
34
  Course course;
35
  List<CATMETeamAssignment> assignments;
36
  CourseRepository courseRepository;
37
  RosterStudentRepository rosterStudentRepository;
38
  TeamRepository teamRepository;
39
  TeamMemberRepository teamMemberRepository;
40
41
  /**
42
   * @return the team assignments this job was given
43
   */
44
  public List<CATMETeamAssignment> getAssignments() {
45 1 1. getAssignments : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/jobs/CreateTeamsFromCATMEJob::getAssignments → KILLED
    return assignments;
46
  }
47
48
  @Override
49
  public String getScopeType() {
50 1 1. getScopeType : replaced return value with "" for edu/ucsb/cs156/frontiers/jobs/CreateTeamsFromCATMEJob::getScopeType → KILLED
    return "course";
51
  }
52
53
  @Override
54
  public Long getScopeId() {
55 1 1. getScopeId : replaced Long return value with 0L for edu/ucsb/cs156/frontiers/jobs/CreateTeamsFromCATMEJob::getScopeId → KILLED
    return course.getId();
56
  }
57
58
  @Override
59
  public void accept(JobContext ctx) throws Exception {
60
    Course currentCourse = courseRepository.findById(course.getId()).orElseThrow();
61 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
    ctx.log("Creating teams from CATME file (teams are NOT pushed to GitHub by this job)");
62
63
    Map<String, RosterStudent> studentsById = new HashMap<>();
64
    for (RosterStudent student : rosterStudentRepository.findByCourseId(currentCourse.getId())) {
65 1 1. accept : negated conditional → KILLED
      if (student.getStudentId() != null
66 1 1. accept : negated conditional → KILLED
          && (student.getRosterStatus() == RosterStatus.ROSTER
67 1 1. accept : negated conditional → KILLED
              || student.getRosterStatus() == RosterStatus.MANUAL)) {
68
        studentsById.put(student.getStudentId(), student);
69
      }
70
    }
71
72
    // Group the assignments by team, keeping the order of the file
73
    Map<String, List<CATMETeamAssignment>> assignmentsByTeam = new LinkedHashMap<>();
74
    int withoutTeam = 0;
75
    for (CATMETeamAssignment assignment : assignments) {
76 1 1. accept : negated conditional → KILLED
      String teamName = assignment.teamName() == null ? "" : assignment.teamName().strip();
77 1 1. accept : negated conditional → KILLED
      if (teamName.isEmpty()) {
78 1 1. accept : Changed increment from 1 to -1 → KILLED
        withoutTeam++;
79
        continue;
80
      }
81 1 1. lambda$accept$0 : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/jobs/CreateTeamsFromCATMEJob::lambda$accept$0 → KILLED
      assignmentsByTeam.computeIfAbsent(teamName, name -> new ArrayList<>()).add(assignment);
82
    }
83 2 1. accept : changed conditional boundary → KILLED
2. accept : negated conditional → KILLED
    if (withoutTeam > 0) {
84 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
      ctx.log("%d student(s) in the file have no team name; skipped".formatted(withoutTeam));
85
    }
86
87
    int created = 0;
88
    int added = 0;
89
    for (Map.Entry<String, List<CATMETeamAssignment>> entry : assignmentsByTeam.entrySet()) {
90
      String teamName = entry.getKey();
91
      Team team =
92
          teamRepository.findByCourseIdAndName(currentCourse.getId(), teamName).orElse(null);
93 1 1. accept : negated conditional → KILLED
      if (team == null) {
94
        team =
95
            teamRepository.save(
96
                Team.builder()
97
                    .name(teamName)
98
                    .course(currentCourse)
99
                    .teamMembers(new ArrayList<>())
100
                    .build());
101 1 1. accept : Changed increment from 1 to -1 → KILLED
        created++;
102 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
        ctx.log("Created team %s".formatted(teamName));
103
      } else {
104 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
        ctx.log("Team %s already exists".formatted(teamName));
105
      }
106
107
      for (CATMETeamAssignment assignment : entry.getValue()) {
108
        RosterStudent student = studentsById.get(assignment.studentId());
109 1 1. accept : negated conditional → KILLED
        if (student == null) {
110 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
          ctx.log(
111
              "Student %s (%s) is not an enrolled student of this course; skipped"
112
                  .formatted(assignment.name(), assignment.studentId()));
113
          continue;
114
        }
115 1 1. accept : negated conditional → KILLED
        if (teamMemberRepository.findByTeamAndRosterStudent(team, student).isPresent()) {
116 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
          ctx.log(
117
              "%s (%s) is already on team %s"
118
                  .formatted(assignment.name(), assignment.studentId(), teamName));
119
          continue;
120
        }
121
        teamMemberRepository.save(TeamMember.builder().team(team).rosterStudent(student).build());
122 1 1. accept : Changed increment from 1 to -1 → KILLED
        added++;
123 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
        ctx.log(
124
            "Added %s (%s) to team %s"
125
                .formatted(assignment.name(), assignment.studentId(), teamName));
126
      }
127
    }
128 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
    ctx.log(
129
        "Done: %d team(s) created, %d student(s) added to teams. Teams have NOT been pushed to GitHub; use Push Teams to GitHub on the Teams tab when ready."
130
            .formatted(created, added));
131
  }
132
}

Mutations

45

1.1
Location : getAssignments
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:scope_is_the_course_and_assignments_are_exposed()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/jobs/CreateTeamsFromCATMEJob::getAssignments → KILLED

50

1.1
Location : getScopeType
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:scope_is_the_course_and_assignments_are_exposed()]
replaced return value with "" for edu/ucsb/cs156/frontiers/jobs/CreateTeamsFromCATMEJob::getScopeType → KILLED

55

1.1
Location : getScopeId
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:scope_is_the_course_and_assignments_are_exposed()]
replaced Long return value with 0L for edu/ucsb/cs156/frontiers/jobs/CreateTeamsFromCATMEJob::getScopeId → KILLED

61

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:no_assignments_creates_nothing()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

65

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
negated conditional → KILLED

66

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
negated conditional → KILLED

67

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
negated conditional → KILLED

76

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
negated conditional → KILLED

77

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
negated conditional → KILLED

78

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
Changed increment from 1 to -1 → KILLED

81

1.1
Location : lambda$accept$0
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/jobs/CreateTeamsFromCATMEJob::lambda$accept$0 → KILLED

83

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:no_assignments_creates_nothing()]
changed conditional boundary → KILLED

2.2
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:no_assignments_creates_nothing()]
negated conditional → KILLED

84

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

93

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
negated conditional → KILLED

101

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
Changed increment from 1 to -1 → KILLED

102

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

104

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

109

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
negated conditional → KILLED

110

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

115

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
negated conditional → KILLED

116

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

122

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
Changed increment from 1 to -1 → KILLED

123

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:creates_teams_and_adds_students_without_pushing_to_github()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

128

1.1
Location : accept
Killed by : edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.jobs.CreateTeamsFromCATMEJobTests]/[method:no_assignments_creates_nothing()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support