easytests.core.options.SubjectsOptions   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 132
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
c 1
b 0
f 0
loc 132
rs 10
wmc 22

11 Methods

Rating   Name   Duplication   Size   Complexity  
withUser 0 3 ?
withTopics 0 3 ?
withIssues 0 3 ?
A withUser(UsersOptionsInterface) 0 3 1
A withTopics(TopicsOptionsInterface) 0 3 1
A withIssueStandard(IssueStandardsOptionsInterface) 0 3 1
A withIssues(IssuesOptionsInterface) 0 3 1
B withRelations(SubjectModelInterface) 0 23 6
A withRelations(List) 0 6 2
B deleteWithRelations(SubjectModelInterface) 0 21 5
B saveWithRelations(SubjectModelInterface) 0 26 5
1
package easytests.core.options;
2
3
import easytests.core.models.IssueStandardModelInterface;
4
import easytests.core.models.SubjectModelInterface;
5
import easytests.core.services.*;
6
import java.util.List;
7
import lombok.EqualsAndHashCode;
8
import lombok.Setter;
9
10
11
/**
12
 * @author vkpankov
13
 */
14
@EqualsAndHashCode
15
public class SubjectsOptions implements SubjectsOptionsInterface {
16
17
    @Setter
18
    private UsersServiceInterface usersService;
19
20
    @Setter
21
    private SubjectsServiceInterface subjectsService;
22
23
    @Setter
24
    private TopicsServiceInterface topicsService;
25
26
    @Setter
27
    private IssuesServiceInterface issuesService;
28
29
    @Setter
30
    private IssueStandardsServiceInterface issueStandardsService;
31
32
    private UsersOptionsInterface usersOptions;
33
34
    private TopicsOptionsInterface topicsOptions;
35
36
    private IssuesOptionsInterface issuesOptions;
37
38
    private IssueStandardsOptionsInterface issueStandardsOptions;
39
40
    public SubjectsOptionsInterface withIssues(IssuesOptionsInterface issuesOptions) {
41
        this.issuesOptions = issuesOptions;
42
        return this;
43
    }
44
45
    public SubjectsOptionsInterface withUser(UsersOptionsInterface usersOptions) {
46
        this.usersOptions = usersOptions;
47
        return this;
48
    }
49
50
    public SubjectsOptionsInterface withIssueStandard(IssueStandardsOptionsInterface issueStandardOptions) {
51
        this.issueStandardsOptions = issueStandardOptions;
52
        return this;
53
    }
54
55
    public SubjectsOptionsInterface withTopics(TopicsOptionsInterface topicsOptions) {
56
        this.topicsOptions = topicsOptions;
57
        return this;
58
    }
59
60
    public SubjectModelInterface withRelations(SubjectModelInterface subjectModel) {
61
62
        if (subjectModel == null) {
63
            return subjectModel;
64
        }
65
66
        if (this.usersOptions != null) {
67
            subjectModel.setUser(this.usersService.find(subjectModel.getUser().getId(), this.usersOptions));
68
        }
69
        if (this.topicsOptions != null) {
70
            subjectModel.setTopics(this.topicsService.findBySubject(subjectModel, this.topicsOptions));
71
        }
72
        if (this.issueStandardsOptions != null) {
73
            final IssueStandardModelInterface issueStandard =
74
                    this.issueStandardsService.findBySubject(subjectModel, this.issueStandardsOptions);
75
76
            subjectModel.setIssueStandard(issueStandard);
77
        }
78
        if (this.issuesOptions != null) {
79
            subjectModel.setIssues(this.issuesService.findBySubject(subjectModel, this.issuesOptions));
80
        }
81
82
        return subjectModel;
83
84
    }
85
86
    public List<SubjectModelInterface> withRelations(List<SubjectModelInterface> subjectsModels) {
87
88
        for (SubjectModelInterface subjectModel: subjectsModels) {
89
            this.withRelations(subjectModel);
90
        }
91
        return subjectsModels;
92
93
    }
94
95
    public void saveWithRelations(SubjectModelInterface subjectModel) {
96
97
        if (this.usersOptions != null) {
98
99
            this.usersOptions.withSubjects(this);
100
            this.usersOptions.saveWithRelations(subjectModel.getUser());
101
            return;
102
103
        }
104
105
        this.subjectsService.save(subjectModel);
106
107
        if (this.issueStandardsOptions != null) {
108
109
            this.issueStandardsService.save(subjectModel.getIssueStandard(), this.issueStandardsOptions);
110
111
        }
112
113
        if (this.topicsOptions != null) {
114
115
            this.topicsService.save(subjectModel.getTopics(), this.topicsOptions);
116
117
        }
118
        if (this.issuesOptions != null) {
119
120
            this.issuesService.save(subjectModel.getIssues(), this.issuesOptions);
121
        }
122
123
    }
124
125
    public void deleteWithRelations(SubjectModelInterface subjectModel) {
126
127
        if (this.usersOptions != null) {
128
            this.usersOptions.withSubjects(this);
129
            this.usersOptions.deleteWithRelations(subjectModel.getUser());
130
            return;
131
        }
132
133
        if (this.topicsOptions != null) {
134
            this.topicsService.delete(subjectModel.getTopics(), this.topicsOptions);
135
136
        }
137
        if (this.issueStandardsOptions != null) {
138
            this.issueStandardsService.delete(subjectModel.getIssueStandard(), this.issueStandardsOptions);
139
        }
140
141
        if (this.issuesOptions != null) {
142
            this.issuesService.delete(subjectModel.getIssues(), this.issuesOptions);
143
        }
144
145
        this.subjectsService.delete(subjectModel);
146
147
    }
148
}
149