1 | package edu.ucsb.cs156.courses.jobs; | |
2 | ||
3 | import edu.ucsb.cs156.courses.collections.ConvertedSectionCollection; | |
4 | import edu.ucsb.cs156.courses.collections.UpdateCollection; | |
5 | import edu.ucsb.cs156.courses.documents.ConvertedSection; | |
6 | import edu.ucsb.cs156.courses.documents.Update; | |
7 | import edu.ucsb.cs156.courses.models.Quarter; | |
8 | import edu.ucsb.cs156.courses.repositories.EnrollmentDataPointRepository; | |
9 | import edu.ucsb.cs156.courses.services.IsStaleService; | |
10 | import edu.ucsb.cs156.courses.services.UCSBAPIQuarterService; | |
11 | import edu.ucsb.cs156.courses.services.UCSBCurriculumService; | |
12 | import edu.ucsb.cs156.courses.services.jobs.JobContext; | |
13 | import edu.ucsb.cs156.courses.services.jobs.JobContextConsumer; | |
14 | import edu.ucsb.cs156.courses.services.jobs.JobRateLimit; | |
15 | import java.util.List; | |
16 | import java.util.Optional; | |
17 | import lombok.AllArgsConstructor; | |
18 | import lombok.Builder; | |
19 | import lombok.Getter; | |
20 | import lombok.extern.slf4j.Slf4j; | |
21 | ||
22 | @Builder | |
23 | @Getter | |
24 | @AllArgsConstructor | |
25 | @Slf4j | |
26 | public class UpdateCourseDataJob implements JobContextConsumer { | |
27 | ||
28 | private String start_quarterYYYYQ; | |
29 | private String end_quarterYYYYQ; | |
30 | private List<String> subjects; | |
31 | private UCSBCurriculumService ucsbCurriculumService; | |
32 | private ConvertedSectionCollection convertedSectionCollection; | |
33 | private UpdateCollection updateCollection; | |
34 | private IsStaleService isStaleService; | |
35 | private boolean ifStale; | |
36 | private EnrollmentDataPointRepository enrollmentDataPointRepository; | |
37 | private UCSBAPIQuarterService ucsbapiQuarterService; | |
38 | private JobRateLimit jobRateLimit; | |
39 | ||
40 | @Override | |
41 | public void accept(JobContext ctx) throws Exception { | |
42 | ||
43 |
1
1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log( |
44 | String.format( | |
45 | "Updating courses from %s to %s for %d subjects", | |
46 | start_quarterYYYYQ, end_quarterYYYYQ, subjects.size())); | |
47 | List<Quarter> quarters = Quarter.quarterList(start_quarterYYYYQ, end_quarterYYYYQ); | |
48 | for (Quarter quarter : quarters) { | |
49 | String quarterYYYYQ = quarter.getYYYYQ(); | |
50 | for (String subjectArea : subjects) { | |
51 | boolean isStale = isStaleService.isStale(subjectArea, quarterYYYYQ); | |
52 |
1
1. accept : negated conditional → KILLED |
if (ifStale) { |
53 |
1
1. accept : negated conditional → KILLED |
if (!isStale) { |
54 | continue; | |
55 | } | |
56 | } | |
57 |
1
1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobRateLimit::sleep → KILLED |
jobRateLimit.sleep(); |
58 |
1
1. accept : removed call to edu/ucsb/cs156/courses/jobs/UpdateCourseDataJob::updateCourses → KILLED |
updateCourses(ctx, quarterYYYYQ, subjectArea); |
59 | } | |
60 | } | |
61 |
1
1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log("Finished updating courses"); |
62 | } | |
63 | ||
64 | public Update updateUpdatesCollection( | |
65 | String quarterYYYYQ, String subjectArea, int saved, int updated, int errors) { | |
66 | Update update = new Update(null, subjectArea, quarterYYYYQ, saved, updated, errors, null); | |
67 | Update savedUpdate = updateCollection.save(update); | |
68 |
1
1. updateUpdatesCollection : replaced return value with null for edu/ucsb/cs156/courses/jobs/UpdateCourseDataJob::updateUpdatesCollection → KILLED |
return savedUpdate; |
69 | } | |
70 | ||
71 | public void updateCourses(JobContext ctx, String quarterYYYYQ, String subjectArea) | |
72 | throws Exception { | |
73 |
1
1. updateCourses : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log("Updating courses for [" + subjectArea + " " + quarterYYYYQ + "]"); |
74 | ||
75 | List<ConvertedSection> convertedSections = | |
76 | ucsbCurriculumService.getConvertedSections(subjectArea, quarterYYYYQ, "A"); | |
77 | ||
78 | int newSections = 0; | |
79 | int updatedSections = 0; | |
80 | int errors = 0; | |
81 | boolean isInRegistrationPass = ucsbapiQuarterService.isQuarterInRegistrationPass(quarterYYYYQ); | |
82 | ||
83 | for (ConvertedSection section : convertedSections) { | |
84 | try { | |
85 | String quarter = section.getCourseInfo().getQuarter(); | |
86 | String enrollCode = section.getSection().getEnrollCode(); | |
87 | Optional<ConvertedSection> optionalSection = | |
88 | convertedSectionCollection.findOneByQuarterAndEnrollCode(quarter, enrollCode); | |
89 |
1
1. updateCourses : negated conditional → KILLED |
if (optionalSection.isPresent()) { |
90 | ConvertedSection existingSection = optionalSection.get(); | |
91 |
1
1. updateCourses : removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setCourseInfo → KILLED |
existingSection.setCourseInfo(section.getCourseInfo()); |
92 |
1
1. updateCourses : removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setSection → KILLED |
existingSection.setSection(section.getSection()); |
93 | convertedSectionCollection.save(existingSection); | |
94 |
1
1. updateCourses : Changed increment from 1 to -1 → KILLED |
updatedSections++; |
95 | } else { | |
96 | convertedSectionCollection.save(section); | |
97 |
1
1. updateCourses : Changed increment from 1 to -1 → KILLED |
newSections++; |
98 | } | |
99 |
1
1. updateCourses : negated conditional → KILLED |
if (isInRegistrationPass) { |
100 | enrollmentDataPointRepository.save(section.getEnrollmentDataPoint()); | |
101 | } | |
102 | } catch (Exception e) { | |
103 |
1
1. updateCourses : Changed increment from 1 to -1 → KILLED |
errors++; |
104 | } | |
105 | } | |
106 | ||
107 | Update savedUpdate = | |
108 | updateUpdatesCollection(quarterYYYYQ, subjectArea, newSections, updatedSections, errors); | |
109 | ||
110 |
1
1. updateCourses : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log( |
111 | String.format( | |
112 | "%d new sections saved, %d sections updated, %d errors, last update: %s", | |
113 | newSections, updatedSections, errors, savedUpdate.getLastUpdate())); | |
114 | ||
115 |
1
1. updateCourses : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log("Saved update: " + savedUpdate); |
116 | } | |
117 | } | |
Mutations | ||
43 |
1.1 |
|
52 |
1.1 |
|
53 |
1.1 |
|
57 |
1.1 |
|
58 |
1.1 |
|
61 |
1.1 |
|
68 |
1.1 |
|
73 |
1.1 |
|
89 |
1.1 |
|
91 |
1.1 |
|
92 |
1.1 |
|
94 |
1.1 |
|
97 |
1.1 |
|
99 |
1.1 |
|
103 |
1.1 |
|
110 |
1.1 |
|
115 |
1.1 |