| 1 | package edu.ucsb.cs156.rec.services; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.rec.entities.RequestType; | |
| 4 | import edu.ucsb.cs156.rec.repositories.RequestTypeRepository; | |
| 5 | import org.springframework.stereotype.Service; | |
| 6 | ||
| 7 | import java.util.ArrayList; | |
| 8 | import java.util.List; | |
| 9 | ||
| 10 | /** | |
| 11 |  * Service for managing RequestType entities. | |
| 12 |  */ | |
| 13 | @Service | |
| 14 | public class RequestTypeService { | |
| 15 | ||
| 16 |     private final RequestTypeRepository requestTypeRepository; | |
| 17 | ||
| 18 |     /** | |
| 19 |      * Constructor for RequestTypeService with dependency injection. | |
| 20 |      *  | |
| 21 |      * @param requestTypeRepository The repository for RequestType entities | |
| 22 |      */ | |
| 23 |     public RequestTypeService(RequestTypeRepository requestTypeRepository) { | |
| 24 |         this.requestTypeRepository = requestTypeRepository; | |
| 25 |     } | |
| 26 | ||
| 27 |     /** | |
| 28 |      * Initializes the RequestType table with hardcoded values if they are not already present. | |
| 29 |      */ | |
| 30 |     public List<RequestType> initializeRequestTypes() { | |
| 31 |         List<String> hardcodedRequestTypes = List.of( | |
| 32 |             "CS Department BS/MS program", | |
| 33 |             "Scholarship or Fellowship", | |
| 34 |             "MS program (other than CS Dept BS/MS)", | |
| 35 |             "PhD program", | |
| 36 |             "Other" | |
| 37 |         ); | |
| 38 | ||
| 39 |         List<RequestType> savedRequestTypes = new ArrayList<>(); | |
| 40 | ||
| 41 |         for (String type : hardcodedRequestTypes) { | |
| 42 |             RequestType savedRequestType = requestTypeRepository.findByRequestType(type) | |
| 43 |                 .orElseGet(() -> { | |
| 44 |                     RequestType requestType = RequestType.builder() | |
| 45 |                         .requestType(type) | |
| 46 |                         .build(); | |
| 47 |                     RequestType saved = requestTypeRepository.save(requestType); | |
| 48 | 
1
1. lambda$initializeRequestTypes$0 : negated conditional → KILLED | 
                    if (saved == null) { | 
| 49 |                         throw new IllegalStateException("Failed to save RequestType: " + type); | |
| 50 |                     } | |
| 51 | 
1
1. lambda$initializeRequestTypes$0 : replaced return value with null for edu/ucsb/cs156/rec/services/RequestTypeService::lambda$initializeRequestTypes$0 → KILLED | 
                    return saved; | 
| 52 |                 }); | |
| 53 |             savedRequestTypes.add(savedRequestType); | |
| 54 |         } | |
| 55 | ||
| 56 | 
1
1. initializeRequestTypes : replaced return value with Collections.emptyList for edu/ucsb/cs156/rec/services/RequestTypeService::initializeRequestTypes → KILLED | 
        return savedRequestTypes; | 
| 57 |     } | |
| 58 | ||
| 59 | } | |
Mutations | ||
| 48 | 
 
 1.1  | 
|
| 51 | 
 
 1.1  | 
|
| 56 | 
 
 1.1  |