Skip to content

Commit

Permalink
feat(console): get integrations list and create integrations with stu…
Browse files Browse the repository at this point in the history
…b response provided
  • Loading branch information
JedrzejJanasiak committed Mar 18, 2024
1 parent d164b83 commit e774d2d
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 0 deletions.
Expand Up @@ -35,6 +35,7 @@
import io.gravitee.rest.api.management.v2.rest.resource.installation.EnvironmentsResource;
import io.gravitee.rest.api.management.v2.rest.resource.installation.GraviteeLicenseResource;
import io.gravitee.rest.api.management.v2.rest.resource.installation.OrganizationResource;
import io.gravitee.rest.api.management.v2.rest.resource.integration.IntegrationsResource;
import io.gravitee.rest.api.management.v2.rest.resource.plugin.ApiServicesResource;
import io.gravitee.rest.api.management.v2.rest.resource.plugin.EndpointsResource;
import io.gravitee.rest.api.management.v2.rest.resource.plugin.EntrypointsResource;
Expand Down Expand Up @@ -71,6 +72,7 @@ public GraviteeManagementV2Application() {
register(EntrypointsResource.class);
register(ApiServicesResource.class);
register(PoliciesResource.class);
register(IntegrationsResource.class);

register(MultiPartFeature.class);

Expand Down
@@ -0,0 +1,75 @@
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.rest.api.management.v2.rest.resource.integration;

import io.gravitee.common.data.domain.Page;
import io.gravitee.common.http.MediaType;
import io.gravitee.rest.api.management.v2.rest.model.*;
import io.gravitee.rest.api.management.v2.rest.pagination.PaginationInfo;
import io.gravitee.rest.api.management.v2.rest.resource.AbstractResource;
import io.gravitee.rest.api.management.v2.rest.resource.param.PaginationParam;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.*;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;

/**
* @author Remi Baptiste (remi.baptiste at graviteesource.com)
* @author GraviteeSource Team
*/
@Path("/environments/{envId}/integrations")
@Slf4j
public class IntegrationsResource extends AbstractResource {

private static final List<Integration> integrationsMock = new ArrayList<>();

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response createIntegration(@Valid @NotNull final CreateIntegration integration) {
Integration mockIntegration = Integration
.builder()
.id(UUID.randomUUID().toString())
.name(integration.getName())
.description(integration.getDescription())
.provider(integration.getProvider())
.build();
integrationsMock.add(mockIntegration);
return Response.created(this.getLocationHeader(mockIntegration.getId())).entity(mockIntegration).build();
}

@GET
@Produces(MediaType.APPLICATION_JSON)
public IntegrationsResponse listIntegrations(
@PathParam("envId") String environmentId,
@BeanParam @Valid PaginationParam paginationParam
) {
Page<Integration> integrationPage = new Page<>(integrationsMock, 0, integrationsMock.size(), integrationsMock.size());

long totalCount = integrationPage.getTotalElements();
Integer pageItemsCount = Math.toIntExact(integrationPage.getPageElements());

return new IntegrationsResponse()
.data(integrationsMock)
.pagination(PaginationInfo.computePaginationInfo(totalCount, pageItemsCount, paginationParam))
.links(computePaginationLinks(totalCount, paginationParam));
}
}
Expand Up @@ -56,6 +56,8 @@ tags:
description: Everything about API subscriptions
- name: Groups
description: Everything about groups
- name: Integration
description: Everything about integration

paths:
# APIs
Expand Down Expand Up @@ -1031,6 +1033,53 @@ paths:
default:
$ref: "#/components/responses/Error"

# Integration
/environments/{envId}/integrations:
parameters:
- $ref: "#/components/parameters/envIdParam"
get:
parameters:
- $ref: "#/components/parameters/pageParam"
- $ref: "#/components/parameters/perPageParam"
tags:
- Integration
summary: List Integrations
description: |-
Get the list of Integration for a specific environment.<br>
The results are paginated.
User must have the ENVIRONMENT_INTEGRATION[READ] permission.
operationId: listIntegrations
responses:
"200":
$ref: "#/components/responses/IntegrationsResponse"
default:
$ref: "#/components/responses/Error"
post:
tags:
- Integration
summary: Create an Integration
description: |-
Create a new Integration.
User must have the ENVIRONMENT_INTEGRATION[CREATE] permission.
operationId: createIntegration
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/CreateIntegration"
required: true
responses:
"201":
description: Integration successfully created
content:
application/json:
schema:
$ref: "#/components/schemas/Integration"
default:
$ref: "#/components/responses/Error"

# API Subscriptions
/environments/{envId}/apis/{apiId}/subscribers:
parameters:
Expand Down Expand Up @@ -2958,6 +3007,21 @@ components:
items:
$ref: "#/components/schemas/HttpMethod"
uniqueItems: true
Integration:
type: object
properties:
id:
type: string
description: Id of the integration
name:
type: string
description: Name of the integration
description:
type: string
description: Description of the integration
provider:
type: string
description: Provider of this integration
Links:
description: List of links for pagination
properties:
Expand Down Expand Up @@ -5776,6 +5840,19 @@ components:
additionalProperties:
type: object

CreateIntegration:
type: object
properties:
name:
type: string
description: Name of the integration
description:
type: string
description: Description of the integration
provider:
type: string
description: Provider of this integration

parameters:
#############
# PathParam #
Expand Down Expand Up @@ -5873,6 +5950,13 @@ components:
description: Id of a policy.
schema:
type: string
integrationIdParam:
name: integrationId
in: path
required: true
description: Id of an integration.
schema:
type: string
###############################
# Pagination Query Parameters #
###############################
Expand Down Expand Up @@ -6105,6 +6189,22 @@ components:
links:
$ref: "#/components/schemas/Links"

IntegrationsResponse:
description: Page of integrations
content:
application/json:
schema:
title: "IntegrationsResponse"
properties:
data:
description: List of Integrations.
type: array
items:
$ref: "#/components/schemas/Integration"
pagination:
$ref: "#/components/schemas/Pagination"
links:
$ref: "#/components/schemas/Links"
PlansResponse:
description: Page of API plans
content:
Expand Down

0 comments on commit e774d2d

Please sign in to comment.