SharedServiceDefault.java
2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package org.legrog.web.xyz;
import org.legrog.entities.*;
import org.legrog.web.account.AccountService;
import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.List;
import java.util.Random;
import java.util.Vector;
/**
* SharedService implementation
*/
@Stateless
public class SharedServiceDefault implements SharedService {
CountryRepository countryRepository;
AccountRoleRepository accountRoleRepository;
AccountPropertyRepository accountPropertyRepository;
AccountService accountService;
private List<DisplayNameMask> allDisplayNameMasks;
/**
* Uses shared repositories for country and related to account and also AccountService
*
* @param countryRepository injected CountryRepository
* @param accountRoleRepository injected accountRoleRepository
* @param accountPropertyRepository injected AccountPropertyRepository
* @param accountService injected AccountService
*/
@Inject
public SharedServiceDefault(CountryRepository countryRepository, AccountRoleRepository accountRoleRepository,
AccountPropertyRepository accountPropertyRepository, AccountService accountService) {
this.countryRepository = countryRepository;
this.accountRoleRepository = accountRoleRepository;
this.accountPropertyRepository = accountPropertyRepository;
this.accountService = accountService;
}
@Override
public Country addCountry(Country country) {
countryRepository.save(country);
return country;
}
@Override
public List<Country> getAllCountries() {
return countryRepository.findAll();
}
@Override
public List<DisplayNameMask> getAllDisplayNameMasks() {
if (allDisplayNameMasks == null)
{
allDisplayNameMasks = new Vector<>(DisplayNameMask.values().length);
for (DisplayNameMask mask : DisplayNameMask.values())
{
allDisplayNameMasks.add(mask);
}
}
return allDisplayNameMasks;
}
@Override
public List<AccountRole> getAvailableUserRoles() {
return accountRoleRepository.findAll();
}
@Override
public List<AccountProperty> getAvailableUserProperties() { return accountPropertyRepository.findAll(); }
@Override
public Account getCurrentUser() {
// TODO Implement instead of randomly choosing one
List<Account> accounts = accountService.getAllUsers();
Random random = new Random();
return accounts.get(random.nextInt(accounts.size()));
// End TODO
}
}