| 1 | package fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.services; | |
| 2 | ||
| 3 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.exception.DateSondageAlreadyExistsException; | |
| 4 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.exception.DateSondeeAlreadyExistsException; | |
| 5 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.exception.SondageCloturedException; | |
| 6 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.models.DateSondage; | |
| 7 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.models.DateSondee; | |
| 8 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.models.Participant; | |
| 9 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.repositories.DateSondeeRepository; | |
| 10 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.utils.ErrorMessages; | |
| 11 | import jakarta.persistence.NoResultException; | |
| 12 | import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | import org.springframework.dao.DataIntegrityViolationException; | |
| 14 | import org.springframework.stereotype.Service; | |
| 15 | ||
| 16 | import java.util.Date; | |
| 17 | import java.util.List; | |
| 18 | import java.util.NoSuchElementException; | |
| 19 | ||
| 20 | @Service | |
| 21 | public class DateSondeeService { | |
| 22 | ||
| 23 | @Autowired | |
| 24 | private DateSondeeRepository repository; | |
| 25 | ||
| 26 | @Autowired | |
| 27 | private SondageService sondageService; | |
| 28 | ||
| 29 | @Autowired | |
| 30 | private DateSondageService dateSondageService; | |
| 31 | ||
| 32 | @Autowired | |
| 33 | private ParticipantService participantService; | |
| 34 | ||
| 35 | public DateSondee create(Long dateSondageId, Long participantId, DateSondee dateSondee) throws SondageCloturedException, NoResultException, DateSondageAlreadyExistsException { | |
| 36 | DateSondage date = dateSondageService.getById(dateSondageId); | |
| 37 |
1
1. create : negated conditional → KILLED |
if(Boolean.TRUE.equals(date.getSondage().getCloture())) |
| 38 | throw new SondageCloturedException(); | |
| 39 | Participant participant = participantService.getById(participantId); | |
| 40 |
1
1. create : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/DateSondee::setDateSondage → KILLED |
dateSondee.setDateSondage(date); |
| 41 |
1
1. create : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/DateSondee::setParticipant → KILLED |
dateSondee.setParticipant(participant); |
| 42 | try { | |
| 43 |
1
1. create : replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/DateSondeeService::create → KILLED |
return repository.save(dateSondee); |
| 44 | } catch (DataIntegrityViolationException e){ | |
| 45 | throw new DateSondageAlreadyExistsException(); | |
| 46 | } | |
| 47 | } | |
| 48 | ||
| 49 | public List<Date> getBestDateBySondageId(Long id) { | |
| 50 |
1
1. getBestDateBySondageId : negated conditional → KILLED |
if(!sondageService.exists(id)) |
| 51 | throw new NoSuchElementException(ErrorMessages.SONDAGE_DOES_NOT_EXISTS); | |
| 52 |
1
1. getBestDateBySondageId : replaced return value with Collections.emptyList for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/DateSondeeService::getBestDateBySondageId → KILLED |
return repository.bestDate(id); |
| 53 | } | |
| 54 | ||
| 55 | public List<Date> getMaybeBestDateBySondageId(Long id) { | |
| 56 |
1
1. getMaybeBestDateBySondageId : negated conditional → KILLED |
if(!sondageService.exists(id)) |
| 57 | throw new NoSuchElementException(ErrorMessages.SONDAGE_DOES_NOT_EXISTS); | |
| 58 |
1
1. getMaybeBestDateBySondageId : replaced return value with Collections.emptyList for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/DateSondeeService::getMaybeBestDateBySondageId → KILLED |
return repository.maybeBestDate(id); |
| 59 | } | |
| 60 | ||
| 61 | public void checkIfDateSondeeAlreadyExists(Long dateSondageId, Long participantId) throws DateSondeeAlreadyExistsException { | |
| 62 | List<DateSondee> datesSondees = repository.getAllByDateSondageAndParticipant(dateSondageId, participantId); | |
| 63 |
1
1. checkIfDateSondeeAlreadyExists : negated conditional → KILLED |
if (!datesSondees.isEmpty()) |
| 64 | throw new DateSondeeAlreadyExistsException(); | |
| 65 | } | |
| 66 | } | |
Mutations | ||
| 37 |
1.1 |
|
| 40 |
1.1 |
|
| 41 |
1.1 |
|
| 43 |
1.1 |
|
| 50 |
1.1 |
|
| 52 |
1.1 |
|
| 56 |
1.1 |
|
| 58 |
1.1 |
|
| 63 |
1.1 |