|
1
|
|
|
package easytests.core.options; |
|
2
|
|
|
|
|
3
|
|
|
import easytests.core.models.UserModelInterface; |
|
4
|
|
|
import easytests.core.services.SubjectsServiceInterface; |
|
5
|
|
|
import easytests.core.services.UsersServiceInterface; |
|
6
|
|
|
import java.util.List; |
|
7
|
|
|
import lombok.EqualsAndHashCode; |
|
8
|
|
|
import lombok.Setter; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @author malinink |
|
13
|
|
|
*/ |
|
14
|
|
|
@EqualsAndHashCode |
|
15
|
|
|
public class UsersOptions implements UsersOptionsInterface { |
|
16
|
|
|
@Setter |
|
17
|
|
|
private UsersServiceInterface usersService; |
|
18
|
|
|
|
|
19
|
|
|
@Setter |
|
20
|
|
|
private SubjectsServiceInterface subjectsService; |
|
21
|
|
|
|
|
22
|
|
|
private SubjectsOptionsInterface subjectsOptions; |
|
23
|
|
|
|
|
24
|
|
|
@Override |
|
25
|
|
|
public UsersOptionsInterface withSubjects(SubjectsOptionsInterface subjectsOptions) { |
|
26
|
|
|
this.subjectsOptions = subjectsOptions; |
|
27
|
|
|
return this; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
@Override |
|
31
|
|
|
public UserModelInterface withRelations(UserModelInterface userModel) { |
|
32
|
|
|
if (userModel == null) { |
|
33
|
|
|
return userModel; |
|
34
|
|
|
} |
|
35
|
|
|
if (this.subjectsOptions != null) { |
|
36
|
|
|
userModel.setSubjects(this.subjectsService.findByUser(userModel, this.subjectsOptions)); |
|
37
|
|
|
} |
|
38
|
|
|
return userModel; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
@Override |
|
42
|
|
|
public List<UserModelInterface> withRelations(List<UserModelInterface> usersModels) { |
|
43
|
|
|
for (UserModelInterface userModel: usersModels) { |
|
44
|
|
|
this.withRelations(userModel); |
|
45
|
|
|
} |
|
46
|
|
|
return usersModels; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
@Override |
|
50
|
|
|
public void saveWithRelations(UserModelInterface userModel) { |
|
51
|
|
|
this.usersService.save(userModel); |
|
52
|
|
|
if (this.subjectsOptions != null) { |
|
53
|
|
|
this.subjectsService.save(userModel.getSubjects(), this.subjectsOptions); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
@Override |
|
58
|
|
|
public void deleteWithRelations(UserModelInterface userModel) { |
|
59
|
|
|
if (this.subjectsOptions != null) { |
|
60
|
|
|
this.subjectsService.delete(userModel.getSubjects(), this.subjectsOptions); |
|
61
|
|
|
} |
|
62
|
|
|
this.usersService.delete(userModel); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|