|
1
|
|
|
package easytests.core.services; |
|
2
|
|
|
|
|
3
|
|
|
import easytests.core.entities.*; |
|
4
|
|
|
import easytests.core.mappers.SubjectsMapper; |
|
5
|
|
|
import easytests.core.models.SubjectModel; |
|
6
|
|
|
import easytests.core.models.SubjectModelInterface; |
|
7
|
|
|
import easytests.core.models.UserModelInterface; |
|
8
|
|
|
import easytests.core.options.SubjectsOptionsInterface; |
|
9
|
|
|
import easytests.core.services.exceptions.DeleteUnidentifiedModelException; |
|
10
|
|
|
import java.util.ArrayList; |
|
11
|
|
|
import java.util.List; |
|
12
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
13
|
|
|
import org.springframework.stereotype.Service; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author vkpankov |
|
18
|
|
|
*/ |
|
19
|
|
|
@Service |
|
20
|
|
|
public class SubjectsService implements SubjectsServiceInterface { |
|
21
|
|
|
|
|
22
|
|
|
@Autowired |
|
23
|
|
|
private SubjectsMapper subjectsMapper; |
|
24
|
|
|
|
|
25
|
|
|
@Autowired |
|
26
|
|
|
private UsersService usersService; |
|
27
|
|
|
|
|
28
|
|
|
@Autowired |
|
29
|
|
|
private TopicsService topicsService; |
|
30
|
|
|
|
|
31
|
|
|
@Autowired |
|
32
|
|
|
private IssuesService issuesService; |
|
33
|
|
|
|
|
34
|
|
|
@Autowired |
|
35
|
|
|
private IssueStandardsService issueStandardsService; |
|
36
|
|
|
|
|
37
|
|
|
@Override |
|
38
|
|
|
public List<SubjectModelInterface> findAll() { |
|
39
|
|
|
return this.map(this.subjectsMapper.findAll()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
@Override |
|
43
|
|
|
public List<SubjectModelInterface> findAll(SubjectsOptionsInterface subjectsOptions) { |
|
44
|
|
|
return this.withServices(subjectsOptions).withRelations(this.findAll()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
@Override |
|
48
|
|
|
public SubjectModelInterface find(Integer id) { |
|
49
|
|
|
final SubjectEntity subjectEntity = this.subjectsMapper.find(id); |
|
50
|
|
|
if (subjectEntity == null) { |
|
51
|
|
|
return null; |
|
52
|
|
|
} |
|
53
|
|
|
return this.map(subjectEntity); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
@Override |
|
57
|
|
|
public SubjectModelInterface find(Integer id, SubjectsOptionsInterface subjectsOptions) { |
|
58
|
|
|
return this.withServices(subjectsOptions).withRelations(this.find(id)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
@Override |
|
62
|
|
|
public List<SubjectModelInterface> findByUser(UserModelInterface userModel) { |
|
63
|
|
|
return this.map(this.subjectsMapper.findByUserId(userModel.getId())); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
@Override |
|
67
|
|
|
public List<SubjectModelInterface> findByUser( |
|
68
|
|
|
UserModelInterface userModel, |
|
69
|
|
|
SubjectsOptionsInterface subjectsOptions |
|
70
|
|
|
) { |
|
71
|
|
|
return this.withServices(subjectsOptions).withRelations(this.findByUser(userModel)); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
@Override |
|
75
|
|
|
public void save(SubjectModelInterface subjectModel) { |
|
76
|
|
|
final SubjectEntity subjectEntity = this.map(subjectModel); |
|
77
|
|
|
if (subjectEntity.getId() == null) { |
|
78
|
|
|
this.subjectsMapper.insert(subjectEntity); |
|
79
|
|
|
subjectModel.setId(subjectEntity.getId()); |
|
80
|
|
|
return; |
|
81
|
|
|
} |
|
82
|
|
|
this.subjectsMapper.update(subjectEntity); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
@Override |
|
86
|
|
|
public void save(SubjectModelInterface subjectModel, SubjectsOptionsInterface subjectsOptions) { |
|
87
|
|
|
this.withServices(subjectsOptions).saveWithRelations(subjectModel); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
@Override |
|
91
|
|
|
public void save(List<SubjectModelInterface> subjectsModels) { |
|
92
|
|
|
for (SubjectModelInterface subjectModel: subjectsModels) { |
|
93
|
|
|
this.save(subjectModel); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
@Override |
|
98
|
|
|
public void save(List<SubjectModelInterface> subjectsModels, SubjectsOptionsInterface subjectsOptions) { |
|
99
|
|
|
for (SubjectModelInterface subjectModel: subjectsModels) { |
|
100
|
|
|
this.save(subjectModel, subjectsOptions); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
@Override |
|
105
|
|
|
public void delete(SubjectModelInterface subjectModel) { |
|
106
|
|
|
final SubjectEntity subjectEntity = this.map(subjectModel); |
|
107
|
|
|
if (subjectEntity.getId() == null) { |
|
108
|
|
|
throw new DeleteUnidentifiedModelException(); |
|
109
|
|
|
} |
|
110
|
|
|
this.subjectsMapper.delete(subjectEntity); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
@Override |
|
114
|
|
|
public void delete(SubjectModelInterface subjectModel, SubjectsOptionsInterface subjectsOptions) { |
|
115
|
|
|
this.withServices(subjectsOptions).deleteWithRelations(subjectModel); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
@Override |
|
119
|
|
|
public void delete(List<SubjectModelInterface> subjectsModels) { |
|
120
|
|
|
for (SubjectModelInterface subjectModel: subjectsModels) { |
|
121
|
|
|
this.delete(subjectModel); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
@Override |
|
126
|
|
|
public void delete(List<SubjectModelInterface> subjectsModels, SubjectsOptionsInterface subjectsOptions) { |
|
127
|
|
|
for (SubjectModelInterface subjectModel: subjectsModels) { |
|
128
|
|
|
this.delete(subjectModel, subjectsOptions); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
private SubjectEntity map(SubjectModelInterface subjectModel) { |
|
133
|
|
|
final SubjectEntity subjectEntity = new SubjectEntity(); |
|
134
|
|
|
subjectEntity.map(subjectModel); |
|
135
|
|
|
return subjectEntity; |
|
136
|
|
|
|
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
private SubjectModel map(SubjectEntity subjectEntity) { |
|
140
|
|
|
final SubjectModel subjectModel = new SubjectModel(); |
|
141
|
|
|
subjectModel.map(subjectEntity); |
|
142
|
|
|
return subjectModel; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
private List<SubjectModelInterface> map(List<SubjectEntity> subjectsList) { |
|
146
|
|
|
final List<SubjectModelInterface> resultSubjectList = new ArrayList(subjectsList.size()); |
|
147
|
|
|
for (SubjectEntity subject: subjectsList) { |
|
148
|
|
|
resultSubjectList.add(this.map(subject)); |
|
149
|
|
|
} |
|
150
|
|
|
return resultSubjectList; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
private SubjectsOptionsInterface withServices(SubjectsOptionsInterface subjectsOptions) { |
|
154
|
|
|
subjectsOptions.setIssuesService(this.issuesService); |
|
155
|
|
|
subjectsOptions.setSubjectsService(this); |
|
156
|
|
|
subjectsOptions.setUsersService(this.usersService); |
|
157
|
|
|
subjectsOptions.setIssueStandardsService(this.issueStandardsService); |
|
158
|
|
|
subjectsOptions.setTopicsService(this.topicsService); |
|
159
|
|
|
return subjectsOptions; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
} |
|
163
|
|
|
|