@@ -131,51 +131,55 @@ public boolean delete(CustomerAttachmentDto template) throws RPException {
131
131
}
132
132
}
133
133
134
- //TODO Refactoring
135
134
private List <CustomerDto > fillCustomers (List <CustomerDto > customers ) throws RPException {
136
- UserDto userTemplate = new UserDto ();
137
- userTemplate .setUnit_coordinator (1 );
138
- List <UserDto > coordinators = userDao .searchAll (userTemplate );
139
- userTemplate .setUnit_coordinator (null );
140
- userTemplate .setAccount_manager (1 );
141
- List <UserDto > accountManagers = userDao .searchAll (userTemplate );
135
+ List <UserDto > users = userDao .getAll ();
142
136
143
137
for (CustomerDto customer : customers ){
144
- customer .setCoordinator (coordinators .stream ().filter (x -> x .getId ().equals (customer .getCoordinator_id ())).findFirst ().orElse (null ));
138
+ customer .setCoordinator (users .stream ().filter (x -> x .getId ().equals (customer .getCoordinator_id ())).findFirst ().orElse (null ));
145
139
customer .getCoordinator ().toPublic ();
140
+
146
141
if (customer .getAccounting () == 1 ){
147
142
Integer accountManagerId = customer .getAccount_manager_id ();
148
- customer .setAccount_manager (accountManagers .stream ().filter (x ->x .getId ().equals (accountManagerId )).findFirst ().orElse (null ));
143
+ customer .setAccount_manager (users .stream ().filter (x ->x .getId ().equals (accountManagerId )).findFirst ().orElse (null ));
149
144
customer .getAccount_manager ().toPublic ();
150
145
}
151
146
152
147
if (baseUser .isCoordinator ()){
153
- CustomerMemberDto customerMemberDto = new CustomerMemberDto ();
154
- customerMemberDto .setCustomer_id (customer .getId ());
155
- List <CustomerMemberDto > customerMembers = get (customerMemberDto );
156
- customer .setAccount_team (customerMembers );
157
-
158
- CustomerCommentDto customerCommentDtoTemplate = new CustomerCommentDto ();
159
- customerCommentDtoTemplate .setCustomer_id (customer .getId ());
160
- List <CustomerCommentDto > customerComments = get (customerCommentDtoTemplate );
161
- customer .setComments (customerComments );
162
-
163
-
164
- CustomerAttachmentDto customerAttachmentDtoTemplate = new CustomerAttachmentDto ();
165
- customerAttachmentDtoTemplate .setCustomer_id (customer .getId ());
166
- List <CustomerAttachmentDto > customerAttachments = get (customerAttachmentDtoTemplate );
167
- customer .setAttachments (customerAttachments );
168
-
169
- ProjectDao projectDao = new ProjectDao ();
170
- ProjectDto projectTemplate = new ProjectDto ();
171
- projectTemplate .setCustomer_id (customer .getId ());
172
- customer .setProjects (projectDao .searchAll (projectTemplate ));
148
+ customer .setAccount_team (getMembers (customer ));
149
+ customer .setComments (getComments (customer ));
150
+ customer .setAttachments (getAttachments (customer ));
151
+ customer .setProjects (getProjects (customer ));
173
152
}
174
153
}
175
154
176
155
return customers ;
177
156
}
178
157
158
+ private List <ProjectDto > getProjects (CustomerDto customer ) throws RPException {
159
+ ProjectDao projectDao = new ProjectDao ();
160
+ ProjectDto projectTemplate = new ProjectDto ();
161
+ projectTemplate .setCustomer_id (customer .getId ());
162
+ return projectDao .searchAll (projectTemplate );
163
+ }
164
+
165
+ private List <CustomerAttachmentDto > getAttachments (CustomerDto customer ) throws RPException {
166
+ CustomerAttachmentDto customerAttachmentDtoTemplate = new CustomerAttachmentDto ();
167
+ customerAttachmentDtoTemplate .setCustomer_id (customer .getId ());
168
+ return get (customerAttachmentDtoTemplate );
169
+ }
170
+
171
+ private List <CustomerCommentDto > getComments (CustomerDto customer ) throws RPException {
172
+ CustomerCommentDto customerCommentDtoTemplate = new CustomerCommentDto ();
173
+ customerCommentDtoTemplate .setCustomer_id (customer .getId ());
174
+ return get (customerCommentDtoTemplate );
175
+ }
176
+
177
+ private List <CustomerMemberDto > getMembers (CustomerDto customer ) throws RPException {
178
+ CustomerMemberDto customerMemberDto = new CustomerMemberDto ();
179
+ customerMemberDto .setCustomer_id (customer .getId ());
180
+ return get (customerMemberDto );
181
+ }
182
+
179
183
private CustomerDto fillCustomer (CustomerDto customer ) throws RPException {
180
184
List <CustomerDto > customers = new ArrayList <>();
181
185
customers .add (customer );
0 commit comments