| 1 | package edu.ucsb.cs156.dining.startup; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.dining.entities.Admin; | |
| 4 | import edu.ucsb.cs156.dining.repositories.AdminRepository; | |
| 5 | import java.util.List; | |
| 6 | import lombok.extern.slf4j.Slf4j; | |
| 7 | import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | import org.springframework.beans.factory.annotation.Value; | |
| 9 | import org.springframework.stereotype.Component; | |
| 10 | ||
| 11 | /** This class contains a `run` method that is called once at application startup time. */ | |
| 12 | @Slf4j | |
| 13 | @Component | |
| 14 | public class DiningStartup { | |
| 15 | ||
| 16 | @Value("#{'${app.admin.emails}'.split(',')}") | |
| 17 | List<String> adminEmails; | |
| 18 | ||
| 19 | @Autowired AdminRepository adminRepository; | |
| 20 | ||
| 21 | /** | |
| 22 | * Called once at application startup time . Put code here if you want it to run once each time | |
| 23 | * the Spring Boot application starts up in all environments. | |
| 24 | */ | |
| 25 | public void alwaysRunOnStartup() { | |
| 26 | log.info("alwaysRunOnStartup called"); | |
| 27 | ||
| 28 | try { | |
| 29 |
1
1. alwaysRunOnStartup : removed call to java/util/List::forEach → KILLED |
adminEmails.forEach( |
| 30 | (email) -> { | |
| 31 | Admin admin = new Admin(email); | |
| 32 | adminRepository.save(admin); | |
| 33 | }); | |
| 34 | } catch (Exception e) { | |
| 35 | log.error("Error in loading all ADMIN_EMAILS:", e); | |
| 36 | } | |
| 37 | } | |
| 38 | } | |
Mutations | ||
| 29 |
1.1 |