| 1 | package edu.ucsb.cs156.happiercows.jobs; | |
| 2 | ||
| 3 | import java.util.Optional; | |
| 4 | ||
| 5 | import edu.ucsb.cs156.happiercows.entities.Commons; | |
| 6 | import edu.ucsb.cs156.happiercows.entities.CommonsPlus; | |
| 7 | import edu.ucsb.cs156.happiercows.repositories.CommonsRepository; | |
| 8 | import edu.ucsb.cs156.happiercows.repositories.UserCommonsRepository; | |
| 9 | import edu.ucsb.cs156.happiercows.repositories.UserRepository; | |
| 10 | import edu.ucsb.cs156.happiercows.services.CommonsPlusBuilderService; | |
| 11 | import edu.ucsb.cs156.jobs.services.JobContext; | |
| 12 | import edu.ucsb.cs156.jobs.services.JobContextConsumer; | |
| 13 | import lombok.AllArgsConstructor; | |
| 14 | import lombok.Getter; | |
| 15 | ||
| 16 | @AllArgsConstructor | |
| 17 | public class UpdateCowHealthJobInd 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 CommonsPlusBuilderService commonsPlusBuilderService; | |
| 27 | @Getter | |
| 28 | private Long commonsID; | |
| 29 | ||
| 30 | @Override | |
| 31 | public void accept(JobContext ctx) throws Exception { | |
| 32 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Updating cow health..."); |
| 33 | ||
| 34 | Optional<Commons> commonUpdatedOpt = commonsRepository.findById(commonsID); | |
| 35 | ||
| 36 | ||
| 37 |
1
1. accept : negated conditional → KILLED |
if(commonUpdatedOpt.isPresent()){ |
| 38 | Commons commonsUpdated = commonUpdatedOpt.get(); | |
| 39 |
1
1. accept : negated conditional → KILLED |
if (!CommonsGate.shouldProcess(commonsUpdated, commonsRepository, ctx)) { |
| 40 | return; | |
| 41 | } | |
| 42 | CommonsPlus commonsPlus = commonsPlusBuilderService.toCommonsPlus(commonsUpdated); | |
| 43 |
1
1. accept : removed call to edu/ucsb/cs156/happiercows/jobs/UpdateCowHealthJob::runUpdateJobInCommons → KILLED |
UpdateCowHealthJob.runUpdateJobInCommons(commonsUpdated, commonsPlus, commonsPlusBuilderService, commonsRepository, userCommonsRepository, ctx); |
| 44 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Cow health has been updated!"); |
| 45 | } else { | |
| 46 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log(String.format("No commons found for id %d", commonsID)); |
| 47 | } | |
| 48 | } | |
| 49 | | |
| 50 | } | |
Mutations | ||
| 32 |
1.1 |
|
| 37 |
1.1 |
|
| 39 |
1.1 |
|
| 43 |
1.1 |
|
| 44 |
1.1 |
|
| 46 |
1.1 |