use of io.gravitee.rest.api.model.common.SortableImpl 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.SortableImpl 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());
}
use of io.gravitee.rest.api.model.common.SortableImpl in project gravitee-management-rest-api by gravitee-io.
the class PromotionsResource method searchPromotions.
@POST
@Path("_search")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Search for Promotion")
@ApiResponses({ @ApiResponse(code = 200, message = "List promotions matching request parameters", response = PromotionEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
public Response searchPromotions(@ApiParam(name = "statuses", required = true) @NotNull @QueryParam("statuses") List<String> statuses, @ApiParam(name = "apiId", required = true) @NotNull @QueryParam("apiId") String apiId) {
PromotionQuery promotionQuery = new PromotionQuery();
promotionQuery.setStatuses(statuses.stream().map(PromotionEntityStatus::valueOf).collect(toList()));
promotionQuery.setApiId(apiId);
List<PromotionEntity> promotions = promotionService.search(promotionQuery, new SortableImpl("created_at", false), null).getContent();
return Response.ok().entity(promotions).build();
}
use of io.gravitee.rest.api.model.common.SortableImpl in project gravitee-management-rest-api by gravitee-io.
the class TicketsResourceTest method shouldSearchTickets.
@Test
public void shouldSearchTickets() {
resetAllMocks();
TicketEntity ticketEntity = new TicketEntity();
ticketEntity.setId("1");
ArgumentCaptor<TicketQuery> queryCaptor = ArgumentCaptor.forClass(TicketQuery.class);
ArgumentCaptor<SortableImpl> sortableCaptor = ArgumentCaptor.forClass(SortableImpl.class);
when(ticketService.search(queryCaptor.capture(), sortableCaptor.capture(), any())).thenReturn(new Page<>(singletonList(ticketEntity), 1, 1, 1));
Response response = target().queryParam("page", 1).queryParam("size", 10).queryParam("apiId", "apiId").queryParam("order", "-subject").request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
TicketQuery query = queryCaptor.getValue();
SortableImpl sortable = sortableCaptor.getValue();
assertEquals("Criteria user", USER_NAME, query.getFromUser());
assertEquals("Criteria api", "apiId", query.getApi());
assertEquals("Query sort field", "subject", sortable.getField());
assertEquals("Query sort order", false, sortable.isAscOrder());
verify(ticketService, Mockito.times(1)).search(any(), argThat(o -> o.getField().equals("subject") && !o.isAscOrder()), argThat(o -> o.getPageNumber() == 1 && o.getPageSize() == 10));
TicketsResponse ticketsResponse = response.readEntity(TicketsResponse.class);
assertEquals("Ticket list had not the good size", 1, ticketsResponse.getData().size());
}
use of io.gravitee.rest.api.model.common.SortableImpl in project gravitee-management-rest-api by gravitee-io.
the class PromotionTasksServiceImpl method getPromotionTasksForEnvironments.
@NotNull
private List<TaskEntity> getPromotionTasksForEnvironments(List<EnvironmentEntity> environments, boolean selectUpdatePromotion) {
if (environments.isEmpty()) {
return emptyList();
}
List<String> envCockpitIds = environments.stream().map(EnvironmentEntity::getCockpitId).filter(Objects::nonNull).collect(toList());
final PromotionQuery promotionQuery = new PromotionQuery();
promotionQuery.setStatuses(Collections.singletonList(PromotionEntityStatus.TO_BE_VALIDATED));
promotionQuery.setTargetEnvCockpitIds(envCockpitIds);
final Page<PromotionEntity> promotionsPage = promotionService.search(promotionQuery, new SortableImpl("created_at", false), null);
final PromotionQuery previousPromotionsQuery = new PromotionQuery();
previousPromotionsQuery.setStatuses(Collections.singletonList(PromotionEntityStatus.ACCEPTED));
previousPromotionsQuery.setTargetEnvCockpitIds(envCockpitIds);
previousPromotionsQuery.setTargetApiExists(true);
List<PromotionEntity> previousPromotions = promotionService.search(previousPromotionsQuery, new SortableImpl("created_at", false), null).getContent();
final Map<String, List<String>> promotionByApiWithTargetApiId = previousPromotions.stream().collect(groupingBy(PromotionEntity::getApiId, Collectors.mapping(PromotionEntity::getTargetApiId, toList())));
return promotionsPage.getContent().stream().map(promotionEntity -> {
Optional<String> foundTargetApiId = promotionByApiWithTargetApiId.getOrDefault(promotionEntity.getApiId(), emptyList()).stream().filter(StringUtils::hasText).findFirst();
boolean isUpdate = foundTargetApiId.isPresent() && apiService.exists(foundTargetApiId.get());
return convert(promotionEntity, isUpdate, foundTargetApiId);
}).filter(taskEntity -> ((Boolean) ((Map<String, Object>) taskEntity.getData()).getOrDefault("isApiUpdate", false) == selectUpdatePromotion)).collect(toList());
}
Aggregations