| 1 | package edu.ucsb.cs156.courses.services; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.type.TypeReference; | |
| 4 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 5 | import edu.ucsb.cs156.courses.documents.ConvertedSection; | |
| 6 | import edu.ucsb.cs156.courses.documents.CoursePage; | |
| 7 | import edu.ucsb.cs156.courses.documents.GERequirement; | |
| 8 | import edu.ucsb.cs156.courses.documents.Primary; | |
| 9 | import java.time.Duration; | |
| 10 | import java.util.ArrayList; | |
| 11 | import java.util.Arrays; | |
| 12 | import java.util.HashMap; | |
| 13 | import java.util.List; | |
| 14 | import java.util.Map; | |
| 15 | import java.util.stream.Collectors; | |
| 16 | import lombok.extern.slf4j.Slf4j; | |
| 17 | import org.springframework.beans.factory.annotation.Autowired; | |
| 18 | import org.springframework.beans.factory.annotation.Value; | |
| 19 | import org.springframework.boot.web.client.RestTemplateBuilder; | |
| 20 | import org.springframework.http.HttpEntity; | |
| 21 | import org.springframework.http.HttpHeaders; | |
| 22 | import org.springframework.http.HttpMethod; | |
| 23 | import org.springframework.http.HttpStatus; | |
| 24 | import org.springframework.http.MediaType; | |
| 25 | import org.springframework.http.ResponseEntity; | |
| 26 | import org.springframework.stereotype.Service; | |
| 27 | import org.springframework.web.client.RestTemplate; | |
| 28 | ||
| 29 | /** Service object that wraps the UCSB Academic Curriculum API */ | |
| 30 | @Service | |
| 31 | @Slf4j | |
| 32 | public class UCSBCurriculumService { | |
| 33 | ||
| 34 | @Autowired private ObjectMapper objectMapper; | |
| 35 | ||
| 36 | @Autowired private ConvertedSectionUpsertService upsertService; | |
| 37 | ||
| 38 | @Value("${app.ucsb.api.consumer_key}") | |
| 39 | private String apiKey; | |
| 40 | ||
| 41 | @Value("${app.ucsb.api.host}") | |
| 42 | private String apiHost; | |
| 43 | ||
| 44 | private static final Duration CONNECT_TIMEOUT = Duration.ofSeconds(10); | |
| 45 | private static final Duration READ_TIMEOUT = Duration.ofSeconds(60); | |
| 46 | ||
| 47 | private RestTemplate restTemplate = new RestTemplate(); | |
| 48 | ||
| 49 | public UCSBCurriculumService(RestTemplateBuilder restTemplateBuilder) throws Exception { | |
| 50 | restTemplate = | |
| 51 | restTemplateBuilder.connectTimeout(CONNECT_TIMEOUT).readTimeout(READ_TIMEOUT).build(); | |
| 52 | } | |
| 53 | ||
| 54 | public static final String CURRICULUM_ENDPOINT = | |
| 55 | "{apiHost}/academics/curriculums/v1/classes/search"; | |
| 56 | ||
| 57 | public static final String SUBJECTS_ENDPOINT = "{apiHost}/students/lookups/v1/subjects"; | |
| 58 | ||
| 59 | public static final String SECTION_ENDPOINT = | |
| 60 | "{apiHost}/academics/curriculums/v1/classsection/{quarter}/{enrollcode}"; | |
| 61 | ||
| 62 | public static final String ALL_SECTIONS_ENDPOINT = | |
| 63 | "{apiHost}/academics/curriculums/v3/classes/{quarter}/{enrollcode}"; | |
| 64 | ||
| 65 | public static final String FINALS_ENDPOINT = "{apiHost}/academics/curriculums/v3/finals"; | |
| 66 | ||
| 67 | public static final String GE_ENDPOINT = "{apiHost}/students/lookups/v1/requirements"; | |
| 68 | ||
| 69 | public String getJSON(String subjectArea, String quarter, String courseLevel) throws Exception { | |
| 70 |
1
1. getJSON : replaced return value with "" for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getJSON → KILLED |
return getJSON(subjectArea, quarter, courseLevel, 1); |
| 71 | } | |
| 72 | ||
| 73 | public String getJSON(String subjectArea, String quarter, String courseLevel, int pageNumber) | |
| 74 | throws Exception { | |
| 75 | ||
| 76 | HttpHeaders headers = new HttpHeaders(); | |
| 77 |
1
1. getJSON : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED |
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); |
| 78 |
1
1. getJSON : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED |
headers.setContentType(MediaType.APPLICATION_JSON); |
| 79 |
1
1. getJSON : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-version", "1.0"); |
| 80 |
1
1. getJSON : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-key", this.apiKey); |
| 81 | ||
| 82 | HttpEntity<String> entity = new HttpEntity<>("body", headers); | |
| 83 | ||
| 84 | String params = | |
| 85 | String.format( | |
| 86 | "?quarter=%s&subjectCode=%s&objLevelCode=%s&pageNumber=%d&pageSize=%d&includeClassSections=%s", | |
| 87 | quarter, subjectArea, courseLevel, pageNumber, 100, "true"); | |
| 88 | String url = CURRICULUM_ENDPOINT + params; | |
| 89 | ||
| 90 |
1
1. getJSON : negated conditional → KILLED |
if (courseLevel.equals("A")) { |
| 91 | params = | |
| 92 | String.format( | |
| 93 | "?quarter=%s&subjectCode=%s&pageNumber=%d&pageSize=%d&includeClassSections=%s", | |
| 94 | quarter, subjectArea, pageNumber, 100, "true"); | |
| 95 | url = CURRICULUM_ENDPOINT + params; | |
| 96 | } | |
| 97 | ||
| 98 | url = url.replace("{apiHost}", apiHost); | |
| 99 | ||
| 100 | log.info("url=" + url); | |
| 101 | ||
| 102 | String retVal = ""; | |
| 103 | MediaType contentType = null; | |
| 104 | HttpStatus statusCode = null; | |
| 105 | ||
| 106 | ResponseEntity<String> re = restTemplate.exchange(url, HttpMethod.GET, entity, String.class); | |
| 107 | contentType = re.getHeaders().getContentType(); | |
| 108 | statusCode = (HttpStatus) re.getStatusCode(); | |
| 109 | retVal = re.getBody(); | |
| 110 | ||
| 111 | log.trace("json: {}", retVal); | |
| 112 | log.info("contentType: {} statusCode: {}", contentType, statusCode); | |
| 113 |
1
1. getJSON : replaced return value with "" for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getJSON → KILLED |
return retVal; |
| 114 | } | |
| 115 | ||
| 116 | public List<ConvertedSection> getConvertedSections( | |
| 117 | String subjectArea, String quarter, String courseLevel) throws Exception { | |
| 118 | List<ConvertedSection> result = new ArrayList<>(); | |
| 119 | int pageNumber = 1; | |
| 120 | int coursesRead = 0; | |
| 121 | int totalCourses = -1; | |
| 122 | ||
| 123 | do { | |
| 124 | String json = getJSON(subjectArea, quarter, courseLevel, pageNumber); | |
| 125 | CoursePage coursePage = objectMapper.readValue(json, CoursePage.class); | |
| 126 | ||
| 127 |
1
1. getConvertedSections : negated conditional → KILLED |
if (pageNumber == 1) { |
| 128 | totalCourses = coursePage.getTotal(); | |
| 129 | } | |
| 130 | ||
| 131 |
2
1. getConvertedSections : negated conditional → KILLED 2. getConvertedSections : negated conditional → KILLED |
if (coursePage.getPageNumber() != pageNumber || coursePage.getTotal() != totalCourses) { |
| 132 | throw new IllegalStateException("Inconsistent course pagination"); | |
| 133 | } | |
| 134 | ||
| 135 | int coursesOnPage = coursePage.getClasses().size(); | |
| 136 |
3
1. getConvertedSections : changed conditional boundary → KILLED 2. getConvertedSections : negated conditional → KILLED 3. getConvertedSections : negated conditional → KILLED |
if (coursesOnPage == 0 && coursesRead < totalCourses) { |
| 137 | throw new IllegalStateException("Course data ended before the reported total"); | |
| 138 | } | |
| 139 | ||
| 140 |
1
1. getConvertedSections : Replaced integer addition with subtraction → KILLED |
coursesRead += coursesOnPage; |
| 141 | result.addAll(coursePage.convertedSections()); | |
| 142 |
1
1. getConvertedSections : Changed increment from 1 to -1 → KILLED |
pageNumber++; |
| 143 |
2
1. getConvertedSections : changed conditional boundary → KILLED 2. getConvertedSections : negated conditional → KILLED |
} while (coursesRead < totalCourses); |
| 144 | ||
| 145 |
1
1. getConvertedSections : negated conditional → KILLED |
if (coursesRead != totalCourses) { |
| 146 | throw new IllegalStateException("Course count does not match the reported total"); | |
| 147 | } | |
| 148 | ||
| 149 |
1
1. getConvertedSections : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getConvertedSections → KILLED |
return result; |
| 150 | } | |
| 151 | ||
| 152 | /** | |
| 153 | * This method retrieves course information and reformats it so that each primary is a single | |
| 154 | * object, that has a list of all of it's secondaries. | |
| 155 | * | |
| 156 | * <p>As a reminder, the UCSB course registration systems (GOLD, Blue, Star, etc.) treat all | |
| 157 | * courses as "sections", even what we typically call "lectures". In the database, some courses | |
| 158 | * have both primary and secondary sections. Primary sections have section numbers ending in 00 | |
| 159 | * (e.g. 100, 200, 300, up to 9900), while secondaries have numbers ending with 01, 02, 03, etc. | |
| 160 | * and "belong" with a primary. | |
| 161 | * | |
| 162 | * <p>What we typically refer to as "lectures" are primary sections ending in 00 (e.g. 100, 200, | |
| 163 | * 300). What we typically refer to as discussion sections are secondaries and end with 01, 02, | |
| 164 | * 03, etc. | |
| 165 | * | |
| 166 | * <p> | |
| 167 | * | |
| 168 | * <p>The UCSB API <i>almost</i> does this, but not quite. It returns a list of all sections, but | |
| 169 | * does not group them into primaries and secondaries. This method relies on the <code> | |
| 170 | * getPrimaries</code> method of the <code>Page</code> class to reformat the data so that each | |
| 171 | * primary section is a single object, with a list of all of its secondaries. | |
| 172 | * | |
| 173 | * @param subjectArea | |
| 174 | * @param quarter | |
| 175 | * @param courseLevel | |
| 176 | * @return a list of Primaries | |
| 177 | * @throws Exception | |
| 178 | */ | |
| 179 | public List<Primary> getPrimaries(String subjectArea, String quarter, String courseLevel) | |
| 180 | throws Exception { | |
| 181 | String json = getJSON(subjectArea, quarter, courseLevel); | |
| 182 | CoursePage coursePage = objectMapper.readValue(json, CoursePage.class); | |
| 183 | for (ConvertedSection section : coursePage.convertedSections()) { | |
| 184 | try { | |
| 185 |
1
1. getPrimaries : removed call to edu/ucsb/cs156/courses/services/ConvertedSectionUpsertService::upsert → KILLED |
upsertService.upsert(section); |
| 186 | } catch (RuntimeException e) { | |
| 187 | log.warn("Unable to cache course section from live search", e); | |
| 188 | } | |
| 189 | } | |
| 190 | List<Primary> result = coursePage.getPrimaries(); | |
| 191 |
1
1. getPrimaries : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getPrimaries → KILLED |
return result; |
| 192 | } | |
| 193 | ||
| 194 | public String getJSONByGE(String quarter, String area) throws Exception { | |
| 195 | HttpHeaders headers = new HttpHeaders(); | |
| 196 |
1
1. getJSONByGE : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED |
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); |
| 197 |
1
1. getJSONByGE : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED |
headers.setContentType(MediaType.APPLICATION_JSON); |
| 198 |
1
1. getJSONByGE : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-version", "1.0"); |
| 199 |
1
1. getJSONByGE : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-key", this.apiKey); |
| 200 | ||
| 201 | HttpEntity<String> entity = new HttpEntity<>("body", headers); | |
| 202 | ||
| 203 | String params = | |
| 204 | String.format("?quarter=%s&areas=%s&pageNumber=%d&pageSize=%d", quarter, area, 1, 500); | |
| 205 | String url = (CURRICULUM_ENDPOINT + params).replace("{apiHost}", apiHost); | |
| 206 | ||
| 207 | log.info("url=" + url); | |
| 208 | ||
| 209 | String retVal = ""; | |
| 210 | MediaType contentType = null; | |
| 211 | HttpStatus statusCode = null; | |
| 212 | ||
| 213 | ResponseEntity<String> re = restTemplate.exchange(url, HttpMethod.GET, entity, String.class); | |
| 214 | contentType = re.getHeaders().getContentType(); | |
| 215 | statusCode = (HttpStatus) re.getStatusCode(); | |
| 216 | retVal = re.getBody(); | |
| 217 | ||
| 218 | log.trace("json: {}", retVal); | |
| 219 | log.info("contentType: {} statusCode: {}", contentType, statusCode); | |
| 220 |
1
1. getJSONByGE : replaced return value with "" for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getJSONByGE → KILLED |
return retVal; |
| 221 | } | |
| 222 | ||
| 223 | public List<Primary> getPrimariesByGE(String quarter, String area) throws Exception { | |
| 224 | String json = getJSONByGE(quarter, area); | |
| 225 | CoursePage coursePage = objectMapper.readValue(json, CoursePage.class); | |
| 226 | List<Primary> result = coursePage.getPrimaries(); | |
| 227 |
1
1. getPrimariesByGE : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getPrimariesByGE → KILLED |
return result; |
| 228 | } | |
| 229 | ||
| 230 | public String getSectionJSON(String subjectArea, String quarter, String courseLevel) | |
| 231 | throws Exception { | |
| 232 | List<ConvertedSection> l = getConvertedSections(subjectArea, quarter, courseLevel); | |
| 233 | ||
| 234 | String arrayToJson = objectMapper.writeValueAsString(l); | |
| 235 | ||
| 236 |
1
1. getSectionJSON : replaced return value with "" for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getSectionJSON → KILLED |
return arrayToJson; |
| 237 | } | |
| 238 | ||
| 239 | public String getSubjectsJSON() throws Exception { | |
| 240 | ||
| 241 | HttpHeaders headers = new HttpHeaders(); | |
| 242 |
1
1. getSubjectsJSON : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED |
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); |
| 243 |
1
1. getSubjectsJSON : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED |
headers.setContentType(MediaType.APPLICATION_JSON); |
| 244 |
1
1. getSubjectsJSON : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-version", "1.0"); |
| 245 |
1
1. getSubjectsJSON : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-key", this.apiKey); |
| 246 | ||
| 247 | HttpEntity<String> entity = new HttpEntity<>("body", headers); | |
| 248 | ||
| 249 | String url = SUBJECTS_ENDPOINT.replace("{apiHost}", apiHost); | |
| 250 | ||
| 251 | log.info("url=" + url); | |
| 252 | ||
| 253 | String retVal = ""; | |
| 254 | MediaType contentType = null; | |
| 255 | HttpStatus statusCode = null; | |
| 256 | ||
| 257 | ResponseEntity<String> re = restTemplate.exchange(url, HttpMethod.GET, entity, String.class); | |
| 258 | contentType = re.getHeaders().getContentType(); | |
| 259 | statusCode = (HttpStatus) re.getStatusCode(); | |
| 260 | retVal = re.getBody(); | |
| 261 | ||
| 262 | log.info("json: {} contentType: {} statusCode: {}", retVal, contentType, statusCode); | |
| 263 |
1
1. getSubjectsJSON : replaced return value with "" for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getSubjectsJSON → KILLED |
return retVal; |
| 264 | } | |
| 265 | ||
| 266 | /** | |
| 267 | * This method retrieves exactly one section matching the enrollCode and quarter arguments, if | |
| 268 | * such a section exists. | |
| 269 | */ | |
| 270 | public String getSection(String enrollCode, String quarter) throws Exception { | |
| 271 | ||
| 272 | HttpHeaders headers = new HttpHeaders(); | |
| 273 |
1
1. getSection : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED |
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); |
| 274 |
1
1. getSection : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED |
headers.setContentType(MediaType.APPLICATION_JSON); |
| 275 |
1
1. getSection : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-version", "1.0"); |
| 276 |
1
1. getSection : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-key", this.apiKey); |
| 277 | ||
| 278 | HttpEntity<String> entity = new HttpEntity<>("body", headers); | |
| 279 | ||
| 280 | String url = SECTION_ENDPOINT.replace("{apiHost}", apiHost); | |
| 281 | ||
| 282 | log.info("url=" + url); | |
| 283 | ||
| 284 | Map<String, String> params = new HashMap<>(); | |
| 285 | params.put("quarter", quarter); | |
| 286 | params.put("enrollcode", enrollCode); | |
| 287 | ||
| 288 | String retVal = ""; | |
| 289 | MediaType contentType = null; | |
| 290 | HttpStatus statusCode = null; | |
| 291 | ||
| 292 | ResponseEntity<String> re = | |
| 293 | restTemplate.exchange(url, HttpMethod.GET, entity, String.class, params); | |
| 294 | contentType = re.getHeaders().getContentType(); | |
| 295 | statusCode = (HttpStatus) re.getStatusCode(); | |
| 296 | retVal = re.getBody(); | |
| 297 | ||
| 298 |
1
1. getSection : negated conditional → KILLED |
if (retVal.equals("null")) { |
| 299 | retVal = "{\"error\": \"Enroll code doesn't exist in that quarter.\"}"; | |
| 300 | } | |
| 301 | ||
| 302 | log.info("json: {} contentType: {} statusCode: {}", retVal, contentType, statusCode); | |
| 303 |
1
1. getSection : replaced return value with "" for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getSection → KILLED |
return retVal; |
| 304 | } | |
| 305 | ||
| 306 | /** | |
| 307 | * This method retrieves all of the sections related to a certain enroll code. For example, if the | |
| 308 | * enrollCode is for a discussion section, the lecture section and all related discussion sections | |
| 309 | * will also be returned. | |
| 310 | */ | |
| 311 | public String getAllSections(String enrollCode, String quarter) throws Exception { | |
| 312 | ||
| 313 | HttpHeaders headers = new HttpHeaders(); | |
| 314 |
1
1. getAllSections : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED |
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); |
| 315 |
1
1. getAllSections : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED |
headers.setContentType(MediaType.APPLICATION_JSON); |
| 316 |
1
1. getAllSections : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-version", "3.0"); |
| 317 |
1
1. getAllSections : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-key", this.apiKey); |
| 318 | ||
| 319 | HttpEntity<String> entity = new HttpEntity<>("body", headers); | |
| 320 | ||
| 321 | String url = ALL_SECTIONS_ENDPOINT.replace("{apiHost}", apiHost); | |
| 322 | ||
| 323 | log.info("url=" + url); | |
| 324 | ||
| 325 | Map<String, String> params = new HashMap<>(); | |
| 326 | params.put("quarter", quarter); | |
| 327 | params.put("enrollcode", enrollCode); | |
| 328 | ||
| 329 | String retVal = ""; | |
| 330 | MediaType contentType = null; | |
| 331 | HttpStatus statusCode = null; | |
| 332 | ||
| 333 | ResponseEntity<String> re = | |
| 334 | restTemplate.exchange(url, HttpMethod.GET, entity, String.class, params); | |
| 335 | contentType = re.getHeaders().getContentType(); | |
| 336 | statusCode = (HttpStatus) re.getStatusCode(); | |
| 337 | retVal = re.getBody(); | |
| 338 | ||
| 339 |
1
1. getAllSections : negated conditional → KILLED |
if (retVal.equals("null")) { |
| 340 | retVal = "{\"error\": \"Enroll code doesn't exist in that quarter.\"}"; | |
| 341 | } | |
| 342 | ||
| 343 | log.info("json: {} contentType: {} statusCode: {}", retVal, contentType, statusCode); | |
| 344 |
1
1. getAllSections : replaced return value with "" for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getAllSections → KILLED |
return retVal; |
| 345 | } | |
| 346 | ||
| 347 | public String getJSONbyQtrEnrollCd(String quarter, String enrollCd) throws Exception { | |
| 348 | ||
| 349 | HttpHeaders headers = new HttpHeaders(); | |
| 350 |
1
1. getJSONbyQtrEnrollCd : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED |
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); |
| 351 |
1
1. getJSONbyQtrEnrollCd : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED |
headers.setContentType(MediaType.APPLICATION_JSON); |
| 352 |
1
1. getJSONbyQtrEnrollCd : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-version", "1.0"); |
| 353 |
1
1. getJSONbyQtrEnrollCd : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-key", this.apiKey); |
| 354 | ||
| 355 | HttpEntity<String> entity = new HttpEntity<>("body", headers); | |
| 356 | ||
| 357 | String url = "{apiHost}/academics/curriculums/v3/classsection/" + quarter + "/" + enrollCd; | |
| 358 | url = url.replace("{apiHost}", apiHost); | |
| 359 | ||
| 360 | log.info("url=" + url); | |
| 361 | ||
| 362 | String retVal = ""; | |
| 363 | MediaType contentType = null; | |
| 364 | HttpStatus statusCode = null; | |
| 365 | ||
| 366 | ResponseEntity<String> re = restTemplate.exchange(url, HttpMethod.GET, entity, String.class); | |
| 367 | contentType = re.getHeaders().getContentType(); | |
| 368 | statusCode = (HttpStatus) re.getStatusCode(); | |
| 369 | retVal = re.getBody(); | |
| 370 | ||
| 371 | log.info("json: {} contentType: {} statusCode: {}", retVal, contentType, statusCode); | |
| 372 |
1
1. getJSONbyQtrEnrollCd : replaced return value with "" for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getJSONbyQtrEnrollCd → KILLED |
return retVal; |
| 373 | } | |
| 374 | ||
| 375 | public String getFinalsInfo(String quarter, String enrollCd) throws Exception { | |
| 376 | HttpHeaders headers = new HttpHeaders(); | |
| 377 |
1
1. getFinalsInfo : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED |
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); |
| 378 |
1
1. getFinalsInfo : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-version", "3.0"); |
| 379 |
1
1. getFinalsInfo : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-key", this.apiKey); |
| 380 | ||
| 381 | HttpEntity<String> entity = new HttpEntity<>("body", headers); | |
| 382 | ||
| 383 | String params = String.format("?quarter=%s&enrollCode=%s", quarter, enrollCd); | |
| 384 | String url = (FINALS_ENDPOINT + params).replace("{apiHost}", apiHost); | |
| 385 | ||
| 386 | log.info("url=" + url); | |
| 387 | ||
| 388 | String retVal; | |
| 389 | MediaType contentType; | |
| 390 | HttpStatus statusCode; | |
| 391 | ||
| 392 | ResponseEntity<String> re = restTemplate.exchange(url, HttpMethod.GET, entity, String.class); | |
| 393 | contentType = re.getHeaders().getContentType(); | |
| 394 | statusCode = (HttpStatus) re.getStatusCode(); | |
| 395 | retVal = re.getBody(); | |
| 396 | ||
| 397 | log.info("json: {} contentType: {} statusCode: {}", retVal, contentType, statusCode); | |
| 398 |
1
1. getFinalsInfo : replaced return value with "" for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getFinalsInfo → KILLED |
return retVal; |
| 399 | } | |
| 400 | ||
| 401 | public String getGeneralEducationInfo() throws Exception { | |
| 402 | HttpHeaders headers = new HttpHeaders(); | |
| 403 |
1
1. getGeneralEducationInfo : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED |
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); |
| 404 |
1
1. getGeneralEducationInfo : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED |
headers.setContentType(MediaType.APPLICATION_JSON); |
| 405 |
1
1. getGeneralEducationInfo : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-version", "1.0"); |
| 406 |
1
1. getGeneralEducationInfo : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-key", this.apiKey); |
| 407 | ||
| 408 | HttpEntity<String> entity = new HttpEntity<>("body", headers); | |
| 409 | ||
| 410 | String url = GE_ENDPOINT.replace("{apiHost}", apiHost); | |
| 411 | ||
| 412 | log.info("Fetching GE areas from {}", url); | |
| 413 | ResponseEntity<String> response = | |
| 414 | restTemplate.exchange(url, HttpMethod.GET, entity, String.class); | |
| 415 | ||
| 416 | log.debug("GE areas JSON: {}", response.getBody()); | |
| 417 |
1
1. getGeneralEducationInfo : replaced return value with "" for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getGeneralEducationInfo → KILLED |
return response.getBody(); |
| 418 | } | |
| 419 | ||
| 420 | public List<String> getRequirementCodesByCollege(String collegeCode) throws Exception { | |
| 421 | String json = getGeneralEducationInfo(); | |
| 422 | ||
| 423 | List<GERequirement> allAreas = | |
| 424 | objectMapper.readValue(json, new TypeReference<List<GERequirement>>() {}); | |
| 425 | ||
| 426 |
1
1. getRequirementCodesByCollege : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/services/UCSBCurriculumService::getRequirementCodesByCollege → KILLED |
return allAreas.stream() |
| 427 |
2
1. lambda$getRequirementCodesByCollege$0 : replaced boolean return with false for edu/ucsb/cs156/courses/services/UCSBCurriculumService::lambda$getRequirementCodesByCollege$0 → KILLED 2. lambda$getRequirementCodesByCollege$0 : replaced boolean return with true for edu/ucsb/cs156/courses/services/UCSBCurriculumService::lambda$getRequirementCodesByCollege$0 → KILLED |
.filter(area -> area.getCollegeCode().equalsIgnoreCase(collegeCode)) |
| 428 | .map(GERequirement::getRequirementCode) | |
| 429 | .distinct() | |
| 430 | .collect(Collectors.toList()); | |
| 431 | } | |
| 432 | } | |
Mutations | ||
| 70 |
1.1 |
|
| 77 |
1.1 |
|
| 78 |
1.1 |
|
| 79 |
1.1 |
|
| 80 |
1.1 |
|
| 90 |
1.1 |
|
| 113 |
1.1 |
|
| 127 |
1.1 |
|
| 131 |
1.1 2.2 |
|
| 136 |
1.1 2.2 3.3 |
|
| 140 |
1.1 |
|
| 142 |
1.1 |
|
| 143 |
1.1 2.2 |
|
| 145 |
1.1 |
|
| 149 |
1.1 |
|
| 185 |
1.1 |
|
| 191 |
1.1 |
|
| 196 |
1.1 |
|
| 197 |
1.1 |
|
| 198 |
1.1 |
|
| 199 |
1.1 |
|
| 220 |
1.1 |
|
| 227 |
1.1 |
|
| 236 |
1.1 |
|
| 242 |
1.1 |
|
| 243 |
1.1 |
|
| 244 |
1.1 |
|
| 245 |
1.1 |
|
| 263 |
1.1 |
|
| 273 |
1.1 |
|
| 274 |
1.1 |
|
| 275 |
1.1 |
|
| 276 |
1.1 |
|
| 298 |
1.1 |
|
| 303 |
1.1 |
|
| 314 |
1.1 |
|
| 315 |
1.1 |
|
| 316 |
1.1 |
|
| 317 |
1.1 |
|
| 339 |
1.1 |
|
| 344 |
1.1 |
|
| 350 |
1.1 |
|
| 351 |
1.1 |
|
| 352 |
1.1 |
|
| 353 |
1.1 |
|
| 372 |
1.1 |
|
| 377 |
1.1 |
|
| 378 |
1.1 |
|
| 379 |
1.1 |
|
| 398 |
1.1 |
|
| 403 |
1.1 |
|
| 404 |
1.1 |
|
| 405 |
1.1 |
|
| 406 |
1.1 |
|
| 417 |
1.1 |
|
| 426 |
1.1 |
|
| 427 |
1.1 2.2 |