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