1 | package edu.ucsb.cs156.courses.services; | |
2 | ||
3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
4 | import com.fasterxml.jackson.core.type.TypeReference; | |
5 | import com.fasterxml.jackson.databind.ObjectMapper; | |
6 | import edu.ucsb.cs156.courses.entities.UCSBSubject; | |
7 | import java.util.List; | |
8 | import lombok.extern.slf4j.Slf4j; | |
9 | import org.springframework.beans.factory.annotation.Autowired; | |
10 | import org.springframework.beans.factory.annotation.Value; | |
11 | import org.springframework.boot.web.client.RestTemplateBuilder; | |
12 | import org.springframework.http.HttpEntity; | |
13 | import org.springframework.http.HttpHeaders; | |
14 | import org.springframework.http.HttpMethod; | |
15 | import org.springframework.http.MediaType; | |
16 | import org.springframework.http.ResponseEntity; | |
17 | import org.springframework.stereotype.Service; | |
18 | import org.springframework.web.client.RestTemplate; | |
19 | ||
20 | @Slf4j | |
21 | @Service("UCSBSubjects") | |
22 | public class UCSBSubjectsService { | |
23 | ||
24 | @Autowired private ObjectMapper mapper; | |
25 | ||
26 | @Value("${app.ucsb.api.consumer_key}") | |
27 | private String apiKey; | |
28 | ||
29 | public static final String ENDPOINT = | |
30 | "https://api.ucsb.edu/students/lookups/v1/subjects?includeInactive=false"; | |
31 | ||
32 | private final RestTemplate restTemplate; | |
33 | ||
34 | public UCSBSubjectsService(RestTemplateBuilder restTemplateBuilder) { | |
35 | restTemplate = restTemplateBuilder.build(); | |
36 | } | |
37 | ||
38 | public List<UCSBSubject> get() throws JsonProcessingException { | |
39 | ||
40 | HttpHeaders headers = new HttpHeaders(); | |
41 |
1
1. get : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED |
headers.setAccept(List.of(MediaType.APPLICATION_JSON)); |
42 |
1
1. get : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED |
headers.setContentType(MediaType.APPLICATION_JSON); |
43 |
1
1. get : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-key", this.apiKey); |
44 | ||
45 | HttpEntity<String> entity = new HttpEntity<>(headers); | |
46 | ResponseEntity<String> re = | |
47 | restTemplate.exchange(ENDPOINT, HttpMethod.GET, entity, String.class); | |
48 | ||
49 | String retBody = re.getBody(); | |
50 | List<UCSBSubject> subjects = | |
51 | mapper.readValue(retBody, new TypeReference<List<UCSBSubject>>() {}); | |
52 | ||
53 |
1
1. get : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/services/UCSBSubjectsService::get → KILLED |
return subjects; |
54 | } | |
55 | } | |
Mutations | ||
41 |
1.1 |
|
42 |
1.1 |
|
43 |
1.1 |
|
53 |
1.1 |