2626
2727import sqlalchemy
2828from sqlalchemy .sql .expression import or_ , and_ , not_ , func , \
29- asc , desc , union_all , select , bindparam , literal_column , case , cast , true
29+ asc , desc , union_all , select , bindparam , literal_column , cast , true
3030from sqlalchemy .orm import contains_eager
3131from sqlalchemy .types import ARRAY , String
3232
@@ -1383,48 +1383,6 @@ def get_run_id_expression(session, report_filter):
13831383 return Run .id .label ("run_id" )
13841384
13851385
1386- def get_is_enabled_case (subquery ):
1387- """
1388- Creating a case statement to decide the report
1389- is enabled or not based on the detection status
1390- """
1391- detection_status_filters = subquery .c .detection_status .in_ (list (
1392- map (detection_status_str ,
1393- (DetectionStatus .OFF , DetectionStatus .UNAVAILABLE ))
1394- ))
1395-
1396- return case (
1397- (detection_status_filters , False ),
1398- else_ = True
1399- )
1400-
1401-
1402- def get_is_opened_case (subquery ):
1403- """
1404- Creating a case statement to decide the report is opened or not
1405- based on the detection status and the review status
1406- """
1407- detection_statuses = (
1408- DetectionStatus .NEW ,
1409- DetectionStatus .UNRESOLVED ,
1410- DetectionStatus .REOPENED
1411- )
1412- review_statuses = (
1413- API_ReviewStatus .UNREVIEWED ,
1414- API_ReviewStatus .CONFIRMED
1415- )
1416- detection_and_review_status_filters = [
1417- subquery .c .detection_status .in_ (list (map (
1418- detection_status_str , detection_statuses ))),
1419- subquery .c .review_status .in_ (list (map (
1420- review_status_str , review_statuses )))
1421- ]
1422- return case (
1423- (and_ (* detection_and_review_status_filters ), True ),
1424- else_ = False
1425- )
1426-
1427-
14281386def remove_reports (session : DBSession ,
14291387 report_ids : Collection ,
14301388 chunk_size : int = SQLITE_MAX_VARIABLE_NUMBER ):
@@ -3116,18 +3074,15 @@ def getCheckerStatusVerificationDetails(self, run_ids, report_filter):
31163074
31173075 subquery = subquery .subquery ()
31183076
3119- is_enabled_case = get_is_enabled_case (subquery )
3120- is_opened_case = get_is_opened_case (subquery )
3121-
31223077 query = (
31233078 session .query (
31243079 subquery .c .checker_id ,
31253080 subquery .c .checker_name ,
31263081 subquery .c .analyzer_name ,
31273082 subquery .c .severity ,
31283083 subquery .c .run_id ,
3129- is_enabled_case . label ( "isEnabled" ) ,
3130- is_opened_case . label ( "isOpened" ) ,
3084+ subquery . c . detection_status ,
3085+ subquery . c . review_status ,
31313086 func .count (subquery .c .bug_id )
31323087 )
31333088 .group_by (
@@ -3136,8 +3091,8 @@ def getCheckerStatusVerificationDetails(self, run_ids, report_filter):
31363091 subquery .c .analyzer_name ,
31373092 subquery .c .severity ,
31383093 subquery .c .run_id ,
3139- is_enabled_case ,
3140- is_opened_case
3094+ subquery . c . detection_status ,
3095+ subquery . c . review_status
31413096 )
31423097 )
31433098
@@ -3148,8 +3103,8 @@ def getCheckerStatusVerificationDetails(self, run_ids, report_filter):
31483103 analyzer_name , \
31493104 severity , \
31503105 run_id_list , \
3151- is_enabled , \
3152- is_opened , \
3106+ detection_status , \
3107+ review_status , \
31533108 cnt \
31543109 in query .all ():
31553110
@@ -3165,6 +3120,22 @@ def getCheckerStatusVerificationDetails(self, run_ids, report_filter):
31653120 outstanding = 0
31663121 ))
31673122
3123+ is_enabled = detection_status not in map (
3124+ detection_status_str ,
3125+ (DetectionStatus .OFF , DetectionStatus .UNAVAILABLE ))
3126+
3127+ is_opened = \
3128+ detection_status in map (
3129+ detection_status_str ,
3130+ (DetectionStatus .NEW ,
3131+ DetectionStatus .UNRESOLVED ,
3132+ DetectionStatus .REOPENED )) \
3133+ and \
3134+ review_status in map (
3135+ review_status_str ,
3136+ (API_ReviewStatus .UNREVIEWED ,
3137+ API_ReviewStatus .CONFIRMED ))
3138+
31683139 if is_enabled :
31693140 for r in (run_id_list .split ("," )
31703141 if isinstance (run_id_list , str )
@@ -3373,10 +3344,24 @@ def getReportStatusCounts(self, run_ids, report_filter, cmp_data):
33733344 filter_expression , join_tables = process_report_filter (
33743345 session , run_ids , report_filter , cmp_data )
33753346
3347+ detection_and_review_status_filters = [
3348+ Report .detection_status .in_ (list (map (
3349+ detection_status_str ,
3350+ (DetectionStatus .NEW ,
3351+ DetectionStatus .UNRESOLVED ,
3352+ DetectionStatus .REOPENED )))),
3353+ Report .review_status .in_ (list (map (
3354+ review_status_str ,
3355+ (API_ReviewStatus .UNREVIEWED ,
3356+ API_ReviewStatus .CONFIRMED ))))
3357+ ]
3358+
33763359 extended_table = session .query (
33773360 Report .review_status ,
33783361 Report .detection_status ,
3379- Report .bug_id
3362+ Report .bug_id ,
3363+ and_ (* detection_and_review_status_filters )
3364+ .label ("isOutstanding" )
33803365 )
33813366
33823367 if report_filter .annotations is not None :
@@ -3391,19 +3376,16 @@ def getReportStatusCounts(self, run_ids, report_filter, cmp_data):
33913376
33923377 extended_table = extended_table .subquery ()
33933378
3394- is_outstanding_case = get_is_opened_case (extended_table )
3395- case_label = "isOutstanding"
3396-
33973379 if report_filter .isUnique :
33983380 q = session .query (
3399- is_outstanding_case . label ( case_label ) ,
3381+ extended_table . c . isOutstanding ,
34003382 func .count (extended_table .c .bug_id .distinct ())) \
3401- .group_by (is_outstanding_case )
3383+ .group_by (extended_table . c . isOutstanding )
34023384 else :
34033385 q = session .query (
3404- is_outstanding_case . label ( case_label ) ,
3386+ extended_table . c . isOutstanding ,
34053387 func .count (extended_table .c .bug_id )) \
3406- .group_by (is_outstanding_case )
3388+ .group_by (extended_table . c . isOutstanding )
34073389
34083390 results = {
34093391 report_status_enum (
0 commit comments