Search in sources :

Example 1 with ApiCriteria

use of io.gravitee.repository.management.api.search.ApiCriteria in project gravitee-management-rest-api by gravitee-io.

the class ApiServiceImpl method search.

@Override
public Page<ApiEntity> search(String query, Map<String, Object> filters, Sortable sortable, Pageable pageable) {
    try {
        LOGGER.debug("Search paged APIs by {}", query);
        Query<ApiEntity> apiQuery = QueryBuilder.create(ApiEntity.class).setQuery(query).setFilters(filters).build();
        SearchResult matchApis = searchEngineService.search(apiQuery);
        if (matchApis.getDocuments().isEmpty()) {
            return new Page<>(emptyList(), 0, 0, 0);
        }
        final ApiCriteria apiCriteria = new ApiCriteria.Builder().ids(matchApis.getDocuments().toArray(new String[0])).build();
        final Page<Api> apiPage = sortAndPaginate(apiRepository.search(apiCriteria), sortable, pageable);
        // merge all apis
        final List<ApiEntity> apis = convert(apiPage.getContent());
        return new Page<>(apis, apiPage.getPageNumber(), (int) apiPage.getPageElements(), apiPage.getTotalElements());
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to search paged apis", ex);
        throw new TechnicalManagementException("An error occurs while trying to search paged apis", ex);
    }
}
Also used : ApiCriteria(io.gravitee.repository.management.api.search.ApiCriteria) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) NotificationParamsBuilder(io.gravitee.rest.api.service.notification.NotificationParamsBuilder) EmailNotificationBuilder(io.gravitee.rest.api.service.builder.EmailNotificationBuilder) QueryBuilder(io.gravitee.rest.api.service.search.query.QueryBuilder) SearchResult(io.gravitee.rest.api.service.impl.search.SearchResult) Page(io.gravitee.common.data.domain.Page) Api(io.gravitee.repository.management.model.Api)

Aggregations

Page (io.gravitee.common.data.domain.Page)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 ApiCriteria (io.gravitee.repository.management.api.search.ApiCriteria)1 Api (io.gravitee.repository.management.model.Api)1 EmailNotificationBuilder (io.gravitee.rest.api.service.builder.EmailNotificationBuilder)1 SearchResult (io.gravitee.rest.api.service.impl.search.SearchResult)1 NotificationParamsBuilder (io.gravitee.rest.api.service.notification.NotificationParamsBuilder)1 QueryBuilder (io.gravitee.rest.api.service.search.query.QueryBuilder)1