1
|
package vldc.aswi.service.parameter;
|
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.stereotype.Service;
|
9
|
import vldc.aswi.dao.parameter.ParameterInConfigurationRepository;
|
10
|
import vldc.aswi.domain.parameter.ParameterInConfiguration;
|
11
|
|
12
|
import javax.transaction.Transactional;
|
13
|
import java.util.LinkedList;
|
14
|
import java.util.List;
|
15
|
|
16
|
/**
|
17
|
* Manager for ParameterInConfiguration.
|
18
|
*/
|
19
|
@Service
|
20
|
@Slf4j
|
21
|
public class ParameterInConfigurationManagerImpl implements ParameterInConfigurationManager {
|
22
|
|
23
|
/** Autowired parameter in configuration repository. */
|
24
|
@Autowired
|
25
|
private ParameterInConfigurationRepository parameterInConfigurationRepository;
|
26
|
|
27
|
/**
|
28
|
* Initialization setup for parameter in configuration manager. Check if parameter in configuration repository
|
29
|
* contains records and if not, initialize default values.
|
30
|
*/
|
31
|
@EventListener(classes = {
|
32
|
ContextRefreshedEvent.class
|
33
|
})
|
34
|
@Order(1)
|
35
|
@Transactional
|
36
|
public void setup() {
|
37
|
if (this.parameterInConfigurationRepository.count() == 0) {
|
38
|
log.info("No parameter in configuration present, creating items.");
|
39
|
|
40
|
}
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* Get all parameter in configuration from database.
|
45
|
* @return List of parameter in configuration.
|
46
|
*/
|
47
|
@Override
|
48
|
public List<ParameterInConfiguration> getAllParameterInConfiguration() {
|
49
|
List<ParameterInConfiguration> retVal = new LinkedList<>();
|
50
|
this.parameterInConfigurationRepository.findAll().forEach(retVal::add);
|
51
|
return retVal;
|
52
|
}
|
53
|
}
|