Search in sources :

Example 1 with DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel 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 DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel 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 DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.

the class StaticJobAccessor method convertToDistributionJobModelFromEntity.

private DistributionJobModel convertToDistributionJobModelFromEntity(DistributionJobEntity distributionJobEntity) {
    DistributionJobModel result;
    ChannelKey channelKey = ChannelKeys.getChannelKey(distributionJobEntity.getChannelDescriptorName());
    if (jobDetailsAccessorMap.containsKey(channelKey)) {
        JobDetailsAccessor2<? extends DistributionJobDetailsModel> accessor = jobDetailsAccessorMap.get(channelKey);
        DistributionJobDetailsModel detailsModel = accessor.retrieveDetails(distributionJobEntity.getJobId()).orElse(null);
        result = convertToDistributionJobModel(distributionJobEntity, detailsModel);
    } else {
        result = convertToDistributionJobModel(distributionJobEntity);
    }
    return result;
}
Also used : DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 4 with DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel 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 5 with DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.

the class DefaultDistributionAccessorTestIT method createAndSave6JobAndAudit.

private Map<UUID, Pair<DistributionJobModel, List<AuditEntryEntity>>> createAndSave6JobAndAudit() {
    DistributionJobRequestModel firstJob = createSlackJob(true);
    DistributionJobRequestModel secondJob = createSlackJob(false);
    DistributionJobRequestModel thirdJob = createSlackJob(true);
    DistributionJobRequestModel fourthJob = createSlackJob(false);
    DistributionJobRequestModel fifthJob = createMSTeamsJob(true);
    DistributionJobRequestModel sixthJob = createMSTeamsJob(false);
    DistributionJobModel firstJobSaved = jobAccessor.createJob(firstJob);
    DistributionJobModel secondJobSaved = jobAccessor.createJob(secondJob);
    DistributionJobModel thirdJobSaved = jobAccessor.createJob(thirdJob);
    DistributionJobModel fourthJobSaved = jobAccessor.createJob(fourthJob);
    DistributionJobModel fifthJobSaved = jobAccessor.createJob(fifthJob);
    DistributionJobModel sixthJobSaved = jobAccessor.createJob(sixthJob);
    createdJobs.add(firstJobSaved.getJobId());
    createdJobs.add(secondJobSaved.getJobId());
    createdJobs.add(thirdJobSaved.getJobId());
    createdJobs.add(fourthJobSaved.getJobId());
    createdJobs.add(fifthJobSaved.getJobId());
    createdJobs.add(sixthJobSaved.getJobId());
    AuditEntryEntity firstAudit = createAuditEntryEntity(firstJobSaved.getJobId(), OffsetDateTime.now(), AuditEntryStatus.SUCCESS);
    AuditEntryEntity secondAudit = createAuditEntryEntity(firstJobSaved.getJobId(), OffsetDateTime.now().minusDays(1), AuditEntryStatus.PENDING);
    AuditEntryEntity thirdAudit = createAuditEntryEntity(secondJobSaved.getJobId(), OffsetDateTime.now().minusMinutes(1), AuditEntryStatus.FAILURE);
    AuditEntryEntity fourthAudit = createAuditEntryEntity(fourthJobSaved.getJobId(), OffsetDateTime.now().minusHours(1), AuditEntryStatus.SUCCESS);
    AuditEntryEntity fifthAudit = createAuditEntryEntity(fifthJobSaved.getJobId(), OffsetDateTime.now().minusHours(2), AuditEntryStatus.SUCCESS);
    AuditEntryEntity sixthAudit = createAuditEntryEntity(fifthJobSaved.getJobId(), OffsetDateTime.now().minusMinutes(2), AuditEntryStatus.FAILURE);
    AuditEntryEntity seventhAudit = createAuditEntryEntity(sixthJobSaved.getJobId(), null, AuditEntryStatus.SUCCESS);
    AuditEntryEntity eighthAudit = createAuditEntryEntity(sixthJobSaved.getJobId(), OffsetDateTime.now(), AuditEntryStatus.FAILURE);
    AuditEntryEntity ninthAudit = createAuditEntryEntity(sixthJobSaved.getJobId(), null, AuditEntryStatus.PENDING);
    saveAllAudits(List.of(firstAudit, secondAudit, thirdAudit, fourthAudit, fifthAudit, sixthAudit, seventhAudit, eighthAudit, ninthAudit));
    return Map.of(firstJobSaved.getJobId(), Pair.of(firstJobSaved, List.of(firstAudit, secondAudit)), secondJobSaved.getJobId(), Pair.of(secondJobSaved, List.of(thirdAudit)), thirdJobSaved.getJobId(), Pair.of(thirdJobSaved, List.of()), fourthJobSaved.getJobId(), Pair.of(fourthJobSaved, List.of(fourthAudit)), fifthJobSaved.getJobId(), Pair.of(fifthJobSaved, List.of(fifthAudit, sixthAudit)), sixthJobSaved.getJobId(), Pair.of(sixthJobSaved, List.of(seventhAudit, eighthAudit, ninthAudit)));
}
Also used : AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Aggregations

DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)52 Test (org.junit.jupiter.api.Test)35 UUID (java.util.UUID)24 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)20 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)15 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)14 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)10 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)9 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)9 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)8 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)8 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)8 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)8 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)8 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)7 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)7 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)7 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)7 OffsetDateTime (java.time.OffsetDateTime)7 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)6