UCSBCurriculumController.java

1
package edu.ucsb.cs156.courses.controllers;
2
3
import edu.ucsb.cs156.courses.documents.CoursePage;
4
import edu.ucsb.cs156.courses.documents.Primary;
5
import edu.ucsb.cs156.courses.repositories.UserRepository;
6
import edu.ucsb.cs156.courses.services.UCSBCurriculumService;
7
import edu.ucsb.cs156.courses.services.UpdateCoursesService;
8
import io.swagger.v3.oas.annotations.Operation;
9
import io.swagger.v3.oas.annotations.Parameter;
10
import io.swagger.v3.oas.annotations.tags.Tag;
11
import java.util.List;
12
import lombok.extern.slf4j.Slf4j;
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.http.ResponseEntity;
15
import org.springframework.web.bind.annotation.GetMapping;
16
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RequestParam;
18
import org.springframework.web.bind.annotation.RestController;
19
20
@Tag(name = "UCSBCurriculumController")
21
@RestController
22
@RequestMapping("/api/public")
23
@Slf4j
24
public class UCSBCurriculumController extends ApiController {
25
26
  @Autowired UserRepository userRepository;
27
  @Autowired UCSBCurriculumService ucsbCurriculumService;
28
  @Autowired UpdateCoursesService updateCoursesService;
29
30
  @Operation(
31
      summary =
32
          "Get course data (in original UCSB API format) for a given quarter, department, and level")
33
  @GetMapping(value = "/basicsearch", produces = "application/json")
34
  public ResponseEntity<String> basicsearch(
35
      @RequestParam String qtr, @RequestParam String dept, @RequestParam String level)
36
      throws Exception {
37
38
    String body = ucsbCurriculumService.getJSON(dept, qtr, level);
39
40 1 1. basicsearch : replaced return value with null for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::basicsearch → KILLED
    return ResponseEntity.ok().body(body);
41
  }
42
43
  /**
44
   * Get primaries for a given quarter, department, and level. This endpoint returns a list of
45
   * Primary objects.
46
   *
47
   * @param qtr the quarter in YYYYQ format
48
   * @param dept the department code (e.g., "CS")
49
   * @param level the course level (e.g., "UG" for undergraduate)
50
   * @return a list of Primary objects
51
   */
52
  @Operation(summary = "Get primaries for a given quarter, department, and level")
53
  @GetMapping(value = "/primaries", produces = "application/json")
54
  public List<Primary> primaries(
55
      @RequestParam String qtr, @RequestParam String dept, @RequestParam String level)
56
      throws Exception {
57
58
    CoursePage coursePage = ucsbCurriculumService.getCoursePage(dept, qtr, level);
59
    // Runs on a background thread (see UpdateCoursesService.upsertAsync); never blocks or fails
60
    // this response.
61 1 1. primaries : removed call to edu/ucsb/cs156/courses/services/UpdateCoursesService::upsertAsync → KILLED
    updateCoursesService.upsertAsync(coursePage.convertedSections(), qtr, dept);
62
63 1 1. primaries : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::primaries → KILLED
    return coursePage.getPrimaries();
64
  }
65
66
  @Operation(summary = "Get primaries for a given quarter and GE area")
67
  @GetMapping(value = "/primariesge", produces = "application/json")
68
  public List<Primary> primariesGE(@RequestParam String qtr, @RequestParam String area)
69
      throws Exception {
70
    CoursePage coursePage = ucsbCurriculumService.getCoursePageByGE(qtr, area);
71
    // GE results span many subjects; `area` only labels the in-memory Update returned by upsert,
72
    // which is never saved for user searches (fromJob = false).
73 1 1. primariesGE : removed call to edu/ucsb/cs156/courses/services/UpdateCoursesService::upsertAsync → KILLED
    updateCoursesService.upsertAsync(coursePage.convertedSections(), qtr, area);
74
75 1 1. primariesGE : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::primariesGE → KILLED
    return coursePage.getPrimaries();
76
  }
77
78
  // Backend for final exam info, similar to the above operation:
79
  @Operation(summary = "Get final exam information for a given quarter and course enrollment code")
80
  @GetMapping(value = "/finalsInfo", produces = "application/json")
81
  public ResponseEntity<String> finalsInfo(
82
      @RequestParam String quarterYYYYQ, @RequestParam String enrollCd)
83
      throws Exception { // Looks for quarter and code
84
85
    String body = ucsbCurriculumService.getFinalsInfo(quarterYYYYQ, enrollCd);
86
87 1 1. finalsInfo : replaced return value with null for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::finalsInfo → KILLED
    return ResponseEntity.ok().body(body);
88
  }
89
90
  @Operation(summary = "Get General Education areas, optionally filtered by collegeCode")
91
  @GetMapping(value = "/generalEducationInfo", produces = "application/json")
92
  public ResponseEntity<?> generalEducationInfo(
93
      @Parameter(description = "Enter either L&S, ENGR, or CRST")
94
          @RequestParam(value = "collegeCode", required = false)
95
          String collegeCode)
96
      throws Exception {
97
98 1 1. generalEducationInfo : negated conditional → KILLED
    if (collegeCode != null) {
99
      // returns List<String> of requirementCode
100
      List<String> codes = ucsbCurriculumService.getRequirementCodesByCollege(collegeCode);
101 1 1. generalEducationInfo : replaced return value with null for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::generalEducationInfo → KILLED
      return ResponseEntity.ok().body(codes);
102
    } else {
103
      // returns the full raw JSON array
104
      String body = ucsbCurriculumService.getGeneralEducationInfo();
105 1 1. generalEducationInfo : replaced return value with null for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::generalEducationInfo → KILLED
      return ResponseEntity.ok().body(body);
106
    }
107
  }
108
}

Mutations

40

1.1
Location : basicsearch
Killed by : edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests]/[method:test_search()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::basicsearch → KILLED

61

1.1
Location : primaries
Killed by : edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests]/[method:test_getPrimaries()]
removed call to edu/ucsb/cs156/courses/services/UpdateCoursesService::upsertAsync → KILLED

63

1.1
Location : primaries
Killed by : edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests]/[method:test_getPrimaries()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::primaries → KILLED

73

1.1
Location : primariesGE
Killed by : edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests]/[method:test_getPrimariesGE()]
removed call to edu/ucsb/cs156/courses/services/UpdateCoursesService::upsertAsync → KILLED

75

1.1
Location : primariesGE
Killed by : edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests]/[method:test_getPrimariesGE()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::primariesGE → KILLED

87

1.1
Location : finalsInfo
Killed by : edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests]/[method:test_finalsInfo()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::finalsInfo → KILLED

98

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

101

1.1
Location : generalEducationInfo
Killed by : edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests]/[method:test_generalEducationInfo_withCollegeCode()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::generalEducationInfo → KILLED

105

1.1
Location : generalEducationInfo
Killed by : edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.UCSBCurriculumControllerTests]/[method:test_generalEducationInfo_noCollegeCode()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/UCSBCurriculumController::generalEducationInfo → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1