Search in sources :

Example 21 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException 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 22 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class JiraCloudIssueCreator method retrieveProjectComponent.

private ProjectComponent retrieveProjectComponent() throws AlertException {
    String jiraProjectName = distributionDetails.getProjectNameOrKey();
    PageOfProjectsResponseModel projectsResponseModel;
    try {
        projectsResponseModel = projectService.getProjectsByName(jiraProjectName);
    } catch (IntegrationException e) {
        throw new AlertException("Failed to retrieve projects from Jira", e);
    }
    return projectsResponseModel.getProjects().stream().filter(project -> jiraProjectName.equals(project.getName()) || jiraProjectName.equals(project.getKey())).findAny().orElseThrow(() -> new AlertException(String.format("Unable to find project matching '%s'", jiraProjectName)));
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) PageOfProjectsResponseModel(com.synopsys.integration.jira.common.model.response.PageOfProjectsResponseModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 23 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class NotificationWaitJobTask method waitForNotificationToBeProcessedByAllJobs.

private boolean waitForNotificationToBeProcessedByAllJobs() throws IntegrationException {
    String response = alertRequestUtility.executeGetRequest("/api/audit?pageNumber=0&pageSize=2&searchTerm=VULNERABILITY&sortField=createdAt&sortOrder=desc&onlyShowSentNotifications=false", "Could not get the Alert audit entries.");
    AuditEntryPageModel auditEntryPageModel = gson.fromJson(response, AuditEntryPageModel.class);
    Optional<AuditEntryModel> matchingAuditEntry = auditEntryPageModel.getContent().stream().filter(auditEntryModel -> isNotificationAfterTime(startSearchTime, auditEntryModel.getNotification())).filter(auditEntryModel -> NotificationType.VULNERABILITY.name().equals(auditEntryModel.getNotification().getNotificationType())).filter(auditEntryModel -> isNotificationForNewVulnerabilities(auditEntryModel.getNotification())).findFirst();
    if (matchingAuditEntry.isPresent()) {
        AuditEntryModel auditEntryModel = matchingAuditEntry.get();
        intLogger.info(String.format("The notification has been received by %s jobs.", auditEntryModel.getJobs().size()));
        return haveAllJobsSuccessfullyProcessed(auditEntryModel.getJobs());
    }
    return false;
}
Also used : AuditEntryModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryModel) JsonObject(com.google.gson.JsonObject) WaitJobCondition(com.synopsys.integration.wait.WaitJobCondition) IntegrationException(com.synopsys.integration.exception.IntegrationException) VulnerabilityNotificationContent(com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent) AuditEntryPageModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel) LocalDateTime(java.time.LocalDateTime) AuditEntryStatus(com.synopsys.integration.alert.common.enumeration.AuditEntryStatus) NotificationType(com.synopsys.integration.blackduck.api.manual.enumeration.NotificationType) IntLogger(com.synopsys.integration.log.IntLogger) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) List(java.util.List) NotificationConfig(com.synopsys.integration.alert.common.rest.model.NotificationConfig) Gson(com.google.gson.Gson) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) JobAuditModel(com.synopsys.integration.alert.common.rest.model.JobAuditModel) AuditEntryModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryModel) AuditEntryPageModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel)

Example 24 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class BlackDuckNotificationRetrieverTest method retrievePageOfFilteredNotificationsTest.

@Test
public void retrievePageOfFilteredNotificationsTest() throws IntegrationException {
    ProjectNotificationUserView projectNotificationView = new ProjectNotificationUserView();
    BlackDuckPageResponse<NotificationUserView> pageResponse = new BlackDuckPageResponse<>(1, List.of(projectNotificationView));
    UrlMultipleResponses<NotificationUserView> currentUserNotificationsUrl = new UrlMultipleResponses<>(new HttpUrl(THROWAWAY_SERVER), NotificationUserView.class);
    UserView apiUser = Mockito.mock(UserView.class);
    Mockito.doReturn(currentUserNotificationsUrl).when(apiUser).metaNotificationsLink();
    UrlSingleResponse<UserView> currentUserUrl = new UrlSingleResponse<>(new HttpUrl(THROWAWAY_SERVER), UserView.class);
    ApiDiscovery apiDiscovery = Mockito.mock(ApiDiscovery.class);
    Mockito.doReturn(currentUserUrl).when(apiDiscovery).metaCurrentUserLink();
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.doReturn(pageResponse).when(blackDuckApiClient).getPageResponse(Mockito.any(BlackDuckMultipleRequest.class));
    Mockito.doReturn(apiUser).when(blackDuckApiClient).getResponse(Mockito.eq(currentUserUrl));
    BlackDuckAccumulatorSearchDateManager dateRangeCreator = createDateRangeCreator();
    BlackDuckNotificationRetriever notificationRetriever = new BlackDuckNotificationRetriever(blackDuckApiClient, apiDiscovery);
    StatefulAlertPage<NotificationUserView, IntegrationException> notificationPage = notificationRetriever.retrievePageOfFilteredNotifications(dateRangeCreator.retrieveNextSearchDateRange(), List.of());
    assertEquals(pageResponse.getItems(), notificationPage.getCurrentModels());
}
Also used : UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckMultipleRequest(com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) ProjectNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) HttpUrl(com.synopsys.integration.rest.HttpUrl) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse) UrlMultipleResponses(com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) ProjectNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) ProjectNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView) Test(org.junit.jupiter.api.Test)

Example 25 with IntegrationException

use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class DockerTagRetrieverTest method getTagsModelTestIT.

@Test
@Tags({ @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION) })
public void getTagsModelTestIT() throws IntegrationException {
    IntLogger intLogger = new PrintStreamIntLogger(System.out, LogLevel.INFO);
    IntHttpClient intHttpClient = new IntHttpClient(intLogger, gson, 10, true, ProxyInfo.NO_PROXY_INFO);
    HttpUrl httpUrl = new HttpUrl("https://google.com");
    Request testRequest = new Request.Builder(httpUrl).build();
    try (Response googleResponse = intHttpClient.execute(testRequest)) {
        googleResponse.throwExceptionForError();
    } catch (IntegrationException | IOException e) {
        assumeTrue(null == e, "Could not connect. Skipping this test...");
    }
    DockerTagRetriever dockerTagRetriever = new DockerTagRetriever(gson, intHttpClient);
    DockerTagsResponseModel tagsModel = dockerTagRetriever.getTagsModel();
    assertFalse(tagsModel.isEmpty(), "Expected tags from the docker repo to exist");
}
Also used : Response(com.synopsys.integration.rest.response.Response) DockerTagsResponseModel(com.synopsys.integration.alert.update.model.DockerTagsResponseModel) PrintStreamIntLogger(com.synopsys.integration.log.PrintStreamIntLogger) IntegrationException(com.synopsys.integration.exception.IntegrationException) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) Request(com.synopsys.integration.rest.request.Request) IntLogger(com.synopsys.integration.log.IntLogger) PrintStreamIntLogger(com.synopsys.integration.log.PrintStreamIntLogger) IOException(java.io.IOException) HttpUrl(com.synopsys.integration.rest.HttpUrl) Test(org.junit.jupiter.api.Test) TestTags(com.synopsys.integration.alert.test.common.TestTags) Tags(org.junit.jupiter.api.Tags)

Aggregations

IntegrationException (com.synopsys.integration.exception.IntegrationException)53 HttpUrl (com.synopsys.integration.rest.HttpUrl)19 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)14 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)13 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)12 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)11 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)10 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)9 ArrayList (java.util.ArrayList)9 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)8 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)8 Set (java.util.Set)8 Test (org.junit.jupiter.api.Test)8 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)7 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)7 List (java.util.List)7 Optional (java.util.Optional)7 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)6 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)6 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)6