SharedServiceSpring.java 1.73 KB
package org.legrog.web.xyz;

import org.legrog.entities.*;
import org.legrog.web.user.UserService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;

import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.List;
import java.util.Random;
import java.util.Vector;

@Stateless
public class SharedServiceSpring implements SharedService {

    @Inject
    CountryRepository countryRepository;
    @Inject
    UserRoleRepository userRoleRepository;
    @Inject
    UserPropertyRepository userPropertyRepository;
    @Inject
    UserService userService;

    private List<DisplayNameMask> allDisplayNameMasks;

    public void addCountry(Country country) {
        countryRepository.save(country);
    }

    public List<Country> getAllCountries() {
        return countryRepository.findAll();
    }

    public List<DisplayNameMask> getAllDisplayNameMasks() {
        if (allDisplayNameMasks == null)
        {
            allDisplayNameMasks = new Vector<DisplayNameMask>(DisplayNameMask.values().length);

            for (DisplayNameMask mask : DisplayNameMask.values())
            {
                allDisplayNameMasks.add(mask);
            }
        }
        return allDisplayNameMasks;
    }

    public List<UserRole> getAvailableUserRoles() {
        return userRoleRepository.findAll();
    }

    public List<UserProperty> getAvailableUserProperties() { return userPropertyRepository.findAll(); }

    public Person getCurrentUser() {
        // TODO Remplacer l'astuce par une vraie récupération de l'utilisateur
        List<Person> persons = userService.getAllUsers();
        Random random = new Random();
        Person person = persons.get(random.nextInt(persons.size()));
        // End TODO
        return person;
    }
}