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());
}
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);
}
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);
}
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);
}
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());
}
Aggregations