use of com.checkmarx.flow.exception.InvalidCredentialsException in project cx-flow by checkmarx-ltd.
the class ResultsService method getCxFields.
private void getCxFields(ScanRequest request, ScanResults results) throws MachinaException {
try {
/*Are cx fields required?*/
if (!requiresCxCustomFields(request.getBugTracker().getFields())) {
return;
}
/*if so, then get them and add them to the request object*/
if (!ScanUtils.empty(results.getProjectId()) && !results.getProjectId().equals(Constants.UNKNOWN)) {
CxProject project = cxScannerService.getScannerClient().getProject(Integer.parseInt(results.getProjectId()));
Map<String, String> fields = new HashMap<>();
for (CxProject.CustomField field : project.getCustomFields()) {
if (!ScanUtils.empty(field.getName()) && !ScanUtils.empty(field.getValue())) {
fields.put(field.getName(), field.getValue());
}
}
if (!fields.isEmpty()) {
request.setCxFields(fields);
if (!ScanUtils.empty(cxScannerService.getProperties().getJiraProjectField())) {
String jiraProject = fields.get(cxScannerService.getProperties().getJiraProjectField());
if (!ScanUtils.empty(jiraProject)) {
request.getBugTracker().setProjectKey(jiraProject);
}
}
if (!ScanUtils.empty(cxScannerService.getProperties().getJiraIssuetypeField())) {
String jiraIssuetype = fields.get(cxScannerService.getProperties().getJiraIssuetypeField());
if (!ScanUtils.empty(jiraIssuetype)) {
request.getBugTracker().setIssueType(jiraIssuetype);
}
}
}
}
} catch (InvalidCredentialsException e) {
log.warn("Error retrieving Checkmarx Project details for {}, no custom fields will be available", results.getProjectId(), e);
throw new MachinaException("Error logging into Checkmarx");
}
}
Aggregations