-
Notifications
You must be signed in to change notification settings - Fork 8
/
ACCServerManager.java
68 lines (56 loc) · 2.4 KB
/
ACCServerManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package grimsi.accservermanager.backend;
import grimsi.accservermanager.backend.configuration.ApplicationConfiguration;
import grimsi.accservermanager.backend.dto.UserDto;
import grimsi.accservermanager.backend.repository.ConfigRepository;
import grimsi.accservermanager.backend.repository.InstanceRepository;
import grimsi.accservermanager.backend.repository.UserRepository;
import grimsi.accservermanager.backend.service.FileSystemService;
import grimsi.accservermanager.backend.service.UserService;
import org.modelmapper.ModelMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@EnableConfigurationProperties(ApplicationConfiguration.class)
public class ACCServerManager implements CommandLineRunner {
private static final Logger log = LoggerFactory.getLogger(ACCServerManager.class);
@Autowired
private UserRepository userRepository;
@Autowired
private FileSystemService fileSystemService;
@Autowired
private ApplicationConfiguration config;
@Autowired
private UserService userService;
public static void main(String[] args) throws Exception {
new SpringApplication(ACCServerManager.class).run(args);
}
@Override
public void run(String... arg0) throws Exception {
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
throw new ExitException();
}
fileSystemService.initFileSystem();
log.info("Initialized filesystem.");
userRepository.deleteAll();
userService.registerUser(new UserDto(config.getUsername(), config.getPassword()));
log.info("Created user with username '" + config.getUsername() + "' and pre-defined password.");
}
@Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}
class ExitException extends RuntimeException implements ExitCodeGenerator {
private static final long serialVersionUID = 1L;
@Override
public int getExitCode() {
return 10;
}
}
}