UpdateCourseDataRangeOfQuartersJob.java

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

Mutations

35

1.1
Location : accept
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests]/[method:test_log_output_with_errors()]
removed call to edu/ucsb/cs156/courses/jobs/UpdateCourseDataRangeOfQuartersJob::updateCourses → KILLED

47

1.1
Location : updateCourses
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests]/[method:test_log_output_with_errors()]
removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED

52

1.1
Location : updateCourses
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests]/[method:test_log_output_with_errors()]
removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED

53

1.1
Location : updateCourses
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests]/[method:test_log_output_with_errors()]
removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED

65

1.1
Location : updateCourses
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests]/[method:test_log_output_with_updates()]
negated conditional → KILLED

67

1.1
Location : updateCourses
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests]/[method:test_updating_to_new_values()]
removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setCourseInfo → KILLED

68

1.1
Location : updateCourses
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests]/[method:test_updating_to_new_values()]
removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setSection → KILLED

70

1.1
Location : updateCourses
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests]/[method:test_log_output_with_updates()]
Changed increment from 1 to -1 → KILLED

73

1.1
Location : updateCourses
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests]/[method:test_log_output_with_updates()]
Changed increment from 1 to -1 → KILLED

76

1.1
Location : updateCourses
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests]/[method:test_log_output_with_errors()]
removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED

77

1.1
Location : updateCourses
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests]/[method:test_log_output_with_errors()]
Changed increment from 1 to -1 → KILLED

81

1.1
Location : updateCourses
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests]/[method:test_log_output_with_errors()]
removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED

83

1.1
Location : updateCourses
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobTests]/[method:test_log_output_with_errors()]
removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3