use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.
the class BomComponentDetails method combine.
@Override
public List<BomComponentDetails> combine(BomComponentDetails otherDetails) {
List<BomComponentDetails> uncombinedDetails = List.of(this, otherDetails);
if (!getComponent().equals(otherDetails.getComponent())) {
return uncombinedDetails;
}
LinkableItem nullableComponentVersion = getComponentVersion().orElse(null);
LinkableItem nullableOtherComponentVersion = otherDetails.getComponentVersion().orElse(null);
if (!EqualsBuilder.reflectionEquals(nullableComponentVersion, nullableOtherComponentVersion)) {
return uncombinedDetails;
}
if (hasComponentConcerns() != otherDetails.hasComponentConcerns()) {
return uncombinedDetails;
}
return combineComponentConcerns(otherDetails);
}
use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.
the class AzureBoardsAlertIssuePropertiesManager method createWorkItemRequestCustomFieldOperations.
public List<WorkItemElementOperationModel> createWorkItemRequestCustomFieldOperations(ProjectIssueModel alertIssueSource) {
LinkableItem provider = alertIssueSource.getProvider();
String providerKey = AzureBoardsSearchPropertiesUtils.createProviderKey(provider.getLabel(), provider.getUrl().orElse(null));
String topicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(alertIssueSource.getProject());
String subTopicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(alertIssueSource.getProjectVersion().orElse(null));
IssueBomComponentDetails bomComponentDetails = alertIssueSource.getBomComponentDetails();
String componentKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(bomComponentDetails.getComponent());
String subComponentKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(bomComponentDetails.getComponentVersion().orElse(null));
AzureSearchFieldBuilder azureSearchFieldBuilder = AzureSearchFieldBuilder.create().addProviderKey(providerKey).addTopicKey(topicKey).addSubTopicKey(subTopicKey).addComponentKey(componentKey).addSubComponentKey(subComponentKey);
String categoryKey = CATEGORY_TYPE_VULNERABILITY_COMPATIBILITY_LABEL;
Optional<String> optionalPolicyName = alertIssueSource.getPolicyDetails().map(IssuePolicyDetails::getName);
if (optionalPolicyName.isPresent()) {
String additionalInfoKey = POLICY_ADDITIONAL_KEY_COMPATIBILITY_LABEL + optionalPolicyName.get();
azureSearchFieldBuilder.addAdditionalInfoKey(additionalInfoKey);
categoryKey = CATEGORY_TYPE_POLICY_COMPATIBILITY_LABEL;
}
boolean unknownVersionCategory = alertIssueSource.getComponentUnknownVersionDetails().isPresent();
if (unknownVersionCategory) {
categoryKey = CATEGORY_TYPE_COMPONENT_UNKNOWN_VERSION_COMPATIBILITY_LABEL;
}
azureSearchFieldBuilder.addCategoryKey(categoryKey);
return azureSearchFieldBuilder.build();
}
use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.
the class AzureBoardsWorkItemFinderTest method verifyQueryWhereStatementExists.
@Test
public void verifyQueryWhereStatementExists() throws AlertException {
AzureBoardsIssueTrackerQueryManager azureBoardsIssueTrackerQueryManager = Mockito.mock(AzureBoardsIssueTrackerQueryManager.class);
ArgumentCaptor<WorkItemQuery> workItemQueryArgumentCaptor = ArgumentCaptor.forClass(WorkItemQuery.class);
String teamProjectName = "team project name";
AzureBoardsWorkItemFinder azureBoardsWorkItemFinder = new AzureBoardsWorkItemFinder(azureBoardsIssueTrackerQueryManager, teamProjectName);
LinkableItem provider = new LinkableItem("providerLabel", "providerValue");
LinkableItem project = new LinkableItem("projectLabel", "projectValue");
String componentKey = "componentKey";
String subTopicKey = "subTopicKey";
String additionalInfoKey = "additionalInfoKey";
AzureSearchFieldMappingBuilder azureSearchFieldMappingBuilder = AzureSearchFieldMappingBuilder.create().addComponentKey(componentKey).addSubTopic(subTopicKey).addAdditionalInfoKey(additionalInfoKey);
Mockito.doReturn(List.of()).when(azureBoardsIssueTrackerQueryManager).executeQueryAndRetrieveWorkItems(Mockito.any());
azureBoardsWorkItemFinder.findWorkItems(provider, project, azureSearchFieldMappingBuilder);
Mockito.verify(azureBoardsIssueTrackerQueryManager).executeQueryAndRetrieveWorkItems(workItemQueryArgumentCaptor.capture());
WorkItemQuery workItemQuery = workItemQueryArgumentCaptor.getValue();
assertNotNull(workItemQuery);
assertFalse(workItemQuery.exceedsCharLimit());
Map<String, String> whereClauseValues = extractValuesFromWhereClause(workItemQuery.rawQuery());
assertTrue(whereClauseValues.size() > 3);
assertQueryDataFound(whereClauseValues, AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME, subTopicKey);
assertQueryDataFound(whereClauseValues, AzureCustomFieldManager.ALERT_ADDITIONAL_INFO_KEY_FIELD_REFERENCE_NAME, additionalInfoKey);
assertQueryDataFound(whereClauseValues, AzureCustomFieldManager.ALERT_COMPONENT_KEY_FIELD_REFERENCE_NAME, componentKey);
}
use of com.synopsys.integration.alert.common.message.model.LinkableItem 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.common.message.model.LinkableItem 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