UpdateCourseDataJob.java

1
package edu.ucsb.cs156.courses.jobs;
2
3
import edu.ucsb.cs156.courses.collections.ConvertedSectionCollection;
4
import edu.ucsb.cs156.courses.collections.UpdateCollection;
5
import edu.ucsb.cs156.courses.documents.ConvertedSection;
6
import edu.ucsb.cs156.courses.documents.Update;
7
import edu.ucsb.cs156.courses.models.Quarter;
8
import edu.ucsb.cs156.courses.services.IsStaleService;
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 java.util.List;
13
import java.util.Optional;
14
import lombok.AllArgsConstructor;
15
import lombok.Builder;
16
import lombok.Getter;
17
import lombok.extern.slf4j.Slf4j;
18
19
@Builder
20
@Getter
21
@AllArgsConstructor
22
@Slf4j
23
public class UpdateCourseDataJob implements JobContextConsumer {
24
  private String start_quarterYYYYQ;
25
  private String end_quarterYYYYQ;
26
  private List<String> subjects;
27
  private UCSBCurriculumService ucsbCurriculumService;
28
  private ConvertedSectionCollection convertedSectionCollection;
29
  private UpdateCollection updateCollection;
30
  private IsStaleService isStaleService;
31
  private boolean ifStale;
32
33
  @Override
34
  public void accept(JobContext ctx) throws Exception {
35 1 1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
    ctx.log(
36
        String.format(
37
            "Updating courses from %s to %s for %d subjects",
38
            start_quarterYYYYQ, end_quarterYYYYQ, subjects.size()));
39
    List<Quarter> quarters = Quarter.quarterList(start_quarterYYYYQ, end_quarterYYYYQ);
40
    for (Quarter quarter : quarters) {
41
      String quarterYYYYQ = quarter.getYYYYQ();
42
      for (String subjectArea : subjects) {
43
        boolean isStale = isStaleService.isStale(subjectArea, quarterYYYYQ);
44 1 1. accept : negated conditional → KILLED
        if (ifStale) {
45 1 1. accept : negated conditional → KILLED
          if (!isStale) {
46
            continue;
47
          }
48
        }
49 1 1. accept : removed call to edu/ucsb/cs156/courses/jobs/UpdateCourseDataJob::updateCourses → KILLED
        updateCourses(ctx, quarterYYYYQ, subjectArea);
50
      }
51
    }
52 1 1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
    ctx.log("Finished updating courses");
53
  }
54
55
  public Update updateUpdatesCollection(
56
      String quarterYYYYQ, String subjectArea, int saved, int updated, int errors) {
57
    Update update = new Update(null, subjectArea, quarterYYYYQ, saved, updated, errors, null);
58
    Update savedUpdate = updateCollection.save(update);
59 1 1. updateUpdatesCollection : replaced return value with null for edu/ucsb/cs156/courses/jobs/UpdateCourseDataJob::updateUpdatesCollection → KILLED
    return savedUpdate;
60
  }
61
62
  public void updateCourses(JobContext ctx, String quarterYYYYQ, String subjectArea)
63
      throws Exception {
64 1 1. updateCourses : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
    ctx.log("Updating courses for [" + subjectArea + " " + quarterYYYYQ + "]");
65
66
    List<ConvertedSection> convertedSections =
67
        ucsbCurriculumService.getConvertedSections(subjectArea, quarterYYYYQ, "A");
68
69
    int newSections = 0;
70
    int updatedSections = 0;
71
    int errors = 0;
72
73
    for (ConvertedSection section : convertedSections) {
74
      try {
75
        String quarter = section.getCourseInfo().getQuarter();
76
        String enrollCode = section.getSection().getEnrollCode();
77
        Optional<ConvertedSection> optionalSection =
78
            convertedSectionCollection.findOneByQuarterAndEnrollCode(quarter, enrollCode);
79 1 1. updateCourses : negated conditional → KILLED
        if (optionalSection.isPresent()) {
80
          ConvertedSection existingSection = optionalSection.get();
81 1 1. updateCourses : removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setCourseInfo → KILLED
          existingSection.setCourseInfo(section.getCourseInfo());
82 1 1. updateCourses : removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setSection → KILLED
          existingSection.setSection(section.getSection());
83
          convertedSectionCollection.save(existingSection);
84 1 1. updateCourses : Changed increment from 1 to -1 → KILLED
          updatedSections++;
85
        } else {
86
          convertedSectionCollection.save(section);
87 1 1. updateCourses : Changed increment from 1 to -1 → KILLED
          newSections++;
88
        }
89
      } catch (Exception e) {
90 1 1. updateCourses : Changed increment from 1 to -1 → KILLED
        errors++;
91
      }
92
    }
93
94
    Update savedUpdate =
95
        updateUpdatesCollection(quarterYYYYQ, subjectArea, newSections, updatedSections, errors);
96
97 1 1. updateCourses : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
    ctx.log(
98
        String.format(
99
            "%d new sections saved, %d sections updated, %d errors, last update: %s",
100
            newSections, updatedSections, errors, savedUpdate.getLastUpdate()));
101
102 1 1. updateCourses : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
    ctx.log("Saved update: " + savedUpdate);
103
  }
104
}

Mutations

35

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

44

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

45

1.1
Location : accept
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataJobTests]/[method:test_if_stale_and_is_not_stale()]
negated conditional → 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_log_output_with_errors()]
removed call to edu/ucsb/cs156/courses/jobs/UpdateCourseDataJob::updateCourses → KILLED

52

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

59

1.1
Location : updateUpdatesCollection
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataJobTests]/[method:test_log_output_with_errors()]
replaced return value with null for edu/ucsb/cs156/courses/jobs/UpdateCourseDataJob::updateUpdatesCollection → KILLED

64

1.1
Location : updateCourses
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

79

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

81

1.1
Location : updateCourses
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

82

1.1
Location : updateCourses
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

84

1.1
Location : updateCourses
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

87

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

90

1.1
Location : updateCourses
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

97

1.1
Location : updateCourses
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

102

1.1
Location : updateCourses
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.17.0