@@ -409,6 +409,29 @@ public Integer getScanStatus(Integer scanId) {
409409 return UNKNOWN_INT ;
410410 }
411411
412+ public String getScanStatusName (Integer scanId ) {
413+ HttpEntity httpEntity = new HttpEntity <>(authClient .createAuthHeaders ());
414+ log .debug ("Retrieving xml status of xml Id {}" , scanId );
415+ try {
416+ ResponseEntity <String > projects = restTemplate .exchange (cxProperties .getUrl ().concat (SCAN_STATUS ), HttpMethod .GET , httpEntity , String .class , scanId );
417+ JSONObject obj = new JSONObject (projects .getBody ());
418+ JSONObject status = obj .getJSONObject ("status" );
419+ log .debug ("status id {}, status name {}" , status .getInt ("id" ), status .getString ("name" ));
420+ return status .getString ("name" );
421+ } catch (HttpStatusCodeException e ) {
422+ log .error ("HTTP Status Code of {} while getting xml status for xml Id {}" , e .getStatusCode (), scanId );
423+ log .error (ExceptionUtils .getStackTrace (e ));
424+ } catch (JSONException e ) {
425+ log .error ("Error processing JSON Response" );
426+ log .error (ExceptionUtils .getStackTrace (e ));
427+ }
428+ catch (Exception e ) {
429+ log .error ("Error occurred while getting scan status" );
430+ log .error (ExceptionUtils .getStackTrace (e ));
431+ }
432+ return "NA" ;
433+ }
434+
412435 /**
413436 * Generate a scan report request (xml) based on ScanId
414437 */
@@ -639,12 +662,17 @@ public ScanResults getReportContent(Integer reportId, FilterConfiguration filter
639662 cxScanBuilder .setVersion (cxResults .getCheckmarxVersion ());
640663 cxScanBuilder .additionalDetails (getAdditionalScanDetails (cxResults ));
641664 CxScanSummary scanSummary = null ;
665+ CxScanSummary projectSummary = null ;
642666 if (cxProperties .getRestrictResultsToBranch () != null && cxProperties .getRestrictResultsToBranch ()) {
667+ if (cxProperties .getProjectSummary ()!=null && cxProperties .getProjectSummary ()){
668+ projectSummary = getScanSummaryByScanId (Integer .valueOf (cxResults .getScanId ()));
669+ }
643670 scanSummary = new CxScanSummary (summary );
644671 } else {
645672 scanSummary = getScanSummaryByScanId (Integer .valueOf (cxResults .getScanId ()));
646673 }
647674 cxScanBuilder .scanSummary (scanSummary );
675+ cxScanBuilder .projectScanSummary (projectSummary );
648676 ScanResults results = cxScanBuilder .build ();
649677 //Add the summary map (severity, count)
650678 results .getAdditionalDetails ().put (Constants .SUMMARY_KEY , summary );
@@ -837,12 +865,17 @@ public ScanResults getReportContent(File file, FilterConfiguration filter) throw
837865 ScanResults results = cxScanBuilder .build ();
838866 if (!cxProperties .getOffline () && !ScanUtils .empty (cxResults .getScanId ())) {
839867 CxScanSummary scanSummary = null ;
868+ CxScanSummary projectSummary = null ;
840869 if (cxProperties .getRestrictResultsToBranch () != null && cxProperties .getRestrictResultsToBranch ()) {
870+ if (cxProperties .getProjectSummary ()!=null && cxProperties .getProjectSummary ()){
871+ projectSummary = getScanSummaryByScanId (Integer .valueOf (cxResults .getScanId ()));
872+ }
841873 scanSummary = new CxScanSummary (summary );
842874 } else {
843875 scanSummary = getScanSummaryByScanId (Integer .valueOf (cxResults .getScanId ()));
844876 }
845877 results .setScanSummary (scanSummary );
878+ results .setProjectScanSummary (projectSummary );
846879 }
847880 results .getAdditionalDetails ().put (Constants .SUMMARY_KEY , summary );
848881 return results ;
@@ -1028,7 +1061,7 @@ private ScanResults.XIssue buildIssue(ScanResults.XIssue.XIssueBuilder xIssueBui
10281061 xIssueBuilder .severity (result .getSeverity ());
10291062 xIssueBuilder .vulnerability (result .getName ());
10301063 xIssueBuilder .file (resultType .getFileName ());
1031- xIssueBuilder .severity (resultType .getSeverity ( ));
1064+ xIssueBuilder .severity (cxProperties . getSeverityFullName ( resultType .getSeverityIndex () ));
10321065 xIssueBuilder .link (resultType .getDeepLink ());
10331066 xIssueBuilder .vulnerabilityStatus (cxProperties .getStateFullName (resultType .getState ()));
10341067 xIssueBuilder .queryId (result .getId ());
@@ -1171,6 +1204,7 @@ private Map<String, String> getNodeData(List<PathNodeType> nodes, int nodeIndex)
11711204 private void prepareIssuesRemoveDuplicates (List <ScanResults .XIssue > cxIssueList , ResultType resultType , Map <Integer , ScanResults .IssueDetails > details ,
11721205 boolean falsePositive , ScanResults .XIssue issue , Map <String , Integer > summary ) {
11731206 try {
1207+ String severityName = cxProperties .getSeverityFullName (resultType .getSeverityIndex ());
11741208 if (!cxProperties .getDisableClubbing () && cxIssueList .contains (issue )) {
11751209 /*Get existing issue of same vuln+filename*/
11761210 ScanResults .XIssue existingIssue = cxIssueList .get (cxIssueList .indexOf (issue ));
@@ -1179,12 +1213,12 @@ private void prepareIssuesRemoveDuplicates(List<ScanResults.XIssue> cxIssueList,
11791213 if (falsePositive ) {
11801214 existingIssue .setFalsePositiveCount ((existingIssue .getFalsePositiveCount () + 1 ));
11811215 } else {
1182- if (!summary .containsKey (resultType . getSeverity () )) {
1183- summary .put (resultType . getSeverity () , 0 );
1216+ if (!summary .containsKey (severityName )) {
1217+ summary .put (severityName , 0 );
11841218 }
1185- int severityCount = summary .get (resultType . getSeverity () );
1219+ int severityCount = summary .get (severityName );
11861220 severityCount ++;
1187- summary .put (resultType . getSeverity () , severityCount );
1221+ summary .put (severityName , severityCount );
11881222 }
11891223 existingIssue .getDetails ().putAll (details );
11901224 } else { //reference exists, ensure fp flag is maintained
@@ -1194,9 +1228,9 @@ private void prepareIssuesRemoveDuplicates(List<ScanResults.XIssue> cxIssueList,
11941228 existingDetails .setFalsePositive (true );
11951229 existingIssue .setFalsePositiveCount ((existingIssue .getFalsePositiveCount () + 1 ));
11961230 //bump down the count for the severity
1197- int severityCount = summary .get (resultType . getSeverity () );
1231+ int severityCount = summary .get (severityName );
11981232 severityCount --;
1199- summary .put (resultType . getSeverity () , severityCount );
1233+ summary .put (severityName , severityCount );
12001234 }
12011235 }
12021236 //adding description if existing ref found
@@ -1227,12 +1261,12 @@ private void prepareIssuesRemoveDuplicates(List<ScanResults.XIssue> cxIssueList,
12271261 if (falsePositive ) {
12281262 issue .setFalsePositiveCount ((issue .getFalsePositiveCount () + 1 ));
12291263 } else {
1230- if (!summary .containsKey (resultType . getSeverity () )) {
1231- summary .put (resultType . getSeverity () , 0 );
1264+ if (!summary .containsKey (severityName )) {
1265+ summary .put (severityName , 0 );
12321266 }
1233- int severityCount = summary .get (resultType . getSeverity () );
1267+ int severityCount = summary .get (severityName );
12341268 severityCount ++;
1235- summary .put (resultType . getSeverity () , severityCount );
1269+ summary .put (severityName , severityCount );
12361270 }
12371271 cxIssueList .add (issue );
12381272 }
@@ -2298,7 +2332,11 @@ public Integer createScan(CxScanParams params, String comment) throws CheckmarxE
22982332
22992333 derivedProjectName = params .getProjectName ().replace (params .getModifiedProjectName (),defaultBranch );
23002334 }else {
2301- derivedProjectName = params .getProjectName () + "-" + defaultBranch ;
2335+ if (cxProperties .getIsDefaultBranchEmpty () && (defaultBranch ==null || defaultBranch .isEmpty ())){
2336+ derivedProjectName = params .getProjectName ();
2337+ }else {
2338+ derivedProjectName = params .getProjectName () + "-" + defaultBranch ;
2339+ }
23022340 }
23032341 }
23042342
@@ -2307,7 +2345,13 @@ public Integer createScan(CxScanParams params, String comment) throws CheckmarxE
23072345 if (baseProjectId .equals (UNKNOWN_INT )){
23082346 baseProjectId = createProject (teamId , derivedProjectName );
23092347 }
2310- projectId = branchProject (baseProjectId , params .getProjectName ());
2348+
2349+ if (cxProperties .getIsDefaultBranchEmpty () && (defaultBranch ==null || defaultBranch .isEmpty ()) && (currentBranch !=null || !currentBranch .isEmpty ())){
2350+ projectId = branchProject (baseProjectId , params .getProjectName ()+"-" +currentBranch );
2351+ }else {
2352+ projectId = branchProject (baseProjectId , params .getProjectName ());
2353+ }
2354+
23112355 } else {
23122356 projectId = createProject (teamId , params .getProjectName ());
23132357 }
0 commit comments