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