69
69
import org .eclipse .sw360 .datahandler .thrift .attachments .AttachmentUsage ;
70
70
import org .eclipse .sw360 .datahandler .thrift .attachments .CheckStatus ;
71
71
import org .eclipse .sw360 .datahandler .thrift .attachments .UsageData ;
72
- import org .eclipse .sw360 .datahandler .thrift .components .ClearingState ;
73
- import org .eclipse .sw360 .datahandler .thrift .components .Release ;
74
- import org .eclipse .sw360 .datahandler .thrift .components .ReleaseClearingStateSummary ;
75
- import org .eclipse .sw360 .datahandler .thrift .components .ReleaseLink ;
76
- import org .eclipse .sw360 .datahandler .thrift .components .ReleaseNode ;
72
+ import org .eclipse .sw360 .datahandler .thrift .components .*;
77
73
import org .eclipse .sw360 .datahandler .thrift .licenseinfo .LicenseInfo ;
78
74
import org .eclipse .sw360 .datahandler .thrift .licenseinfo .LicenseInfoFile ;
79
75
import org .eclipse .sw360 .datahandler .thrift .licenseinfo .LicenseInfoParsingResult ;
80
76
import org .eclipse .sw360 .datahandler .thrift .licenseinfo .LicenseNameWithText ;
81
77
import org .eclipse .sw360 .datahandler .thrift .licenseinfo .OutputFormatInfo ;
82
78
import org .eclipse .sw360 .datahandler .thrift .licenseinfo .OutputFormatVariant ;
83
79
import org .eclipse .sw360 .datahandler .thrift .licenses .License ;
84
- import org .eclipse .sw360 .datahandler .thrift .projects .ObligationList ;
85
- import org .eclipse .sw360 .datahandler .thrift .projects .ObligationStatusInfo ;
86
- import org .eclipse .sw360 .datahandler .thrift .projects .Project ;
87
- import org .eclipse .sw360 .datahandler .thrift .projects .ProjectClearingState ;
88
- import org .eclipse .sw360 .datahandler .thrift .projects .ProjectLink ;
89
- import org .eclipse .sw360 .datahandler .thrift .projects .ProjectProjectRelationship ;
90
- import org .eclipse .sw360 .datahandler .thrift .projects .ProjectRelationship ;
91
- import org .eclipse .sw360 .datahandler .thrift .projects .ProjectDTO ;
92
- import org .eclipse .sw360 .datahandler .thrift .projects .ClearingRequest ;
80
+ import org .eclipse .sw360 .datahandler .thrift .projects .*;
93
81
import org .eclipse .sw360 .datahandler .thrift .users .User ;
94
82
import org .eclipse .sw360 .datahandler .thrift .users .UserGroup ;
95
83
import org .eclipse .sw360 .datahandler .thrift .vendors .Vendor ;
@@ -259,6 +247,16 @@ public ResponseEntity<CollectionModel<EntityModel<Project>>> getProjectsForUser(
259
247
@ RequestParam (value = "tag" , required = false ) String tag ,
260
248
@ Parameter (description = "Flag to get projects with all details." )
261
249
@ RequestParam (value = "allDetails" , required = false ) boolean allDetails ,
250
+ @ Parameter (description = "The version of the project" )
251
+ @ RequestParam (value = "version" , required = false ) String version ,
252
+ @ Parameter (description = "The projectResponsible of the project" )
253
+ @ RequestParam (value = "projectResponsible" , required = false ) String projectResponsible ,
254
+ @ Parameter (description = "The state of the project" )
255
+ @ RequestParam (value = "state" , required = false ) ProjectState projectState ,
256
+ @ Parameter (description = "The clearingStatus of the project" )
257
+ @ RequestParam (value = "clearingStatus" , required = false ) ProjectClearingState projectClearingState ,
258
+ @ Parameter (description = "The additionalData of the project" )
259
+ @ RequestParam (value = "additionalData" , required = false ) String additionalData ,
262
260
@ Parameter (description = "List project by lucene search" )
263
261
@ RequestParam (value = "luceneSearch" , required = false ) boolean luceneSearch ,
264
262
HttpServletRequest request ) throws TException , URISyntaxException , PaginationParameterException , ResourceClassNotFoundException {
@@ -269,23 +267,13 @@ public ResponseEntity<CollectionModel<EntityModel<Project>>> getProjectsForUser(
269
267
boolean isSearchByType = CommonUtils .isNotNullEmptyOrWhitespace (projectType );
270
268
boolean isSearchByGroup = CommonUtils .isNotNullEmptyOrWhitespace (group );
271
269
boolean isNoFilter = false ;
270
+ boolean isAllProjectAdded =false ;
272
271
String queryString = request .getQueryString ();
273
272
Map <String , String > params = restControllerHelper .parseQueryString (queryString );
274
273
List <Project > sw360Projects = new ArrayList <>();
275
- Map <String , Set <String >> filterMap = new HashMap <>();
276
274
if (luceneSearch ) {
277
- if (CommonUtils .isNotNullEmptyOrWhitespace (projectType )) {
278
- Set <String > values = CommonUtils .splitToSet (projectType );
279
- filterMap .put (Project ._Fields .PROJECT_TYPE .getFieldName (), values );
280
- }
281
- if (CommonUtils .isNotNullEmptyOrWhitespace (group )) {
282
- Set <String > values = CommonUtils .splitToSet (group );
283
- filterMap .put (Project ._Fields .BUSINESS_UNIT .getFieldName (), values );
284
- }
285
- if (CommonUtils .isNotNullEmptyOrWhitespace (tag )) {
286
- Set <String > values = CommonUtils .splitToSet (tag );
287
- filterMap .put (Project ._Fields .TAG .getFieldName (), values );
288
- }
275
+ Map <String , Set <String >> filterMap = getFilterMap (tag , projectType , group , version , projectResponsible , projectState , projectClearingState ,
276
+ additionalData );
289
277
290
278
if (CommonUtils .isNotNullEmptyOrWhitespace (name )) {
291
279
Set <String > values = CommonUtils .splitToSet (name );
@@ -298,24 +286,56 @@ public ResponseEntity<CollectionModel<EntityModel<Project>>> getProjectsForUser(
298
286
} else {
299
287
if (isSearchByName ) {
300
288
sw360Projects .addAll (projectService .searchProjectByName (params .get ("name" ), sw360User ));
301
- } else if (isSearchByGroup ) {
302
- sw360Projects .addAll (projectService .searchProjectByGroup (group , sw360User ));
303
- } else if (isSearchByTag ) {
304
- sw360Projects .addAll (projectService .searchProjectByTag (params .get ("tag" ), sw360User ));
305
- } else if (isSearchByType ) {
306
- sw360Projects .addAll (projectService .searchProjectByType (projectType , sw360User ));
307
289
} else {
308
- sw360Projects .addAll (projectService .getProjectsForUser (sw360User , pageable ));
290
+ isAllProjectAdded =true ;
291
+ sw360Projects .addAll (projectService .getProjectsSummaryForUserWithoutPagination (sw360User ));
292
+ }
293
+ Map <String , Set <String >> restrictions = getFilterMap (tag , projectType , group , version , projectResponsible , projectState , projectClearingState ,
294
+ additionalData );
295
+ if (!restrictions .isEmpty ()) {
296
+ sw360Projects = new ArrayList <>(sw360Projects .stream ()
297
+ .filter (filterProjectMap (restrictions )).toList ());
298
+ }else if (isAllProjectAdded ){
309
299
isNoFilter = true ;
310
300
}
311
301
}
312
- return getProjectResponse (pageable , projectType , group , tag , allDetails , luceneSearch , request , sw360User ,
302
+ return getProjectResponse (pageable , allDetails , luceneSearch , request , sw360User ,
313
303
mapOfProjects , isSearchByName , sw360Projects , isNoFilter );
314
304
}
315
305
306
+ private Map <String , Set <String >> getFilterMap (String tag , String projectType , String group , String version , String projectResponsible ,
307
+ ProjectState projectState , ProjectClearingState projectClearingState , String additionalData ) {
308
+ Map <String , Set <String >> filterMap = new HashMap <>();
309
+ if (CommonUtils .isNotNullEmptyOrWhitespace (tag )) {
310
+ filterMap .put (Project ._Fields .TAG .getFieldName (), CommonUtils .splitToSet (tag ));
311
+ }
312
+ if (CommonUtils .isNotNullEmptyOrWhitespace (projectType )) {
313
+ filterMap .put (Project ._Fields .PROJECT_TYPE .getFieldName (), CommonUtils .splitToSet (projectType ));
314
+ }
315
+ if (CommonUtils .isNotNullEmptyOrWhitespace (group )) {
316
+ filterMap .put (Project ._Fields .BUSINESS_UNIT .getFieldName (), CommonUtils .splitToSet (group ));
317
+ }
318
+ if (CommonUtils .isNotNullEmptyOrWhitespace (version )) {
319
+ filterMap .put (Project ._Fields .VERSION .getFieldName (), CommonUtils .splitToSet (version ));
320
+ }
321
+ if (CommonUtils .isNotNullEmptyOrWhitespace (projectResponsible )) {
322
+ filterMap .put (Project ._Fields .PROJECT_RESPONSIBLE .getFieldName (), CommonUtils .splitToSet (projectResponsible ));
323
+ }
324
+ if (projectState !=null && CommonUtils .isNotNullEmptyOrWhitespace (projectState .name ())) {
325
+ filterMap .put (Project ._Fields .STATE .getFieldName (), CommonUtils .splitToSet (projectState .name ()));
326
+ }
327
+ if (projectClearingState !=null && CommonUtils .isNotNullEmptyOrWhitespace (projectClearingState .name ())) {
328
+ filterMap .put (Project ._Fields .CLEARING_STATE .getFieldName (), CommonUtils .splitToSet (projectClearingState .name ()));
329
+ }
330
+ if (CommonUtils .isNotNullEmptyOrWhitespace (additionalData )) {
331
+ filterMap .put (Project ._Fields .ADDITIONAL_DATA .getFieldName (), CommonUtils .splitToSet (additionalData ));
332
+ }
333
+ return filterMap ;
334
+ }
335
+
316
336
@ NotNull
317
337
private ResponseEntity <CollectionModel <EntityModel <Project >>> getProjectResponse (Pageable pageable ,
318
- String projectType , String group , String tag , boolean allDetails , boolean luceneSearch ,
338
+ boolean allDetails , boolean luceneSearch ,
319
339
HttpServletRequest request , User sw360User , Map <String , Project > mapOfProjects , boolean isSearchByName ,
320
340
List <Project > sw360Projects , boolean isNoFilter ) throws ResourceClassNotFoundException , PaginationParameterException , URISyntaxException , TException {
321
341
sw360Projects .stream ().forEach (prj -> mapOfProjects .put (prj .getId (), prj ));
@@ -347,11 +367,9 @@ private ResponseEntity<CollectionModel<EntityModel<Project>>> getProjectResponse
347
367
if (luceneSearch ) {
348
368
paginationResult .getResources ().stream ().forEach (consumer );
349
369
} else {
350
- paginationResult .getResources ().stream ()
351
- .filter (project -> projectType == null || projectType .equals (project .projectType .name ()))
352
- .filter (project -> group == null || group .isEmpty () || group .equals (project .getBusinessUnit ()))
353
- .filter (project -> tag == null || tag .isEmpty () || tag .equals (project .getTag ())).forEach (consumer );
370
+ paginationResult .getResources ().stream ().forEach (consumer );
354
371
}
372
+
355
373
CollectionModel resources ;
356
374
if (projectResources .size () == 0 ) {
357
375
resources = restControllerHelper .emptyPageResource (Project .class , paginationResult );
@@ -415,7 +433,7 @@ public ResponseEntity<CollectionModel<EntityModel<Project>>> getProjectsFiltered
415
433
List <Project > sw360Projects = projectService .getMyProjects (sw360User , userRoles );
416
434
sw360Projects = projectService .getWithFilledClearingStatus (sw360Projects , clearingState );
417
435
418
- return getProjectResponse (pageable , null , null , null , allDetails , true , request , sw360User ,
436
+ return getProjectResponse (pageable , allDetails , true , request , sw360User ,
419
437
mapOfProjects , true , sw360Projects , false );
420
438
}
421
439
@@ -3418,4 +3436,48 @@ public ResponseEntity<?> createDuplicateProjectWithDependencyNetwork(
3418
3436
3419
3437
return ResponseEntity .created (location ).body (projectDTOHalResource );
3420
3438
}
3439
+
3440
+ /**
3441
+ * Create a filter predicate to remove all projects which do not satisfy the restriction set.
3442
+ * @param restrictions Restrictions set to filter projects on
3443
+ * @return Filter predicate for stream.
3444
+ */
3445
+ private static @ NonNull Predicate <Project > filterProjectMap (Map <String , Set <String >> restrictions ) {
3446
+ return project -> {
3447
+ for (Map .Entry <String , Set <String >> restriction : restrictions .entrySet ()) {
3448
+ final Set <String > filterSet = restriction .getValue ();
3449
+ Project ._Fields field = Project ._Fields .findByName (restriction .getKey ());
3450
+ Object fieldValue = project .getFieldValue (field );
3451
+ if (fieldValue == null ) {
3452
+ return false ;
3453
+ }
3454
+ if (field == Project ._Fields .PROJECT_TYPE && !filterSet .contains (project .projectType .name ())) {
3455
+ return false ;
3456
+ } else if (field == Project ._Fields .VERSION && !filterSet .contains (project .version )) {
3457
+ return false ;
3458
+ } else if (field == Project ._Fields .PROJECT_RESPONSIBLE && !filterSet .contains (project .projectResponsible )) {
3459
+ return false ;
3460
+ } else if (field == Project ._Fields .STATE && !filterSet .contains (project .state .name ())) {
3461
+ return false ;
3462
+ } else if (field == Project ._Fields .CLEARING_STATE && !filterSet .contains (project .clearingState .name ())) {
3463
+ return false ;
3464
+ } else if ((field == Project ._Fields .CREATED_BY || field == Project ._Fields .CREATED_ON )
3465
+ && !fieldValue .toString ().equalsIgnoreCase (filterSet .iterator ().next ())) {
3466
+ return false ;
3467
+ } else if (fieldValue instanceof Set ) {
3468
+ if (Sets .intersection (filterSet , (Set <String >) fieldValue ).isEmpty ()) {
3469
+ return false ;
3470
+ }
3471
+ } else if (fieldValue instanceof Map <?,?>) {
3472
+ Map <?, ?> fieldValueMap = (Map <?, ?>) fieldValue ;
3473
+ boolean hasIntersection = fieldValueMap .keySet ().stream ()
3474
+ .anyMatch (filterSet ::contains );
3475
+ if (!hasIntersection ) {
3476
+ return false ;
3477
+ }
3478
+ }
3479
+ }
3480
+ return true ;
3481
+ };
3482
+ }
3421
3483
}
0 commit comments