| 1 | package edu.ucsb.cs156.happiercows.jobs; | |
| 2 | ||
| 3 | import java.util.Optional; | |
| 4 | import java.util.function.DoubleSupplier; | |
| 5 | ||
| 6 | import edu.ucsb.cs156.happiercows.entities.Game; | |
| 7 | import edu.ucsb.cs156.happiercows.entities.GamePlus; | |
| 8 | import edu.ucsb.cs156.happiercows.repositories.GameRepository; | |
| 9 | import edu.ucsb.cs156.happiercows.repositories.FarmerRepository; | |
| 10 | import edu.ucsb.cs156.happiercows.repositories.HerdRepository; | |
| 11 | import edu.ucsb.cs156.happiercows.repositories.UserRepository; | |
| 12 | import edu.ucsb.cs156.happiercows.services.GamePlusBuilderService; | |
| 13 | import edu.ucsb.cs156.jobs.services.JobContext; | |
| 14 | import edu.ucsb.cs156.jobs.services.JobContextConsumer; | |
| 15 | import lombok.AllArgsConstructor; | |
| 16 | import lombok.Getter; | |
| 17 | ||
| 18 | @AllArgsConstructor | |
| 19 | public class UpdateCowHealthJobInd implements JobContextConsumer { | |
| 20 | ||
| 21 | @Getter | |
| 22 | private GameRepository gameRepository; | |
| 23 | @Getter | |
| 24 | private FarmerRepository farmerRepository; | |
| 25 | @Getter | |
| 26 | private UserRepository userRepository; | |
| 27 | @Getter | |
| 28 | private GamePlusBuilderService gamePlusBuilderService; | |
| 29 | @Getter | |
| 30 | private HerdRepository herdRepository; | |
| 31 | @Getter | |
| 32 | private DoubleSupplier random; | |
| 33 | @Getter | |
| 34 | private Long gameID; | |
| 35 | ||
| 36 | @Override | |
| 37 | public void accept(JobContext ctx) throws Exception { | |
| 38 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Updating cow health..."); |
| 39 | ||
| 40 | Optional<Game> commonUpdatedOpt = gameRepository.findById(gameID); | |
| 41 | ||
| 42 | ||
| 43 |
1
1. accept : negated conditional → KILLED |
if(commonUpdatedOpt.isPresent()){ |
| 44 | Game gameUpdated = commonUpdatedOpt.get(); | |
| 45 |
1
1. accept : negated conditional → KILLED |
if (!GameGate.shouldProcess(gameUpdated, gameRepository, ctx)) { |
| 46 | return; | |
| 47 | } | |
| 48 | GamePlus gamePlus = gamePlusBuilderService.toGamePlus(gameUpdated); | |
| 49 |
1
1. accept : removed call to edu/ucsb/cs156/happiercows/jobs/UpdateCowHealthJob::runUpdateJobInGame → KILLED |
UpdateCowHealthJob.runUpdateJobInGame(gameUpdated, gamePlus, gamePlusBuilderService, gameRepository, farmerRepository, herdRepository, random, ctx); |
| 50 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Cow health has been updated!"); |
| 51 | } else { | |
| 52 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log(String.format("No game found for id %d", gameID)); |
| 53 | } | |
| 54 | } | |
| 55 | | |
| 56 | } | |
Mutations | ||
| 38 |
1.1 |
|
| 43 |
1.1 |
|
| 45 |
1.1 |
|
| 49 |
1.1 |
|
| 50 |
1.1 |
|
| 52 |
1.1 |