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());
}
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);
}
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;
}
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;
}
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)));
}
Aggregations