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