use of io.gravitee.repository.management.api.search.AuditCriteria.Builder 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));
}
Aggregations