1
|
package vldc.aswi.service;
|
2
|
|
3
|
import lombok.extern.slf4j.Slf4j;
|
4
|
import org.springframework.beans.factory.annotation.Autowired;
|
5
|
import org.springframework.context.event.ContextRefreshedEvent;
|
6
|
import org.springframework.context.event.EventListener;
|
7
|
import org.springframework.core.annotation.Order;
|
8
|
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
9
|
import org.springframework.stereotype.Service;
|
10
|
import vldc.aswi.dao.FunctionRepository;
|
11
|
import vldc.aswi.domain.Function;
|
12
|
|
13
|
import javax.transaction.Transactional;
|
14
|
import java.util.LinkedList;
|
15
|
import java.util.List;
|
16
|
|
17
|
/**
|
18
|
* Manager for Function.
|
19
|
*/
|
20
|
@Service
|
21
|
@Slf4j
|
22
|
public class FunctionManagerImpl implements FunctionManager {
|
23
|
|
24
|
/** Autowired function repository. */
|
25
|
@Autowired
|
26
|
private FunctionRepository functionRepository;
|
27
|
|
28
|
/**
|
29
|
* Initialization setup for function manager.
|
30
|
* Check if table "Funkce" exists.
|
31
|
*/
|
32
|
@EventListener(classes = {
|
33
|
ContextRefreshedEvent.class
|
34
|
})
|
35
|
@Order(1)
|
36
|
@Transactional
|
37
|
public void setup() {
|
38
|
try {
|
39
|
if (this.functionRepository.count() == 0) {
|
40
|
// Just checking if table exists.
|
41
|
}
|
42
|
}
|
43
|
catch (InvalidDataAccessResourceUsageException e) {
|
44
|
log.error("Table \"Funkce\" did not exists in database!");
|
45
|
System.exit(1);
|
46
|
}
|
47
|
}
|
48
|
|
49
|
/**
|
50
|
* Get all functions from database.
|
51
|
* @return List of functions.
|
52
|
*/
|
53
|
@Override
|
54
|
public List<Function> getFunctions() {
|
55
|
List<Function> retVal = new LinkedList<>();
|
56
|
this.functionRepository.findAll().forEach(retVal::add);
|
57
|
return retVal;
|
58
|
}
|
59
|
}
|