Search in sources :

Example 6 with ComponentsView

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

the class LicenseService method getComplexLicenseItemFromComponent.

public Optional<ComponentVersionLicenseView> getComplexLicenseItemFromComponent(ExternalId externalId) throws IntegrationException {
    Optional<ComponentsView> componentSearchView = componentDataService.getFirstOrEmptyResult(externalId);
    if (!componentSearchView.isPresent()) {
        return Optional.empty();
    }
    HttpUrl componentVersionUrl = new HttpUrl(componentSearchView.get().getVersion());
    ComponentVersionView componentVersion = blackDuckApiClient.getResponse(componentVersionUrl, ComponentVersionView.class);
    return Optional.ofNullable(componentVersion.getLicense());
}
Also used : ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 7 with ComponentsView

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

the class PolicyRuleService method createPolicyRuleForExternalId.

/**
 * This will create a policy rule that will be violated by the existence of a matching external id in the project's BOM.
 */
public HttpUrl createPolicyRuleForExternalId(ComponentService componentService, ExternalId externalId, String policyName) throws IntegrationException {
    Optional<ComponentsView> componentSearchResult = componentService.getSingleOrEmptyResult(externalId);
    if (!componentSearchResult.isPresent()) {
        throw new BlackDuckIntegrationException(String.format("The external id (%s) provided could not be found, so no policy can be created for it.", externalId.createExternalId()));
    }
    Optional<ComponentVersionView> componentVersionView = componentService.getComponentVersionView(componentSearchResult.get());
    if (!componentVersionView.isPresent()) {
        throw new BlackDuckIntegrationException(String.format("A component version could not be found for the provided external id (%s), so no policy can be created for it.", externalId.createExternalId()));
    }
    PolicyRuleExpressionSetBuilder builder = new PolicyRuleExpressionSetBuilder();
    builder.addComponentVersionCondition(PolicyRuleConditionOperatorType.EQ, componentVersionView.get());
    PolicyRuleExpressionView expressionSet = builder.createPolicyRuleExpressionView();
    PolicyRuleView policyRuleView = new PolicyRuleView();
    policyRuleView.setName(policyName);
    policyRuleView.setEnabled(true);
    policyRuleView.setOverridable(true);
    policyRuleView.setExpression(expressionSet);
    return createPolicyRule(policyRuleView);
}
Also used : PolicyRuleExpressionView(com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) PolicyRuleExpressionSetBuilder(com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView)

Example 8 with ComponentsView

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

the class ProjectBomService method addComponentToProjectVersion.

// TODO investigate what variant is
public Optional<String> addComponentToProjectVersion(ExternalId componentExternalId, ProjectVersionView projectVersionView) throws IntegrationException {
    HttpUrl projectVersionComponentsUrl = projectVersionView.getFirstLink(ProjectVersionView.COMPONENTS_LINK);
    Optional<ComponentsView> componentSearchResultView = componentService.getFirstOrEmptyResult(componentExternalId);
    String componentVersionUrl = null;
    if (componentSearchResultView.isPresent()) {
        if (StringUtils.isNotBlank(componentSearchResultView.get().getVariant())) {
            componentVersionUrl = componentSearchResultView.get().getVariant();
        } else if (StringUtils.isNotBlank(componentSearchResultView.get().getVersion())) {
            componentVersionUrl = componentSearchResultView.get().getVersion();
        } else {
            componentVersionUrl = componentSearchResultView.get().getComponent();
        }
        addComponentToProjectVersion(new HttpUrl(componentVersionUrl), projectVersionComponentsUrl);
    }
    return Optional.ofNullable(componentVersionUrl);
}
Also used : ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView) ProjectVersionVulnerableBomComponentsView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionVulnerableBomComponentsView) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 9 with ComponentsView

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

the class ComponentService method getAllSearchResults.

public List<ComponentsView> getAllSearchResults(ExternalId externalId) throws IntegrationException {
    String forge = externalId.getForge().getName();
    String originId = externalId.createExternalId();
    String componentQuery = String.format("%s|%s", forge, originId);
    BlackDuckQuery blackDuckQuery = new BlackDuckQuery("id", componentQuery);
    BlackDuckRequestBuilder blackDuckRequestBuilder = new BlackDuckRequestBuilder().commonGet().addBlackDuckQuery(blackDuckQuery);
    BlackDuckMultipleRequest<ComponentsView> requestMultiple = blackDuckRequestBuilder.buildBlackDuckRequest(componentsResponses);
    return blackDuckApiClient.getAllResponses(requestMultiple);
}
Also used : BlackDuckQuery(com.synopsys.integration.blackduck.http.BlackDuckQuery) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView)

Example 10 with ComponentsView

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

the class ComponentServiceTestIT method testGettingIntegrationCommon.

@Test
public void testGettingIntegrationCommon() throws Exception {
    ExternalId integrationCommonExternalId = externalIdFactory.createMavenExternalId("com.blackducksoftware.integration", "integration-common", "15.0.0");
    Optional<ComponentsView> componentView = componentService.getFirstOrEmptyResult(integrationCommonExternalId);
    assertTrue(componentView.isPresent());
}
Also used : ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView) Test(org.junit.jupiter.api.Test)

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