Search in sources :

Example 1 with NewApiMetadataEntity

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

the class ApiMetadataResource method createApiMetadata.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create an API metadata", notes = "User must have the API_METADATA[CREATE] permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "A new API metadata", response = ApiMetadataEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_METADATA, acls = RolePermissionAction.CREATE) })
public Response createApiMetadata(@Valid @NotNull final NewApiMetadataEntity metadata) {
    // prevent creation of a metadata on an another API
    metadata.setApiId(api);
    final ApiMetadataEntity apiMetadataEntity = metadataService.create(metadata);
    ApiEntity apiEntity = apiService.fetchMetadataForApi(apiService.findById(api));
    searchEngineService.index(apiEntity, false);
    return Response.created(this.getLocationHeader(apiMetadataEntity.getKey())).entity(apiMetadataEntity).build();
}
Also used : NewApiMetadataEntity(io.gravitee.rest.api.model.NewApiMetadataEntity) UpdateApiMetadataEntity(io.gravitee.rest.api.model.UpdateApiMetadataEntity) ApiMetadataEntity(io.gravitee.rest.api.model.ApiMetadataEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 2 with NewApiMetadataEntity

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

the class ApiMetadataResourceTest method shouldCreateMetadata.

@Test
public void shouldCreateMetadata() {
    NewApiMetadataEntity newMetadata = new NewApiMetadataEntity();
    newMetadata.setName("my-metadata-name");
    ApiMetadataEntity createdMetadata = new ApiMetadataEntity();
    createdMetadata.setKey("my-metadata-id");
    when(apiMetadataService.create(any())).thenReturn(createdMetadata);
    final Response response = envTarget().path(API).path("metadata").request().post(Entity.json(newMetadata));
    assertEquals(CREATED_201, response.getStatus());
    assertEquals(envTarget().path(API).path("metadata").path("my-metadata-id").getUri().toString(), response.getHeaders().getFirst(HttpHeaders.LOCATION));
    verify(searchEngineService, times(1)).index(any(), eq(false));
}
Also used : NewApiMetadataEntity(io.gravitee.rest.api.model.NewApiMetadataEntity) Response(javax.ws.rs.core.Response) NewApiMetadataEntity(io.gravitee.rest.api.model.NewApiMetadataEntity) ApiMetadataEntity(io.gravitee.rest.api.model.ApiMetadataEntity) Test(org.junit.Test)

Aggregations

ApiMetadataEntity (io.gravitee.rest.api.model.ApiMetadataEntity)2 NewApiMetadataEntity (io.gravitee.rest.api.model.NewApiMetadataEntity)2 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)1 UpdateApiMetadataEntity (io.gravitee.rest.api.model.UpdateApiMetadataEntity)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1