a800fde0
jcartign
First version, in...
|
1
2
3
|
package fr.plil.sio.persistence.jdbc;
import fr.plil.sio.persistence.api.Right;
|
ef4eb263
rvangrev
Nouvelles modific...
|
4
|
import fr.plil.sio.persistence.api.Group;
|
a800fde0
jcartign
First version, in...
|
5
6
7
8
9
10
11
12
13
|
import fr.plil.sio.persistence.api.User;
import fr.plil.sio.persistence.api.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceJdbc implements UserService {
@Autowired
|
ef4eb263
rvangrev
Nouvelles modific...
|
14
15
|
private UserRepository userRepository;
private GroupRepository groupRepository;
|
a800fde0
jcartign
First version, in...
|
16
17
|
@Override
|
5418cb05
jcartign
Javadoc of API is...
|
18
|
public User create(String name, String groupName) {
|
e1ed8749
Rémi Vangrevelynghe
save before merge
|
19
|
if(name==null || groupName==null){
|
ef4eb263
rvangrev
Nouvelles modific...
|
20
21
22
23
24
25
26
27
|
throw new IllegalArgumentException("name cannot be null");
}
User user = userRepository.findByName(name);
if(user!=null){
throw new IllegalStateException("a user with the same name already exists");
}
user = new User();
user.setName(name);
|
e1ed8749
Rémi Vangrevelynghe
save before merge
|
28
29
30
|
Group group = new Group();
group.setName(groupName);
// Group group = groupRepository.findByName(groupName);
|
ef4eb263
rvangrev
Nouvelles modific...
|
31
32
|
userRepository.save(user, group);
return user;
|
a800fde0
jcartign
First version, in...
|
33
34
35
|
}
@Override
|
5418cb05
jcartign
Javadoc of API is...
|
36
|
public boolean delete(String name) {
|
ef4eb263
rvangrev
Nouvelles modific...
|
37
38
39
40
41
42
43
44
45
|
if(name == null){
throw new IllegalStateException("not implemented !");
}
User user = findByName(name);
if(user==null){
return false;
}
userRepository.delete(user.getId());
return true;
|
a800fde0
jcartign
First version, in...
|
46
47
48
49
|
}
@Override
public User findByName(String name) {
|
ef4eb263
rvangrev
Nouvelles modific...
|
50
51
52
53
|
if(name==null){
throw new IllegalArgumentException("name cannot be null");
}
return userRepository.findByName(name);
|
a800fde0
jcartign
First version, in...
|
54
55
|
}
|
5418cb05
jcartign
Javadoc of API is...
|
56
57
|
@Override
public boolean isUserHasRight(String userName, Right right) {
|
ef4eb263
rvangrev
Nouvelles modific...
|
58
59
60
61
62
63
|
if(right==null){
throw new IllegalArgumentException("name cannot be null");
}
else{
return false;
}
|
a800fde0
jcartign
First version, in...
|
64
65
|
}
}
|