Search in sources :

Example 21 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.

the class IntelligentPersistenceBatchRunner method uploadTargets.

private UploadBatchOutput uploadTargets(UploadBatch uploadBatch, long timeout) throws BlackDuckIntegrationException {
    List<UploadOutput> uploadOutputs = new ArrayList<>();
    try {
        List<IntelligentPersistenceCallable> callables = createCallables(uploadBatch, timeout);
        List<Future<UploadOutput>> submitted = new ArrayList<>();
        for (IntelligentPersistenceCallable callable : callables) {
            submitted.add(executorService.submit(callable));
        }
        for (Future<UploadOutput> future : submitted) {
            UploadOutput uploadOutput = future.get();
            uploadOutputs.add(uploadOutput);
        }
    } catch (Exception e) {
        throw new BlackDuckIntegrationException(String.format("Encountered a problem uploading a file: %s", e.getMessage()), e);
    }
    return new UploadBatchOutput(uploadOutputs);
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) UploadOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadOutput) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)

Example 22 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.

the class UploadBdio2BatchRunner method uploadTargets.

private UploadBatchOutput uploadTargets(UploadBatch uploadBatch) throws BlackDuckIntegrationException {
    List<UploadOutput> uploadOutputs = new ArrayList<>();
    try {
        List<UploadBdio2Callable> callables = createCallables(uploadBatch);
        List<Future<UploadOutput>> submitted = new ArrayList<>();
        for (UploadBdio2Callable callable : callables) {
            submitted.add(executorService.submit(callable));
        }
        for (Future<UploadOutput> future : submitted) {
            UploadOutput uploadOutput = future.get();
            uploadOutputs.add(uploadOutput);
        }
    } catch (Exception e) {
        throw new BlackDuckIntegrationException(String.format("Encountered a problem uploading a file: %s", e.getMessage()), e);
    }
    return new UploadBatchOutput(uploadOutputs);
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) UploadOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadOutput) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)

Example 23 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException 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 24 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.

the class ProjectMappingService method populateApplicationId.

public void populateApplicationId(ProjectView projectView, String applicationId) throws IntegrationException {
    List<ProjectMappingView> projectMappings = blackDuckApiClient.getAllResponses(projectView.metaProjectMappingsLink());
    boolean canCreate = projectMappings.isEmpty();
    if (canCreate) {
        if (!projectView.hasLink(ProjectView.PROJECT_MAPPINGS_LINK)) {
            throw new BlackDuckIntegrationException(String.format("The supplied projectView does not have the link (%s) to create a project mapping.", ProjectView.PROJECT_MAPPINGS_LINK));
        }
        HttpUrl projectMappingsLink = projectView.getFirstLink(ProjectView.PROJECT_MAPPINGS_LINK);
        ProjectMappingView projectMappingView = new ProjectMappingView();
        projectMappingView.setApplicationId(applicationId);
        blackDuckApiClient.post(projectMappingsLink, projectMappingView);
    } else {
        // Currently there exists only one project-mapping which is the project's Application ID.
        // Eventually, this method would need to take in a namespace on which we will need to filter.
        ProjectMappingView projectMappingView = projectMappings.get(0);
        projectMappingView.setApplicationId(applicationId);
        blackDuckApiClient.put(projectMappingView);
    }
}
Also used : ProjectMappingView(com.synopsys.integration.blackduck.api.manual.view.ProjectMappingView) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 25 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.

the class ProjectUsersService method addUserToProject.

public void addUserToProject(ProjectView projectView, String username) throws IntegrationException {
    UrlMultipleResponses<UserView> userResponses = apiDiscovery.metaUsersLink();
    List<UserView> allUsers = blackDuckApiClient.getAllResponses(userResponses);
    UserView userView = null;
    for (UserView user : allUsers) {
        if (user.getUserName().equalsIgnoreCase(username)) {
            userView = user;
        }
    }
    if (null == userView) {
        throw new BlackDuckIntegrationException(String.format("The user (%s) does not exist.", username));
    }
    addUserToProject(projectView, userView);
}
Also used : BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) AssignedUserView(com.synopsys.integration.blackduck.api.manual.temporary.view.AssignedUserView) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView)

Aggregations

BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)29 File (java.io.File)8 HttpUrl (com.synopsys.integration.rest.HttpUrl)7 ArrayList (java.util.ArrayList)7 IntegrationException (com.synopsys.integration.exception.IntegrationException)6 IOException (java.io.IOException)6 Future (java.util.concurrent.Future)5 UploadBatchOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput)3 UploadOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadOutput)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)2 ProjectVersionReportView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionReportView)2 BdioFileContent (com.synopsys.integration.blackduck.bdio2.model.BdioFileContent)2 Bdio2ContentExtractor (com.synopsys.integration.blackduck.bdio2.util.Bdio2ContentExtractor)2 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)2 BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)2 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)2 DataService (com.synopsys.integration.blackduck.service.DataService)2 BlackDuckRequestBuilderEditor (com.synopsys.integration.blackduck.service.request.BlackDuckRequestBuilderEditor)2 IntLogger (com.synopsys.integration.log.IntLogger)2