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
    List<Quarter> quarters = Quarter.quarterList(start_quarterYYYYQ, end_quarterYYYYQ);
36
    for (Quarter quarter : quarters) {
37
      String quarterYYYYQ = quarter.getYYYYQ();
38
      for (String subjectArea : subjects) {
39
        boolean isStale = isStaleService.isStale(subjectArea, quarterYYYYQ);
40 1 1. accept : negated conditional → KILLED
        if (ifStale) {
41 1 1. accept : negated conditional → KILLED
          if (!isStale) {
42
            continue;
43
          }
44
        }
45 1 1. accept : removed call to edu/ucsb/cs156/courses/jobs/UpdateCourseDataJob::updateCourses → KILLED
        updateCourses(ctx, quarterYYYYQ, subjectArea);
46
      }
47
    }
48
  }
49
50
  public Update updateUpdatesCollection(
51
      String quarterYYYYQ, String subjectArea, int saved, int updated, int errors) {
52
    Update update = new Update(null, subjectArea, quarterYYYYQ, saved, updated, errors, null);
53
    Update savedUpdate = updateCollection.save(update);
54 1 1. updateUpdatesCollection : replaced return value with null for edu/ucsb/cs156/courses/jobs/UpdateCourseDataJob::updateUpdatesCollection → KILLED
    return savedUpdate;
55
  }
56
57
  public void updateCourses(JobContext ctx, String quarterYYYYQ, String subjectArea)
58
      throws Exception {
59 1 1. updateCourses : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
    ctx.log("Updating courses for [" + subjectArea + " " + quarterYYYYQ + "]");
60
61
    List<ConvertedSection> convertedSections =
62
        ucsbCurriculumService.getConvertedSections(subjectArea, quarterYYYYQ, "A");
63
64
    int newSections = 0;
65
    int updatedSections = 0;
66
    int errors = 0;
67
68
    for (ConvertedSection section : convertedSections) {
69
      try {
70
        String quarter = section.getCourseInfo().getQuarter();
71
        String enrollCode = section.getSection().getEnrollCode();
72
        Optional<ConvertedSection> optionalSection =
73
            convertedSectionCollection.findOneByQuarterAndEnrollCode(quarter, enrollCode);
74 1 1. updateCourses : negated conditional → KILLED
        if (optionalSection.isPresent()) {
75
          ConvertedSection existingSection = optionalSection.get();
76 1 1. updateCourses : removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setCourseInfo → KILLED
          existingSection.setCourseInfo(section.getCourseInfo());
77 1 1. updateCourses : removed call to edu/ucsb/cs156/courses/documents/ConvertedSection::setSection → KILLED
          existingSection.setSection(section.getSection());
78
          convertedSectionCollection.save(existingSection);
79 1 1. updateCourses : Changed increment from 1 to -1 → KILLED
          updatedSections++;
80
        } else {
81
          convertedSectionCollection.save(section);
82 1 1. updateCourses : Changed increment from 1 to -1 → KILLED
          newSections++;
83
        }
84
      } catch (Exception e) {
85 1 1. updateCourses : Changed increment from 1 to -1 → KILLED
        errors++;
86
      }
87
    }
88
89
    Update savedUpdate =
90
        updateUpdatesCollection(quarterYYYYQ, subjectArea, newSections, updatedSections, errors);
91
92 1 1. updateCourses : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
    ctx.log(
93
        String.format(
94
            "%d new sections saved, %d sections updated, %d errors, last update: %s",
95
            newSections, updatedSections, errors, savedUpdate.getLastUpdate()));
96
97 1 1. updateCourses : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
    ctx.log("Saved update: " + savedUpdate);
98
  }
99
}

Mutations

40

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

41

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_log_output_with_errors()]
removed call to edu/ucsb/cs156/courses/jobs/UpdateCourseDataJob::updateCourses → KILLED

54

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

59

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

74

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()]
negated conditional → KILLED

76

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

77

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

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_with_updates()]
Changed increment from 1 to -1 → 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_log_output_with_updates()]
Changed increment from 1 to -1 → KILLED

85

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

92

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

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

Active mutators

Tests examined


Report generated by PIT 1.17.0