use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.
the class AzureBoardsProjectAndVersionIssueFinder method findWorkItemsAndConvertToSearchResults.
private List<ProjectIssueSearchResult<Integer>> findWorkItemsAndConvertToSearchResults(ProviderDetails providerDetails, LinkableItem project, @Nullable LinkableItem projectVersion, AzureSearchFieldMappingBuilder fieldReferenceNameToExpectedValue) throws AlertException {
List<WorkItemResponseModel> workItems = workItemFinder.findWorkItems(providerDetails.getProvider(), project, fieldReferenceNameToExpectedValue);
List<ProjectIssueSearchResult<Integer>> searchResults = new ArrayList<>(workItems.size());
for (WorkItemResponseModel workItem : workItems) {
WorkItemFieldsWrapper workItemFields = workItem.createFieldsWrapper(gson);
ProjectIssueModel projectIssueModel = createProjectIssueModel(providerDetails, project, projectVersion, workItemFields);
ExistingIssueDetails<Integer> issueDetails = issueDetailsCreator.createIssueDetails(workItem, workItemFields, projectIssueModel);
ProjectIssueSearchResult<Integer> searchResult = new ProjectIssueSearchResult<>(issueDetails, projectIssueModel);
searchResults.add(searchResult);
}
return searchResults;
}
use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel 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.model.ProjectIssueModel 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());
}
use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.
the class AzureBoardsComponentIssueFinder method findIssuesByComponent.
@Override
public List<ProjectIssueSearchResult<Integer>> findIssuesByComponent(ProviderDetails providerDetails, LinkableItem project, LinkableItem projectVersion, BomComponentDetails bomComponent) throws AlertException {
AzureSearchFieldMappingBuilder fieldRefNameToValue = createBomFieldReferenceToValueMap(projectVersion, bomComponent);
List<WorkItemResponseModel> workItems = workItemFinder.findWorkItems(providerDetails.getProvider(), project, fieldRefNameToValue);
List<ProjectIssueSearchResult<Integer>> searchResults = new ArrayList<>(workItems.size());
for (WorkItemResponseModel workItem : workItems) {
IssueBomComponentDetails issueBomComponent = IssueBomComponentDetails.fromBomComponentDetails(bomComponent);
ProjectIssueModel projectIssueModel = ProjectIssueModel.bom(providerDetails, project, projectVersion, issueBomComponent);
ExistingIssueDetails<Integer> issueDetails = issueDetailsCreator.createIssueDetails(workItem, workItem.createFieldsWrapper(gson), projectIssueModel);
ProjectIssueSearchResult<Integer> searchResult = new ProjectIssueSearchResult<>(issueDetails, projectIssueModel);
searchResults.add(searchResult);
}
return searchResults;
}
use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.
the class AzureBoardsAlertIssuePropertiesManagerTest method verifyValidPolicyIssuesAreCreated.
@Test
public void verifyValidPolicyIssuesAreCreated() {
AzureBoardsAlertIssuePropertiesManager azureBoardsAlertIssuePropertiesManager = new AzureBoardsAlertIssuePropertiesManager();
LinkableItem providerConfig = new LinkableItem("providerConfigLabel", "providerConfigValue");
ProviderDetails providerDetails = new ProviderDetails(1L, providerConfig);
LinkableItem project = new LinkableItem("projectLabel", "projectValue");
LinkableItem projectVersion = new LinkableItem("projectVersionLabel", "projectVersionValue");
LinkableItem component = new LinkableItem("componentLabel", "componentValue");
LinkableItem componentVersion = new LinkableItem("componentVersionLabel", "componentVersionValue");
IssueBomComponentDetails issueBomComponentDetails = IssueBomComponentDetails.fromSearchResults(component, componentVersion);
IssuePolicyDetails issuePolicyDetails = new IssuePolicyDetails("policy", ItemOperation.ADD, ComponentConcernSeverity.CRITICAL);
ProjectIssueModel policy = ProjectIssueModel.policy(providerDetails, project, projectVersion, issueBomComponentDetails, issuePolicyDetails);
List<WorkItemElementOperationModel> workItemRequestCustomFieldOperations = azureBoardsAlertIssuePropertiesManager.createWorkItemRequestCustomFieldOperations(policy);
LinkableItem provider = providerDetails.getProvider();
String providerKey = AzureBoardsSearchPropertiesUtils.createProviderKey(provider.getLabel(), provider.getUrl().orElse(null));
assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_PROVIDER_KEY_FIELD_REFERENCE_NAME, providerKey);
String additionalInfo = AzureBoardsAlertIssuePropertiesManager.POLICY_ADDITIONAL_KEY_COMPATIBILITY_LABEL + issuePolicyDetails.getName();
assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_ADDITIONAL_INFO_KEY_FIELD_REFERENCE_NAME, additionalInfo);
assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_CATEGORY_KEY_FIELD_REFERENCE_NAME, AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_POLICY_COMPATIBILITY_LABEL);
String subTopicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(policy.getProjectVersion().orElse(null));
assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME, subTopicKey);
}
Aggregations