CourseOverTimeInstructorController.java

1
package edu.ucsb.cs156.courses.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
import edu.ucsb.cs156.courses.collections.ConvertedSectionCollection;
6
import edu.ucsb.cs156.courses.documents.ConvertedSection;
7
import edu.ucsb.cs156.courses.documents.Primary;
8
import io.swagger.v3.oas.annotations.Operation;
9
import io.swagger.v3.oas.annotations.Parameter;
10
import java.util.List;
11
import java.util.Set;
12
import java.util.stream.Collectors;
13
import java.util.stream.Stream;
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.http.ResponseEntity;
16
import org.springframework.web.bind.annotation.GetMapping;
17
import org.springframework.web.bind.annotation.RequestMapping;
18
import org.springframework.web.bind.annotation.RequestParam;
19
import org.springframework.web.bind.annotation.RestController;
20
21
@RestController
22
@RequestMapping("/api/public/courseovertime")
23
public class CourseOverTimeInstructorController {
24
25
  private ObjectMapper mapper = new ObjectMapper();
26
27
  @Autowired ConvertedSectionCollection convertedSectionCollection;
28
29
  @Operation(summary = "Get a list of courses over time, filtered by instructor name")
30
  @GetMapping(value = "/instructorsearch", produces = "application/json")
31
  public ResponseEntity<String> search(
32
      @Parameter(
33
              name = "startQtr",
34
              description =
35
                  "Starting quarter in yyyyq format, e.g. 20231 for W23, 20232 for S23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)",
36
              example = "20231",
37
              required = true)
38
          @RequestParam
39
          String startQtr,
40
      @Parameter(
41
              name = "endQtr",
42
              description =
43
                  "Ending quarter in yyyyq format, e.g. 20231 for W23, 20232 for S23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)",
44
              example = "20231",
45
              required = true)
46
          @RequestParam
47
          String endQtr,
48
      @Parameter(
49
              name = "instructor",
50
              description = "Instructor name; e.g. 'conrad' or 'CONRAD' or 'CONRAD P T'",
51
              example = "CONRAD",
52
              required = true)
53
          @RequestParam
54
          String instructor,
55
      @Parameter(
56
              name = "lectureOnly",
57
              description = "Lectures only",
58
              example = "true",
59
              required = true)
60
          @RequestParam
61
          boolean lectureOnly)
62
      throws JsonProcessingException {
63 1 1. search : negated conditional → KILLED
    String functionCode = lectureOnly ? "^(Teaching and in charge)" : "^.*";
64
    List<ConvertedSection> matches =
65
        convertedSectionCollection.findByQuarterRangeAndInstructor(
66
            startQtr, endQtr, "^" + instructor.toUpperCase(), functionCode);
67
68
    // Discussion sections usually list only TAs, so they rarely match the instructor themselves.
69
    // Fetch every section of the matched courses, group them under their lectures, and keep
70
    // the lectures where the instructor teaches the lecture or one of its sections.
71
    Set<String> matchedSections =
72
        matches.stream()
73 1 1. lambda$search$0 : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::lambda$search$0 → KILLED
            .map(cs -> cs.getCourseInfo().getQuarter() + cs.getSection().getEnrollCode())
74
            .collect(Collectors.toSet());
75
    List<String> courseIds =
76 1 1. lambda$search$1 : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::lambda$search$1 → KILLED
        matches.stream().map(cs -> cs.getCourseInfo().getCourseId()).distinct().toList();
77
78
    List<Primary> primaries =
79
        Primary.fromConvertedSections(
80
                convertedSectionCollection.findByQuarterRangeAndCourseIdIn(
81
                    startQtr, endQtr, courseIds))
82
            .stream()
83
            .filter(
84
                p ->
85 2 1. lambda$search$2 : replaced boolean return with true for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::lambda$search$2 → KILLED
2. lambda$search$2 : replaced boolean return with false for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::lambda$search$2 → KILLED
                    Stream.concat(Stream.of(p.getPrimary()), p.getSubRows().stream())
86
                        .anyMatch(
87 2 1. lambda$search$3 : replaced boolean return with true for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::lambda$search$3 → KILLED
2. lambda$search$3 : replaced boolean return with false for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::lambda$search$3 → KILLED
                            s -> matchedSections.contains(p.getQuarter() + s.getEnrollCode())))
88
            .toList();
89
90
    String body = mapper.writeValueAsString(primaries);
91 1 1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::search → KILLED
    return ResponseEntity.ok().body(body);
92
  }
93
}

Mutations

63

1.1
Location : search
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests]/[method:test_search_matchOnDiscussionSection_returnsWholeLecture()]
negated conditional → KILLED

73

1.1
Location : lambda$search$0
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests]/[method:test_search_matchOnDiscussionSection_returnsWholeLecture()]
replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::lambda$search$0 → KILLED

76

1.1
Location : lambda$search$1
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests]/[method:test_search_matchOnDiscussionSection_returnsWholeLecture()]
replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::lambda$search$1 → KILLED

85

1.1
Location : lambda$search$2
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests]/[method:test_search_lectureOnly_returnsLectureWithItsDiscussionSections()]
replaced boolean return with true for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::lambda$search$2 → KILLED

2.2
Location : lambda$search$2
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests]/[method:test_search_matchOnDiscussionSection_returnsWholeLecture()]
replaced boolean return with false for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::lambda$search$2 → KILLED

87

1.1
Location : lambda$search$3
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests]/[method:test_search_lectureOnly_returnsLectureWithItsDiscussionSections()]
replaced boolean return with true for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::lambda$search$3 → KILLED

2.2
Location : lambda$search$3
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests]/[method:test_search_matchOnDiscussionSection_returnsWholeLecture()]
replaced boolean return with false for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::lambda$search$3 → KILLED

91

1.1
Location : search
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeInstructorControllerTests]/[method:test_search_noMatches_returnsEmptyList()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeInstructorController::search → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1