| 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 java.util.Arrays; | |
| 6 | import java.util.List; | |
| 7 | import lombok.AllArgsConstructor; | |
| 8 | import lombok.Data; | |
| 9 | import lombok.extern.slf4j.Slf4j; | |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | |
| 11 | import org.springframework.stereotype.Service; | |
| 12 | ||
| 13 | /** Service for managing Request Types. */ | |
| 14 | @Service | |
| 15 | @Slf4j | |
| 16 | public class RequestTypeService { | |
| 17 | ||
| 18 | @Autowired private RequestTypeRepository requestTypeRepository; | |
| 19 | ||
| 20 | /** List of hardcoded request types to be loaded at startup. */ | |
| 21 | private static final List<String> HARDCODED_REQUEST_TYPES = | |
| 22 | Arrays.asList( | |
| 23 | "CS Department BS/MS program", | |
| 24 | "Scholarship or Fellowship", | |
| 25 | "MS program (other than CS Dept BS/MS)", | |
| 26 | "PhD program", | |
| 27 | "Other"); | |
| 28 | ||
| 29 | /** Result class for loadRequestTypes method. */ | |
| 30 | @Data | |
| 31 | @AllArgsConstructor | |
| 32 | public static class LoadResult { | |
| 33 | private int loaded; | |
| 34 | private int skipped; | |
| 35 | } | |
| 36 | ||
| 37 | /** | |
| 38 | * Load hardcoded request types into the database if they don't already exist. | |
| 39 | * | |
| 40 | * <p>This method checks for each hardcoded request type and only creates it if it's not already | |
| 41 | * in the database. | |
| 42 | * | |
| 43 | * @return LoadResult containing the number of types loaded and skipped | |
| 44 | */ | |
| 45 | public LoadResult loadRequestTypes() { | |
| 46 | log.info("Loading hardcoded request types..."); | |
| 47 | int loadedCount = 0; | |
| 48 | int skippedCount = 0; | |
| 49 | ||
| 50 | for (String type : HARDCODED_REQUEST_TYPES) { | |
| 51 |
1
1. loadRequestTypes : negated conditional → KILLED |
if (requestTypeRepository.findByRequestType(type).isEmpty()) { |
| 52 | RequestType requestType = RequestType.builder().requestType(type).build(); | |
| 53 | requestTypeRepository.save(requestType); | |
| 54 | log.info("Loaded request type: {}", type); | |
| 55 |
1
1. loadRequestTypes : Changed increment from 1 to -1 → KILLED |
loadedCount++; |
| 56 | } else { | |
| 57 | log.debug("Request type already exists, skipping: {}", type); | |
| 58 |
1
1. loadRequestTypes : Changed increment from 1 to -1 → KILLED |
skippedCount++; |
| 59 | } | |
| 60 | } | |
| 61 | ||
| 62 | log.info("Request type loading completed. Loaded: {}, Skipped: {}", loadedCount, skippedCount); | |
| 63 |
1
1. loadRequestTypes : replaced return value with null for edu/ucsb/cs156/rec/services/RequestTypeService::loadRequestTypes → KILLED |
return new LoadResult(loadedCount, skippedCount); |
| 64 | } | |
| 65 | } | |
Mutations | ||
| 51 |
1.1 |
|
| 55 |
1.1 |
|
| 58 |
1.1 |
|
| 63 |
1.1 |