1
|
|
package edu.ucsb.cs156.courses.services; |
2
|
|
|
3
|
|
import edu.ucsb.cs156.courses.entities.UCSBAPIQuarter; |
4
|
|
import edu.ucsb.cs156.courses.repositories.UCSBAPIQuarterRepository; |
5
|
|
import java.time.LocalDateTime; |
6
|
|
import java.util.Optional; |
7
|
|
import lombok.extern.slf4j.Slf4j; |
8
|
|
import org.springframework.beans.factory.annotation.Autowired; |
9
|
|
import org.springframework.beans.factory.annotation.Value; |
10
|
|
import org.springframework.boot.context.properties.ConfigurationProperties; |
11
|
|
import org.springframework.stereotype.Service; |
12
|
|
|
13
|
|
@Slf4j |
14
|
|
@Service("IsStaleService") |
15
|
|
@ConfigurationProperties |
16
|
|
public class IsStaleService { |
17
|
|
|
18
|
|
@Value("#{new Integer('${app.courseDataStaleThresholdMinutes:1440}')}") |
19
|
|
private Integer courseDataStaleThresholdMinutes; |
20
|
|
|
21
|
|
@Autowired private UCSBAPIQuarterService ucsbApiQuarterService; |
22
|
|
@Autowired private UCSBAPIQuarterRepository ucsbApiQuarterRepository; |
23
|
|
@Autowired private UpdateService updateService; |
24
|
|
|
25
|
|
public int getCourseDataStaleThresholdMinutes() { |
26
|
1
1. getCourseDataStaleThresholdMinutes : replaced int return with 0 for edu/ucsb/cs156/courses/services/IsStaleService::getCourseDataStaleThresholdMinutes → KILLED
|
return courseDataStaleThresholdMinutes; |
27
|
|
} |
28
|
|
|
29
|
|
/** |
30
|
|
* Check if the data is stale for a given subject area and quarter |
31
|
|
* |
32
|
|
* @param subjectArea e.g. CMPSC |
33
|
|
* @param quarterYYYYQ e.g. 20221 for Winter 2022 |
34
|
|
* @return true if the data is stale, false otherwise |
35
|
|
* @throws Exception |
36
|
|
*/ |
37
|
|
public boolean isStale(String subjectArea, String quarterYYYYQ) throws Exception { |
38
|
|
|
39
|
|
Optional<LocalDateTime> lastUpdateOptional = |
40
|
|
updateService.getLastUpdate(subjectArea, quarterYYYYQ); |
41
|
1
1. isStale : negated conditional → KILLED
|
if (lastUpdateOptional.isEmpty()) { |
42
|
1
1. isStale : replaced boolean return with false for edu/ucsb/cs156/courses/services/IsStaleService::isStale → KILLED
|
return true; // no update found, so data has never been loaded |
43
|
|
} |
44
|
|
LocalDateTime lastUpdate = lastUpdateOptional.get(); |
45
|
|
|
46
|
|
String currentQuarterYYYYQ = ucsbApiQuarterService.getCurrentQuarterYYYYQ(); |
47
|
|
|
48
|
|
// is the quarter in the past? |
49
|
2
1. isStale : negated conditional → KILLED
2. isStale : changed conditional boundary → KILLED
|
if (quarterYYYYQ.compareTo(currentQuarterYYYYQ) < 0) { |
50
|
|
// this quarter is in the past |
51
|
|
// check if the last update was after last day of that quarter |
52
|
|
Optional<UCSBAPIQuarter> optionalQuarter = |
53
|
|
ucsbApiQuarterRepository.findByQuarter(quarterYYYYQ); |
54
|
1
1. isStale : negated conditional → KILLED
|
if (optionalQuarter.isEmpty()) { |
55
|
1
1. isStale : replaced boolean return with false for edu/ucsb/cs156/courses/services/IsStaleService::isStale → KILLED
|
return true; // quarter not found |
56
|
|
} |
57
|
|
// Data is stale if the last update was before the last day of the quarter |
58
|
|
UCSBAPIQuarter quarter = optionalQuarter.get(); |
59
|
|
LocalDateTime lastDayOfQuarter = quarter.getLastDayOfSchedule(); |
60
|
2
1. isStale : replaced boolean return with true for edu/ucsb/cs156/courses/services/IsStaleService::isStale → KILLED
2. isStale : replaced boolean return with false for edu/ucsb/cs156/courses/services/IsStaleService::isStale → KILLED
|
return lastUpdate.isBefore(lastDayOfQuarter); |
61
|
|
} |
62
|
|
// This quarter is the current quarter or in the future |
63
|
|
// So data becomes stale at last update + app. |
64
|
|
|
65
|
|
LocalDateTime staleTime = lastUpdate.plusMinutes(courseDataStaleThresholdMinutes); |
66
|
|
LocalDateTime now = LocalDateTime.now(); |
67
|
2
1. isStale : replaced boolean return with true for edu/ucsb/cs156/courses/services/IsStaleService::isStale → KILLED
2. isStale : replaced boolean return with false for edu/ucsb/cs156/courses/services/IsStaleService::isStale → KILLED
|
return now.isAfter(staleTime); |
68
|
|
} |
69
|
|
} |
| | Mutations |
26 |
|
1.1 Location : getCourseDataStaleThresholdMinutes Killed by : edu.ucsb.cs156.courses.services.IsStaleServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.IsStaleServiceTests]/[method:test_getCourseDataStaleThresholdMinutes()] replaced int return with 0 for edu/ucsb/cs156/courses/services/IsStaleService::getCourseDataStaleThresholdMinutes → KILLED
|
41 |
|
1.1 Location : isStale Killed by : edu.ucsb.cs156.courses.services.IsStaleServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.IsStaleServiceTests]/[method:test_getLastUpdate__no_update_exists__true()] negated conditional → KILLED
|
42 |
|
1.1 Location : isStale Killed by : edu.ucsb.cs156.courses.services.IsStaleServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.IsStaleServiceTests]/[method:test_getLastUpdate__no_update_exists__true()] replaced boolean return with false for edu/ucsb/cs156/courses/services/IsStaleService::isStale → KILLED
|
49 |
|
1.1 Location : isStale Killed by : edu.ucsb.cs156.courses.services.IsStaleServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.IsStaleServiceTests]/[method:test_getLastUpdate__update_exists__past_quarter__updated_after_end_of_quarter()] negated conditional → KILLED
2.2 Location : isStale Killed by : edu.ucsb.cs156.courses.services.IsStaleServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.IsStaleServiceTests]/[method:test_getLastUpdate__update_exists__current_quarter__recent_update()] changed conditional boundary → KILLED
|
54 |
|
1.1 Location : isStale Killed by : edu.ucsb.cs156.courses.services.IsStaleServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.IsStaleServiceTests]/[method:test_getLastUpdate__update_exists__details_for_quarter_do_not_exist__default_to_stale()] negated conditional → KILLED
|
55 |
|
1.1 Location : isStale Killed by : edu.ucsb.cs156.courses.services.IsStaleServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.IsStaleServiceTests]/[method:test_getLastUpdate__update_exists__details_for_quarter_do_not_exist__default_to_stale()] replaced boolean return with false for edu/ucsb/cs156/courses/services/IsStaleService::isStale → KILLED
|
60 |
|
1.1 Location : isStale Killed by : edu.ucsb.cs156.courses.services.IsStaleServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.IsStaleServiceTests]/[method:test_getLastUpdate__update_exists__past_quarter__updated_after_end_of_quarter()] replaced boolean return with true for edu/ucsb/cs156/courses/services/IsStaleService::isStale → KILLED
2.2 Location : isStale Killed by : edu.ucsb.cs156.courses.services.IsStaleServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.IsStaleServiceTests]/[method:test_getLastUpdate__update_exists__past_quarter__updated_before_end_of_quarter()] replaced boolean return with false for edu/ucsb/cs156/courses/services/IsStaleService::isStale → KILLED
|
67 |
|
1.1 Location : isStale Killed by : edu.ucsb.cs156.courses.services.IsStaleServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.IsStaleServiceTests]/[method:test_getLastUpdate__update_exists__current_quarter__recent_update()] replaced boolean return with true for edu/ucsb/cs156/courses/services/IsStaleService::isStale → KILLED
2.2 Location : isStale Killed by : edu.ucsb.cs156.courses.services.IsStaleServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.IsStaleServiceTests]/[method:test_getLastUpdate__update_exists__current_quarter__not_a_recent_update()] replaced boolean return with false for edu/ucsb/cs156/courses/services/IsStaleService::isStale → KILLED
|