use of io.gravitee.repository.management.api.search.builder.PageableBuilder in project gravitee-management-rest-api by gravitee-io.
the class AuditServiceImpl method search.
@Override
public MetadataPage<AuditEntity> search(AuditQuery query) {
Audit.AuditReferenceType referenceType = query.isManagementLogsOnly() ? Audit.AuditReferenceType.PORTAL : (query.getApiIds() != null && !query.getApiIds().isEmpty()) ? Audit.AuditReferenceType.API : (query.getApplicationIds() != null && !query.getApplicationIds().isEmpty()) ? Audit.AuditReferenceType.APPLICATION : null;
Builder criteria = new Builder().from(query.getFrom()).to(query.getTo());
if (referenceType != null) {
List<String> referenceIds;
switch(referenceType) {
case API:
referenceIds = query.getApiIds();
break;
case APPLICATION:
referenceIds = query.getApplicationIds();
break;
default:
referenceIds = Collections.singletonList("DEFAULT");
}
criteria.references(referenceType, referenceIds);
}
if (query.getEvents() != null && !query.getEvents().isEmpty()) {
criteria.events(query.getEvents());
}
Page<Audit> auditPage = auditRepository.search(criteria.build(), new PageableBuilder().pageNumber(query.getPage() - 1).pageSize(query.getSize()).build());
List<AuditEntity> content = auditPage.getContent().stream().map(this::convert).collect(Collectors.toList());
return new MetadataPage<>(content, query.getPage(), query.getSize(), auditPage.getTotalElements(), getMetadata(content));
}
use of io.gravitee.repository.management.api.search.builder.PageableBuilder in project gravitee-gateway by gravitee-io.
the class SyncManager method getLastEvent.
private Event getLastEvent(final String api, long nextLastRefreshAt) {
final EventCriteria.Builder eventCriteriaBuilder;
if (lastRefreshAt == -1) {
eventCriteriaBuilder = new EventCriteria.Builder().property(Event.EventProperties.API_ID.getValue(), api);
} else {
eventCriteriaBuilder = new EventCriteria.Builder().property(Event.EventProperties.API_ID.getValue(), api).from(lastRefreshAt - TIMEFRAME_BEFORE_DELAY).to(nextLastRefreshAt + TIMEFRAME_AFTER_DELAY);
}
List<Event> events = eventRepository.search(eventCriteriaBuilder.types(EventType.PUBLISH_API, EventType.UNPUBLISH_API, EventType.START_API, EventType.STOP_API).build(), new PageableBuilder().pageNumber(0).pageSize(1).build()).getContent();
return (!events.isEmpty()) ? events.get(0) : null;
}
use of io.gravitee.repository.management.api.search.builder.PageableBuilder in project gravitee-management-rest-api by gravitee-io.
the class SyncManager method getLastEvent.
private Event getLastEvent(String api) {
EventCriteria eventCriteria;
if (lastRefreshAt == -1) {
eventCriteria = new EventCriteria.Builder().property(Event.EventProperties.API_ID.getValue(), api).build();
} else {
eventCriteria = new EventCriteria.Builder().property(Event.EventProperties.API_ID.getValue(), api).from(lastRefreshAt).to(System.currentTimeMillis()).build();
}
List<Event> events = eventRepository.search(eventCriteria, new PageableBuilder().pageNumber(0).pageSize(1).build()).getContent();
return (!events.isEmpty()) ? events.get(0) : null;
}
use of io.gravitee.repository.management.api.search.builder.PageableBuilder in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceTest method shouldFindByApi.
@Test
public void shouldFindByApi() throws TechnicalException {
final Pageable pageable = mock(Pageable.class);
when(pageable.pageNumber()).thenReturn(1);
when(pageable.pageSize()).thenReturn(1);
final Page<Rating> pageRating = mock(Page.class);
when(pageRating.getPageNumber()).thenReturn(1);
when(pageRating.getPageElements()).thenReturn(10L);
when(pageRating.getTotalElements()).thenReturn(100L);
when(pageRating.getContent()).thenReturn(singletonList(rating));
when(ratingRepository.findByApiPageable(eq(API_ID), eq(new PageableBuilder().pageNumber(0).pageSize(1).build()))).thenReturn(pageRating);
final Page<RatingEntity> pageRatingEntity = ratingService.findByApi(API_ID, pageable);
assertEquals(1, pageRatingEntity.getPageNumber());
assertEquals(10, pageRatingEntity.getPageElements());
assertEquals(100, pageRatingEntity.getTotalElements());
final RatingEntity ratingEntity = pageRatingEntity.getContent().get(0);
assertEquals(USER, ratingEntity.getUser());
assertEquals(API_ID, ratingEntity.getApi());
assertEquals(TITLE, ratingEntity.getTitle());
assertEquals(COMMENT, ratingEntity.getComment());
assertEquals(RATE, ratingEntity.getRate(), 0);
assertEquals(ratingEntity.getCreatedAt(), ratingEntity.getUpdatedAt());
}
use of io.gravitee.repository.management.api.search.builder.PageableBuilder in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceImpl method findByApi.
@Override
public Page<RatingEntity> findByApi(final String api, final Pageable pageable) {
if (!enabled) {
throw new ApiRatingUnavailableException();
}
try {
final Page<Rating> pageRating = ratingRepository.findByApiPageable(api, new PageableBuilder().pageNumber(pageable.pageNumber() - 1).pageSize(pageable.pageSize()).build());
final List<RatingEntity> ratingEntities = pageRating.getContent().stream().map(this::convert).collect(toList());
return new Page<>(ratingEntities, pageRating.getPageNumber(), (int) pageRating.getPageElements(), pageRating.getTotalElements());
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to find ratings for api {}", api, ex);
throw new TechnicalManagementException("An error occurred while trying to find ratings for api " + api, ex);
}
}
Aggregations