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