Search in sources :

Example 1 with DistributionWithAuditInfo

use of com.synopsys.integration.alert.common.rest.model.DistributionWithAuditInfo 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 2 with DistributionWithAuditInfo

use of com.synopsys.integration.alert.common.rest.model.DistributionWithAuditInfo 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)

Example 3 with DistributionWithAuditInfo

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

the class DefaultDistributionAccessorTestIT method assertSorted.

private <T extends Comparable> AlertPagedModel<DistributionWithAuditInfo> assertSorted(int expectedTotal, int pageSize, String sortName, Direction sortDirection, Function<DistributionWithAuditInfo, T> getNullableValue) throws ParseException {
    AlertPagedModel<DistributionWithAuditInfo> distributionWithAuditInfoSorted = assertValidQueryFunctionality(expectedTotal, () -> distributionAccessor.getDistributionWithAuditInfo(0, pageSize, sortName, sortDirection, getAllDescriptorNames()));
    T previouslyRetrievedValue = null;
    boolean inOrder = true;
    for (DistributionWithAuditInfo info : distributionWithAuditInfoSorted.getModels()) {
        T retrievedValue = getNullableValue.apply(info);
        if (retrievedValue != null && previouslyRetrievedValue != null) {
            int comparisonResult = previouslyRetrievedValue.compareTo(retrievedValue);
            boolean previousTimeLessThanCurrent = (sortDirection == Direction.ASC) ? comparisonResult <= 0 : comparisonResult >= 0;
            inOrder = inOrder && previousTimeLessThanCurrent;
            if (!inOrder) {
                break;
            }
        }
        previouslyRetrievedValue = retrievedValue;
    }
    assertTrue(inOrder);
    return distributionWithAuditInfoSorted;
}
Also used : DistributionWithAuditInfo(com.synopsys.integration.alert.common.rest.model.DistributionWithAuditInfo)

Example 4 with DistributionWithAuditInfo

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

the class DistributionActions method retrieveJobWithAuditInfo.

public ActionResponse<AlertPagedModel<DistributionWithAuditInfo>> retrieveJobWithAuditInfo(int page, int pageSize, @Nullable String sortName, @Nullable String sortOrder, @Nullable String searchTerm) {
    Set<String> authorizedChannelDescriptorNames = findAuthorizedChannelDescriptorNames();
    if (authorizedChannelDescriptorNames.isEmpty()) {
        return ActionResponse.createForbiddenResponse();
    }
    String applicableSortName = convertSortName(sortName);
    Direction validSortOrder = Direction.ASC;
    if (Direction.DESC.name().equalsIgnoreCase(sortOrder)) {
        validSortOrder = Direction.DESC;
    }
    AlertPagedModel<DistributionWithAuditInfo> distributionWithAuditInfo;
    if (searchTerm != null) {
        distributionWithAuditInfo = distributionAccessor.getDistributionWithAuditInfoWithSearch(page, pageSize, applicableSortName, validSortOrder, authorizedChannelDescriptorNames, searchTerm);
    } else {
        distributionWithAuditInfo = distributionAccessor.getDistributionWithAuditInfo(page, pageSize, applicableSortName, validSortOrder, authorizedChannelDescriptorNames);
    }
    AlertPagedModel<DistributionWithAuditInfo> sortedPagedModel = sortByChannelDisplayNameIfApplicable(distributionWithAuditInfo, applicableSortName, validSortOrder);
    return new ActionResponse(HttpStatus.OK, sortedPagedModel);
}
Also used : DistributionWithAuditInfo(com.synopsys.integration.alert.common.rest.model.DistributionWithAuditInfo) Direction(org.springframework.data.domain.Sort.Direction) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Aggregations

DistributionWithAuditInfo (com.synopsys.integration.alert.common.rest.model.DistributionWithAuditInfo)4 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)2 Direction (org.springframework.data.domain.Sort.Direction)2 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)1 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)1 AuditEntryStatus (com.synopsys.integration.alert.common.enumeration.AuditEntryStatus)1 FrequencyType (com.synopsys.integration.alert.common.enumeration.FrequencyType)1 ProcessingType (com.synopsys.integration.alert.common.enumeration.ProcessingType)1 DistributionAccessor (com.synopsys.integration.alert.common.persistence.accessor.DistributionAccessor)1 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)1 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)1 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)1 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)1 MSTeamsJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel)1 SlackJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel)1 DateUtils (com.synopsys.integration.alert.common.util.DateUtils)1 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)1 AuditEntryRepository (com.synopsys.integration.alert.database.audit.AuditEntryRepository)1 DistributionDBResponse (com.synopsys.integration.alert.database.distribution.DistributionRepository.DistributionDBResponse)1 MsTeamsKey (com.synopsys.integration.alert.descriptor.api.MsTeamsKey)1