| 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.boot.context.event.ApplicationReadyEvent; | |
| 10 | import org.springframework.context.event.EventListener; | |
| 11 | import org.springframework.stereotype.Component; | |
| 12 | ||
| 13 | /** This class contains a method that is called once at application startup time. */ | |
| 14 | @Slf4j | |
| 15 | @Component | |
| 16 | public class DiningStartup { | |
| 17 | ||
| 18 | @Value("#{'${app.admin.emails}'.split(',')}") | |
| 19 | List<String> adminEmails; | |
| 20 | ||
| 21 | @Autowired AdminRepository adminRepository; | |
| 22 | ||
| 23 | /** | |
| 24 | * Called once at application startup time. Loads all emails in ADMIN_EMAILS into the Admin table. | |
| 25 | */ | |
| 26 | @EventListener(ApplicationReadyEvent.class) | |
| 27 | public void alwaysRunOnStartup() { | |
| 28 | log.info("alwaysRunOnStartup called"); | |
| 29 | ||
| 30 |
1
1. alwaysRunOnStartup : removed call to java/util/List::forEach → KILLED |
adminEmails.forEach( |
| 31 | (email) -> { | |
| 32 | try { | |
| 33 |
1
1. lambda$alwaysRunOnStartup$0 : negated conditional → KILLED |
if (!adminRepository.existsByEmail(email)) { |
| 34 | Admin admin = new Admin(email); | |
| 35 | adminRepository.save(admin); | |
| 36 | } | |
| 37 | } catch (Exception e) { | |
| 38 | log.error("Error saving admin email {}: {}", email, e.getMessage()); | |
| 39 | } | |
| 40 | }); | |
| 41 | } | |
| 42 | } | |
Mutations | ||
| 30 |
1.1 |
|
| 33 |
1.1 |