use of com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails in project hub-alert by blackducksoftware.
the class JiraExactIssueFinder method findExistingIssuesByProjectIssueModel.
@Override
public List<ExistingIssueDetails<String>> findExistingIssuesByProjectIssueModel(ProjectIssueModel projectIssueModel) throws AlertException {
LinkableItem provider = projectIssueModel.getProvider();
LinkableItem project = projectIssueModel.getProject();
IssueBomComponentDetails bomComponent = projectIssueModel.getBomComponentDetails();
ComponentConcernType concernType = ComponentConcernType.VULNERABILITY;
String policyName = null;
Optional<IssuePolicyDetails> policyDetails = projectIssueModel.getPolicyDetails();
Optional<String> optionalPolicyName = policyDetails.map(IssuePolicyDetails::getName);
if (optionalPolicyName.isPresent()) {
concernType = ComponentConcernType.POLICY;
policyName = optionalPolicyName.get();
}
if (projectIssueModel.getComponentUnknownVersionDetails().isPresent()) {
concernType = ComponentConcernType.UNKNOWN_VERSION;
}
String jqlString = JqlStringCreator.createBlackDuckComponentConcernIssuesSearchString(jiraProjectKey, provider, project, projectIssueModel.getProjectVersion().orElse(null), bomComponent.getComponent(), bomComponent.getComponentVersion().orElse(null), concernType, policyName);
logger.debug("Searching for Jira issues with this Query: {}", jqlString);
IssueCategory issueCategory = issueCategoryRetriever.retrieveIssueCategoryFromComponentConcernType(concernType);
return jqlQueryExecutor.executeQuery(jqlString).stream().map(jiraSearcherResponseModel -> searchResultCreator.createExistingIssueDetails(jiraSearcherResponseModel, issueCategory)).collect(Collectors.toList());
}
use of com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails in project hub-alert by blackducksoftware.
the class AzureBoardsIssueCreator method extractIssueDetails.
private ExistingIssueDetails<Integer> extractIssueDetails(WorkItemResponseModel workItem, IssueCreationModel alertIssueCreationModel) {
WorkItemFieldsWrapper workItemFields = workItem.createFieldsWrapper(gson);
String workItemKey = Objects.toString(workItem.getId());
String workItemTitle = workItemFields.getField(WorkItemResponseFields.System_Title).orElse("Unknown Title");
String workItemUILink = AzureBoardsUILinkUtils.extractUILink(organizationName, workItem);
IssueCategory issueCategory = alertIssueCreationModel.getSource().map(issueCategoryRetriever::retrieveIssueCategoryFromProjectIssueModel).orElse(IssueCategory.BOM);
return new ExistingIssueDetails<>(workItem.getId(), workItemKey, workItemTitle, workItemUILink, IssueStatus.RESOLVABLE, issueCategory);
}
use of com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails in project hub-alert by blackducksoftware.
the class AzureBoardsExistingIssueDetailsCreator method createIssueDetails.
public ExistingIssueDetails<Integer> createIssueDetails(WorkItemResponseModel workItem, WorkItemFieldsWrapper workItemFields, ProjectIssueModel projectIssueModel) {
Integer workItemId = workItem.getId();
String workItemTitle = workItemFields.getField(WorkItemResponseFields.System_Title).orElse("Unknown Title");
String workItemUILink = AzureBoardsUILinkUtils.extractUILink(organizationName, workItem);
IssueCategory issueCategory = issueCategoryRetriever.retrieveIssueCategoryFromProjectIssueModel(projectIssueModel);
String workItemState = workItemFields.getField(WorkItemResponseFields.System_State).orElse("Unknown");
IssueStatus issueStatus = issueStatusResolver.resolveIssueStatus(workItemState);
return new ExistingIssueDetails<>(workItemId, Objects.toString(workItemId), workItemTitle, workItemUILink, issueStatus, issueCategory);
}
use of com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails in project hub-alert by blackducksoftware.
the class AzureBoardsComponentIssueFinderTest method findExistingIssuesByProjectIssueModelTest.
@Test
public void findExistingIssuesByProjectIssueModelTest() throws AlertException {
Gson gson = new Gson();
String organizationName = "orgName";
AzureBoardsIssueTrackerQueryManager queryManager = Mockito.mock(AzureBoardsIssueTrackerQueryManager.class);
IssueCategoryRetriever issueCategoryRetriever = new IssueCategoryRetriever();
AzureBoardsExistingIssueDetailsCreator issueDetailsCreator = new AzureBoardsExistingIssueDetailsCreator(organizationName, issueCategoryRetriever, azureBoardsIssueStatusResolver);
AzureBoardsWorkItemFinder workItemFinder = new AzureBoardsWorkItemFinder(queryManager, "test proj");
AzureBoardsComponentIssueFinder componentIssueFinder = new AzureBoardsComponentIssueFinder(gson, workItemFinder, issueDetailsCreator);
IssuePolicyDetails testPolicy = new IssuePolicyDetails("Test Policy", ItemOperation.ADD, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
ProjectIssueModel projectIssueModel = ProjectIssueModel.policy(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, ISSUE_BOM_COMPONENT_DETAILS, testPolicy);
WorkItemResponseModel workItemResponseModel = createWorkItemResponseModel(workItemReopenState);
Mockito.when(queryManager.executeQueryAndRetrieveWorkItems(Mockito.any())).thenReturn(List.of(workItemResponseModel));
List<ExistingIssueDetails<Integer>> existingIssueDetailsList = componentIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel);
assertEquals(1, existingIssueDetailsList.size());
ExistingIssueDetails<Integer> existingIssueDetails = existingIssueDetailsList.get(0);
assertEquals(IssueStatus.RESOLVABLE, existingIssueDetails.getIssueStatus());
assertEquals(IssueCategory.POLICY, existingIssueDetails.getIssueCategory());
}
use of com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails in project hub-alert by blackducksoftware.
the class AzureBoardsComponentIssueFinder method findExistingIssuesByProjectIssueModel.
@Override
public List<ExistingIssueDetails<Integer>> findExistingIssuesByProjectIssueModel(ProjectIssueModel projectIssueModel) throws AlertException {
LinkableItem projectVersion = projectIssueModel.getProjectVersion().orElseThrow(() -> new AlertRuntimeException("Missing project-version"));
String categoryKey = AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_VULNERABILITY_COMPATIBILITY_LABEL;
AzureSearchFieldMappingBuilder fieldRefNameToValue = createBomFieldReferenceToValueMap(projectVersion, projectIssueModel.getBomComponentDetails());
Optional<IssuePolicyDetails> policyDetails = projectIssueModel.getPolicyDetails();
Optional<String> optionalPolicyName = policyDetails.map(IssuePolicyDetails::getName);
if (optionalPolicyName.isPresent()) {
categoryKey = AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_POLICY_COMPATIBILITY_LABEL;
String additionalInfoKey = AzureBoardsAlertIssuePropertiesManager.POLICY_ADDITIONAL_KEY_COMPATIBILITY_LABEL + optionalPolicyName.get();
fieldRefNameToValue.addAdditionalInfoKey(additionalInfoKey);
}
if (projectIssueModel.getComponentUnknownVersionDetails().isPresent()) {
categoryKey = AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_COMPONENT_UNKNOWN_VERSION_COMPATIBILITY_LABEL;
}
fieldRefNameToValue.addCategoryKey(categoryKey);
return workItemFinder.findWorkItems(projectIssueModel.getProvider(), projectIssueModel.getProject(), fieldRefNameToValue).stream().map(workItemResponseModel -> createIssueDetails(workItemResponseModel, projectIssueModel)).collect(Collectors.toList());
}
Aggregations