| 1 | package edu.ucsb.cs156.happiercows.jobs; | |
| 2 | ||
| 3 | ||
| 4 | import edu.ucsb.cs156.happiercows.entities.Commons; | |
| 5 | import edu.ucsb.cs156.happiercows.entities.UserCommons; | |
| 6 | import edu.ucsb.cs156.happiercows.repositories.CommonsRepository; | |
| 7 | import edu.ucsb.cs156.happiercows.repositories.ProfitRepository; | |
| 8 | import edu.ucsb.cs156.happiercows.repositories.UserCommonsRepository; | |
| 9 | import edu.ucsb.cs156.happiercows.repositories.UserRepository; | |
| 10 | import edu.ucsb.cs156.happiercows.services.jobs.JobContext; | |
| 11 | import edu.ucsb.cs156.happiercows.services.jobs.JobContextConsumer; | |
| 12 | import lombok.AllArgsConstructor; | |
| 13 | import lombok.Getter; | |
| 14 | import java.util.Optional; | |
| 15 | ||
| 16 | @AllArgsConstructor | |
| 17 | public class MilkTheCowsJobInd implements JobContextConsumer { | |
| 18 | ||
| 19 | @Getter | |
| 20 | private CommonsRepository commonsRepository; | |
| 21 | @Getter | |
| 22 | private UserCommonsRepository userCommonsRepository; | |
| 23 | @Getter | |
| 24 | private UserRepository userRepository; | |
| 25 | @Getter | |
| 26 | private ProfitRepository profitRepository; | |
| 27 | @Getter | |
| 28 | private long commonsID; | |
| 29 | ||
| 30 | public String formatDollars(double amount) { | |
| 31 |
1
1. formatDollars : replaced return value with "" for edu/ucsb/cs156/happiercows/jobs/MilkTheCowsJobInd::formatDollars → KILLED |
return String.format("$%.2f", amount); |
| 32 | } | |
| 33 | ||
| 34 | @Override | |
| 35 | public void accept(JobContext ctx) throws Exception { | |
| 36 |
1
1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED |
ctx.log("Starting to milk the cows"); |
| 37 | Optional<Commons> commonMilkedOpt = commonsRepository.findById(commonsID); | |
| 38 | ||
| 39 |
1
1. accept : negated conditional → KILLED |
if(commonMilkedOpt.isPresent()){ |
| 40 | Commons commonMilked = commonMilkedOpt.get(); | |
| 41 | String name = commonMilked.getName(); | |
| 42 | double milkPrice = commonMilked.getMilkPrice(); | |
| 43 |
1
1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED |
ctx.log("Milking cows for Commons: " + name + ", Milk Price: " + formatDollars(milkPrice)); |
| 44 | ||
| 45 | Iterable<UserCommons> allUserCommons = userCommonsRepository.findByCommonsId(commonMilked.getId()); | |
| 46 | ||
| 47 | for (UserCommons userCommons : allUserCommons) { | |
| 48 |
1
1. accept : removed call to edu/ucsb/cs156/happiercows/jobs/MilkTheCowsJob::milkCows → KILLED |
MilkTheCowsJob.milkCows(ctx, commonMilked, userCommons, profitRepository, userCommonsRepository); |
| 49 | } | |
| 50 | | |
| 51 | ||
| 52 |
1
1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED |
ctx.log("Cows have been milked!"); |
| 53 | } else { | |
| 54 |
1
1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED |
ctx.log(String.format("No commons found for id %d", commonsID)); |
| 55 | } | |
| 56 | } | |
| 57 | ||
| 58 | } | |
Mutations | ||
| 31 |
1.1 |
|
| 36 |
1.1 |
|
| 39 |
1.1 |
|
| 43 |
1.1 |
|
| 48 |
1.1 |
|
| 52 |
1.1 |
|
| 54 |
1.1 |