|
5 | 5 | import com.checkmarx.sdk.config.CxPropertiesBase; |
6 | 6 | import com.checkmarx.sdk.dto.cx.preandpostaction.CustomTaskByName; |
7 | 7 | import com.checkmarx.sdk.dto.cx.preandpostaction.ScanSettings; |
| 8 | +import com.checkmarx.sdk.dto.cx.projectdetails.CustomField; |
8 | 9 | import com.checkmarx.sdk.dto.cx.projectdetails.ProjectFieldDetails; |
9 | 10 | import com.checkmarx.sdk.dto.sast.Filter; |
10 | 11 | import com.checkmarx.sdk.dto.ScanResults; |
|
40 | 41 | import org.json.JSONException; |
41 | 42 | import org.json.JSONObject; |
42 | 43 | import org.slf4j.Logger; |
| 44 | +import org.slf4j.LoggerFactory; |
43 | 45 | import org.springframework.beans.factory.annotation.Qualifier; |
44 | 46 | import org.springframework.core.io.FileSystemResource; |
45 | 47 | import org.springframework.http.*; |
@@ -104,7 +106,7 @@ public class CxService implements CxClient { |
104 | 106 | Created (2) |
105 | 107 | */ |
106 | 108 | public static final Integer REPORT_STATUS_CREATED = 2; |
107 | | - private static final Logger log = org.slf4j.LoggerFactory.getLogger(CxService.class); |
| 109 | + private static final Logger log = LoggerFactory.getLogger(CxService.class); |
108 | 110 | private static final String CUSTOM_FIELDS = "/customFields"; |
109 | 111 | private static final String TEAMS = "/auth/teams"; |
110 | 112 | private static final String TEAM = "/auth/teams/{id}"; |
@@ -663,11 +665,14 @@ public ScanResults getReportContent(Integer reportId, FilterConfiguration filter |
663 | 665 | cxScanBuilder.additionalDetails(getAdditionalScanDetails(cxResults)); |
664 | 666 | CxScanSummary scanSummary = null; |
665 | 667 | CxScanSummary projectSummary = null; |
666 | | - if (cxProperties.getRestrictResultsToBranch() != null && cxProperties.getRestrictResultsToBranch()) { |
667 | | - if(cxProperties.getProjectSummary()!=null && cxProperties.getProjectSummary()){ |
668 | | - projectSummary = getScanSummaryByScanId(Integer.valueOf(cxResults.getScanId())); |
669 | | - } |
670 | | - scanSummary = new CxScanSummary(summary); |
| 668 | + if (cxProperties.getCxBranch() && cxProperties.getRestrictResultsToBranch() != null && cxProperties.getRestrictResultsToBranch()) { |
| 669 | + if(cxProperties.getProjectSummary()!=null && cxProperties.getProjectSummary()){ |
| 670 | + CxProjectBranchingStatus branch = getProjectBranchingStatus(Integer.valueOf(cxResults.getProjectId())); |
| 671 | + if(branch!=null){ |
| 672 | + projectSummary = getScanSummary(branch.getOriginalProjectId()); |
| 673 | + } |
| 674 | + } |
| 675 | + scanSummary = new CxScanSummary(summary); |
671 | 676 | } else { |
672 | 677 | scanSummary = getScanSummaryByScanId(Integer.valueOf(cxResults.getScanId())); |
673 | 678 | } |
@@ -695,6 +700,15 @@ public ScanResults getReportContent(Integer reportId, FilterConfiguration filter |
695 | 700 | } |
696 | 701 | } |
697 | 702 |
|
| 703 | + private Map<String, Integer> normalizeSummary(Map<String, Integer> summary){ |
| 704 | + // Normalize keys to capitalize format eg: HIGH -> High |
| 705 | + Map<String, Integer> normalized = new HashMap<>(); |
| 706 | + for (Map.Entry<String, Integer> entry : summary.entrySet()) { |
| 707 | + normalized.put(org.springframework.util.StringUtils.capitalize(entry.getKey().toLowerCase()), entry.getValue()); |
| 708 | + } |
| 709 | + return normalized; |
| 710 | + } |
| 711 | + |
698 | 712 | /** |
699 | 713 | * Retrieve the report by reportId, mapped to ScanResults DTO, applying filtering as requested |
700 | 714 | */ |
@@ -866,9 +880,12 @@ public ScanResults getReportContent(File file, FilterConfiguration filter) throw |
866 | 880 | if (!cxProperties.getOffline() && !ScanUtils.empty(cxResults.getScanId())) { |
867 | 881 | CxScanSummary scanSummary = null; |
868 | 882 | CxScanSummary projectSummary = null; |
869 | | - if (cxProperties.getRestrictResultsToBranch() != null && cxProperties.getRestrictResultsToBranch()) { |
| 883 | + if (cxProperties.getCxBranch() && cxProperties.getRestrictResultsToBranch() != null && cxProperties.getRestrictResultsToBranch()) { |
870 | 884 | if(cxProperties.getProjectSummary()!=null && cxProperties.getProjectSummary()){ |
871 | | - projectSummary = getScanSummaryByScanId(Integer.valueOf(cxResults.getScanId())); |
| 885 | + CxProjectBranchingStatus branch = getProjectBranchingStatus(Integer.valueOf(cxResults.getProjectId())); |
| 886 | + if(branch!=null){ |
| 887 | + projectSummary = getScanSummary(branch.getOriginalProjectId()); |
| 888 | + } |
872 | 889 | } |
873 | 890 | scanSummary = new CxScanSummary(summary); |
874 | 891 | } else { |
@@ -1006,7 +1023,7 @@ private Map<String, Integer> getIssues(FilterConfiguration filter, String sessio |
1006 | 1023 | log.debug("sastFilters: {}", sastFilters); |
1007 | 1024 |
|
1008 | 1025 | Set<Integer> similarityIdsToExclude = null; |
1009 | | - if (cxProperties.getRestrictResultsToBranch() != null && cxProperties.getRestrictResultsToBranch()) { |
| 1026 | + if (cxProperties.getCxBranch() && cxProperties.getRestrictResultsToBranch() != null && cxProperties.getRestrictResultsToBranch()) { |
1010 | 1027 | log.debug("Restricting results to current branch"); |
1011 | 1028 | int projectId = Integer.parseInt(cxResults.getProjectId()); |
1012 | 1029 | CxProjectBranchingStatus branch = getProjectBranchingStatus(projectId); |
@@ -1043,7 +1060,7 @@ private Map<String, Integer> getIssues(FilterConfiguration filter, String sessio |
1043 | 1060 | log.error("Null Pointer Exception Occurred while getting issue"); |
1044 | 1061 | log.error(ExceptionUtils.getStackTrace(e)); |
1045 | 1062 | } |
1046 | | - return summary; |
| 1063 | + return normalizeSummary(summary); |
1047 | 1064 | } |
1048 | 1065 |
|
1049 | 1066 | private ScanResults.XIssue buildIssue(ScanResults.XIssue.XIssueBuilder xIssueBuilder,ResultType resultType,QueryType result,DateTimeFormatter formatter,CxXMLResultsType cxResults,String session,List<ScanResults.XIssue> cxIssueList,Map<String, Integer> summary,boolean flag){ |
|
0 commit comments