CourseOverTimeDescriptionController.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 io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import java.util.ArrayList;
10
import java.util.List;
11
import java.util.regex.Pattern;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.http.ResponseEntity;
14
import org.springframework.web.bind.annotation.GetMapping;
15
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestParam;
17
import org.springframework.web.bind.annotation.RestController;
18
19
@RestController
20
@RequestMapping("/api/public/description")
21
public class CourseOverTimeDescriptionController {
22
23
  private ObjectMapper mapper = new ObjectMapper();
24
25
  @Autowired ConvertedSectionCollection convertedSectionCollection;
26
27
  @Operation(summary = "Get a list of courses over time, filtered by course title or description")
28
  @GetMapping(value = "/search", produces = "application/json")
29
  public ResponseEntity<String> search(
30
      @Parameter(
31
              name = "startQtr",
32
              description =
33
                  "Starting quarter in yyyyq format, e.g. 20232 for S23, 20234 for F23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)",
34
              example = "20232",
35
              required = true)
36
          @RequestParam
37
          String startQtr,
38
      @Parameter(
39
              name = "endQtr",
40
              description =
41
                  "Ending quarter in yyyyq format, e.g. 20232 for S23, 20234 for F23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)",
42
              example = "20232",
43
              required = true)
44
          @RequestParam
45
          String endQtr,
46
      @Parameter(
47
              name = "searchTerms",
48
              description =
49
                  "Search terms to filter by course title or description, e.g. 'data science', 'computer architecture', etc.",
50
              example = "Data",
51
              required = true)
52
          @RequestParam
53
          String searchTerms,
54
      @Parameter(
55
              name = "lectureOnly",
56
              description = "Lectures only",
57
              example = "true",
58
              required = true)
59
          @RequestParam
60
          boolean lectureOnly)
61
      throws JsonProcessingException {
62
    List<ConvertedSection> courseResults;
63 1 1. search : negated conditional → KILLED
    String sectionRegex = lectureOnly ? ".*00$" : ".*";
64
    String escapedSearchTerms = Pattern.quote(searchTerms);
65
66
    courseResults =
67
        new ArrayList<>(
68
            convertedSectionCollection.findByQuarterRangeAndSearchTerms(
69
                startQtr, endQtr, escapedSearchTerms, sectionRegex));
70
71 1 1. search : removed call to java/util/List::sort → KILLED
    courseResults.sort(new ConvertedSection.ConvertedSectionSortDescendingByQuarterComparator());
72
    String body = mapper.writeValueAsString(courseResults);
73 1 1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeDescriptionController::search → KILLED
    return ResponseEntity.ok().body(body);
74
  }
75
}

Mutations

63

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

71

1.1
Location : search
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeDescriptionControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeDescriptionControllerTests]/[method:test_search_validRequestOnlyLectures()]
removed call to java/util/List::sort → KILLED

73

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

Active mutators

Tests examined


Report generated by PIT 1.17.0