Search in sources :

Example 6 with PolicyRuleExpressionSetBuilder

use of com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder 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

PolicyRuleExpressionView (com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView)6 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)6 PolicyRuleExpressionSetBuilder (com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder)6 ComponentsView (com.synopsys.integration.blackduck.api.generated.response.ComponentsView)4 ComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView)4 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)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 BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)1