Search in sources :

Example 21 with BlackDuckServicesFactory

use of com.synopsys.integration.blackduck.service.BlackDuckServicesFactory in project hub-alert by blackducksoftware.

the class BlackDuckProviderDataAccessor method findFirstUserByEmailAddress.

@Override
public Optional<ProviderUserModel> findFirstUserByEmailAddress(Long providerConfigId, String emailAddress) {
    Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
    if (providerConfigOptional.isPresent()) {
        try {
            BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
            UserService userService = blackDuckServicesFactory.createUserService();
            return userService.findUsersByEmail(emailAddress, new BlackDuckPageDefinition(1, 0)).getItems().stream().map(userView -> new ProviderUserModel(userView.getEmail(), false)).findFirst();
        } catch (IntegrationException e) {
            logger.errorAndDebug(createProjectNotFoundString(providerConfigId, e.getMessage()), e);
        }
    }
    return Optional.empty();
}
Also used : BlackDuckPageDefinition(com.synopsys.integration.blackduck.http.BlackDuckPageDefinition) ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) IntegrationException(com.synopsys.integration.exception.IntegrationException) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) BlackDuckResponse(com.synopsys.integration.blackduck.api.core.BlackDuckResponse) BlackDuckPageDefinition(com.synopsys.integration.blackduck.http.BlackDuckPageDefinition) LoggerFactory(org.slf4j.LoggerFactory) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) StringUtils(org.apache.commons.lang3.StringUtils) BlackDuckMultipleRequest(com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest) IntLogger(com.synopsys.integration.log.IntLogger) HttpUrl(com.synopsys.integration.rest.HttpUrl) ArrayList(java.util.ArrayList) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) Map(java.util.Map) UrlMultipleResponses(com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse) BlackDuckPropertiesFactory(com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory) BlackDuckQuery(com.synopsys.integration.blackduck.http.BlackDuckQuery) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) BlackDuckResponsesTransformer(com.synopsys.integration.blackduck.http.transform.BlackDuckResponsesTransformer) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) Nullable(org.jetbrains.annotations.Nullable) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) List(java.util.List) Component(org.springframework.stereotype.Component) ProjectUsersService(com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService) ThrowingSupplier(com.synopsys.integration.function.ThrowingSupplier) Optional(java.util.Optional) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)

Example 22 with BlackDuckServicesFactory

use of com.synopsys.integration.blackduck.service.BlackDuckServicesFactory in project hub-alert by blackducksoftware.

the class BlackDuckProviderDataAccessor method getEmailAddressesByProvider.

private List<ProviderUserModel> getEmailAddressesByProvider(ConfigurationModel blackDuckConfiguration) throws IntegrationException {
    BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(blackDuckConfiguration);
    BlackDuckApiClient blackDuckService = blackDuckServicesFactory.getBlackDuckApiClient();
    ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
    Set<String> allActiveBlackDuckEmailAddresses = getAllActiveBlackDuckEmailAddresses(blackDuckService, apiDiscovery);
    return allActiveBlackDuckEmailAddresses.stream().map(email -> new ProviderUserModel(email, false)).collect(Collectors.toList());
}
Also used : ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) IntegrationException(com.synopsys.integration.exception.IntegrationException) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) BlackDuckResponse(com.synopsys.integration.blackduck.api.core.BlackDuckResponse) BlackDuckPageDefinition(com.synopsys.integration.blackduck.http.BlackDuckPageDefinition) LoggerFactory(org.slf4j.LoggerFactory) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) StringUtils(org.apache.commons.lang3.StringUtils) BlackDuckMultipleRequest(com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest) IntLogger(com.synopsys.integration.log.IntLogger) HttpUrl(com.synopsys.integration.rest.HttpUrl) ArrayList(java.util.ArrayList) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) Map(java.util.Map) UrlMultipleResponses(com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse) BlackDuckPropertiesFactory(com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory) BlackDuckQuery(com.synopsys.integration.blackduck.http.BlackDuckQuery) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) BlackDuckResponsesTransformer(com.synopsys.integration.blackduck.http.transform.BlackDuckResponsesTransformer) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) Nullable(org.jetbrains.annotations.Nullable) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) List(java.util.List) Component(org.springframework.stereotype.Component) ProjectUsersService(com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService) ThrowingSupplier(com.synopsys.integration.function.ThrowingSupplier) Optional(java.util.Optional) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)

Example 23 with BlackDuckServicesFactory

use of com.synopsys.integration.blackduck.service.BlackDuckServicesFactory in project hub-alert by blackducksoftware.

the class BlackDuckPhoneHomeHandler method populatePhoneHomeData.

@Override
public PhoneHomeRequestBodyBuilder populatePhoneHomeData(ConfigurationModel configurationModel, NameVersion alertArtifactInfo) {
    String registrationId = null;
    String blackDuckUrl = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
    String blackDuckVersion = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
    try {
        descriptorAccessor.getRegisteredDescriptorById(configurationModel.getDescriptorId());
        StatefulProvider statefulProvider = provider.createStatefulProvider(configurationModel);
        BlackDuckProperties blackDuckProperties = (BlackDuckProperties) statefulProvider.getProperties();
        BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(logger);
        BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, new Slf4jIntLogger(logger));
        BlackDuckRegistrationService blackDuckRegistrationService = blackDuckServicesFactory.createBlackDuckRegistrationService();
        BlackDuckServerData blackDuckServerData = blackDuckRegistrationService.getBlackDuckServerData();
        blackDuckVersion = blackDuckServerData.getVersion();
        registrationId = blackDuckServerData.getRegistrationKey().orElse(null);
        blackDuckUrl = blackDuckProperties.getBlackDuckUrl().orElse(PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE);
    } catch (IntegrationException ignored) {
    // ignoring this exception
    }
    // We must check if the reg id is blank because of an edge case in which Black Duck can authenticate (while the webserver is coming up) without registration
    if (StringUtils.isBlank(registrationId)) {
        registrationId = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
    }
    PhoneHomeRequestBodyBuilder phoneHomeBuilder = new PhoneHomeRequestBodyBuilder(registrationId, blackDuckUrl, alertArtifactInfo, UniquePhoneHomeProduct.BLACK_DUCK, blackDuckVersion);
    return phoneHomeBuilder;
}
Also used : PhoneHomeRequestBodyBuilder(com.synopsys.integration.phonehome.request.PhoneHomeRequestBodyBuilder) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) BlackDuckServerData(com.synopsys.integration.blackduck.service.model.BlackDuckServerData) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) BlackDuckRegistrationService(com.synopsys.integration.blackduck.service.dataservice.BlackDuckRegistrationService)

Example 24 with BlackDuckServicesFactory

use of com.synopsys.integration.blackduck.service.BlackDuckServicesFactory in project hub-alert by blackducksoftware.

the class BlackDuckProviderDataAccessor method getProviderConfigUserById.

@Override
public ProviderUserModel getProviderConfigUserById(Long providerConfigId) throws AlertConfigurationException {
    try {
        Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
        if (providerConfigOptional.isPresent()) {
            BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
            UserService userService = blackDuckServicesFactory.createUserService();
            UserView providerConfigUser = userService.findCurrentUser();
            return new ProviderUserModel(providerConfigUser.getEmail(), false);
        }
    } catch (IntegrationException e) {
        throw new AlertConfigurationException(createUserNotFoundString(providerConfigId, e.getMessage()), e);
    }
    throw new AlertConfigurationException(String.format("The provider config with id '%s' is invalid", providerConfigId));
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 25 with BlackDuckServicesFactory

use of com.synopsys.integration.blackduck.service.BlackDuckServicesFactory 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());
}
Also used : ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView)

Aggregations

BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)47 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)30 HttpUrl (com.synopsys.integration.rest.HttpUrl)27 Test (org.junit.jupiter.api.Test)20 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)16 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)15 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)12 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)12 IntegrationException (com.synopsys.integration.exception.IntegrationException)12 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)11 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)10 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)9 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)8 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)7 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)7 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)6 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)6 ProjectUsersService (com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService)6 IntLogger (com.synopsys.integration.log.IntLogger)6 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)5