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