1 | package edu.ucsb.cs156.spring.backenddemo.services; | |
2 | ||
3 | ||
4 | ||
5 | import com.fasterxml.jackson.databind.ObjectMapper; | |
6 | ||
7 | import org.springframework.web.client.RestTemplate; | |
8 | ||
9 | import lombok.extern.slf4j.Slf4j; | |
10 | ||
11 | import java.util.List; | |
12 | import java.util.Map; | |
13 | ||
14 | import org.springframework.boot.web.client.RestTemplateBuilder; | |
15 | import org.springframework.http.HttpEntity; | |
16 | import org.springframework.http.HttpHeaders; | |
17 | import org.springframework.http.HttpMethod; | |
18 | import org.springframework.http.MediaType; | |
19 | import org.springframework.http.ResponseEntity; | |
20 | import org.springframework.stereotype.Service; | |
21 | import org.springframework.web.client.HttpClientErrorException; | |
22 | ||
23 | ||
24 | @Slf4j | |
25 | @Service | |
26 | public class TidesQueryService { | |
27 | ||
28 | ObjectMapper mapper = new ObjectMapper(); | |
29 | ||
30 | private final RestTemplate restTemplate; | |
31 | ||
32 | public TidesQueryService(RestTemplateBuilder restTemplateBuilder) { | |
33 | restTemplate = restTemplateBuilder.build(); | |
34 | ||
35 | } | |
36 | ||
37 | public static final String ENDPOINT = "https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?application=ucsb-cs156&begin_date={beginDate}&end_date={endDate}&station={station}&product=predictions&datum=mllw&units=english&time_zone=lst_ldt&interval=hilo&format=json"; | |
38 | ||
39 | public String getJSON(String beginDate, String endDate, String station) throws HttpClientErrorException { | |
40 | log.info("beginDate={}, endDate={}, station={}", beginDate, endDate, station); | |
41 | HttpHeaders headers = new HttpHeaders(); | |
42 |
1
1. getJSON : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED |
headers.setAccept(List.of(MediaType.APPLICATION_JSON)); |
43 |
1
1. getJSON : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED |
headers.setContentType(MediaType.APPLICATION_JSON); |
44 | ||
45 | HttpEntity<String> entity = new HttpEntity<>(headers); | |
46 | ||
47 | Map<String, String> uriVariables = Map.of("beginDate", beginDate, "endDate", endDate, "station", station); | |
48 | ||
49 | ResponseEntity<String> re = restTemplate.exchange(ENDPOINT, HttpMethod.GET, entity, String.class, | |
50 | uriVariables); | |
51 |
1
1. getJSON : replaced return value with "" for edu/ucsb/cs156/spring/backenddemo/services/TidesQueryService::getJSON → KILLED |
return re.getBody(); |
52 | } | |
53 | } | |
Mutations | ||
42 |
1.1 |
|
43 |
1.1 |
|
51 |
1.1 |