Search in sources :

Example 11 with ProviderProject

use of com.synopsys.integration.alert.common.persistence.model.ProviderProject in project hub-alert by blackducksoftware.

the class BlackDuckDataSyncTask method runProviderTask.

@Override
public void runProviderTask() {
    try {
        BlackDuckProperties providerProperties = getProviderProperties();
        Optional<BlackDuckHttpClient> optionalBlackDuckHttpClient = providerProperties.createBlackDuckHttpClientAndLogErrors(logger);
        if (optionalBlackDuckHttpClient.isPresent()) {
            BlackDuckHttpClient blackDuckHttpClient = optionalBlackDuckHttpClient.get();
            BlackDuckServicesFactory blackDuckServicesFactory = providerProperties.createBlackDuckServicesFactory(blackDuckHttpClient, new Slf4jIntLogger(logger));
            ProjectUsersService projectUsersService = blackDuckServicesFactory.createProjectUsersService();
            BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
            ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
            List<ProjectView> projectViews = blackDuckApiClient.getAllResponses(apiDiscovery.metaProjectsLink());
            Map<ProjectView, ProviderProject> blackDuckToAlertProjects = mapBlackDuckProjectsToAlertProjects(projectViews, blackDuckApiClient);
            Map<ProviderProject, Set<String>> projectToEmailAddresses = getEmailsPerProject(blackDuckToAlertProjects, projectUsersService);
            Set<String> allRelevantBlackDuckUsers = getAllActiveBlackDuckUserEmailAddresses(blackDuckApiClient, apiDiscovery);
            blackDuckDataAccessor.updateProjectAndUserData(providerProperties.getConfigId(), projectToEmailAddresses, allRelevantBlackDuckUsers);
        } else {
            logger.error("Missing BlackDuck global configuration.");
        }
    } catch (IntegrationException | AlertRuntimeException e) {
        logger.error(String.format("Could not retrieve the current data from the BlackDuck server: %s", e.getMessage()), e);
    }
}
Also used : ProjectUsersService(com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) Set(java.util.Set) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject)

Example 12 with ProviderProject

use of com.synopsys.integration.alert.common.persistence.model.ProviderProject in project hub-alert by blackducksoftware.

the class EmailTestActionHelperTest method verifyAllProjectsProperlyRetrieved.

@Test
public void verifyAllProjectsProperlyRetrieved() throws AlertException {
    ProviderDataAccessor providerDataAccessor = Mockito.mock(ProviderDataAccessor.class);
    List<ProviderProject> providerProjects = createProviderProjects();
    Mockito.when(providerDataAccessor.getProjectsByProviderConfigId(Mockito.anyLong())).thenReturn(providerProjects);
    Mockito.when(providerDataAccessor.getEmailAddressesForProjectHref(Mockito.anyLong(), Mockito.anyString())).thenAnswer(i -> Set.of(UUID.randomUUID().toString()));
    EmailTestActionHelper emailTestActionHelper = new EmailTestActionHelper(providerDataAccessor);
    DistributionJobModel distributionJobModel = createDefaultDistributionJobModel();
    Set<String> emailAddresses = emailTestActionHelper.createUpdatedEmailAddresses(distributionJobModel);
    assertEquals(providerProjects.size(), emailAddresses.size());
}
Also used : ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Example 13 with ProviderProject

use of com.synopsys.integration.alert.common.persistence.model.ProviderProject in project hub-alert by blackducksoftware.

the class ProviderDataAccessorTest method getProjectByHrefTest.

@Test
void getProjectByHrefTest() throws IntegrationException {
    ProjectView projectView = createProjectView1();
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(HttpUrl.class), Mockito.eq(ProjectView.class))).thenReturn(projectView);
    BlackDuckProviderDataAccessor blackDuckProviderDataAccessor = new BlackDuckProviderDataAccessor(configurationModelConfigurationAccessor, blackDuckPropertiesFactory);
    Optional<ProviderProject> projectByHref = blackDuckProviderDataAccessor.getProjectByHref(providerConfiguration.getConfigurationId(), HREF_1);
    assertTrue(projectByHref.isPresent());
    ProviderProject providerProject = projectByHref.get();
    assertEquals(HREF_1, providerProject.getHref());
}
Also used : ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) HttpUrl(com.synopsys.integration.rest.HttpUrl) Test(org.junit.jupiter.api.Test)

Aggregations

ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)13 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)6 IntegrationException (com.synopsys.integration.exception.IntegrationException)4 ProviderDataAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor)3 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)3 HttpUrl (com.synopsys.integration.rest.HttpUrl)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Test (org.junit.jupiter.api.Test)3 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)2 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)2 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)2 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)2 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)2 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)2 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ProviderDescriptor (com.synopsys.integration.alert.api.provider.ProviderDescriptor)1 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)1 PagedCustomFunctionAction (com.synopsys.integration.alert.common.action.PagedCustomFunctionAction)1