Projekt

Obecné

Profil

Stáhnout (1.39 KB) Statistiky
| Větev: | Revize:
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.LocationRepository;
10
import vldc.aswi.domain.Location;
11

    
12
import javax.transaction.Transactional;
13
import java.util.LinkedList;
14
import java.util.List;
15

    
16
@Service
17
@Slf4j
18
public class LocationManagerImpl implements LocationManager {
19

    
20
    /** Autowired location repository. */
21
    @Autowired
22
    private LocationRepository locationRepository;
23

    
24
    /**
25
     * Initialization setup for location manager. Check if location 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.locationRepository.count() == 0) {
35
            log.info("No location present, creating items.");
36

    
37
        }
38
    }
39

    
40
    /**
41
     * Get all locations from database.
42
     * @return List of locations.
43
     */
44
    @Override
45
    public List<Location> getLocations() {
46
        List<Location> retVal = new LinkedList<>();
47
        this.locationRepository.findAll().forEach(retVal::add);
48
        return retVal;
49
    }
50
}
(8-8/14)