Search in sources :

Example 1 with OrderParam

use of io.gravitee.rest.api.management.rest.resource.param.OrderParam in project gravitee-management-rest-api by gravitee-io.

the class ApisResource method searchApis.

@POST
@Path("_search/_paged")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Search for API using the search engine")
@ApiResponses({ @ApiResponse(code = 200, message = "List accessible APIs for current user", response = ApiListItem.class), @ApiResponse(code = 500, message = "Internal server error") })
public PagedResult<ApiListItem> searchApis(@ApiParam(name = "q", required = true) @NotNull @QueryParam("q") String query, @ApiParam(name = "order") @QueryParam("order") String order, @Valid @BeanParam Pageable pageable) {
    final ApiQuery apiQuery = new ApiQuery();
    Map<String, Object> filters = new HashMap<>();
    Sortable sortable = null;
    if (!StringUtils.isEmpty(order)) {
        final OrderParam orderParam = new OrderParam(order);
        sortable = new SortableImpl(orderParam.getValue().getField(), orderParam.getValue().isOrder());
    }
    io.gravitee.rest.api.model.common.Pageable commonPageable = null;
    if (pageable != null) {
        commonPageable = pageable.toPageable();
    }
    if (!isAdmin()) {
        filters.put("api", apiService.findIdsByUser(getAuthenticatedUser(), apiQuery, false));
    }
    final boolean isRatingServiceEnabled = ratingService.isEnabled();
    final Page<ApiEntity> apis = apiService.search(query, filters, sortable, commonPageable);
    return new PagedResult<>(apis.getContent().stream().map(apiEntity -> this.convert(apiEntity, isRatingServiceEnabled)).collect(toList()), apis.getPageNumber(), (int) apis.getPageElements(), (int) apis.getTotalElements());
}
Also used : SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) OrderParam(io.gravitee.rest.api.management.rest.resource.param.OrderParam) Sortable(io.gravitee.rest.api.model.common.Sortable) io.gravitee.rest.api.model.api(io.gravitee.rest.api.model.api) PagedResult(io.gravitee.rest.api.management.rest.model.PagedResult)

Aggregations

PagedResult (io.gravitee.rest.api.management.rest.model.PagedResult)1 OrderParam (io.gravitee.rest.api.management.rest.resource.param.OrderParam)1 io.gravitee.rest.api.model.api (io.gravitee.rest.api.model.api)1 Sortable (io.gravitee.rest.api.model.common.Sortable)1 SortableImpl (io.gravitee.rest.api.model.common.SortableImpl)1