|
1
|
|
|
package easytests.core.options; |
|
2
|
|
|
|
|
3
|
|
|
import easytests.core.models.QuizModelInterface; |
|
4
|
|
|
import easytests.core.models.TesteeModelInterface; |
|
5
|
|
|
import easytests.core.services.IssuesServiceInterface; |
|
6
|
|
|
import easytests.core.services.PointsServiceInterface; |
|
7
|
|
|
import easytests.core.services.QuizzesServiceInterface; |
|
8
|
|
|
import easytests.core.services.TesteesServiceInterface; |
|
9
|
|
|
import java.util.List; |
|
10
|
|
|
|
|
11
|
|
|
import lombok.EqualsAndHashCode; |
|
12
|
|
|
import lombok.Setter; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author DoZor-80 |
|
16
|
|
|
*/ |
|
17
|
|
|
@EqualsAndHashCode |
|
18
|
|
|
public class QuizzesOptions implements QuizzesOptionsInterface { |
|
19
|
|
|
@Setter |
|
20
|
|
|
private IssuesServiceInterface issuesService; |
|
21
|
|
|
|
|
22
|
|
|
@Setter |
|
23
|
|
|
private QuizzesServiceInterface quizzesService; |
|
24
|
|
|
|
|
25
|
|
|
@Setter |
|
26
|
|
|
private TesteesServiceInterface testeesService; |
|
27
|
|
|
|
|
28
|
|
|
@Setter |
|
29
|
|
|
private PointsServiceInterface pointsService; |
|
30
|
|
|
|
|
31
|
|
|
private IssuesOptionsInterface issuesOptions; |
|
32
|
|
|
|
|
33
|
|
|
private TesteesOptionsInterface testeesOptions; |
|
34
|
|
|
|
|
35
|
|
|
private PointsOptionsInterface pointsOptions; |
|
36
|
|
|
|
|
37
|
|
|
public QuizzesOptionsInterface withIssue(IssuesOptionsInterface issuesOptions) { |
|
38
|
|
|
this.issuesOptions = issuesOptions; |
|
39
|
|
|
return this; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public QuizzesOptionsInterface withTestee(TesteesOptionsInterface testeeOptions) { |
|
43
|
|
|
this.testeesOptions = testeeOptions; |
|
44
|
|
|
return this; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public QuizzesOptionsInterface withPoints(PointsOptionsInterface pointsOptions) { |
|
48
|
|
|
this.pointsOptions = pointsOptions; |
|
49
|
|
|
return this; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public QuizModelInterface withRelations(QuizModelInterface quizModel) { |
|
53
|
|
|
|
|
54
|
|
|
if (quizModel == null) { |
|
55
|
|
|
return quizModel; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if (this.issuesOptions != null) { |
|
59
|
|
|
quizModel.setIssue(this.issuesService.find(quizModel.getIssue().getId(), this.issuesOptions)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if (this.testeesOptions != null) { |
|
63
|
|
|
final TesteeModelInterface testee = |
|
64
|
|
|
this.testeesService.findByQuiz(quizModel, this.testeesOptions); |
|
65
|
|
|
|
|
66
|
|
|
quizModel.setTestee(testee); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if (this.pointsOptions != null) { |
|
70
|
|
|
quizModel.setPoints(this.pointsService.findByQuiz(quizModel, this.pointsOptions)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return quizModel; |
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public List<QuizModelInterface> withRelations(List<QuizModelInterface> quizzesModels) { |
|
78
|
|
|
|
|
79
|
|
|
for (QuizModelInterface quizModel: quizzesModels) { |
|
80
|
|
|
this.withRelations(quizModel); |
|
81
|
|
|
} |
|
82
|
|
|
return quizzesModels; |
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public void saveWithRelations(QuizModelInterface quizModel) { |
|
87
|
|
|
|
|
88
|
|
|
if (this.issuesOptions != null) { |
|
89
|
|
|
|
|
90
|
|
|
this.issuesService.save(quizModel.getIssue(), this.issuesOptions); |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
this.quizzesService.save(quizModel); |
|
95
|
|
|
|
|
96
|
|
|
if (this.testeesOptions != null) { |
|
97
|
|
|
|
|
98
|
|
|
this.testeesService.save(quizModel.getTestee(), this.testeesOptions); |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
if (this.pointsOptions != null) { |
|
103
|
|
|
this.pointsService.save(quizModel.getPoints(), this.pointsOptions); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public void deleteWithRelations(QuizModelInterface quizModel) { |
|
109
|
|
|
|
|
110
|
|
|
if (this.pointsOptions != null) { |
|
111
|
|
|
this.pointsService.delete(quizModel.getPoints(), this.pointsOptions); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
this.quizzesService.delete(quizModel); |
|
115
|
|
|
|
|
116
|
|
|
if (this.issuesOptions != null) { |
|
117
|
|
|
this.issuesService.delete(quizModel.getIssue(), this.issuesOptions); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
if (this.testeesOptions != null) { |
|
121
|
|
|
this.testeesService.delete(quizModel.getTestee(), this.testeesOptions); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|