use of com.synopsys.integration.blackduck.service.dataservice.ProjectService in project hub-alert by blackducksoftware.
the class ProviderDataAccessorTest method init.
@BeforeEach
void init() throws Exception {
blackDuckPropertiesFactory = Mockito.mock(BlackDuckPropertiesFactory.class);
BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
Mockito.when(blackDuckPropertiesFactory.createProperties(Mockito.any(ConfigurationModel.class))).thenReturn(blackDuckProperties);
BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
Mockito.when(blackDuckProperties.createBlackDuckHttpClient(Mockito.any(IntLogger.class))).thenReturn(blackDuckHttpClient);
blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
Mockito.when(blackDuckProperties.createBlackDuckServicesFactory(Mockito.any(BlackDuckHttpClient.class), Mockito.any(IntLogger.class))).thenReturn(blackDuckServicesFactory);
projectService = Mockito.mock(ProjectService.class);
Mockito.when(blackDuckServicesFactory.createProjectService()).thenReturn(projectService);
blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
projectUsersService = Mockito.mock(ProjectUsersService.class);
Mockito.when(blackDuckServicesFactory.createProjectUsersService()).thenReturn(projectUsersService);
apiDiscovery = Mockito.mock(ApiDiscovery.class);
UrlMultipleResponses<UserView> usersLink = Mockito.mock(UrlMultipleResponses.class);
Mockito.when(apiDiscovery.metaUsersLink()).thenReturn(usersLink);
Mockito.when(blackDuckServicesFactory.getApiDiscovery()).thenReturn(apiDiscovery);
ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
configurationFieldModel.setFieldValue(PROVIDER_CONFIG_NAME);
configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
providerConfiguration = new ConfigurationModel(1L, 1L, "createdAt", "lastModified", ConfigContextEnum.GLOBAL, Map.of(PROVIDER_CONFIG_NAME, configurationFieldModel));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(1L)).thenReturn(Optional.of(providerConfiguration));
Mockito.when(configurationModelConfigurationAccessor.getProviderConfigurationByName(Mockito.anyString())).thenReturn(Optional.of(providerConfiguration));
}
use of com.synopsys.integration.blackduck.service.dataservice.ProjectService in project hub-alert by blackducksoftware.
the class BlackDuckProviderService method triggerBlackDuckNotification.
public void triggerBlackDuckNotification(Supplier<ExternalId> externalIdSupplier, Predicate<ProjectVersionComponentVersionView> componentFilter) throws IntegrationException {
setupBlackDuckServicesFactory();
BlackDuckApiClient blackDuckService = blackDuckServicesFactory.getBlackDuckApiClient();
ProjectService projectService = blackDuckServicesFactory.createProjectService();
ProjectVersionWrapper projectVersion = projectService.getProjectVersion(blackDuckProjectName, blackDuckProjectVersion).orElseThrow(() -> new IntegrationException(String.format("Could not find the Black Duck project '%s' version '%s'", blackDuckProjectName, blackDuckProjectVersion)));
ProjectVersionView projectVersionView = projectVersion.getProjectVersionView();
List<ProjectVersionComponentVersionView> bomComponents = blackDuckService.getAllResponses(projectVersionView.metaComponentsLink());
Optional<ProjectVersionComponentVersionView> apacheCommonsFileUpload = bomComponents.stream().filter(componentFilter).findFirst();
if (apacheCommonsFileUpload.isPresent()) {
blackDuckService.delete(apacheCommonsFileUpload.get());
// Thread.currentThread().wait(1000);
}
ExternalId externalId = externalIdSupplier.get();
ProjectBomService projectBomService = blackDuckServicesFactory.createProjectBomService();
projectBomService.addComponentToProjectVersion(externalId, projectVersionView);
}
use of com.synopsys.integration.blackduck.service.dataservice.ProjectService in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method getProjectsForProvider.
private List<ProviderProject> getProjectsForProvider(ConfigurationModel blackDuckConfigurationModel) throws IntegrationException {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(blackDuckConfigurationModel);
ProjectService projectService = blackDuckServicesFactory.createProjectService();
List<ProjectView> allProjects = projectService.getAllProjects();
return convertBlackDuckProjects(allProjects, blackDuckServicesFactory.getBlackDuckApiClient());
}
Aggregations