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