| 1 | package edu.ucsb.cs156.happiercows.jobs; | |
| 2 | ||
| 3 | import java.util.Optional; | |
| 4 | ||
| 5 | import edu.ucsb.cs156.happiercows.entities.Game; | |
| 6 | import edu.ucsb.cs156.happiercows.entities.GamePlus; | |
| 7 | import edu.ucsb.cs156.happiercows.repositories.GameRepository; | |
| 8 | import edu.ucsb.cs156.happiercows.repositories.FarmerRepository; | |
| 9 | import edu.ucsb.cs156.happiercows.repositories.UserRepository; | |
| 10 | import edu.ucsb.cs156.happiercows.services.GamePlusBuilderService; | |
| 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 GameRepository gameRepository; | |
| 21 | @Getter | |
| 22 | private FarmerRepository farmerRepository; | |
| 23 | @Getter | |
| 24 | private UserRepository userRepository; | |
| 25 | @Getter | |
| 26 | private GamePlusBuilderService gamePlusBuilderService; | |
| 27 | @Getter | |
| 28 | private Long gameID; | |
| 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<Game> commonUpdatedOpt = gameRepository.findById(gameID); | |
| 35 | ||
| 36 | ||
| 37 |
1
1. accept : negated conditional → KILLED |
if(commonUpdatedOpt.isPresent()){ |
| 38 | Game gameUpdated = commonUpdatedOpt.get(); | |
| 39 |
1
1. accept : negated conditional → KILLED |
if (!GameGate.shouldProcess(gameUpdated, gameRepository, ctx)) { |
| 40 | return; | |
| 41 | } | |
| 42 | GamePlus gamePlus = gamePlusBuilderService.toGamePlus(gameUpdated); | |
| 43 |
1
1. accept : removed call to edu/ucsb/cs156/happiercows/jobs/UpdateCowHealthJob::runUpdateJobInGame → KILLED |
UpdateCowHealthJob.runUpdateJobInGame(gameUpdated, gamePlus, gamePlusBuilderService, gameRepository, farmerRepository, 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 game found for id %d", gameID)); |
| 47 | } | |
| 48 | } | |
| 49 | | |
| 50 | } | |
Mutations | ||
| 32 |
1.1 |
|
| 37 |
1.1 |
|
| 39 |
1.1 |
|
| 43 |
1.1 |
|
| 44 |
1.1 |
|
| 46 |
1.1 |