|
1
|
|
|
package easytests.core.options; |
|
2
|
|
|
|
|
3
|
|
|
import easytests.core.models.AnswerModelInterface; |
|
4
|
|
|
import easytests.core.services.*; |
|
5
|
|
|
import java.util.List; |
|
6
|
|
|
import lombok.EqualsAndHashCode; |
|
7
|
|
|
import lombok.Setter; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @author rezenbekk |
|
12
|
|
|
*/ |
|
13
|
|
|
@EqualsAndHashCode |
|
14
|
|
|
public class AnswersOptions implements AnswersOptionsInterface { |
|
15
|
|
|
|
|
16
|
|
|
@Setter |
|
17
|
|
|
private QuestionsServiceInterface questionsService; |
|
18
|
|
|
|
|
19
|
|
|
@Setter |
|
20
|
|
|
private AnswersServiceInterface answersService; |
|
21
|
|
|
|
|
22
|
|
|
private QuestionsOptionsInterface questionsOptions; |
|
23
|
|
|
|
|
24
|
|
|
@Override |
|
25
|
|
|
public AnswersOptionsInterface withQuestion(QuestionsOptionsInterface questionsOptions) { |
|
26
|
|
|
this.questionsOptions = questionsOptions; |
|
27
|
|
|
return this; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
@Override |
|
31
|
|
|
public AnswerModelInterface withRelations(AnswerModelInterface answerModel) { |
|
32
|
|
|
|
|
33
|
|
|
if (answerModel == null) { |
|
34
|
|
|
return answerModel; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if (this.questionsOptions != null) { |
|
38
|
|
|
answerModel.setQuestion(this.questionsService.find( |
|
39
|
|
|
answerModel.getQuestion().getId(), this.questionsOptions)); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return answerModel; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
@Override |
|
46
|
|
|
public List<AnswerModelInterface> withRelations(List<AnswerModelInterface> answerModels) { |
|
47
|
|
|
|
|
48
|
|
|
for (AnswerModelInterface answerModel: answerModels) { |
|
49
|
|
|
this.withRelations(answerModel); |
|
50
|
|
|
} |
|
51
|
|
|
return answerModels; |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
@Override |
|
56
|
|
|
public void saveWithRelations(AnswerModelInterface answerModel) { |
|
57
|
|
|
|
|
58
|
|
|
if (this.questionsOptions != null) { |
|
59
|
|
|
this.questionsOptions.withAnswers(this); |
|
60
|
|
|
this.questionsOptions.saveWithRelations(answerModel.getQuestion()); |
|
61
|
|
|
return; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
@Override |
|
67
|
|
|
public void deleteWithRelations(AnswerModelInterface answerModel) { |
|
68
|
|
|
|
|
69
|
|
|
if (this.questionsOptions != null) { |
|
70
|
|
|
this.questionsOptions.withAnswers(this); |
|
71
|
|
|
this.questionsOptions.deleteWithRelations(answerModel.getQuestion()); |
|
72
|
|
|
return; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
this.answersService.delete(answerModel); |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|