| 1 | package edu.ucsb.cs156.frontiers.startup; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.frontiers.entities.Admin; | |
| 4 | import edu.ucsb.cs156.frontiers.repositories.AdminRepository; | |
| 5 | import lombok.extern.slf4j.Slf4j; | |
| 6 | import org.springframework.beans.factory.annotation.Value; | |
| 7 | import org.springframework.stereotype.Component; | |
| 8 | import org.springframework.stereotype.Service; | |
| 9 | ||
| 10 | import java.util.List; | |
| 11 | ||
| 12 | /** This class contains a `run` method that is called once at application startup time. */ | |
| 13 | @Slf4j | |
| 14 | @Component | |
| 15 | public class FrontiersStartup { | |
| 16 | ||
| 17 |     private final AdminRepository adminRepository; | |
| 18 | ||
| 19 |     @Value("${app.admin.emails}") | |
| 20 |     private List<String> adminEmails; | |
| 21 | ||
| 22 |     public FrontiersStartup(AdminRepository adminRepository) { | |
| 23 |         this.adminRepository = adminRepository; | |
| 24 |     } | |
| 25 | ||
| 26 |     /** | |
| 27 |     * Called once at application startup time . Put code here if you want it to run once each time | |
| 28 |     * the Spring Boot application starts up in all environments. | |
| 29 |     */ | |
| 30 |     public void alwaysRunOnStartup() { | |
| 31 |         log.info("Running FrontiersStartup.alwaysRunOnStartup"); | |
| 32 | ||
| 33 |         for (String email : adminEmails) { | |
| 34 | 
1
1. alwaysRunOnStartup : negated conditional → KILLED | 
            if (!adminRepository.existsByEmail(email)) { | 
| 35 |                 Admin admin = Admin.builder().email(email).build(); | |
| 36 |                 adminRepository.save(admin); | |
| 37 |                 log.info("Added admin: {}", email); | |
| 38 |             } else { | |
| 39 |                 log.info("Admin already exists: {}", email); | |
| 40 |             } | |
| 41 |         } | |
| 42 |     } | |
| 43 | } | |
Mutations | ||
| 34 | 
 
 1.1  |