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