Search in sources :

Example 1 with ProviderProject

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

the class EmailTestActionHelperTest method verifyProjectsRetrievedWithOnlyVersionPattern.

@Test
public void verifyProjectsRetrievedWithOnlyVersionPattern() 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()));
    Mockito.when(providerDataAccessor.getProjectVersionNamesByHref(Mockito.anyLong(), Mockito.anyString(), Mockito.anyInt())).thenReturn(getProjectVersions());
    EmailTestActionHelper emailTestActionHelper = new EmailTestActionHelper(providerDataAccessor);
    DistributionJobModel distributionJobModel = createDistributionJobModel(createDefaultEmailJobDetails(), null, "1.0.*", List.of());
    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 2 with ProviderProject

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

the class EmailTestActionHelper method addEmailAddresses.

private Set<String> addEmailAddresses(Long providerConfigId, Set<ProviderProject> providerProjects, DistributionJobModel distributionJobModel, EmailJobDetailsModel emailJobDetails) throws AlertFieldException {
    boolean projectOwnerOnly = emailJobDetails.isProjectOwnerOnly();
    Set<String> emailAddresses = new HashSet<>();
    Set<String> projectsWithoutEmails = new HashSet<>();
    for (ProviderProject project : providerProjects) {
        Set<String> emailsForProject = retrieveEmailAddressesForProject(providerConfigId, project, projectOwnerOnly);
        if (emailsForProject.isEmpty()) {
            projectsWithoutEmails.add(project.getName());
        }
        emailAddresses.addAll(emailsForProject);
    }
    if (!projectsWithoutEmails.isEmpty()) {
        String projects = StringUtils.join(projectsWithoutEmails, ", ");
        String errorMessage;
        if (projectOwnerOnly) {
            errorMessage = String.format("Could not find Project owners for the projects: %s", projects);
        } else {
            errorMessage = String.format("Could not find any email addresses for the projects: %s", projects);
        }
        String errorField = ProviderDescriptor.KEY_CONFIGURED_PROJECT;
        boolean filterByProject = distributionJobModel.isFilterByProject();
        if (!filterByProject) {
            errorField = ProviderDescriptor.KEY_FILTER_BY_PROJECT;
        }
        throw AlertFieldException.singleFieldError(errorField, errorMessage);
    }
    return emailAddresses;
}
Also used : ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) HashSet(java.util.HashSet)

Example 3 with ProviderProject

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

the class BlackDuckProjectCustomFunctionAction method getBlackDuckProjectsActionResponse.

private ActionResponse<ProviderProjectOptions> getBlackDuckProjectsActionResponse(Long blackDuckGlobalConfigId, int pageNumber, int pageSize, String searchTerm) {
    AlertPagedModel<ProviderProject> providerProjectsPage = providerDataAccessor.getProjectsByProviderConfigId(blackDuckGlobalConfigId, pageNumber, pageSize, searchTerm);
    List<ProviderProjectSelectOption> options = providerProjectsPage.getModels().stream().map(project -> new ProviderProjectSelectOption(project.getName(), project.getHref(), project.getDescription())).collect(Collectors.toList());
    return new ActionResponse<>(HttpStatus.OK, new ProviderProjectOptions(providerProjectsPage.getTotalPages(), providerProjectsPage.getCurrentPage(), providerProjectsPage.getPageSize(), options));
}
Also used : ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ProviderDescriptor(com.synopsys.integration.alert.api.provider.ProviderDescriptor) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) BlackDuckPropertiesFactory(com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory) BlackDuckApiTokenValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckApiTokenValidator) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ResponseStatusException(org.springframework.web.server.ResponseStatusException) Collection(java.util.Collection) ProviderProjectOptions(com.synopsys.integration.alert.common.descriptor.config.field.endpoint.table.model.ProviderProjectOptions) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) ProviderProjectSelectOption(com.synopsys.integration.alert.common.descriptor.config.field.endpoint.table.model.ProviderProjectSelectOption) Set(java.util.Set) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) Collectors(java.util.stream.Collectors) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) HttpServletContentWrapper(com.synopsys.integration.alert.common.rest.HttpServletContentWrapper) HttpStatus(org.springframework.http.HttpStatus) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) List(java.util.List) Component(org.springframework.stereotype.Component) PagedCustomFunctionAction(com.synopsys.integration.alert.common.action.PagedCustomFunctionAction) Optional(java.util.Optional) ProviderProjectOptions(com.synopsys.integration.alert.common.descriptor.config.field.endpoint.table.model.ProviderProjectOptions) ProviderProjectSelectOption(com.synopsys.integration.alert.common.descriptor.config.field.endpoint.table.model.ProviderProjectSelectOption) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 4 with ProviderProject

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

the class BlackDuckDataSyncTask method getEmailsPerProject.

private Map<ProviderProject, Set<String>> getEmailsPerProject(Map<ProjectView, ProviderProject> blackDuckToAlertProjects, ProjectUsersService projectUsersService) {
    Map<ProviderProject, Set<String>> projectToEmailAddresses = new ConcurrentHashMap<>();
    blackDuckToAlertProjects.entrySet().parallelStream().forEach(entry -> {
        try {
            ProjectView blackDuckProjectView = entry.getKey();
            ProviderProject alertProject = entry.getValue();
            Set<String> projectUserEmailAddresses = projectUsersService.getAllActiveUsersForProject(blackDuckProjectView).stream().filter(UserView::getActive).map(UserView::getEmail).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
            if (StringUtils.isNotBlank(alertProject.getProjectOwnerEmail())) {
                projectUserEmailAddresses.add(alertProject.getProjectOwnerEmail());
            }
            projectToEmailAddresses.put(alertProject, projectUserEmailAddresses);
        } catch (IntegrationException e) {
            // We do this to break out of the stream
            throw new AlertRuntimeException(e.getMessage(), e);
        }
    });
    return projectToEmailAddresses;
}
Also used : Set(java.util.Set) IntegrationException(com.synopsys.integration.exception.IntegrationException) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 5 with ProviderProject

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

the class BlackDuckProviderDataAccessor method createProviderProject.

private ProviderProject createProviderProject(ProjectView projectView, BlackDuckApiClient blackDuckService) {
    String projectOwnerEmail = null;
    if (StringUtils.isNotBlank(projectView.getProjectOwner())) {
        try {
            HttpUrl projectOwnerHttpUrl = new HttpUrl(projectView.getProjectOwner());
            UserView projectOwner = blackDuckService.getResponse(projectOwnerHttpUrl, UserView.class);
            projectOwnerEmail = projectOwner.getEmail();
        } catch (IntegrationException e) {
            logger.errorAndDebug(createProjectOwnerNotFoundString(projectView.getName(), e.getMessage()), e);
        }
    }
    String truncatedDescription = truncateDescription(projectView.getDescription());
    return new ProviderProject(projectView.getName(), truncatedDescription, projectView.getMeta().getHref().toString(), projectOwnerEmail);
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) HttpUrl(com.synopsys.integration.rest.HttpUrl)

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