Projekt

Obecné

Profil

Stáhnout (1.62 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
/**
17
 * Manager for Location.
18
 */
19
@Service
20
@Slf4j
21
public class LocationManagerImpl implements LocationManager {
22

    
23
    /** Autowired location repository. */
24
    @Autowired
25
    private LocationRepository locationRepository;
26

    
27
    /**
28
     * Initialization setup for location manager. Check if location repository contains
29
     * 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.locationRepository.count() == 0) {
38
            log.info("No location present, creating items.");
39

    
40
        }
41
    }
42

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

    
54
    /**
55
     * Get location from database by ID.
56
     * @return location by ID.
57
     */
58
    @Override
59
    public Location getLocationById(long id) {
60
        return locationRepository.getById(id);
61
    }
62
}
(8-8/16)