Search in sources :

Example 11 with ComponentsView

use of com.synopsys.integration.blackduck.api.generated.response.ComponentsView in project blackduck-alert by blackducksoftware.

the class BlackDuckProviderService method createBlackDuckPolicyRuleView.

public PolicyRuleView createBlackDuckPolicyRuleView(String policyName, Supplier<ExternalId> externalIdSupplier) throws IntegrationException {
    setupBlackDuckServicesFactory();
    ComponentService componentService = blackDuckServicesFactory.createComponentService();
    ExternalId externalId = externalIdSupplier.get();
    ComponentsView searchResult = componentService.getSingleOrEmptyResult(externalId).orElseThrow(() -> new IntegrationException(String.format("Could not find the ComponentsView for component: %s", externalId.getName())));
    ComponentVersionView componentVersionView = componentService.getComponentVersionView(searchResult).orElseThrow(() -> new IntegrationException(String.format("Could not find the ComponentVersionView for component: %s", searchResult.getComponentName())));
    PolicyRuleExpressionSetBuilder builder = new PolicyRuleExpressionSetBuilder();
    builder.addComponentVersionCondition(PolicyRuleConditionOperatorType.EQ, componentVersionView);
    PolicyRuleExpressionView expressionSet = builder.createPolicyRuleExpressionView();
    PolicyRuleView policyRuleView = new PolicyRuleView();
    policyRuleView.setName(policyName);
    policyRuleView.setEnabled(true);
    policyRuleView.setOverridable(true);
    policyRuleView.setExpression(expressionSet);
    return policyRuleView;
}
Also used : PolicyRuleExpressionView(com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView) IntegrationException(com.synopsys.integration.exception.IntegrationException) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) PolicyRuleExpressionSetBuilder(com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) ComponentService(com.synopsys.integration.blackduck.service.dataservice.ComponentService) ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView)

Aggregations

ComponentsView (com.synopsys.integration.blackduck.api.generated.response.ComponentsView)11 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)7 ComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView)6 PolicyRuleExpressionView (com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView)4 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)4 PolicyRuleExpressionSetBuilder (com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder)4 Test (org.junit.jupiter.api.Test)3 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)2 ComponentService (com.synopsys.integration.blackduck.service.dataservice.ComponentService)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 HttpUrl (com.synopsys.integration.rest.HttpUrl)2 SimpleBdioFactory (com.synopsys.integration.bdio.SimpleBdioFactory)1 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1 ProjectVersionVulnerableBomComponentsView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionVulnerableBomComponentsView)1 VulnerabilityView (com.synopsys.integration.blackduck.api.generated.view.VulnerabilityView)1 BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)1 BlackDuckQuery (com.synopsys.integration.blackduck.http.BlackDuckQuery)1 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)1 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)1 ComponentVersionVulnerabilities (com.synopsys.integration.blackduck.service.model.ComponentVersionVulnerabilities)1