@@ -47,134 +47,141 @@ public AuditController(UserDto user) {
47
47
public List <AuditDto > get (AuditDto searchTemplate ) throws AqualityException {
48
48
List <AuditDto > audits = auditDao .searchAll (searchTemplate );
49
49
Integer projectId ;
50
- try {
50
+ try {
51
51
projectId = searchTemplate .getId () == null
52
- ? searchTemplate .getProject_id ()
53
- : audits .get (0 ).getProject_id ();
54
- }catch (IndexOutOfBoundsException e ){
52
+ ? searchTemplate .getProject_id ()
53
+ : audits .get (0 ).getProject_id ();
54
+ } catch (IndexOutOfBoundsException e ) {
55
55
throw new AqualityException ("The Audit you trying to access is not present!" );
56
56
}
57
- if (baseUser .isFromGlobalManagement () || baseUser .getProjectUser (projectId ).isViewer ()){
57
+ if (baseUser .isFromGlobalManagement () || baseUser .getProjectUser (projectId ).isViewer ()) {
58
58
return completeAudits (audits );
59
- }else {
59
+ } else {
60
60
throw new AqualityPermissionsException ("Account is not allowed to view Audits." , baseUser );
61
61
}
62
62
}
63
+
63
64
public List <ServiceDto > get (ServiceDto template ) throws AqualityException {
64
65
return serviceDao .searchAll (template );
65
66
}
67
+
66
68
public List <AuditCommentDto > get (AuditCommentDto template ) throws AqualityException {
67
- if (baseUser .isFromGlobalManagement () || baseUser .getProjectUser (template .getProject_id ()).isViewer ()){
69
+ if (baseUser .isFromGlobalManagement () || baseUser .getProjectUser (template .getProject_id ()).isViewer ()) {
68
70
return completeComments (auditCommentsDao .searchAll (template ));
69
- }else {
71
+ } else {
70
72
throw new AqualityPermissionsException ("Account is not allowed to view Audit Comments." , baseUser );
71
73
}
72
74
}
75
+
73
76
public List <AuditStatisticDto > get (AuditStatisticDto template ) throws AqualityException {
74
- if (baseUser .isFromGlobalManagement ()){
77
+ if (baseUser .isFromGlobalManagement ()) {
75
78
return completeAuditStatistic (auditStatisticDao .searchAll (template ));
76
- }else {
79
+ } else {
77
80
throw new AqualityPermissionsException ("Account is not allowed to view Audits." , baseUser );
78
81
}
79
82
}
83
+
80
84
public List <AuditAttachmentDto > get (AuditAttachmentDto searchTemplate ) throws AqualityException {
81
85
AuditDto audit = new AuditDto ();
82
86
audit .setId (searchTemplate .getAudit_id ());
83
87
Integer projectId ;
84
- try {
88
+ try {
85
89
projectId = auditDao .searchAll (audit ).get (0 ).getProject_id ();
86
- }catch (IndexOutOfBoundsException e ){
90
+ } catch (IndexOutOfBoundsException e ) {
87
91
throw new AqualityException ("The Audit you trying to access is not present!" );
88
92
}
89
- if (baseUser .isFromGlobalManagement () || baseUser .getProjectUser (projectId ).isViewer ()){
93
+ if (baseUser .isFromGlobalManagement () || baseUser .getProjectUser (projectId ).isViewer ()) {
90
94
return auditAttachmentsDao .searchAll (searchTemplate );
91
- }else {
95
+ } else {
92
96
throw new AqualityPermissionsException ("Account is not allowed to view Audit Attachments." , baseUser );
93
97
}
94
98
}
95
99
96
100
@ Override
97
101
public AuditDto create (AuditDto createTemplate ) throws AqualityException {
98
- if (baseUser .isAuditAdmin () || isAssignedAuditor (createTemplate .getId ())){
102
+ if (baseUser .isAuditAdmin () || isAssignedAuditor (createTemplate .getId ())) {
99
103
AuditDto createdAudit = auditDao .create (createTemplate );
100
- if (createdAudit .getAuditors () != null ){
104
+ if (createdAudit .getAuditors () != null ) {
101
105
AuditorDto template = new AuditorDto ();
102
106
template .setAudit_id (createdAudit .getId ());
103
107
updateAuditors (createdAudit .getAuditors ());
104
108
}
105
109
106
110
return createdAudit ;
107
- }else {
111
+ } else {
108
112
throw new AqualityPermissionsException ("Account is not allowed to create Audits." , baseUser );
109
113
}
110
114
}
115
+
111
116
public AuditCommentDto create (AuditCommentDto template ) throws AqualityException {
112
117
AuditDto audit = new AuditDto ();
113
118
audit .setId (template .getAudit_id ());
114
119
audit = get (audit ).get (0 );
115
- if (baseUser .isFromGlobalManagement () || baseUser .getProjectUser (audit .getProject_id ()).isEditor ()){
120
+ if (baseUser .isFromGlobalManagement () || baseUser .getProjectUser (audit .getProject_id ()).isEditor ()) {
116
121
template .setUser_id (baseUser .getId ());
117
122
return auditCommentsDao .create (template );
118
- }else {
123
+ } else {
119
124
throw new AqualityPermissionsException ("Account is not allowed to create Audit Comments." , baseUser );
120
125
}
121
126
}
127
+
122
128
public String create (boolean all , boolean xls ) throws AqualityException {
123
129
ExcelUtils excelUtils = new ExcelUtils ();
124
130
AuditDto auditDto = new AuditDto ();
125
131
AuditStatusDto auditStatusDto = new AuditStatusDto ();
126
132
auditStatusDto .setId (4 );
127
133
auditDto .setStatus (auditStatusDto );
128
134
List <AuditDto > audits = get (auditDto );
129
- if (!all ){
135
+ if (!all ) {
130
136
audits = getLatestAudits (audits );
131
137
}
132
138
133
139
JSONArray resArray = new JSONArray ();
134
140
List <Pair <String , String >> fields = processExportArrayCreation (resArray , audits );
135
- try {
136
- if (xls ){
137
- return excelUtils .writeXLSFile (resArray ,fields , MessageFormat .format ("Aquality_Tracking_{0}_Submitted_Audits_{1}" , all ? "All" : "Last" , formatter .format (new Date ())), MessageFormat .format ("{0} Submitted Audits" , all ? "All" : "Last" ));
138
- }else {
139
- return excelUtils .writeXLSXFile (resArray ,fields , MessageFormat .format ("Aquality_Tracking_{0}_Submitted_Audits_{1}" , all ? "All" : "Last" ,formatter .format (new Date ())), MessageFormat .format ("{0} Submitted Audits" , all ? "All" : "Last" ));
141
+ try {
142
+ if (xls ) {
143
+ return excelUtils .writeXLSFile (resArray , fields , MessageFormat .format ("Aquality_Tracking_{0}_Submitted_Audits_{1}" , all ? "All" : "Last" , formatter .format (new Date ())), MessageFormat .format ("{0} Submitted Audits" , all ? "All" : "Last" ));
144
+ } else {
145
+ return excelUtils .writeXLSXFile (resArray , fields , MessageFormat .format ("Aquality_Tracking_{0}_Submitted_Audits_{1}" , all ? "All" : "Last" , formatter .format (new Date ())), MessageFormat .format ("{0} Submitted Audits" , all ? "All" : "Last" ));
140
146
}
141
- } catch (Exception e ){
147
+ } catch (Exception e ) {
142
148
throw new AqualityException ("Cannot create Export" );
143
149
}
144
150
}
145
151
146
152
public void createMultiply (List <AuditAttachmentDto > listOfAttachments ) throws AqualityException {
147
- if ((baseUser .isAuditAdmin () || isAssignedAuditor (listOfAttachments .get (0 ).getAudit_id ())) && isAuditOpened (listOfAttachments .get (0 ).getAudit_id ())){
153
+ if ((baseUser .isAuditAdmin () || isAssignedAuditor (listOfAttachments .get (0 ).getAudit_id ())) && isAuditOpened (listOfAttachments .get (0 ).getAudit_id ())) {
148
154
auditAttachmentsDao .createMultiply (listOfAttachments );
149
- }else {
155
+ } else {
150
156
throw new AqualityPermissionsException ("Account is not allowed to create Audit Attachments." , baseUser );
151
157
}
152
158
}
153
159
154
160
@ Override
155
161
public boolean delete (AuditDto template ) throws AqualityException {
156
- if (baseUser .isAuditAdmin ()){
162
+ if (baseUser .isAuditAdmin ()) {
157
163
return auditDao .delete (template );
158
- }else {
164
+ } else {
159
165
throw new AqualityPermissionsException ("Account is not allowed to delete Audits." , baseUser );
160
166
}
161
167
}
168
+
162
169
public boolean delete (AuditAttachmentDto template ) throws AqualityException {
163
- if (baseUser .isAuditor () ||baseUser .isAuditAdmin ()){
170
+ if (baseUser .isAuditor () || baseUser .isAuditAdmin ()) {
164
171
FileUtils fileUtils = new FileUtils ();
165
172
List <AuditAttachmentDto > attachments = get (template );
166
173
List <String > pathes = new ArrayList <>();
167
174
pathes .add (attachments .get (0 ).getPath ());
168
175
fileUtils .removeFiles (pathes );
169
176
return auditAttachmentsDao .delete (template );
170
- }else {
177
+ } else {
171
178
throw new AqualityPermissionsException ("Account is not allowed to delete Audit Attachments." , baseUser );
172
179
}
173
180
}
174
181
175
182
public void updateAuditors (List <AuditorDto > newAuditors ) throws AqualityException {
176
- if (baseUser .isAuditAdmin ()){
177
- if (newAuditors .size () == 0 ){
183
+ if (baseUser .isAuditAdmin ()) {
184
+ if (newAuditors .size () == 0 ) {
178
185
throw new AqualityException ("no new auditors" );
179
186
}
180
187
AuditorDto auditorDtoTemplate = new AuditorDto ();
@@ -192,12 +199,12 @@ public void updateAuditors(List<AuditorDto> newAuditors) throws AqualityExceptio
192
199
}
193
200
}
194
201
195
- if (oldAuditors .size () > 0 ) {
202
+ if (oldAuditors .size () > 0 ) {
196
203
for (AuditorDto oldAuditor : oldAuditors ) {
197
204
auditorsDao .delete (oldAuditor );
198
205
}
199
206
}
200
- }else {
207
+ } else {
201
208
throw new AqualityPermissionsException ("Account is not allowed to update Audit Auditors." , baseUser );
202
209
}
203
210
}
@@ -214,7 +221,7 @@ private List<AuditDto> completeAudits(List<AuditDto> audits) throws AqualityExce
214
221
List <AuditStatusDto > statuses = auditStatusDao .getAll ();
215
222
List <ServiceDto > services = serviceDao .getAll ();
216
223
217
- for (AuditDto audit : audits ){
224
+ for (AuditDto audit : audits ) {
218
225
filledAudits .add (completeAuditDto (audit , statuses , services ));
219
226
}
220
227
@@ -224,18 +231,18 @@ private List<AuditDto> completeAudits(List<AuditDto> audits) throws AqualityExce
224
231
private AuditDto completeAuditDto (AuditDto audit , List <AuditStatusDto > statuses , List <ServiceDto > services ) throws AqualityException {
225
232
audit .setProject (searchForProject (audit ));
226
233
audit .setAuditors (searchForAuditors (audit ));
227
- audit .setStatus (searchForStatus (audit ,statuses ));
228
- audit .setService (searchForService (audit ,services ));
234
+ audit .setStatus (searchForStatus (audit , statuses ));
235
+ audit .setService (searchForService (audit , services ));
229
236
audit .setComments (getAuditComments (audit ));
230
237
231
238
return audit ;
232
239
}
233
240
234
- private AuditStatusDto searchForStatus (AuditDto audit , List <AuditStatusDto > statuses ){
241
+ private AuditStatusDto searchForStatus (AuditDto audit , List <AuditStatusDto > statuses ) {
235
242
return statuses .stream ().filter (x -> x .getId ().equals (audit .getStatus_id ())).findAny ().orElse (null );
236
243
}
237
244
238
- private ServiceDto searchForService (AuditDto audit , List <ServiceDto > services ){
245
+ private ServiceDto searchForService (AuditDto audit , List <ServiceDto > services ) {
239
246
return services .stream ().filter (x -> x .getId ().equals (audit .getService_type_id ())).findAny ().orElse (null );
240
247
}
241
248
@@ -255,7 +262,7 @@ private List<AuditorDto> searchForAuditors(AuditDto audit) throws AqualityExcept
255
262
}
256
263
257
264
private boolean isAssignedAuditor (Integer auditId ) throws AqualityException {
258
- if (auditId != null ){
265
+ if (auditId != null ) {
259
266
AuditDto searchAudit = new AuditDto ();
260
267
searchAudit .setId (auditId );
261
268
List <AuditorDto > auditors = searchForAuditors (searchAudit );
@@ -265,7 +272,7 @@ private boolean isAssignedAuditor(Integer auditId) throws AqualityException {
265
272
}
266
273
267
274
private boolean isAuditOpened (Integer auditId ) throws AqualityException {
268
- if (auditId != null ){
275
+ if (auditId != null ) {
269
276
AuditDto searchAudit = new AuditDto ();
270
277
searchAudit .setId (auditId );
271
278
return get (searchAudit ).get (0 ).getStatus_id () < 4 ;
@@ -276,11 +283,11 @@ private boolean isAuditOpened(Integer auditId) throws AqualityException {
276
283
private List <AuditCommentDto > completeComments (List <AuditCommentDto > comments ) throws AqualityUserException {
277
284
UserDto userTemplate = new UserDto ();
278
285
279
- for (AuditCommentDto comment : comments ){
286
+ for (AuditCommentDto comment : comments ) {
280
287
281
- if (comment .getUser_id () != null ){
288
+ if (comment .getUser_id () != null ) {
282
289
userTemplate .setId (comment .getUser_id ());
283
- }else {
290
+ } else {
284
291
userTemplate .setId (1 );
285
292
}
286
293
comment .setAuthor (getUser (userTemplate ));
@@ -300,20 +307,20 @@ private List<AuditStatisticDto> completeAuditStatistic(List<AuditStatisticDto> a
300
307
List <ServiceDto > services = serviceDao .getAll ();
301
308
List <ProjectDto > projects = projectDao .getAll ();
302
309
303
- for (AuditStatisticDto auditStatistic : auditStatistics ) {
304
- if (auditStatistic .getLast_submitted_id () != null ){
310
+ for (AuditStatisticDto auditStatistic : auditStatistics ) {
311
+ if (auditStatistic .getLast_submitted_id () != null ) {
305
312
AuditorDto auditorDtoTemplate = new AuditorDto ();
306
313
auditorDtoTemplate .setAudit_id (auditStatistic .getLast_submitted_id ());
307
314
List <AuditorDto > auditors = auditorsDao .searchAll (auditorDtoTemplate );
308
315
auditStatistic .setAuditors_last (auditors );
309
316
}
310
- if (auditStatistic .getLast_created_id () != null && auditStatistic .getStatus_id () != 4 ){
317
+ if (auditStatistic .getLast_created_id () != null && auditStatistic .getStatus_id () != 4 ) {
311
318
AuditorDto auditorDtoTemplate = new AuditorDto ();
312
319
auditorDtoTemplate .setAudit_id (auditStatistic .getLast_created_id ());
313
320
List <AuditorDto > auditors = auditorsDao .searchAll (auditorDtoTemplate );
314
321
auditStatistic .setAuditors_next (auditors );
315
322
}
316
- if (auditStatistic .getService_type_id () != null ){
323
+ if (auditStatistic .getService_type_id () != null ) {
317
324
Integer serviceTypeId = auditStatistic .getService_type_id ();
318
325
auditStatistic .setService (services .stream ().filter (x -> Objects .equals (x .getId (), serviceTypeId )).findFirst ().orElse (null ));
319
326
}
@@ -327,7 +334,7 @@ private List<AuditDto> getLatestAudits(List<AuditDto> audits) throws AqualityExc
327
334
List <AuditDto > latest = new ArrayList <>();
328
335
ProjectDao projectDao = new ProjectDao ();
329
336
List <ProjectDto > projects = projectDao .getAll ();
330
- audits = audits .stream ().filter (x -> x .getSubmitted () != null ).collect (Collectors .toList ());
337
+ audits = audits .stream ().filter (x -> x .getSubmitted () != null ).collect (Collectors .toList ());
331
338
for (ProjectDto project : projects ) {
332
339
Integer id = project .getId ();
333
340
List <AuditDto > auditDtoList = audits .stream ().filter (x -> Objects .equals (x .getProject ().getId (), id )).collect (Collectors .toList ());
@@ -340,33 +347,35 @@ private List<AuditDto> getLatestAudits(List<AuditDto> audits) throws AqualityExc
340
347
return latest ;
341
348
}
342
349
343
- private List <Pair <String ,String >> processExportArrayCreation (JSONArray resArray , List <AuditDto > audits ) throws AqualityException {
344
- try {
350
+ private List <Pair <String , String >> processExportArrayCreation (JSONArray resArray , List <AuditDto > audits ) throws AqualityException {
351
+ try {
345
352
for (AuditDto auditDto : audits ) {
346
353
JSONObject jsonObject = new JSONObject ();
347
354
jsonObject .put ("id" , auditDto .getId ());
348
355
jsonObject .put ("project_name" , auditDto .getProject ().getName ());
349
- if (auditDto .getCreated () != null ) jsonObject .put ("created" , formatter .format (auditDto .getCreated ()));
350
- if (auditDto .getStarted ()!= null ) jsonObject .put ("started" , formatter .format (auditDto .getStarted ()));
351
- if (auditDto .getProgress_finished () != null ) jsonObject .put ("finished" , formatter .format (auditDto .getProgress_finished ()));
352
- if (auditDto .getSubmitted () != null ) jsonObject .put ("submitted" , formatter .format (auditDto .getSubmitted ()));
356
+ if (auditDto .getCreated () != null ) jsonObject .put ("created" , formatter .format (auditDto .getCreated ()));
357
+ if (auditDto .getStarted () != null ) jsonObject .put ("started" , formatter .format (auditDto .getStarted ()));
358
+ if (auditDto .getProgress_finished () != null )
359
+ jsonObject .put ("finished" , formatter .format (auditDto .getProgress_finished ()));
360
+ if (auditDto .getSubmitted () != null )
361
+ jsonObject .put ("submitted" , formatter .format (auditDto .getSubmitted ()));
353
362
jsonObject .put ("result" , auditDto .getResult ());
354
363
String auditorsString = "" ;
355
364
List <AuditorDto > auditors = auditDto .getAuditors ();
356
365
for (int j = 0 ; j < auditors .size (); j ++) {
357
366
if (j > 0 ) {
358
367
auditorsString += ", " ;
359
368
}
360
- try {
369
+ try {
361
370
auditorsString += auditors .get (j ).getFirst_name () + " " + auditors .get (j ).getSecond_name ();
362
- }catch (Exception e ){
371
+ } catch (Exception e ) {
363
372
//error on getting user info
364
373
}
365
374
}
366
375
jsonObject .put ("auditors" , auditorsString );
367
376
resArray .put (jsonObject );
368
377
}
369
- List <Pair <String ,String >> fields = new ArrayList <>();
378
+ List <Pair <String , String >> fields = new ArrayList <>();
370
379
fields .add (new Pair <>("Audit Id" , "id" ));
371
380
fields .add (new Pair <>("Project" , "project_name" ));
372
381
fields .add (new Pair <>("Date Created" , "created" ));
@@ -377,7 +386,7 @@ private List<Pair<String,String>> processExportArrayCreation(JSONArray resArray,
377
386
fields .add (new Pair <>("Auditors" , "auditors" ));
378
387
379
388
return fields ;
380
- } catch (Exception e ){
389
+ } catch (Exception e ) {
381
390
throw new AqualityException ("Cannot process export creation" );
382
391
}
383
392
}
0 commit comments