Search in sources :

Example 6 with AlertPagedModel

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));
}
Also used : JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) JiraServerGlobalConfigAccessor(com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor) Test(org.junit.jupiter.api.Test)

Example 7 with AlertPagedModel

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();
}
Also used : BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) FieldStatusSeverity(com.synopsys.integration.alert.common.descriptor.config.field.errors.FieldStatusSeverity) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) IntegrationException(com.synopsys.integration.exception.IntegrationException) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Nullable(org.springframework.lang.Nullable) ProviderDescriptor(com.synopsys.integration.alert.api.provider.ProviderDescriptor) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) BlackDuckApiTokenValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckApiTokenValidator) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) Collectors(java.util.stream.Collectors) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) List(java.util.List) Component(org.springframework.stereotype.Component) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) FieldModelTestAction(com.synopsys.integration.alert.common.action.FieldModelTestAction) Pattern(java.util.regex.Pattern)

Example 8 with AlertPagedModel

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));
}
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 9 with AlertPagedModel

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());
}
Also used : OffsetDateTime(java.time.OffsetDateTime) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel)

Example 10 with AlertPagedModel

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());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ArrayList(java.util.ArrayList) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel)

Aggregations

AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)17 PageRequest (org.springframework.data.domain.PageRequest)6 ArrayList (java.util.ArrayList)5 Transactional (org.springframework.transaction.annotation.Transactional)5 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)4 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)4 Test (org.junit.jupiter.api.Test)4 ProviderDataAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor)3 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)3 List (java.util.List)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 StringUtils (org.apache.commons.lang3.StringUtils)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 ProviderDescriptor (com.synopsys.integration.alert.api.provider.ProviderDescriptor)2 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)2 DistributionWithAuditInfo (com.synopsys.integration.alert.common.rest.model.DistributionWithAuditInfo)2 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)2 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)2