UpdateCourseDataJob.java

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

Mutations

28

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

33

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

34

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

46

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

48

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

49

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

51

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

54

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

57

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

58

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

62

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

64

1.1
Location : accept
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataJobTests]/[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