| 1 | package edu.ucsb.cs156.frontiers.controllers; | |
| 2 | ||
| 3 | import com.opencsv.CSVReader; | |
| 4 | import com.opencsv.exceptions.CsvException; | |
| 5 | import edu.ucsb.cs156.frontiers.entities.Course; | |
| 6 | import edu.ucsb.cs156.frontiers.entities.RosterStudent; | |
| 7 | import edu.ucsb.cs156.frontiers.entities.Team; | |
| 8 | import edu.ucsb.cs156.frontiers.entities.TeamMember; | |
| 9 | import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException; | |
| 10 | import edu.ucsb.cs156.frontiers.jobs.PushTeamsToGithubJob; | |
| 11 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
| 12 | import edu.ucsb.cs156.frontiers.repositories.RosterStudentRepository; | |
| 13 | import edu.ucsb.cs156.frontiers.repositories.TeamMemberRepository; | |
| 14 | import edu.ucsb.cs156.frontiers.repositories.TeamRepository; | |
| 15 | import edu.ucsb.cs156.frontiers.services.GithubTeamService; | |
| 16 | import edu.ucsb.cs156.jobs.services.JobService; | |
| 17 | import io.swagger.v3.oas.annotations.Operation; | |
| 18 | import io.swagger.v3.oas.annotations.Parameter; | |
| 19 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 20 | import java.io.BufferedInputStream; | |
| 21 | import java.io.IOException; | |
| 22 | import java.io.InputStream; | |
| 23 | import java.io.InputStreamReader; | |
| 24 | import java.util.*; | |
| 25 | import lombok.extern.slf4j.Slf4j; | |
| 26 | import org.springframework.beans.factory.annotation.Autowired; | |
| 27 | import org.springframework.http.HttpStatus; | |
| 28 | import org.springframework.http.ResponseEntity; | |
| 29 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 30 | import org.springframework.transaction.annotation.Transactional; | |
| 31 | import org.springframework.web.bind.annotation.*; | |
| 32 | import org.springframework.web.multipart.MultipartFile; | |
| 33 | import org.springframework.web.server.ResponseStatusException; | |
| 34 | ||
| 35 | @Tag(name = "Teams") | |
| 36 | @RequestMapping("/api/teams") | |
| 37 | @RestController | |
| 38 | @Slf4j | |
| 39 | public class TeamsController extends ApiController { | |
| 40 | ||
| 41 | @Autowired private TeamRepository teamRepository; | |
| 42 | ||
| 43 | @Autowired private TeamMemberRepository teamMemberRepository; | |
| 44 | ||
| 45 | @Autowired private CourseRepository courseRepository; | |
| 46 | ||
| 47 | @Autowired private RosterStudentRepository rosterStudentRepository; | |
| 48 | ||
| 49 | @Autowired private JobService jobService; | |
| 50 | ||
| 51 | @Autowired private GithubTeamService githubTeamService; | |
| 52 | ||
| 53 | public record TeamMemberResult( | |
| 54 | TeamMember teamMember, TeamMemberStatus status, String rejectedEmail) { | |
| 55 | public TeamMemberResult(TeamMember teamMember, TeamMemberStatus status) { | |
| 56 | this(teamMember, status, null); | |
| 57 | } | |
| 58 | ||
| 59 | public TeamMemberResult(String rejectedEmail) { | |
| 60 | this(null, TeamMemberStatus.MISSING, rejectedEmail); | |
| 61 | } | |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * Result of a team CSV upload. | |
| 66 | * | |
| 67 | * @param typeMatched the CSV format that was recognized | |
| 68 | * @param created number of team memberships created | |
| 69 | * @param existing number of team memberships that already existed | |
| 70 | * @param rejected emails on rows that could not be added (e.g. not on the roster) | |
| 71 | * @param missingTeam emails on rows that did not name a team | |
| 72 | */ | |
| 73 | public record TeamCreationResponse( | |
| 74 | TeamSourceType typeMatched, | |
| 75 | Integer created, | |
| 76 | Integer existing, | |
| 77 | List<String> rejected, | |
| 78 | List<String> missingTeam) {} | |
| 79 | ||
| 80 | public record TeamMemberMapping( | |
| 81 | Long teamId, | |
| 82 | String teamName, | |
| 83 | Long rosterStudentId, | |
| 84 | String email, | |
| 85 | String firstName, | |
| 86 | String lastName, | |
| 87 | String githubLogin) { | |
| 88 | public static TeamMemberMapping from(TeamMember member) { | |
| 89 |
1
1. from : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController$TeamMemberMapping::from → KILLED |
return new TeamMemberMapping( |
| 90 | member.getTeam().getId(), | |
| 91 | member.getTeam().getName(), | |
| 92 | member.getRosterStudent().getId(), | |
| 93 | member.getRosterStudent().getEmail(), | |
| 94 | member.getRosterStudent().getFirstName(), | |
| 95 | member.getRosterStudent().getLastName(), | |
| 96 | member.getRosterStudent().getGithubLogin()); | |
| 97 | } | |
| 98 | } | |
| 99 | ||
| 100 | /** | |
| 101 | * This method creates a new Team. | |
| 102 | * | |
| 103 | * @param name the name of the team | |
| 104 | * @param courseId the ID of the course this team belongs to | |
| 105 | * @param isStaffTeam true for a staff team, whose members are the course staff rather than roster | |
| 106 | * students (default false) | |
| 107 | * @return the created team | |
| 108 | */ | |
| 109 | @Operation(summary = "Create a new team") | |
| 110 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 111 | @PostMapping("/post") | |
| 112 | public Team postTeam( | |
| 113 | @Parameter(name = "name") @RequestParam String name, | |
| 114 | @Parameter(name = "courseId") @RequestParam Long courseId, | |
| 115 | @Parameter(name = "isStaffTeam") @RequestParam(required = false, defaultValue = "false") | |
| 116 | Boolean isStaffTeam) { | |
| 117 | ||
| 118 | Course course = | |
| 119 | courseRepository | |
| 120 | .findById(courseId) | |
| 121 |
1
1. lambda$postTeam$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::lambda$postTeam$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
| 122 | ||
| 123 | Team team = Team.builder().name(name).course(course).isStaffTeam(isStaffTeam).build(); | |
| 124 | ||
| 125 |
1
1. postTeam : negated conditional → KILLED |
if (teamRepository.findByCourseIdAndName(course.getId(), name).isPresent()) { |
| 126 | throw new ResponseStatusException( | |
| 127 | HttpStatus.CONFLICT, "Team with name %s already exists".formatted(name)); | |
| 128 | } else { | |
| 129 | team = teamRepository.save(team); | |
| 130 | } | |
| 131 | ||
| 132 |
1
1. postTeam : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::postTeam → KILLED |
return team; |
| 133 | } | |
| 134 | ||
| 135 | /** | |
| 136 | * Upload teams in CSV format (team, email) It is important to keep the code in this method | |
| 137 | * consistent with the code for adding a single roster student. A row that names a staff team is | |
| 138 | * rejected, since a staff team's members are the course staff. A row with an empty team is | |
| 139 | * skipped and its email is reported in {@code missingTeam}; the other rows are still processed. | |
| 140 | * If any row was rejected or had no team, the response status is 409 (Conflict). | |
| 141 | * | |
| 142 | * @param courseId course the teams are for | |
| 143 | * @param file csv file with roster student emails and team assignments | |
| 144 | * @return Count of students added to teams and already existing, plus the emails of rejected rows | |
| 145 | * and of rows without a team | |
| 146 | */ | |
| 147 | @Operation(summary = "Upload team assignments; CSV in format team,email") | |
| 148 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 149 | @PostMapping( | |
| 150 | value = "/upload/csv", | |
| 151 | consumes = {"multipart/form-data"}) | |
| 152 | public ResponseEntity<TeamCreationResponse> uploadTeamsCsv( | |
| 153 | @Parameter(name = "courseId") @RequestParam Long courseId, | |
| 154 | @Parameter(name = "file") @RequestParam("file") MultipartFile file) | |
| 155 | throws IOException, CsvException { | |
| 156 | ||
| 157 | Course course = | |
| 158 | courseRepository | |
| 159 | .findById(courseId) | |
| 160 |
1
1. lambda$uploadTeamsCsv$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::lambda$uploadTeamsCsv$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId.toString())); |
| 161 | ||
| 162 | int counts[] = {0, 0}; | |
| 163 | ||
| 164 | List<String> failed = new ArrayList<>(); | |
| 165 | List<String> missingTeam = new ArrayList<>(); | |
| 166 | ||
| 167 | try (InputStream inputStream = new BufferedInputStream(file.getInputStream()); | |
| 168 | InputStreamReader reader = new InputStreamReader(inputStream); | |
| 169 | CSVReader csvReader = new CSVReader(reader); ) { | |
| 170 | ||
| 171 | String[] headers = csvReader.readNext(); | |
| 172 | TeamSourceType sourceType = getRosterSourceType(headers); | |
| 173 | List<String[]> myEntries = csvReader.readAll(); | |
| 174 | for (String[] row : myEntries) { | |
| 175 | TeamMemberResult rowResult = fromCSVRow(row, sourceType, course); | |
| 176 |
1
1. uploadTeamsCsv : negated conditional → KILLED |
if (rowResult.status == TeamMemberStatus.MISSING) { |
| 177 | failed.add(rowResult.rejectedEmail); | |
| 178 |
1
1. uploadTeamsCsv : negated conditional → KILLED |
} else if (rowResult.status == TeamMemberStatus.NO_TEAM) { |
| 179 | missingTeam.add(rowResult.rejectedEmail); | |
| 180 | } else { | |
| 181 |
1
1. uploadTeamsCsv : Replaced integer addition with subtraction → KILLED |
counts[rowResult.status.ordinal()]++; |
| 182 | } | |
| 183 | } | |
| 184 | TeamCreationResponse response = | |
| 185 | new TeamCreationResponse( | |
| 186 | sourceType, | |
| 187 | counts[TeamMemberStatus.CREATED.ordinal()], | |
| 188 | counts[TeamMemberStatus.EXISTS.ordinal()], | |
| 189 | failed, | |
| 190 | missingTeam); | |
| 191 | ||
| 192 |
1
1. uploadTeamsCsv : removed call to edu/ucsb/cs156/frontiers/controllers/TeamsController::launchPushTeamsToGithubJob → KILLED |
launchPushTeamsToGithubJob(courseId); |
| 193 | ||
| 194 |
2
1. uploadTeamsCsv : negated conditional → KILLED 2. uploadTeamsCsv : negated conditional → KILLED |
if (!failed.isEmpty() || !missingTeam.isEmpty()) { |
| 195 |
1
1. uploadTeamsCsv : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::uploadTeamsCsv → KILLED |
return ResponseEntity.status(HttpStatus.CONFLICT).body(response); |
| 196 | } else { | |
| 197 |
1
1. uploadTeamsCsv : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::uploadTeamsCsv → KILLED |
return ResponseEntity.ok(response); |
| 198 | } | |
| 199 | } | |
| 200 | } | |
| 201 | ||
| 202 | /** | |
| 203 | * This method returns a list of all teams for a course | |
| 204 | * | |
| 205 | * @return a list of all teams for a course | |
| 206 | */ | |
| 207 | @Operation(summary = "List all teams") | |
| 208 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 209 | @GetMapping("/all") | |
| 210 | public Iterable<Team> allTeams(@RequestParam Long courseId) { | |
| 211 | Iterable<Team> teams = teamRepository.findByCourseIdOrderByNameAsc(courseId); | |
| 212 |
1
1. allTeams : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/TeamsController::allTeams → KILLED |
return teams; |
| 213 | } | |
| 214 | ||
| 215 | /** | |
| 216 | * Retrieves a list of mappings between roster students and teams for a given course. Each mapping | |
| 217 | * represents a relationship between a team and its members. | |
| 218 | * | |
| 219 | * @param courseId the unique identifier of the course for which team mappings are retrieved | |
| 220 | * @return an iterable collection of {@code TeamMemberMapping} objects representing the mappings | |
| 221 | */ | |
| 222 | @Operation(summary = "List the mapping of Roster Students to Teams") | |
| 223 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 224 | @GetMapping("/mapping") | |
| 225 | public Iterable<TeamMemberMapping> teamMemberMapping(@RequestParam Long courseId) { | |
| 226 | List<Team> teams = | |
| 227 | courseRepository | |
| 228 | .findById(courseId) | |
| 229 |
1
1. lambda$teamMemberMapping$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::lambda$teamMemberMapping$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)) |
| 230 | .getTeams(); | |
| 231 | List<TeamMemberMapping> mappings = new ArrayList<>(); | |
| 232 | for (Team team : teams) { | |
| 233 | for (TeamMember member : team.getTeamMembers()) { | |
| 234 | mappings.add(TeamMemberMapping.from(member)); | |
| 235 | } | |
| 236 | } | |
| 237 |
1
1. teamMemberMapping : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/TeamsController::teamMemberMapping → KILLED |
return mappings; |
| 238 | } | |
| 239 | ||
| 240 | /** | |
| 241 | * This method returns a single team by its id | |
| 242 | * | |
| 243 | * @param id the id of the team | |
| 244 | * @return the team | |
| 245 | */ | |
| 246 | @Operation(summary = "Get a single team") | |
| 247 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 248 | @GetMapping("") | |
| 249 | public Team getTeamById( | |
| 250 | @Parameter(name = "id") @RequestParam Long id, @RequestParam Long courseId) { | |
| 251 | Team team = | |
| 252 |
1
1. lambda$getTeamById$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::lambda$getTeamById$0 → KILLED |
teamRepository.findById(id).orElseThrow(() -> new EntityNotFoundException(Team.class, id)); |
| 253 |
1
1. getTeamById : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::getTeamById → KILLED |
return team; |
| 254 | } | |
| 255 | ||
| 256 | /** | |
| 257 | * This method deletes a team by its id | |
| 258 | * | |
| 259 | * @param id the id of the team to delete | |
| 260 | * @return a message indicating the team was deleted | |
| 261 | */ | |
| 262 | @Operation(summary = "Delete a team") | |
| 263 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 264 | @DeleteMapping("") | |
| 265 | @Transactional | |
| 266 | public Object deleteTeam( | |
| 267 | @Parameter(name = "id") @RequestParam Long id, @RequestParam Long courseId) { | |
| 268 | Team team = | |
| 269 |
1
1. lambda$deleteTeam$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::lambda$deleteTeam$0 → KILLED |
teamRepository.findById(id).orElseThrow(() -> new EntityNotFoundException(Team.class, id)); |
| 270 | ||
| 271 | // Handle team members that reference this team | |
| 272 |
1
1. deleteTeam : negated conditional → KILLED |
if (!team.getTeamMembers().isEmpty()) { |
| 273 | team.getTeamMembers() | |
| 274 |
1
1. deleteTeam : removed call to java/util/List::forEach → KILLED |
.forEach( |
| 275 | teamMember -> { | |
| 276 | // Remove from roster student's team members list | |
| 277 | teamMember.getRosterStudent().getTeamMembers().remove(teamMember); | |
| 278 |
1
1. lambda$deleteTeam$1 : removed call to edu/ucsb/cs156/frontiers/entities/TeamMember::setRosterStudent → KILLED |
teamMember.setRosterStudent(null); |
| 279 | }); | |
| 280 | } | |
| 281 | ||
| 282 | // Disconnect from course | |
| 283 | team.getCourse().getTeams().remove(team); | |
| 284 |
1
1. deleteTeam : removed call to edu/ucsb/cs156/frontiers/entities/Team::setCourse → KILLED |
team.setCourse(null); |
| 285 | ||
| 286 |
1
1. deleteTeam : removed call to edu/ucsb/cs156/frontiers/repositories/TeamRepository::delete → KILLED |
teamRepository.delete(team); |
| 287 |
1
1. deleteTeam : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::deleteTeam → KILLED |
return genericMessage("Team with id %s deleted".formatted(id)); |
| 288 | } | |
| 289 | ||
| 290 | /** | |
| 291 | * This method adds a roster student as a team member | |
| 292 | * | |
| 293 | * @param teamId the ID of the team | |
| 294 | * @param rosterStudentId the ID of the roster student to add | |
| 295 | * @return the created team member | |
| 296 | */ | |
| 297 | @Operation(summary = "Add a roster student to a team") | |
| 298 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 299 | @PostMapping("/addMember") | |
| 300 | public TeamMember addTeamMember( | |
| 301 | @Parameter(name = "teamId") @RequestParam Long teamId, | |
| 302 | @Parameter(name = "rosterStudentId") @RequestParam Long rosterStudentId, | |
| 303 | @Parameter(name = "courseId") @RequestParam Long courseId) { | |
| 304 | ||
| 305 | Team team = | |
| 306 | teamRepository | |
| 307 | .findById(teamId) | |
| 308 |
1
1. lambda$addTeamMember$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::lambda$addTeamMember$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Team.class, teamId)); |
| 309 | ||
| 310 | RosterStudent rosterStudent = | |
| 311 | rosterStudentRepository | |
| 312 | .findById(rosterStudentId) | |
| 313 |
1
1. lambda$addTeamMember$1 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::lambda$addTeamMember$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RosterStudent.class, rosterStudentId)); |
| 314 | ||
| 315 |
1
1. addTeamMember : negated conditional → KILLED |
if (!team.getCourse().getId().equals(courseId)) { |
| 316 | throw new ResponseStatusException( | |
| 317 | HttpStatus.BAD_REQUEST, "Team is not from course %d".formatted(courseId)); | |
| 318 | } | |
| 319 |
1
1. addTeamMember : negated conditional → KILLED |
if (!rosterStudent.getCourse().getId().equals(courseId)) { |
| 320 | throw new ResponseStatusException( | |
| 321 | HttpStatus.BAD_REQUEST, "Roster student is not from course %d".formatted(courseId)); | |
| 322 | } | |
| 323 |
1
1. addTeamMember : negated conditional → KILLED |
if (Boolean.TRUE.equals(team.getIsStaffTeam())) { |
| 324 | throw new ResponseStatusException( | |
| 325 | HttpStatus.BAD_REQUEST, | |
| 326 | "Team %s is a staff team; its members are the course staff".formatted(team.getName())); | |
| 327 | } | |
| 328 | ||
| 329 |
1
1. addTeamMember : negated conditional → KILLED |
if (teamMemberRepository.findByTeamAndRosterStudent(team, rosterStudent).isPresent()) { |
| 330 | throw new ResponseStatusException( | |
| 331 | HttpStatus.CONFLICT, | |
| 332 | "Team member already exists for team %s and roster student %s" | |
| 333 | .formatted(team.getName(), rosterStudent.getEmail())); | |
| 334 | } | |
| 335 | TeamMember teamMember = TeamMember.builder().team(team).rosterStudent(rosterStudent).build(); | |
| 336 | TeamMember savedTeamMember = teamMemberRepository.save(teamMember); | |
| 337 | ||
| 338 |
1
1. addTeamMember : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::addTeamMember → KILLED |
return savedTeamMember; |
| 339 | } | |
| 340 | ||
| 341 | /** | |
| 342 | * This method removes a team member | |
| 343 | * | |
| 344 | * @param teamMemberId the ID of the team member to remove | |
| 345 | * @return a message indicating the team member was removed | |
| 346 | */ | |
| 347 | @Operation(summary = "Remove a team member") | |
| 348 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 349 | @DeleteMapping("/removeMember") | |
| 350 | @Transactional | |
| 351 | public Object removeTeamMember( | |
| 352 | @Parameter(name = "teamMemberId") @RequestParam Long teamMemberId, | |
| 353 | @Parameter(name = "courseId") @RequestParam Long courseId) { | |
| 354 | TeamMember teamMember = | |
| 355 | teamMemberRepository | |
| 356 | .findById(teamMemberId) | |
| 357 |
1
1. lambda$removeTeamMember$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::lambda$removeTeamMember$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(TeamMember.class, teamMemberId)); |
| 358 | Team team = teamMember.getTeam(); | |
| 359 | RosterStudent rosterStudent = teamMember.getRosterStudent(); | |
| 360 | team.getTeamMembers().remove(teamMember); | |
| 361 | rosterStudent.getTeamMembers().remove(teamMember); | |
| 362 |
1
1. removeTeamMember : removed call to edu/ucsb/cs156/frontiers/repositories/TeamMemberRepository::delete → KILLED |
teamMemberRepository.delete(teamMember); |
| 363 | teamRepository.save(team); | |
| 364 | rosterStudentRepository.save(rosterStudent); | |
| 365 |
1
1. removeTeamMember : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::removeTeamMember → KILLED |
return genericMessage("Team member with id %s deleted".formatted(teamMemberId)); |
| 366 | } | |
| 367 | ||
| 368 | public enum TeamSourceType { | |
| 369 | SIMPLE, | |
| 370 | UNKNOWN | |
| 371 | } | |
| 372 | ||
| 373 | public enum TeamMemberStatus { | |
| 374 | CREATED, | |
| 375 | EXISTS, | |
| 376 | MISSING, | |
| 377 | NO_TEAM | |
| 378 | } | |
| 379 | ||
| 380 | public static final String SIMPLE_HEADERS = "team,email"; | |
| 381 | ||
| 382 | public TeamSourceType getRosterSourceType(String[] headers) { | |
| 383 | ||
| 384 | Map<TeamSourceType, String[]> sourceTypeToHeaders = new HashMap<>(); | |
| 385 | ||
| 386 | sourceTypeToHeaders.put(TeamSourceType.SIMPLE, SIMPLE_HEADERS.split(",")); | |
| 387 | ||
| 388 | for (Map.Entry<TeamSourceType, String[]> entry : sourceTypeToHeaders.entrySet()) { | |
| 389 | TeamSourceType type = entry.getKey(); | |
| 390 | String[] expectedHeaders = entry.getValue(); | |
| 391 |
2
1. getRosterSourceType : negated conditional → KILLED 2. getRosterSourceType : changed conditional boundary → KILLED |
if (headers.length >= expectedHeaders.length) { |
| 392 | boolean matches = true; | |
| 393 |
2
1. getRosterSourceType : changed conditional boundary → KILLED 2. getRosterSourceType : negated conditional → KILLED |
for (int i = 0; i < expectedHeaders.length; i++) { |
| 394 |
1
1. getRosterSourceType : negated conditional → KILLED |
if (!expectedHeaders[i].equalsIgnoreCase(headers[i])) { |
| 395 | matches = false; | |
| 396 | break; | |
| 397 | } | |
| 398 | } | |
| 399 |
1
1. getRosterSourceType : negated conditional → KILLED |
if (matches) { |
| 400 |
1
1. getRosterSourceType : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::getRosterSourceType → KILLED |
return type; |
| 401 | } | |
| 402 | } | |
| 403 | } | |
| 404 | // If no known type matches, throw | |
| 405 | throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unknown Roster Source Type"); | |
| 406 | } | |
| 407 | ||
| 408 | public TeamMemberResult fromCSVRow(String[] row, TeamSourceType sourceType, Course course) { | |
| 409 | // No if statements because this is the only possible value to enter here at the moment. Replace | |
| 410 | // with if when more | |
| 411 | // Formats are added. | |
| 412 |
1
1. fromCSVRow : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::fromCSVRow → KILLED |
return teamMemberFromSimpleCsv(row, course); |
| 413 | } | |
| 414 | ||
| 415 | public TeamMemberResult teamMemberFromSimpleCsv(String[] row, Course course) { | |
| 416 |
1
1. teamMemberFromSimpleCsv : negated conditional → KILLED |
if (row[0].isBlank()) { |
| 417 | // Without a team name there is no team to add the student to (and a team can't have a | |
| 418 | // blank name), so skip this row and report its email | |
| 419 |
1
1. teamMemberFromSimpleCsv : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::teamMemberFromSimpleCsv → KILLED |
return new TeamMemberResult(null, TeamMemberStatus.NO_TEAM, row[1]); |
| 420 | } | |
| 421 | Optional<RosterStudent> student = | |
| 422 | rosterStudentRepository.findByCourseIdAndEmail(course.getId(), row[1]); | |
| 423 | Optional<Team> team = teamRepository.findByCourseIdAndName(course.getId(), row[0]); | |
| 424 |
2
1. teamMemberFromSimpleCsv : negated conditional → KILLED 2. teamMemberFromSimpleCsv : negated conditional → KILLED |
if (team.isPresent() && Boolean.TRUE.equals(team.get().getIsStaffTeam())) { |
| 425 | // A staff team's members are the course staff, so a student cannot be put on it | |
| 426 |
1
1. teamMemberFromSimpleCsv : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::teamMemberFromSimpleCsv → KILLED |
return new TeamMemberResult(row[1]); |
| 427 | } | |
| 428 |
2
1. teamMemberFromSimpleCsv : negated conditional → KILLED 2. teamMemberFromSimpleCsv : negated conditional → KILLED |
if (student.isPresent() && team.isPresent()) { |
| 429 | Optional<TeamMember> teamMember = | |
| 430 | teamMemberRepository.findByTeamAndRosterStudent(team.get(), student.get()); | |
| 431 |
1
1. teamMemberFromSimpleCsv : negated conditional → KILLED |
if (teamMember.isPresent()) { |
| 432 |
1
1. teamMemberFromSimpleCsv : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::teamMemberFromSimpleCsv → KILLED |
return new TeamMemberResult(teamMember.get(), TeamMemberStatus.EXISTS); |
| 433 | } else { | |
| 434 | TeamMember teamMemberToSave = | |
| 435 | TeamMember.builder().team(team.get()).rosterStudent(student.get()).build(); | |
| 436 | TeamMember savedTeamMember = teamMemberRepository.save(teamMemberToSave); | |
| 437 |
1
1. teamMemberFromSimpleCsv : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::teamMemberFromSimpleCsv → KILLED |
return new TeamMemberResult(savedTeamMember, TeamMemberStatus.CREATED); |
| 438 | } | |
| 439 |
1
1. teamMemberFromSimpleCsv : negated conditional → KILLED |
} else if (student.isPresent()) { |
| 440 | Team teamToSave = Team.builder().name(row[0]).course(course).build(); | |
| 441 | teamRepository.save(teamToSave); | |
| 442 | TeamMember saveTeamMember = | |
| 443 | TeamMember.builder().team(teamToSave).rosterStudent(student.get()).build(); | |
| 444 | teamMemberRepository.save(saveTeamMember); | |
| 445 |
1
1. teamMemberFromSimpleCsv : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::teamMemberFromSimpleCsv → KILLED |
return new TeamMemberResult(saveTeamMember, TeamMemberStatus.CREATED); |
| 446 | } else { | |
| 447 |
1
1. teamMemberFromSimpleCsv : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/TeamsController::teamMemberFromSimpleCsv → KILLED |
return new TeamMemberResult(row[1]); |
| 448 | } | |
| 449 | } | |
| 450 | ||
| 451 | private void launchPushTeamsToGithubJob(Long courseId) { | |
| 452 | PushTeamsToGithubJob pushTeamsToGithubJob = | |
| 453 | PushTeamsToGithubJob.builder() | |
| 454 | .courseId(courseId) | |
| 455 | .courseRepository(courseRepository) | |
| 456 | .teamRepository(teamRepository) | |
| 457 | .teamMemberRepository(teamMemberRepository) | |
| 458 | .githubTeamService(githubTeamService) | |
| 459 | .build(); | |
| 460 | jobService.runAsJob(pushTeamsToGithubJob); | |
| 461 | } | |
| 462 | } | |
Mutations | ||
| 89 |
1.1 |
|
| 121 |
1.1 |
|
| 125 |
1.1 |
|
| 132 |
1.1 |
|
| 160 |
1.1 |
|
| 176 |
1.1 |
|
| 178 |
1.1 |
|
| 181 |
1.1 |
|
| 192 |
1.1 |
|
| 194 |
1.1 2.2 |
|
| 195 |
1.1 |
|
| 197 |
1.1 |
|
| 212 |
1.1 |
|
| 229 |
1.1 |
|
| 237 |
1.1 |
|
| 252 |
1.1 |
|
| 253 |
1.1 |
|
| 269 |
1.1 |
|
| 272 |
1.1 |
|
| 274 |
1.1 |
|
| 278 |
1.1 |
|
| 284 |
1.1 |
|
| 286 |
1.1 |
|
| 287 |
1.1 |
|
| 308 |
1.1 |
|
| 313 |
1.1 |
|
| 315 |
1.1 |
|
| 319 |
1.1 |
|
| 323 |
1.1 |
|
| 329 |
1.1 |
|
| 338 |
1.1 |
|
| 357 |
1.1 |
|
| 362 |
1.1 |
|
| 365 |
1.1 |
|
| 391 |
1.1 2.2 |
|
| 393 |
1.1 2.2 |
|
| 394 |
1.1 |
|
| 399 |
1.1 |
|
| 400 |
1.1 |
|
| 412 |
1.1 |
|
| 416 |
1.1 |
|
| 419 |
1.1 |
|
| 424 |
1.1 2.2 |
|
| 426 |
1.1 |
|
| 428 |
1.1 2.2 |
|
| 431 |
1.1 |
|
| 432 |
1.1 |
|
| 437 |
1.1 |
|
| 439 |
1.1 |
|
| 445 |
1.1 |
|
| 447 |
1.1 |