a800fde0
jcartign
First version, in...
|
1
2
3
4
5
|
package fr.plil.sio.persistence.jdbc;
import fr.plil.sio.persistence.api.Group;
import fr.plil.sio.persistence.api.GroupService;
import fr.plil.sio.persistence.api.Right;
|
31bdbe1b
msahmane
Version où les te...
|
6
|
import java.sql.SQLException;
|
7940aa22
jcartign
Finishing API jav...
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
a800fde0
jcartign
First version, in...
|
8
9
10
11
|
import org.springframework.stereotype.Service;
@Service
public class GroupServiceJdbc implements GroupService {
|
7940aa22
jcartign
Finishing API jav...
|
12
13
14
15
|
@Autowired
private GroupRepository groupRepository;
|
a800fde0
jcartign
First version, in...
|
16
17
|
@Override
public Group create(String name) {
|
7940aa22
jcartign
Finishing API jav...
|
18
19
20
21
22
23
24
25
26
27
28
|
if (name == null) {
throw new IllegalArgumentException("name cannot be null");
}
Group group = groupRepository.findByName(name);
if (group != null) {
throw new IllegalStateException("a group with the same name already exists");
}
group = new Group();
group.setName(name);
groupRepository.save(group);
return group;
|
a800fde0
jcartign
First version, in...
|
29
30
31
|
}
@Override
|
5418cb05
jcartign
Javadoc of API is...
|
32
|
public boolean delete(String name) {
|
31bdbe1b
msahmane
Version où les te...
|
33
34
35
36
37
38
39
40
41
42
|
if (name == null) {
throw new IllegalArgumentException("name cannot be null");
}
Group group = groupRepository.findByName(name);
if(group!=null){
groupRepository.delete(group.getId());
return true;
}
return false;
|
a800fde0
jcartign
First version, in...
|
43
44
45
46
|
}
@Override
public Group findByName(String name) {
|
7940aa22
jcartign
Finishing API jav...
|
47
48
49
50
|
if (name == null) {
throw new IllegalArgumentException("name cannot be null");
}
return groupRepository.findByName(name);
|
a800fde0
jcartign
First version, in...
|
51
52
53
|
}
@Override
|
5418cb05
jcartign
Javadoc of API is...
|
54
|
public boolean addRight(String groupName, Right right) {
|
60e63100
msahmane
Test des Right à ...
|
55
56
57
58
59
60
|
if(groupName == null )
throw new IllegalArgumentException("Group name cannot bel null");
if(right == null)
throw new IllegalArgumentException("Right cannot be null");
return groupRepository.addRight(groupName, right);
|
a800fde0
jcartign
First version, in...
|
61
62
63
|
}
@Override
|
5418cb05
jcartign
Javadoc of API is...
|
64
|
public boolean removeRight(String groupName, Right right) {
|
60e63100
msahmane
Test des Right à ...
|
65
66
67
68
69
70
71
|
if(groupName == null)
throw new IllegalArgumentException("Group name cannot be null");
if(right == null)
throw new IllegalArgumentException("Right cannot be null");
return groupRepository.removeRight(groupName, right);
|
a800fde0
jcartign
First version, in...
|
72
73
|
}
}
|