Search in sources :

Example 6 with SortableImpl

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());
}
Also used : SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) Sortable(io.gravitee.rest.api.model.common.Sortable) TicketQuery(io.gravitee.rest.api.model.api.TicketQuery) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with SortableImpl

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());
}
Also used : PUBLIC(io.gravitee.rest.api.model.Visibility.PUBLIC) io.gravitee.rest.api.service(io.gravitee.rest.api.service) PagedResult(io.gravitee.rest.api.management.rest.model.PagedResult) java.util(java.util) PUBLISHED(io.gravitee.rest.api.model.api.ApiLifecycleState.PUBLISHED) ApiHook(io.gravitee.rest.api.service.notification.ApiHook) Page(io.gravitee.common.data.domain.Page) Sortable(io.gravitee.rest.api.model.common.Sortable) VirtualHost(io.gravitee.definition.model.VirtualHost) Hook(io.gravitee.rest.api.service.notification.Hook) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) VerifyApiParam(io.gravitee.rest.api.management.rest.resource.param.VerifyApiParam) Collections.singletonList(java.util.Collections.singletonList) Inject(javax.inject.Inject) Valid(javax.validation.Valid) ImportSwaggerDescriptorEntity(io.gravitee.rest.api.model.ImportSwaggerDescriptorEntity) WorkflowState(io.gravitee.rest.api.model.WorkflowState) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) RatingSummaryEntity(io.gravitee.rest.api.model.RatingSummaryEntity) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) io.swagger.annotations(io.swagger.annotations) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Lifecycle(io.gravitee.common.component.Lifecycle) OrderParam(io.gravitee.rest.api.management.rest.resource.param.OrderParam) RolePermissionAction(io.gravitee.rest.api.model.permissions.RolePermissionAction) Context(javax.ws.rs.core.Context) ApisParam(io.gravitee.rest.api.management.rest.resource.param.ApisParam) Pageable(io.gravitee.rest.api.management.rest.model.Pageable) NotNull(javax.validation.constraints.NotNull) io.gravitee.rest.api.model.api(io.gravitee.rest.api.model.api) Permission(io.gravitee.rest.api.management.rest.security.Permission) Collectors.toList(java.util.stream.Collectors.toList) MediaType(io.gravitee.common.http.MediaType) FlowService(io.gravitee.rest.api.service.configuration.flow.FlowService) DefinitionVersion(io.gravitee.definition.model.DefinitionVersion) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ResourceContext(javax.ws.rs.container.ResourceContext) ApiAlreadyExistsException(io.gravitee.rest.api.service.exceptions.ApiAlreadyExistsException) Permissions(io.gravitee.rest.api.management.rest.security.Permissions) RolePermission(io.gravitee.rest.api.model.permissions.RolePermission) StringUtils(org.springframework.util.StringUtils) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) 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)

Example 8 with SortableImpl

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();
}
Also used : SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) PromotionEntityStatus(io.gravitee.rest.api.model.promotion.PromotionEntityStatus) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) PromotionQuery(io.gravitee.rest.api.model.promotion.PromotionQuery) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 9 with SortableImpl

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());
}
Also used : TicketsResponse(io.gravitee.rest.api.portal.rest.model.TicketsResponse) Response(javax.ws.rs.core.Response) ArgumentMatchers(org.mockito.ArgumentMatchers) ParameterReferenceType(io.gravitee.rest.api.model.parameters.ParameterReferenceType) Page(io.gravitee.common.data.domain.Page) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Entity(javax.ws.rs.client.Entity) TicketInput(io.gravitee.rest.api.portal.rest.model.TicketInput) Collections.singletonList(java.util.Collections.singletonList) Mockito.verify(org.mockito.Mockito.verify) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) TicketsResponse(io.gravitee.rest.api.portal.rest.model.TicketsResponse) TicketEntity(io.gravitee.rest.api.model.TicketEntity) Mockito(org.mockito.Mockito) Assert.assertNull(org.junit.Assert.assertNull) HttpHeaders(javax.ws.rs.core.HttpHeaders) ArgumentCaptor(org.mockito.ArgumentCaptor) Response(javax.ws.rs.core.Response) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) TicketQuery(io.gravitee.rest.api.model.api.TicketQuery) Assert.assertEquals(org.junit.Assert.assertEquals) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) TicketEntity(io.gravitee.rest.api.model.TicketEntity) TicketsResponse(io.gravitee.rest.api.portal.rest.model.TicketsResponse) TicketQuery(io.gravitee.rest.api.model.api.TicketQuery) Test(org.junit.Test)

Example 10 with SortableImpl

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());
}
Also used : java.util(java.util) PromotionQuery(io.gravitee.rest.api.model.promotion.PromotionQuery) Page(io.gravitee.common.data.domain.Page) LoggerFactory(org.slf4j.LoggerFactory) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) PromotionEntityStatus(io.gravitee.rest.api.model.promotion.PromotionEntityStatus) ApiService(io.gravitee.rest.api.service.ApiService) UPDATE(io.gravitee.rest.api.model.permissions.RolePermissionAction.UPDATE) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) PermissionService(io.gravitee.rest.api.service.PermissionService) AbstractService(io.gravitee.rest.api.service.impl.AbstractService) TaskType(io.gravitee.rest.api.model.TaskType) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) TaskEntity(io.gravitee.rest.api.model.TaskEntity) Logger(org.slf4j.Logger) ENVIRONMENT_API(io.gravitee.rest.api.model.permissions.RolePermission.ENVIRONMENT_API) Collections.emptyList(java.util.Collections.emptyList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EnvironmentService(io.gravitee.rest.api.service.EnvironmentService) PromotionService(io.gravitee.rest.api.service.promotion.PromotionService) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Component(org.springframework.stereotype.Component) CREATE(io.gravitee.rest.api.model.permissions.RolePermissionAction.CREATE) NotNull(org.jetbrains.annotations.NotNull) PromotionTasksService(io.gravitee.rest.api.service.promotion.PromotionTasksService) StringUtils(org.springframework.util.StringUtils) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) Collections.emptyList(java.util.Collections.emptyList) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) PromotionQuery(io.gravitee.rest.api.model.promotion.PromotionQuery) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SortableImpl (io.gravitee.rest.api.model.common.SortableImpl)13 TicketQuery (io.gravitee.rest.api.model.api.TicketQuery)6 Test (org.junit.Test)6 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)5 PageableImpl (io.gravitee.rest.api.model.common.PageableImpl)5 Page (io.gravitee.common.data.domain.Page)4 Sortable (io.gravitee.rest.api.model.common.Sortable)4 TicketEntity (io.gravitee.rest.api.model.TicketEntity)3 Collections.singletonList (java.util.Collections.singletonList)3 Response (javax.ws.rs.core.Response)3 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 Pageable (io.gravitee.repository.management.api.search.Pageable)2 Sortable (io.gravitee.repository.management.api.search.Sortable)2 TicketCriteria (io.gravitee.repository.management.api.search.TicketCriteria)2 Api (io.gravitee.repository.management.model.Api)2 Ticket (io.gravitee.repository.management.model.Ticket)2 PagedResult (io.gravitee.rest.api.management.rest.model.PagedResult)2 OrderParam (io.gravitee.rest.api.management.rest.resource.param.OrderParam)2 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)2 PromotionEntity (io.gravitee.rest.api.model.promotion.PromotionEntity)2