|
1
|
|
package fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.services; |
|
2
|
|
|
|
3
|
|
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.dtos.DateSondageDto; |
|
4
|
|
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.exception.DateSondageAlreadyExistsException; |
|
5
|
|
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.models.DateSondage; |
|
6
|
|
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.repositories.DateSondageRepository; |
|
7
|
|
import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.utils.ErrorMessages; |
|
8
|
|
import jakarta.persistence.NoResultException; |
|
9
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
10
|
|
import org.springframework.stereotype.Service; |
|
11
|
|
|
|
12
|
|
import java.util.Calendar; |
|
13
|
|
import java.util.List; |
|
14
|
|
import java.util.NoSuchElementException; |
|
15
|
|
|
|
16
|
|
@Service |
|
17
|
|
public class DateSondageService { |
|
18
|
|
|
|
19
|
|
@Autowired |
|
20
|
|
private DateSondageRepository repository; |
|
21
|
|
|
|
22
|
|
@Autowired |
|
23
|
|
private SondageService sondageService; |
|
24
|
|
|
|
25
|
|
public DateSondage create(Long id, DateSondage date){ |
|
26
|
1
1. create : negated conditional → KILLED
|
if (!sondageService.exists(id)) |
|
27
|
|
throw new NoSuchElementException(ErrorMessages.SONDAGE_DOES_NOT_EXISTS); |
|
28
|
1
1. create : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/DateSondage::setSondage → KILLED
|
date.setSondage(sondageService.getById(id)); |
|
29
|
1
1. create : replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/DateSondageService::create → KILLED
|
return repository.save(date); |
|
30
|
|
} |
|
31
|
|
|
|
32
|
|
public DateSondage getById(Long id) { |
|
33
|
1
1. getById : negated conditional → KILLED
|
if(!exists(id)) |
|
34
|
|
throw new NoResultException(ErrorMessages.DATE_DOES_NOT_EXISTS); |
|
35
|
1
1. getById : replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/DateSondageService::getById → KILLED
|
return repository.getReferenceById(id); |
|
36
|
|
} |
|
37
|
|
|
|
38
|
|
public List<DateSondage> getBySondageId(Long sondageId) { |
|
39
|
1
1. getBySondageId : negated conditional → KILLED
|
if (!sondageService.exists(sondageId)) |
|
40
|
|
throw new NoSuchElementException(ErrorMessages.SONDAGE_DOES_NOT_EXISTS); |
|
41
|
|
List<DateSondage> dateSondages = repository.getAllBySondage(sondageId); |
|
42
|
1
1. getBySondageId : negated conditional → KILLED
|
if (dateSondages.isEmpty()) |
|
43
|
|
throw new NoResultException("Aucune date de sondage n'a été trouvé."); |
|
44
|
1
1. getBySondageId : replaced return value with Collections.emptyList for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/DateSondageService::getBySondageId → KILLED
|
return dateSondages; |
|
45
|
|
} |
|
46
|
|
|
|
47
|
|
public void delete(Long id) { |
|
48
|
1
1. delete : negated conditional → KILLED
|
if (!exists(id)) |
|
49
|
|
throw new NoSuchElementException(ErrorMessages.DATE_DOES_NOT_EXISTS); |
|
50
|
1
1. delete : removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/repositories/DateSondageRepository::deleteById → KILLED
|
repository.deleteById(id); |
|
51
|
|
} |
|
52
|
|
|
|
53
|
|
public boolean exists(Long id) { |
|
54
|
2
1. exists : replaced boolean return with false for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/DateSondageService::exists → KILLED
2. exists : replaced boolean return with true for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/DateSondageService::exists → KILLED
|
return repository.existsById(id); |
|
55
|
|
} |
|
56
|
|
|
|
57
|
|
public void checkIfDateAlreadyExists(Long sondageId, DateSondageDto dto) throws DateSondageAlreadyExistsException { |
|
58
|
|
sondageService.exists(sondageId); |
|
59
|
1
1. checkIfDateAlreadyExists : negated conditional → KILLED
|
if(dto.getDate()==null) |
|
60
|
|
throw new NoSuchElementException(ErrorMessages.DATE_DOES_NOT_EXISTS); |
|
61
|
|
List<DateSondage> datesSondages = repository.getAllBySondage(sondageId); |
|
62
|
|
Calendar calendarDTO = Calendar.getInstance(); |
|
63
|
1
1. checkIfDateAlreadyExists : removed call to java/util/Calendar::setTime → KILLED
|
calendarDTO.setTime(dto.getDate()); |
|
64
|
|
Calendar calendarCheck = Calendar.getInstance(); |
|
65
|
|
for (DateSondage dateSondage : datesSondages) { |
|
66
|
1
1. checkIfDateAlreadyExists : removed call to java/util/Calendar::setTime → KILLED
|
calendarCheck.setTime(dateSondage.getDate()); |
|
67
|
1
1. checkIfDateAlreadyExists : negated conditional → KILLED
|
if (!calendarDTO.getTime().equals(dto.getDate()) || ( |
|
68
|
1
1. checkIfDateAlreadyExists : negated conditional → KILLED
|
calendarDTO.getWeekYear() == calendarCheck.getWeekYear() && |
|
69
|
1
1. checkIfDateAlreadyExists : negated conditional → KILLED
|
calendarDTO.get(Calendar.MONTH) == calendarCheck.get(Calendar.MONTH) && |
|
70
|
1
1. checkIfDateAlreadyExists : negated conditional → KILLED
|
calendarDTO.get(Calendar.DAY_OF_MONTH) == calendarCheck.get(Calendar.DAY_OF_MONTH) && |
|
71
|
1
1. checkIfDateAlreadyExists : negated conditional → KILLED
|
calendarDTO.get(Calendar.HOUR) == calendarCheck.get(Calendar.HOUR) && |
|
72
|
1
1. checkIfDateAlreadyExists : negated conditional → KILLED
|
calendarDTO.get(Calendar.MINUTE) == calendarCheck.get(Calendar.MINUTE))) |
|
73
|
|
throw new DateSondageAlreadyExistsException(); |
|
74
|
|
} |
|
75
|
|
} |
|
76
|
|
} |
| | Mutations |
| 26 |
|
1.1 Location : create Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenASondageIdThatDoesNotExist_whenCreate_thenThrowNoSuchElementException()] negated conditional → KILLED
|
| 28 |
|
1.1 Location : create Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdAndADateSondage_whenCreate_thenSondageServiceAndRepositoryAreCalled()] removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/models/DateSondage::setSondage → KILLED
|
| 29 |
|
1.1 Location : create Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdAndADateSondage_whenCreate_thenSondageServiceAndRepositoryAreCalled()] replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/DateSondageService::create → KILLED
|
| 33 |
|
1.1 Location : getById Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnId_whenGetById_thenRepositoryIsCalled()] negated conditional → KILLED
|
| 35 |
|
1.1 Location : getById Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnId_whenGetById_thenRepositoryIsCalled()] replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/DateSondageService::getById → KILLED
|
| 39 |
|
1.1 Location : getBySondageId Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenASondageId_whenGetBySondageIdDateSondagesEmpty_thenThrowNoResultException()] negated conditional → KILLED
|
| 42 |
|
1.1 Location : getBySondageId Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenASondageId_whenGetBySondageIdDateSondagesEmpty_thenThrowNoResultException()] negated conditional → KILLED
|
| 44 |
|
1.1 Location : getBySondageId Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenASondageId_whenGetBySondageId_thenRepositoryIsCalled()] replaced return value with Collections.emptyList for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/DateSondageService::getBySondageId → KILLED
|
| 48 |
|
1.1 Location : delete Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdThatDoesNotExists_whenDelete_thenThrowNoSuchElementException()] negated conditional → KILLED
|
| 50 |
|
1.1 Location : delete Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdThatExists_whenDelete_thenRepositoryIsCalledTwoTimes()] removed call to fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/repositories/DateSondageRepository::deleteById → KILLED
|
| 54 |
|
1.1 Location : exists Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnId_whenGetById_thenRepositoryIsCalled()] replaced boolean return with false for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/DateSondageService::exists → KILLED 2.2 Location : exists Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdThatDoesNotExists_whenDelete_thenThrowNoSuchElementException()] replaced boolean return with true for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/services/DateSondageService::exists → KILLED
|
| 59 |
|
1.1 Location : checkIfDateAlreadyExists Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdAndDateSondage_whenCheckIfDateAlreadyExists_thenThrowDateSondageAlreadyExist()] negated conditional → KILLED
|
| 63 |
|
1.1 Location : checkIfDateAlreadyExists Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdAndDateSondage_whenCheckIfDateAlreadyExists_thenDoNothing()] removed call to java/util/Calendar::setTime → KILLED
|
| 66 |
|
1.1 Location : checkIfDateAlreadyExists Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdAndDateSondage_whenCheckIfDateAlreadyExists_thenDoNothing()] removed call to java/util/Calendar::setTime → KILLED
|
| 67 |
|
1.1 Location : checkIfDateAlreadyExists Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdAndDateSondage_whenCheckIfDateAlreadyExists_thenDoNothing()] negated conditional → KILLED
|
| 68 |
|
1.1 Location : checkIfDateAlreadyExists Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdAndDateSondage_whenCheckIfDateAlreadyExists_thenThrowDateSondageAlreadyExist()] negated conditional → KILLED
|
| 69 |
|
1.1 Location : checkIfDateAlreadyExists Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdAndDateSondage_whenCheckIfDateAlreadyExists_thenThrowDateSondageAlreadyExist()] negated conditional → KILLED
|
| 70 |
|
1.1 Location : checkIfDateAlreadyExists Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdAndDateSondage_whenCheckIfDateAlreadyExists_thenThrowDateSondageAlreadyExist()] negated conditional → KILLED
|
| 71 |
|
1.1 Location : checkIfDateAlreadyExists Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdAndDateSondage_whenCheckIfDateAlreadyExists_thenThrowDateSondageAlreadyExist()] negated conditional → KILLED
|
| 72 |
|
1.1 Location : checkIfDateAlreadyExists Killed by : fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest.[engine:junit-jupiter]/[class:fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.units.services.DateSondageServiceUnitTest]/[method:givenAnIdAndDateSondage_whenCheckIfDateAlreadyExists_thenThrowDateSondageAlreadyExist()] negated conditional → KILLED
|