Search in sources :

Example 1 with AlertPagedModel

use of com.synopsys.integration.alert.common.rest.model.AlertPagedModel in project hub-alert by blackducksoftware.

the class StaticJobAccessor method getPageOfJobs.

@Override
@Transactional(readOnly = true)
public AlertPagedModel<DistributionJobModel> getPageOfJobs(int pageNumber, int pageLimit) {
    PageRequest pageRequest = PageRequest.of(pageNumber, pageLimit);
    Page<DistributionJobModel> pageOfJobsWithDescriptorNames = distributionJobRepository.findAll(pageRequest).map(this::convertToDistributionJobModelFromEntity);
    return new AlertPagedModel<>(pageOfJobsWithDescriptorNames.getTotalPages(), pageNumber, pageLimit, pageOfJobsWithDescriptorNames.getContent());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with AlertPagedModel

use of com.synopsys.integration.alert.common.rest.model.AlertPagedModel in project hub-alert by blackducksoftware.

the class StaticJobAccessor method getPageOfJobs.

@Override
@Transactional(readOnly = true)
public AlertPagedModel<DistributionJobModel> getPageOfJobs(int pageNumber, int pageLimit, String searchTerm, Collection<String> descriptorsNamesToInclude) {
    if (!descriptorsNamesToInclude.contains(blackDuckProviderKey.getUniversalKey())) {
        return new AlertPagedModel<>(0, pageNumber, pageLimit, List.of());
    }
    PageRequest pageRequest = PageRequest.of(pageNumber, pageLimit);
    Page<DistributionJobEntity> pageOfJobsWithDescriptorNames;
    if (StringUtils.isBlank(searchTerm)) {
        pageOfJobsWithDescriptorNames = distributionJobRepository.findByChannelDescriptorNameIn(descriptorsNamesToInclude, pageRequest);
    } else {
        pageOfJobsWithDescriptorNames = distributionJobRepository.findByChannelDescriptorNamesAndSearchTerm(descriptorsNamesToInclude, searchTerm, pageRequest);
    }
    List<DistributionJobModel> configurationJobModels = pageOfJobsWithDescriptorNames.map(this::convertToDistributionJobModelFromEntity).getContent();
    return new AlertPagedModel<>(pageOfJobsWithDescriptorNames.getTotalPages(), pageNumber, pageLimit, configurationJobModels);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with AlertPagedModel

use of com.synopsys.integration.alert.common.rest.model.AlertPagedModel in project hub-alert by blackducksoftware.

the class DefaultDistributionAccessor method retrieveData.

private AlertPagedModel<DistributionWithAuditInfo> retrieveData(int page, int pageSize, String sortName, Direction sortOrder, Function<PageRequest, Page<DistributionDBResponse>> retrieveData) {
    Sort sort = (sortName == null || sortOrder == null) ? Sort.unsorted() : Sort.by(sortOrder, sortName);
    PageRequest pageRequest = PageRequest.of(page, pageSize, sort);
    Page<DistributionDBResponse> pageOfResponses = retrieveData.apply(pageRequest);
    List<DistributionWithAuditInfo> distributionWithAuditInfos = pageOfResponses.get().map(this::convert).collect(Collectors.toList());
    return new AlertPagedModel<>(pageOfResponses.getTotalPages(), pageOfResponses.getNumber(), pageOfResponses.getSize(), distributionWithAuditInfos);
}
Also used : DistributionWithAuditInfo(com.synopsys.integration.alert.common.rest.model.DistributionWithAuditInfo) PageRequest(org.springframework.data.domain.PageRequest) DistributionDBResponse(com.synopsys.integration.alert.database.distribution.DistributionRepository.DistributionDBResponse) Sort(org.springframework.data.domain.Sort) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel)

Example 4 with AlertPagedModel

use of com.synopsys.integration.alert.common.rest.model.AlertPagedModel in project hub-alert by blackducksoftware.

the class DefaultProcessingJobAccessor method getMatchingEnabledJobsByFilteredNotifications.

@Override
public AlertPagedModel<FilteredDistributionJobResponseModel> getMatchingEnabledJobsByFilteredNotifications(FilteredDistributionJobRequestModel filteredDistributionJobRequestModel, int pageNumber, int pageLimit) {
    List<String> frequencyTypes = filteredDistributionJobRequestModel.getFrequencyTypes().stream().map(Enum::name).collect(Collectors.toList());
    Set<String> projectNames = filteredDistributionJobRequestModel.getProjectName();
    Set<String> notificationTypes = filteredDistributionJobRequestModel.getNotificationTypes();
    // If no policies and/or vulnerabilitySeverities exist the repository query expects a null to be passed
    Set<String> policyNames = filteredDistributionJobRequestModel.getPolicyNames().isEmpty() ? null : filteredDistributionJobRequestModel.getPolicyNames();
    Set<String> vulnerabilitySeverities = filteredDistributionJobRequestModel.getVulnerabilitySeverities().isEmpty() ? null : filteredDistributionJobRequestModel.getVulnerabilitySeverities();
    PageRequest pageRequest = PageRequest.of(pageNumber, pageLimit);
    Page<DistributionJobEntity> pageOfDistributionJobEntities = distributionJobRepository.findAndSortMatchingEnabledJobsByFilteredNotifications(filteredDistributionJobRequestModel.getProviderConfigId(), frequencyTypes, notificationTypes, projectNames, policyNames, vulnerabilitySeverities, pageRequest);
    List<FilteredDistributionJobResponseModel> distributionJobResponseModels = pageOfDistributionJobEntities.getContent().stream().map(this::convertToFilteredDistributionJobResponseModel).collect(Collectors.toList());
    return new AlertPagedModel<>(pageOfDistributionJobEntities.getTotalPages(), pageNumber, pageLimit, distributionJobResponseModels);
}
Also used : FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) PageRequest(org.springframework.data.domain.PageRequest) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel)

Example 5 with AlertPagedModel

use of com.synopsys.integration.alert.common.rest.model.AlertPagedModel in project hub-alert by blackducksoftware.

the class DefaultDistributionAccessorTestIT method assertValidQueryFunctionality.

private AlertPagedModel<DistributionWithAuditInfo> assertValidQueryFunctionality(int expectedNumberOfResults, Supplier<AlertPagedModel<DistributionWithAuditInfo>> dBQuery) throws ParseException {
    Map<UUID, Pair<DistributionJobModel, List<AuditEntryEntity>>> jobAndAuditData = createAndSave6JobAndAudit();
    assertEquals(TOTAL_NUMBER_OF_RECORDS, jobAndAuditData.keySet().size());
    jobAndAuditData.keySet().stream().forEach(uuid -> {
        Optional<DistributionJobModel> job = jobAccessor.getJobById(uuid);
        assertTrue(job.isPresent());
    });
    AlertPagedModel<DistributionWithAuditInfo> queryResult = dBQuery.get();
    assertNotNull(queryResult);
    assertEquals(expectedNumberOfResults, queryResult.getModels().size());
    for (DistributionWithAuditInfo distributionWithAuditInfo : queryResult.getModels()) {
        Pair<DistributionJobModel, List<AuditEntryEntity>> distributionJobModelListPair = jobAndAuditData.get(distributionWithAuditInfo.getJobId());
        DistributionJobModel distributionJobModel = distributionJobModelListPair.getLeft();
        assertEquals(distributionJobModel.getName(), distributionWithAuditInfo.getJobName());
        assertNotEquals(AuditEntryStatus.PENDING.name(), distributionWithAuditInfo.getAuditStatus());
        List<AuditEntryEntity> audits = distributionJobModelListPair.getRight();
        if (!audits.isEmpty()) {
            OffsetDateTime mostRecentAuditEntryTime = audits.stream().filter(auditEntryEntity -> auditEntryEntity.getTimeLastSent() != null).max(Comparator.comparing(AuditEntryEntity::getTimeLastSent)).map(AuditEntryEntity::getTimeLastSent).orElse(null);
            String formattedTime = null;
            if (null != mostRecentAuditEntryTime) {
                formattedTime = DateUtils.formatDate(mostRecentAuditEntryTime, DateUtils.AUDIT_DATE_FORMAT);
            }
            assertEquals(formattedTime, distributionWithAuditInfo.getAuditTimeLastSent());
        }
    }
    return queryResult;
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) AuditEntryStatus(com.synopsys.integration.alert.common.enumeration.AuditEntryStatus) Autowired(org.springframework.beans.factory.annotation.Autowired) FrequencyType(com.synopsys.integration.alert.common.enumeration.FrequencyType) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) Disabled(org.junit.jupiter.api.Disabled) Function(java.util.function.Function) Supplier(java.util.function.Supplier) StringUtils(org.apache.commons.lang3.StringUtils) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) DistributionWithAuditInfo(com.synopsys.integration.alert.common.rest.model.DistributionWithAuditInfo) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) Pair(org.apache.commons.lang3.tuple.Pair) ProcessingType(com.synopsys.integration.alert.common.enumeration.ProcessingType) SlackChannelKey(com.synopsys.integration.alert.descriptor.api.SlackChannelKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Direction(org.springframework.data.domain.Sort.Direction) ParseException(java.text.ParseException) LinkedList(java.util.LinkedList) DateUtils(com.synopsys.integration.alert.common.util.DateUtils) MsTeamsKey(com.synopsys.integration.alert.descriptor.api.MsTeamsKey) Modifying(org.springframework.data.jpa.repository.Modifying) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) Set(java.util.Set) UUID(java.util.UUID) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Collectors(java.util.stream.Collectors) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) OffsetDateTime(java.time.OffsetDateTime) DistributionAccessor(com.synopsys.integration.alert.common.persistence.accessor.DistributionAccessor) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Comparator(java.util.Comparator) Transactional(org.springframework.transaction.annotation.Transactional) DistributionWithAuditInfo(com.synopsys.integration.alert.common.rest.model.DistributionWithAuditInfo) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) OffsetDateTime(java.time.OffsetDateTime) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) LinkedList(java.util.LinkedList) List(java.util.List) UUID(java.util.UUID) Pair(org.apache.commons.lang3.tuple.Pair)

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