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());
}
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;
}
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));
}
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;
}
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);
}
Aggregations