1 | package edu.ucsb.cs156.courses.jobs; | |
2 | ||
3 | import java.util.List; | |
4 | import java.util.Optional; | |
5 | import java.time.ZonedDateTime; | |
6 | ||
7 | import edu.ucsb.cs156.courses.collections.ConvertedSectionCollection; | |
8 | import edu.ucsb.cs156.courses.collections.UpdateCollection; | |
9 | import edu.ucsb.cs156.courses.documents.ConvertedSection; | |
10 | import edu.ucsb.cs156.courses.documents.Update; | |
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 lombok.AllArgsConstructor; | |
15 | import lombok.Getter; | |
16 | import lombok.extern.slf4j.Slf4j; | |
17 | ||
18 | @AllArgsConstructor | |
19 | @Slf4j | |
20 | public class UpdateCourseDataJob implements JobContextConsumer { | |
21 | ||
22 | @Getter private String subjectArea; | |
23 | @Getter private String quarterYYYYQ; | |
24 | @Getter private UCSBCurriculumService ucsbCurriculumService; | |
25 | @Getter private ConvertedSectionCollection convertedSectionCollection; | |
26 | @Getter private UpdateCollection updateCollection; | |
27 | ||
28 | @Override | |
29 | public void accept(JobContext ctx) throws Exception { | |
30 |
1
1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log("Updating courses for [" + subjectArea + " " + quarterYYYYQ + "]"); |
31 | ||
32 | List<ConvertedSection> convertedSections = ucsbCurriculumService.getConvertedSections(subjectArea, quarterYYYYQ, | |
33 | "A"); | |
34 | ||
35 |
1
1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log("Found " + convertedSections.size() + " sections"); |
36 |
1
1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log("Storing in MongoDB Collection..."); |
37 | ||
38 | int newSections = 0; | |
39 | int updatedSections = 0; | |
40 | int errors = 0; | |
41 | ||
42 | for (ConvertedSection section : convertedSections) { | |
43 | try { | |
44 | String quarter = section.getCourseInfo().getQuarter(); | |
45 | String enrollCode = section.getSection().getEnrollCode(); | |
46 | Optional<ConvertedSection> optionalSection = convertedSectionCollection | |
47 | .findOneByQuarterAndEnrollCode(quarter,enrollCode); | |
48 |
1
1. accept : negated conditional → KILLED |
if (optionalSection.isPresent()) { |
49 | ConvertedSection existingSection = optionalSection.get(); | |
50 |
1
1. accept : removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setCourseInfo → KILLED |
existingSection.setCourseInfo(section.getCourseInfo()); |
51 |
1
1. accept : removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setSection → KILLED |
existingSection.setSection(section.getSection()); |
52 | convertedSectionCollection.save(existingSection); | |
53 |
1
1. accept : Changed increment from 1 to -1 → KILLED |
updatedSections++; |
54 | } else { | |
55 | convertedSectionCollection.save(section); | |
56 |
1
1. accept : Changed increment from 1 to -1 → KILLED |
newSections++; |
57 | } | |
58 | } catch (Exception e) { | |
59 |
1
1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log("Error saving section: " + e.getMessage()); |
60 |
1
1. accept : Changed increment from 1 to -1 → KILLED |
errors++; |
61 | } | |
62 | } | |
63 | | |
64 |
1
1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log(String.format("%d new sections saved, %d sections updated, %d errors", newSections, updatedSections, |
65 | errors)); | |
66 |
1
1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log("Courses for [" + subjectArea + " " + quarterYYYYQ + "] have been updated"); |
67 | } | |
68 | } | |
Mutations | ||
30 |
1.1 |
|
35 |
1.1 |
|
36 |
1.1 |
|
48 |
1.1 |
|
50 |
1.1 |
|
51 |
1.1 |
|
53 |
1.1 |
|
56 |
1.1 |
|
59 |
1.1 |
|
60 |
1.1 |
|
64 |
1.1 |
|
66 |
1.1 |