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.documents.FinalExam; | |
6 | import edu.ucsb.cs156.courses.models.Quarter; | |
7 | import edu.ucsb.cs156.courses.services.UCSBCurriculumService; | |
8 | import edu.ucsb.cs156.courses.services.jobs.JobContext; | |
9 | import edu.ucsb.cs156.courses.services.jobs.JobContextConsumer; | |
10 | import java.util.List; | |
11 | import lombok.AllArgsConstructor; | |
12 | import lombok.Getter; | |
13 | ||
14 | @AllArgsConstructor | |
15 | @Getter | |
16 | public class UpdateFinalsDataJob implements JobContextConsumer { | |
17 | private String start_quarterYYYYQ; | |
18 | private String end_quarterYYYYQ; | |
19 | private UCSBCurriculumService ucsbCurriculumService; | |
20 | private ConvertedSectionCollection convertedSectionCollection; | |
21 | ||
22 | @Override | |
23 | public void accept(JobContext ctx) throws Exception { | |
24 | List<Quarter> quarters = Quarter.quarterList(start_quarterYYYYQ, end_quarterYYYYQ); | |
25 | for (Quarter quarter : quarters) { | |
26 | String quarterYYYYQ = quarter.getYYYYQ(); | |
27 |
1
1. accept : removed call to edu/ucsb/cs156/courses/jobs/UpdateFinalsDataJob::updateFinals → KILLED |
updateFinals(ctx, quarterYYYYQ); |
28 | } | |
29 | } | |
30 | ||
31 | public void updateFinals(JobContext ctx, String quarterYYYYQ) throws Exception { | |
32 |
1
1. updateFinals : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log("Updating final exam info for [" + quarterYYYYQ + "]"); |
33 | ||
34 | List<ConvertedSection> convertedSections = | |
35 | convertedSectionCollection.findByQuarterRange(quarterYYYYQ, quarterYYYYQ); | |
36 | ||
37 |
1
1. updateFinals : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log( |
38 | "Attempting to update final exams for " | |
39 | + convertedSections.size() | |
40 | + " sections in MongoDB..."); | |
41 | ||
42 | int updatedSections = 0; | |
43 | int errors = 0; | |
44 | ||
45 | for (ConvertedSection section : convertedSections) { | |
46 | String enrollCd = section.getSection().getEnrollCode(); | |
47 | try { | |
48 | FinalExam finalExam = ucsbCurriculumService.getFinalExamObject(quarterYYYYQ, enrollCd); | |
49 |
1
1. updateFinals : removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setFinalExam → KILLED |
section.setFinalExam(finalExam); |
50 | convertedSectionCollection.save(section); | |
51 |
1
1. updateFinals : Changed increment from 1 to -1 → KILLED |
updatedSections++; |
52 | } catch (Exception e) { | |
53 |
1
1. updateFinals : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log("Error saving final exam: " + e.getMessage()); |
54 |
1
1. updateFinals : Changed increment from 1 to -1 → KILLED |
errors++; |
55 | } | |
56 | } | |
57 | ||
58 |
1
1. updateFinals : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log(String.format("%d final exams updated, %d errors", updatedSections, errors)); |
59 |
1
1. updateFinals : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED |
ctx.log("Final exam info for [" + quarterYYYYQ + "] has been updated"); |
60 | } | |
61 | } | |
Mutations | ||
27 |
1.1 |
|
32 |
1.1 |
|
37 |
1.1 |
|
49 |
1.1 |
|
51 |
1.1 |
|
53 |
1.1 |
|
54 |
1.1 |
|
58 |
1.1 |
|
59 |
1.1 |