UpdateCourseDataWithQuarterJob.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.entities.UCSBSubject;
8
import edu.ucsb.cs156.courses.collections.ConvertedSectionCollection;
9
import edu.ucsb.cs156.courses.documents.ConvertedSection;
10
import edu.ucsb.cs156.courses.services.UCSBSubjectsService;
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 UpdateCourseDataWithQuarterJob implements JobContextConsumer {
22
23
    @Getter private String quarterYYYYQ;
24
    @Getter private UCSBSubjectsService ucsbSubjectService;
25
    @Getter private UCSBCurriculumService ucsbCurriculumService;
26
    @Getter private ConvertedSectionCollection convertedSectionCollection;
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 quarter courses for [" + quarterYYYYQ + "]");
31
32
        List<UCSBSubject> ucsbsubjects = ucsbSubjectService.get();
33
        for (UCSBSubject subject : ucsbsubjects){
34
            String subjectArea = subject.getSubjectCode();
35
36 1 1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
            ctx.log("Updating courses for [" + subjectArea + " " + quarterYYYYQ + "]");
37
38
            List<ConvertedSection> convertedSections = ucsbCurriculumService.getConvertedSections(subjectArea, quarterYYYYQ,
39
                "A");
40
            
41 1 1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
            ctx.log("Found " + convertedSections.size() + " sections");
42 1 1. accept : 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 = convertedSectionCollection
53
                                .findOneByQuarterAndEnrollCode(quarter,enrollCode);
54 1 1. accept : negated conditional → KILLED
                    if (optionalSection.isPresent()) {
55
                        ConvertedSection existingSection = optionalSection.get();
56 1 1. accept : removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setCourseInfo → KILLED
                        existingSection.setCourseInfo(section.getCourseInfo());
57 1 1. accept : removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setSection → KILLED
                        existingSection.setSection(section.getSection());
58
                        convertedSectionCollection.save(existingSection);
59 1 1. accept : Changed increment from 1 to -1 → KILLED
                        updatedSections++;
60
                    } else {
61
                        convertedSectionCollection.save(section);
62 1 1. accept : Changed increment from 1 to -1 → KILLED
                        newSections++;
63
                    }
64
                } catch (Exception e) {
65 1 1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
                    ctx.log("Error saving section: " + e.getMessage());
66 1 1. accept : Changed increment from 1 to -1 → KILLED
                    errors++;
67
                }
68
            }
69
            
70 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,
71
                        errors));
72 1 1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
            ctx.log("Courses for [" + subjectArea + " " + quarterYYYYQ + "] have been updated");
73
        }
74
75 1 1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
        ctx.log("Quarter courses for [" + quarterYYYYQ + "] have been updated");
76
77
    }
78
}

Mutations

30

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

36

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

41

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

42

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

54

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

56

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

57

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

59

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

62

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

65

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

66

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

70

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

72

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

75

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

Active mutators

Tests examined


Report generated by PIT 1.7.3