Search in sources :

Example 1 with ApiInformation

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

the class ApiInformationsResource method getApiInformations.

@GET
@Produces({ MediaType.APPLICATION_JSON })
@RequirePortalAuth
public Response getApiInformations(@Context Request request, @PathParam("apiId") String apiId) {
    final ApiQuery apiQuery = new ApiQuery();
    apiQuery.setIds(Collections.singletonList(apiId));
    Collection<ApiEntity> userApis = apiService.findPublishedByUser(getAuthenticatedUserOrNull(), apiQuery);
    if (userApis.stream().anyMatch(a -> a.getId().equals(apiId))) {
        List<ApiHeaderEntity> all = apiService.getPortalHeaders(apiId);
        List<ApiInformation> information = all.stream().map(apiHeaderEntity -> {
            ApiInformation ai = new ApiInformation();
            ai.setName(apiHeaderEntity.getName());
            ai.setValue(apiHeaderEntity.getValue());
            return ai;
        }).collect(Collectors.toList());
        return Response.ok(information).build();
    }
    throw new ApiNotFoundException(apiId);
}
Also used : ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) PathParam(javax.ws.rs.PathParam) Context(javax.ws.rs.core.Context) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Collection(java.util.Collection) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) RequirePortalAuth(io.gravitee.rest.api.portal.rest.security.RequirePortalAuth) Collectors(java.util.stream.Collectors) ApiService(io.gravitee.rest.api.service.ApiService) Inject(javax.inject.Inject) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) ApiInformation(io.gravitee.rest.api.portal.rest.model.ApiInformation) Response(javax.ws.rs.core.Response) Request(javax.ws.rs.core.Request) ApiHeaderEntity(io.gravitee.rest.api.model.api.header.ApiHeaderEntity) Collections(java.util.Collections) ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) ApiHeaderEntity(io.gravitee.rest.api.model.api.header.ApiHeaderEntity) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) ApiInformation(io.gravitee.rest.api.portal.rest.model.ApiInformation) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RequirePortalAuth(io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)

Aggregations

MediaType (io.gravitee.common.http.MediaType)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)1 ApiHeaderEntity (io.gravitee.rest.api.model.api.header.ApiHeaderEntity)1 ApiInformation (io.gravitee.rest.api.portal.rest.model.ApiInformation)1 RequirePortalAuth (io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)1 ApiService (io.gravitee.rest.api.service.ApiService)1 ApiNotFoundException (io.gravitee.rest.api.service.exceptions.ApiNotFoundException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 GET (javax.ws.rs.GET)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1 Context (javax.ws.rs.core.Context)1 Request (javax.ws.rs.core.Request)1 Response (javax.ws.rs.core.Response)1