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
|
private UserRepository userRepository;
|
fa02d31b
rvangrev
Commit avant le m...
|
15
16
|
@Autowired
|
ef4eb263
rvangrev
Nouvelles modific...
|
17
|
private GroupRepository groupRepository;
|
a800fde0
jcartign
First version, in...
|
18
19
|
@Override
|
5418cb05
jcartign
Javadoc of API is...
|
20
|
public User create(String name, String groupName) {
|
e1ed8749
Rémi Vangrevelynghe
save before merge
|
21
|
if(name==null || groupName==null){
|
ef4eb263
rvangrev
Nouvelles modific...
|
22
23
24
25
|
throw new IllegalArgumentException("name cannot be null");
}
User user = userRepository.findByName(name);
if(user!=null){
|
fa02d31b
rvangrev
Commit avant le m...
|
26
|
throw new IllegalArgumentException("a user with the same name already exists");
|
ef4eb263
rvangrev
Nouvelles modific...
|
27
28
29
|
}
user = new User();
user.setName(name);
|
e1ed8749
Rémi Vangrevelynghe
save before merge
|
30
|
Group group = new Group();
|
fa02d31b
rvangrev
Commit avant le m...
|
31
32
33
34
35
36
|
group = groupRepository.findByName(groupName);
if(group!=null)
user.setGroup(group);
else{
throw new IllegalArgumentException("group trouve avec le find by name null");
}
|
ef4eb263
rvangrev
Nouvelles modific...
|
37
38
|
userRepository.save(user, group);
return user;
|
a800fde0
jcartign
First version, in...
|
39
40
41
|
}
@Override
|
5418cb05
jcartign
Javadoc of API is...
|
42
|
public boolean delete(String name) {
|
ef4eb263
rvangrev
Nouvelles modific...
|
43
|
if(name == null){
|
fa02d31b
rvangrev
Commit avant le m...
|
44
|
throw new IllegalArgumentException("name cannot be null");
|
ef4eb263
rvangrev
Nouvelles modific...
|
45
46
47
48
49
50
51
|
}
User user = findByName(name);
if(user==null){
return false;
}
userRepository.delete(user.getId());
return true;
|
a800fde0
jcartign
First version, in...
|
52
53
54
55
|
}
@Override
public User findByName(String name) {
|
ef4eb263
rvangrev
Nouvelles modific...
|
56
57
58
59
|
if(name==null){
throw new IllegalArgumentException("name cannot be null");
}
return userRepository.findByName(name);
|
a800fde0
jcartign
First version, in...
|
60
61
|
}
|
5418cb05
jcartign
Javadoc of API is...
|
62
63
|
@Override
public boolean isUserHasRight(String userName, Right right) {
|
fa02d31b
rvangrev
Commit avant le m...
|
64
|
if(userName==null){
|
ef4eb263
rvangrev
Nouvelles modific...
|
65
66
|
throw new IllegalArgumentException("name cannot be null");
}
|
fa02d31b
rvangrev
Commit avant le m...
|
67
68
69
|
if(right==null){
throw new IllegalArgumentException("right cannot be null");
}
|
ef4eb263
rvangrev
Nouvelles modific...
|
70
71
72
|
else{
return false;
}
|
a800fde0
jcartign
First version, in...
|
73
74
|
}
}
|