use of io.gravitee.rest.api.model.common.Sortable 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());
}
use of io.gravitee.rest.api.model.common.Sortable in project gravitee-management-rest-api by gravitee-io.
the class TicketsResource method getTickets.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getTickets(@Valid @BeanParam PaginationParam paginationParam, @BeanParam TicketsParam ticketsParam) {
TicketQuery query = new TicketQuery();
query.setApi(ticketsParam.getApi());
query.setApplication(ticketsParam.getApplication());
query.setApi(ticketsParam.getApi());
query.setFromUser(getAuthenticatedUser());
Sortable sortable = null;
if (ticketsParam.getOrder() != null) {
sortable = new SortableImpl(ticketsParam.getOrder().getField(), ticketsParam.getOrder().isSorted());
}
Page<TicketEntity> tickets = ticketService.search(query, sortable, new PageableImpl(paginationParam.getPage(), paginationParam.getSize()));
final Map<String, Object> metadataTotal = new HashMap<>();
metadataTotal.put(METADATA_DATA_TOTAL_KEY, tickets.getTotalElements());
final Map<String, Map<String, Object>> metadata = new HashMap<>();
metadata.put(METADATA_DATA_KEY, metadataTotal);
return createListResponse(tickets.getContent(), paginationParam, metadata, false);
}
use of io.gravitee.rest.api.model.common.Sortable in project gravitee-management-rest-api by gravitee-io.
the class PlatformTicketsResource method getTickets.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Search for platform tickets written by current user")
@ApiResponses({ @ApiResponse(code = 200, message = "List platform tickets written by current user", response = Page.class), @ApiResponse(code = 500, message = "Internal server error") })
public Page<TicketEntity> getTickets(@Valid @BeanParam Pageable pageable, @Valid @BeanParam TicketsParam ticketsParam) {
TicketQuery query = new TicketQuery();
query.setApi(ticketsParam.getApi());
query.setApplication(ticketsParam.getApplication());
query.setApi(ticketsParam.getApi());
query.setFromUser(getAuthenticatedUser());
Sortable sortable = null;
if (ticketsParam.getOrder() != null) {
sortable = new SortableImpl(ticketsParam.getOrder().getField(), ticketsParam.getOrder().isOrder());
}
return ticketService.search(query, sortable, pageable.toPageable());
}
use of io.gravitee.rest.api.model.common.Sortable in project gravitee-management-rest-api by gravitee-io.
the class ApisResource method getApis.
@GET
@Path("_paged")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List APIs with pagination", notes = "List all the APIs accessible to the current user with pagination.", nickname = "getApisPaged")
@ApiResponses({ @ApiResponse(code = 200, message = "Page of APIs for current user", response = PagedResult.class), @ApiResponse(code = 500, message = "Internal server error") })
public PagedResult<ApiListItem> getApis(@BeanParam final ApisParam apisParam, @Valid @BeanParam Pageable pageable) {
final ApiQuery apiQuery = new ApiQuery();
if (apisParam.getGroup() != null) {
apiQuery.setGroups(singletonList(apisParam.getGroup()));
}
apiQuery.setContextPath(apisParam.getContextPath());
apiQuery.setLabel(apisParam.getLabel());
apiQuery.setVersion(apisParam.getVersion());
apiQuery.setName(apisParam.getName());
apiQuery.setTag(apisParam.getTag());
apiQuery.setState(apisParam.getState());
if (apisParam.getCategory() != null) {
apiQuery.setCategory(categoryService.findById(apisParam.getCategory()).getId());
}
Sortable sortable = null;
if (apisParam.getOrder() != null) {
sortable = new SortableImpl(apisParam.getOrder().getField(), apisParam.getOrder().isOrder());
}
io.gravitee.rest.api.model.common.Pageable commonPageable = null;
if (pageable != null) {
commonPageable = pageable.toPageable();
}
final Page<ApiEntity> apis;
if (isAdmin()) {
apis = apiService.search(apiQuery, sortable, commonPageable);
} else {
if (apisParam.isPortal() || apisParam.isTop()) {
apiQuery.setLifecycleStates(singletonList(PUBLISHED));
}
if (isAuthenticated()) {
apis = apiService.findByUser(getAuthenticatedUser(), apiQuery, sortable, commonPageable, apisParam.isPortal());
} else {
apiQuery.setVisibility(PUBLIC);
apis = apiService.search(apiQuery, sortable, commonPageable);
}
}
final boolean isRatingServiceEnabled = ratingService.isEnabled();
if (apisParam.isTop()) {
final List<String> visibleApis = apis.getContent().stream().map(ApiEntity::getId).collect(toList());
return new PagedResult<>(topApiService.findAll().stream().filter(topApi -> visibleApis.contains(topApi.getApi())).map(topApiEntity -> apiService.findById(topApiEntity.getApi())).map(apiEntity -> this.convert(apiEntity, isRatingServiceEnabled)).collect(toList()), apis.getPageNumber(), (int) apis.getPageElements(), (int) apis.getTotalElements());
}
return new PagedResult<>(apis.getContent().stream().map(apiEntity -> this.convert(apiEntity, isRatingServiceEnabled)).collect(toList()), apis.getPageNumber(), (int) apis.getPageElements(), (int) apis.getTotalElements());
}
Aggregations