1 | package edu.ucsb.cs156.rec.services; | |
2 | ||
3 | import edu.ucsb.cs156.rec.entities.RequestType; | |
4 | import edu.ucsb.cs156.rec.errors.EntityAlreadyExistsException; | |
5 | import edu.ucsb.cs156.rec.repositories.RequestTypeRepository; | |
6 | import lombok.extern.slf4j.Slf4j; | |
7 | ||
8 | import java.util.ArrayList; | |
9 | import java.util.List; | |
10 | import java.util.Optional; | |
11 | ||
12 | import org.springframework.beans.factory.annotation.Autowired; | |
13 | import org.springframework.stereotype.Service; | |
14 | ||
15 | /** | |
16 | * This is a service that provides information about the current user. | |
17 | * | |
18 | * This is the version of the service used in production. | |
19 | */ | |
20 | ||
21 | @Slf4j | |
22 | @Service("RequestType") | |
23 | public class RequestTypeService { | |
24 | ||
25 | @Autowired | |
26 | private RequestTypeRepository requestTypeRepository; | |
27 | ||
28 | public RequestType trySave(RequestType requestType) throws EntityAlreadyExistsException { | |
29 | Iterable<RequestType> typeList = requestTypeRepository.findAll(); | |
30 | ||
31 | Optional<RequestType> alreadyContains = requestTypeRepository.findByRequestType(requestType.getRequestType()); | |
32 | ||
33 | ||
34 |
1
1. trySave : negated conditional → KILLED |
if (alreadyContains.isPresent()) { |
35 | throw new EntityAlreadyExistsException(RequestType.class, requestType.getRequestType()); | |
36 | } | |
37 | ||
38 |
1
1. trySave : replaced return value with null for edu/ucsb/cs156/rec/services/RequestTypeService::trySave → KILLED |
return requestTypeRepository.save(requestType); |
39 | } | |
40 | ||
41 | public List<RequestType> trySaveTypes(List<RequestType> toSave) { | |
42 | List<RequestType> savedTypes = new ArrayList<RequestType>(); | |
43 | Iterable<RequestType> typeList = requestTypeRepository.findAll(); | |
44 | ||
45 |
1
1. trySaveTypes : removed call to java/util/List::forEach → KILLED |
toSave.forEach((requestType) -> { |
46 | Optional<RequestType> alreadyContains = requestTypeRepository.findByRequestType(requestType.getRequestType()); | |
47 | ||
48 |
1
1. lambda$trySaveTypes$0 : negated conditional → KILLED |
if (!alreadyContains.isPresent()) { |
49 | savedTypes.add(requestTypeRepository.save(requestType)); | |
50 | } | |
51 | }); | |
52 | ||
53 |
1
1. trySaveTypes : replaced return value with Collections.emptyList for edu/ucsb/cs156/rec/services/RequestTypeService::trySaveTypes → KILLED |
return savedTypes; |
54 | } | |
55 | } | |
Mutations | ||
34 |
1.1 |
|
38 |
1.1 |
|
45 |
1.1 |
|
48 |
1.1 |
|
53 |
1.1 |