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