Search in sources :

Example 1 with MetadataPage

use of io.gravitee.common.data.domain.MetadataPage 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));
}
Also used : AuditEntity(io.gravitee.management.model.audit.AuditEntity) MetadataPage(io.gravitee.common.data.domain.MetadataPage) Builder(io.gravitee.repository.management.api.search.AuditCriteria.Builder) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder)

Aggregations

MetadataPage (io.gravitee.common.data.domain.MetadataPage)1 AuditEntity (io.gravitee.management.model.audit.AuditEntity)1 Builder (io.gravitee.repository.management.api.search.AuditCriteria.Builder)1 PageableBuilder (io.gravitee.repository.management.api.search.builder.PageableBuilder)1