Search in sources :

Example 1 with PagedResult

use of io.gravitee.rest.api.management.rest.model.PagedResult 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)

Example 2 with PagedResult

use of io.gravitee.rest.api.management.rest.model.PagedResult in project gravitee-management-rest-api by gravitee-io.

the class ApiSubscriptionsResource method getApiSubscriptions.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List subscriptions for the API", notes = "User must have the READ_SUBSCRIPTION permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Paged result of API's subscriptions", response = PagedResult.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_SUBSCRIPTION, acls = RolePermissionAction.READ) })
public PagedResult<SubscriptionEntity> getApiSubscriptions(@BeanParam SubscriptionParam subscriptionParam, @Valid @BeanParam Pageable pageable, @ApiParam(allowableValues = "keys", value = "Expansion of data to return in subscriptions") @QueryParam("expand") List<String> expand) {
    // Transform query parameters to a subscription query
    SubscriptionQuery subscriptionQuery = subscriptionParam.toQuery();
    subscriptionQuery.setApi(api);
    Page<SubscriptionEntity> subscriptions = subscriptionService.search(subscriptionQuery, pageable.toPageable());
    if (expand != null && !expand.isEmpty()) {
        for (String e : expand) {
            switch(e) {
                case "keys":
                    subscriptions.getContent().forEach(subscriptionEntity -> {
                        final List<String> keys = apiKeyService.findBySubscription(subscriptionEntity.getId()).stream().filter(apiKeyEntity -> !apiKeyEntity.isExpired() && !apiKeyEntity.isRevoked()).map(ApiKeyEntity::getKey).collect(Collectors.toList());
                        subscriptionEntity.setKeys(keys);
                    });
                    break;
                default:
                    break;
            }
        }
    }
    PagedResult<SubscriptionEntity> result = new PagedResult<>(subscriptions, pageable.getSize());
    result.setMetadata(subscriptionService.getMetadata(subscriptions.getContent()).getMetadata());
    return result;
}
Also used : SubscriptionQuery(io.gravitee.rest.api.model.subscription.SubscriptionQuery) PagedResult(io.gravitee.rest.api.management.rest.model.PagedResult) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 3 with PagedResult

use of io.gravitee.rest.api.management.rest.model.PagedResult 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 4 with PagedResult

use of io.gravitee.rest.api.management.rest.model.PagedResult in project gravitee-management-rest-api by gravitee-io.

the class ApplicationSubscriptionsResource method getApplicationSubscriptions.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List subscriptions for the application", notes = "User must have the READ_SUBSCRIPTION permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Paged result of application's subscriptions", response = PagedResult.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_SUBSCRIPTION, acls = RolePermissionAction.READ) })
public PagedResult<SubscriptionEntity> getApplicationSubscriptions(@BeanParam SubscriptionParam subscriptionParam, @Valid @BeanParam Pageable pageable, @ApiParam(allowableValues = "keys", value = "Expansion of data to return in subscriptions") @QueryParam("expand") List<String> expand) {
    // Transform query parameters to a subscription query
    SubscriptionQuery subscriptionQuery = subscriptionParam.toQuery();
    subscriptionQuery.setApplication(application);
    Page<SubscriptionEntity> subscriptions = subscriptionService.search(subscriptionQuery, pageable.toPageable());
    if (expand != null && !expand.isEmpty()) {
        for (String e : expand) {
            switch(e) {
                case "keys":
                    subscriptions.getContent().forEach(subscriptionEntity -> {
                        final List<String> keys = apiKeyService.findBySubscription(subscriptionEntity.getId()).stream().filter(apiKeyEntity -> !apiKeyEntity.isExpired() && !apiKeyEntity.isRevoked()).map(ApiKeyEntity::getKey).collect(Collectors.toList());
                        subscriptionEntity.setKeys(keys);
                    });
                    break;
                default:
                    break;
            }
        }
    }
    PagedResult<SubscriptionEntity> result = new PagedResult<>(subscriptions, pageable.getSize());
    result.setMetadata(subscriptionService.getMetadata(subscriptions.getContent()).getMetadata());
    return result;
}
Also used : NewSubscriptionEntity(io.gravitee.rest.api.model.NewSubscriptionEntity) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) SubscriptionQuery(io.gravitee.rest.api.model.subscription.SubscriptionQuery) PagedResult(io.gravitee.rest.api.management.rest.model.PagedResult) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Aggregations

PagedResult (io.gravitee.rest.api.management.rest.model.PagedResult)4 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)3 OrderParam (io.gravitee.rest.api.management.rest.resource.param.OrderParam)2 io.gravitee.rest.api.model.api (io.gravitee.rest.api.model.api)2 Sortable (io.gravitee.rest.api.model.common.Sortable)2 SortableImpl (io.gravitee.rest.api.model.common.SortableImpl)2 SubscriptionQuery (io.gravitee.rest.api.model.subscription.SubscriptionQuery)2 Lifecycle (io.gravitee.common.component.Lifecycle)1 Page (io.gravitee.common.data.domain.Page)1 MediaType (io.gravitee.common.http.MediaType)1 DefinitionVersion (io.gravitee.definition.model.DefinitionVersion)1 VirtualHost (io.gravitee.definition.model.VirtualHost)1 Pageable (io.gravitee.rest.api.management.rest.model.Pageable)1 ApisParam (io.gravitee.rest.api.management.rest.resource.param.ApisParam)1 VerifyApiParam (io.gravitee.rest.api.management.rest.resource.param.VerifyApiParam)1 Permission (io.gravitee.rest.api.management.rest.security.Permission)1 ImportSwaggerDescriptorEntity (io.gravitee.rest.api.model.ImportSwaggerDescriptorEntity)1 NewSubscriptionEntity (io.gravitee.rest.api.model.NewSubscriptionEntity)1 RatingSummaryEntity (io.gravitee.rest.api.model.RatingSummaryEntity)1 SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)1