| 1 | package edu.ucsb.cs156.frontiers.startup; | |
| 2 | ||
| 3 | import lombok.extern.slf4j.Slf4j; | |
| 4 | import org.springframework.beans.factory.annotation.Autowired; | |
| 5 | import org.springframework.beans.factory.annotation.Value; | |
| 6 | import org.springframework.stereotype.Component; | |
| 7 | import edu.ucsb.cs156.frontiers.entities.Admin; | |
| 8 | import edu.ucsb.cs156.frontiers.repositories.AdminRepository; | |
| 9 | ||
| 10 | @Slf4j | |
| 11 | @Component | |
| 12 | public class FrontiersStartup { | |
| 13 | ||
| 14 | // Repository for admins | |
| 15 | @Autowired | |
| 16 | private AdminRepository adminRepository; | |
| 17 | ||
| 18 | @Value("${app.admin.emails}") | |
| 19 | private String adminEmails; | |
| 20 | ||
| 21 | public void alwaysRunOnStartup() { | |
| 22 | log.info("AdminStartup.alwaysRunOnStartup called"); | |
| 23 | // Split the comma-separated emails and add them to the database if they don't exist | |
| 24 |
2
1. alwaysRunOnStartup : negated conditional → KILLED 2. alwaysRunOnStartup : negated conditional → KILLED |
if (adminEmails != null && !adminEmails.isEmpty()) { |
| 25 | String[] emails = adminEmails.split(","); | |
| 26 | for (String email : emails) { | |
| 27 | email = email.trim(); | |
| 28 | log.info("Adding admin: {}", email); | |
| 29 | | |
| 30 | // Check if admin already exists | |
| 31 |
1
1. alwaysRunOnStartup : negated conditional → KILLED |
if (!adminRepository.findByEmail(email).isPresent()) { |
| 32 | Admin admin = new Admin(); | |
| 33 |
1
1. alwaysRunOnStartup : removed call to edu/ucsb/cs156/frontiers/entities/Admin::setEmail → KILLED |
admin.setEmail(email); |
| 34 | adminRepository.save(admin); | |
| 35 | log.info("Admin added: {}", email); | |
| 36 | } else { | |
| 37 | log.info("Admin already exists: {}", email); | |
| 38 | } | |
| 39 | } | |
| 40 | } | |
| 41 | } | |
| 42 | } | |
Mutations | ||
| 24 |
1.1 2.2 |
|
| 31 |
1.1 |
|
| 33 |
1.1 |