UploadGradeDataJob.java

1
package edu.ucsb.cs156.courses.jobs;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
6
import edu.ucsb.cs156.courses.entities.GradeHistory;
7
import edu.ucsb.cs156.courses.repositories.GradeHistoryRepository;
8
import edu.ucsb.cs156.courses.services.UCSBGradeHistoryService;
9
import edu.ucsb.cs156.courses.services.jobs.JobContext;
10
import edu.ucsb.cs156.courses.services.jobs.JobContextConsumer;
11
import lombok.AllArgsConstructor;
12
import lombok.Getter;
13
14
@AllArgsConstructor
15
public class UploadGradeDataJob implements JobContextConsumer {
16
    @Getter
17
    private UCSBGradeHistoryService ucsbGradeHistoryService;
18
    @Getter
19
    private GradeHistoryRepository gradeHistoryRepository;
20
21
    @Override
22
    public void accept(JobContext ctx) throws Exception {
23 1 1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
        ctx.log("Updating UCSB Grade History Data");
24
        List<String> urls = ucsbGradeHistoryService.getUrls();
25
26
        GradeHistory previous = new GradeHistory();
27
        List<GradeHistory> results = null;
28
        for (String url : urls) {
29
            results = ucsbGradeHistoryService.getGradeData(url);
30
            GradeHistory topRow = results.get(0);
31
            upsertAll(gradeHistoryRepository, results);
32 1 1. accept : removed call to edu/ucsb/cs156/courses/jobs/UploadGradeDataJob::logProgress → KILLED
            logProgress(ctx, topRow, previous);
33
        }
34
35 1 1. accept : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
        ctx.log("Finished updating UCSB Grade History Data");
36
    }
37
38
    private void logProgress(JobContext ctx, GradeHistory topRow, GradeHistory previous) {
39 1 1. logProgress : negated conditional → KILLED
        if (!topRow.getYyyyq().equals(previous.getYyyyq())) {
40 1 1. logProgress : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
            ctx.log("Processing data for year: " + topRow.getYyyyq());
41 1 1. logProgress : removed call to edu/ucsb/cs156/courses/entities/GradeHistory::setYyyyq → KILLED
            previous.setYyyyq(topRow.getYyyyq());
42
        }
43 1 1. logProgress : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → KILLED
        ctx.log("Processing data for subjectArea: " + topRow.getSubjectArea());
44
    }
45
46
    public static List<GradeHistory> upsertAll(
47
            GradeHistoryRepository gradeHistoryRepository,
48
            List<GradeHistory> gradeHistories) {
49
        List<GradeHistory> result = new ArrayList<GradeHistory>();
50
        for (GradeHistory gradeHistory : gradeHistories) {
51
            List<GradeHistory> query = gradeHistoryRepository.findByYyyyqAndCourseAndInstructorAndGrade(
52
                    gradeHistory.getYyyyq(), gradeHistory.getCourse(), gradeHistory.getInstructor(),
53
                    gradeHistory.getGrade());
54 1 1. upsertAll : negated conditional → KILLED
            if (query.size() == 0) {
55
                gradeHistory = gradeHistoryRepository.save(gradeHistory);
56
                result.add(gradeHistory);
57
            } else {
58
                GradeHistory existing = query.get(0);
59 1 1. upsertAll : removed call to edu/ucsb/cs156/courses/entities/GradeHistory::setCount → KILLED
                existing.setCount(gradeHistory.getCount());
60
                existing = gradeHistoryRepository.save(existing);
61
                result.add(existing);
62
            }
63
        }
64 1 1. upsertAll : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/jobs/UploadGradeDataJob::upsertAll → KILLED
        return result;
65
    }
66
}

Mutations

23

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

32

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

35

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

39

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

40

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

41

1.1
Location : logProgress
Killed by : edu.ucsb.cs156.courses.jobs.UploadGradeDataJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UploadGradeDataJobTests]/[method:test_log_output_success()]
removed call to edu/ucsb/cs156/courses/entities/GradeHistory::setYyyyq → KILLED

43

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

54

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

59

1.1
Location : upsertAll
Killed by : edu.ucsb.cs156.courses.jobs.UploadGradeDataJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UploadGradeDataJobTests]/[method:test_upsertAll()]
removed call to edu/ucsb/cs156/courses/entities/GradeHistory::setCount → KILLED

64

1.1
Location : upsertAll
Killed by : edu.ucsb.cs156.courses.jobs.UploadGradeDataJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UploadGradeDataJobTests]/[method:test_upsertAll()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/jobs/UploadGradeDataJob::upsertAll → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3