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.GradeData;
7
import edu.ucsb.cs156.courses.repositories.GradeDataRepository;
8
import edu.ucsb.cs156.courses.services.UCSBGradeDataService;
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 UCSBGradeDataService ucsbGradeDataService;
18
    @Getter
19
    private GradeDataRepository gradeDataRepository;
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 Data");
24
        List<String> urls = ucsbGradeDataService.getUrls();
25
26
        GradeData previous = new GradeData();
27
        List<GradeData> results = null;
28
        for (String url : urls) {
29
            results = ucsbGradeDataService.getGradeData(url);
30
            GradeData topRow = results.get(0);
31
            upsertAll(gradeDataRepository, 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 Data");
36
    }
37
38
    private void logProgress(JobContext ctx, GradeData topRow, GradeData 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/GradeData::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<GradeData> upsertAll(
47
            GradeDataRepository gradeDataRepository,
48
            List<GradeData> gradeDatas) {
49
        List<GradeData> result = new ArrayList<GradeData>();
50
        for (GradeData gradeData : gradeDatas) {
51
            List<GradeData> query = gradeDataRepository.findByYyyyqAndCourseAndProfessorAndGrade(
52
                    gradeData.getYyyyq(), gradeData.getCourse(), gradeData.getProfessor(),
53
                    gradeData.getGrade());
54 1 1. upsertAll : negated conditional → KILLED
            if (query.size() == 0) {
55
                gradeData = gradeDataRepository.save(gradeData);
56
                result.add(gradeData);
57
            } else {
58
                GradeData existing = query.get(0);
59 1 1. upsertAll : removed call to edu/ucsb/cs156/courses/entities/GradeData::setCount → KILLED
                existing.setCount(gradeData.getCount());
60
                existing = gradeDataRepository.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/GradeData::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/GradeData::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