use of com.synopsys.integration.alert.common.rest.model.AlertPagedModel in project hub-alert by blackducksoftware.
the class JiraServerGlobalCrudActionsTest method getPagedTest.
@Test
void getPagedTest() {
JiraServerGlobalConfigModel jiraServerGlobalConfigModel = createJiraServerGlobalConfigModel(id);
AlertPagedModel<JiraServerGlobalConfigModel> alertPagedModel = new AlertPagedModel<>(1, AlertPagedModel.DEFAULT_PAGE_NUMBER, AlertPagedModel.DEFAULT_PAGE_SIZE, List.of(jiraServerGlobalConfigModel));
JiraServerGlobalConfigAccessor configAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
Mockito.when(configAccessor.getConfigurationPage(AlertPagedModel.DEFAULT_PAGE_NUMBER, AlertPagedModel.DEFAULT_PAGE_SIZE)).thenReturn(alertPagedModel);
JiraServerGlobalCrudActions crudActions = new JiraServerGlobalCrudActions(authorizationManager, configAccessor, validator);
ActionResponse<AlertPagedModel<JiraServerGlobalConfigModel>> actionResponse = crudActions.getPaged(AlertPagedModel.DEFAULT_PAGE_NUMBER, AlertPagedModel.DEFAULT_PAGE_SIZE);
assertTrue(actionResponse.isSuccessful());
assertTrue(actionResponse.hasContent());
assertEquals(HttpStatus.OK, actionResponse.getHttpStatus());
assertTrue(actionResponse.getContent().isPresent());
AlertPagedModel<JiraServerGlobalConfigModel> pagedModel = actionResponse.getContent().get();
assertEquals(1, pagedModel.getModels().size());
assertModelObfuscated(pagedModel.getModels().get(0));
}
use of com.synopsys.integration.alert.common.rest.model.AlertPagedModel in project hub-alert by blackducksoftware.
the class BlackDuckDistributionFieldModelTestAction method validatePatternMatchesProjectVersion.
private Optional<AlertFieldStatus> validatePatternMatchesProjectVersion(Long providerConfigId, String projectVersionNamePattern, String projectNamePattern, Collection<String> configuredProjects) {
if (StringUtils.isNotBlank(projectVersionNamePattern)) {
Pattern compiledProjectVersionPattern = Pattern.compile(projectVersionNamePattern);
Pattern compiledProjectNamePattern = StringUtils.isNotBlank(projectNamePattern) ? Pattern.compile(projectNamePattern) : null;
int currentPage = AlertPagedModel.DEFAULT_PAGE_NUMBER;
AlertPagedModel<String> projectsByProviderConfigId = filterAndMapHrefs(providerConfigId, currentPage, configuredProjects, compiledProjectNamePattern);
boolean foundResult = false;
while (!foundResult && currentPage < projectsByProviderConfigId.getTotalPages()) {
List<String> providerProjects = projectsByProviderConfigId.getModels();
foundResult = providerProjects.stream().anyMatch(href -> iteratePagesAndCheck(versionCurrentPage -> blackDuckDataAccessor.getProjectVersionNamesByHref(providerConfigId, href, versionCurrentPage), versionNames -> versionNames.stream().anyMatch(versionName -> compiledProjectVersionPattern.matcher(versionName).matches()), Boolean.FALSE).isEmpty());
currentPage++;
projectsByProviderConfigId = filterAndMapHrefs(providerConfigId, currentPage, configuredProjects, compiledProjectNamePattern);
}
if (!foundResult) {
return Optional.of(AlertFieldStatus.warning(ProviderDescriptor.KEY_PROJECT_VERSION_NAME_PATTERN, "Does not match any of the project versions."));
}
}
return Optional.empty();
}
use of com.synopsys.integration.alert.common.rest.model.AlertPagedModel 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.rest.model.AlertPagedModel in project hub-alert by blackducksoftware.
the class ProcessingTask method read.
public AlertPagedModel<AlertNotificationModel> read(DateRange dateRange, int pageNumber, int pageSize) {
try {
String taskName = getTaskName();
OffsetDateTime startDate = dateRange.getStart();
OffsetDateTime endDate = dateRange.getEnd();
logger.info("{} Reading Notifications Between {} and {} ", taskName, DateUtils.formatDateAsJsonString(startDate), DateUtils.formatDateAsJsonString(endDate));
return notificationAccessor.findByCreatedAtBetween(startDate, endDate, pageNumber, pageSize);
} catch (Exception ex) {
logger.error("Error reading Digest Notification Data", ex);
}
return new AlertPagedModel<>(0, pageNumber, pageSize, List.of());
}
use of com.synopsys.integration.alert.common.rest.model.AlertPagedModel in project hub-alert by blackducksoftware.
the class MockNotificationAccessor method getFirstPageOfNotificationsNotProcessed.
@Override
public AlertPagedModel<AlertNotificationModel> getFirstPageOfNotificationsNotProcessed(int pageSize) {
ArrayList<AlertNotificationModel> notificationsNotProcessed = new ArrayList<>();
for (AlertNotificationModel notification : alertNotificationModels) {
if (!notification.getProcessed()) {
notificationsNotProcessed.add(notification);
}
}
Page<AlertNotificationModel> pageOfNotifications;
if (notificationsNotProcessed.size() > 0) {
pageOfNotifications = new PageImpl<>(notificationsNotProcessed);
} else {
pageOfNotifications = Page.empty();
}
return new AlertPagedModel<>(pageOfNotifications.getTotalPages(), pageOfNotifications.getNumber(), pageOfNotifications.getSize(), pageOfNotifications.getContent());
}
Aggregations