Search in sources :

Example 61 with ApiEntity

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

the class ApiDuplicatorServiceImpl method createWithImportedDefinition.

@Override
public ApiEntity createWithImportedDefinition(String apiDefinitionOrURL, String userId, String organizationId, String environmentId) {
    String apiDefinition = fetchApiDefinitionContentFromURL(apiDefinitionOrURL);
    try {
        // Read the whole definition
        final JsonNode jsonNode = objectMapper.readTree(apiDefinition);
        UpdateApiEntity importedApi = convertToEntity(apiDefinition, jsonNode);
        ApiEntity createdApiEntity = apiService.createWithApiDefinition(importedApi, userId, jsonNode);
        createPageAndMedia(createdApiEntity, jsonNode, environmentId);
        updateApiReferences(createdApiEntity, jsonNode, organizationId, environmentId, false);
        return createdApiEntity;
    } catch (JsonProcessingException e) {
        LOGGER.error("An error occurs while trying to JSON deserialize the API {}", apiDefinition, e);
        throw new TechnicalManagementException("An error occurs while trying to JSON deserialize the API definition.");
    }
}
Also used : UpdateApiEntity(io.gravitee.rest.api.model.api.UpdateApiEntity) UpdateApiEntity(io.gravitee.rest.api.model.api.UpdateApiEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) DuplicateApiEntity(io.gravitee.rest.api.model.api.DuplicateApiEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) UuidString(io.gravitee.rest.api.service.common.UuidString) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 62 with ApiEntity

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

the class ApiDuplicatorServiceImpl method exportAsJson.

@Override
public String exportAsJson(final String apiId, String exportVersion, String... filteredFields) {
    ApiEntity apiEntity = apiService.findById(apiId);
    // set metadata for serialize process
    Map<String, Object> metadata = new HashMap<>();
    metadata.put(ApiSerializer.METADATA_EXPORT_VERSION, exportVersion);
    metadata.put(ApiSerializer.METADATA_FILTERED_FIELDS_LIST, Arrays.asList(filteredFields));
    apiEntity.setMetadata(metadata);
    try {
        return objectMapper.writeValueAsString(apiEntity);
    } catch (final Exception e) {
        LOGGER.error("An error occurs while trying to JSON serialize the API {}", apiEntity, e);
    }
    return "";
}
Also used : UpdateApiEntity(io.gravitee.rest.api.model.api.UpdateApiEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) DuplicateApiEntity(io.gravitee.rest.api.model.api.DuplicateApiEntity) UuidString(io.gravitee.rest.api.service.common.UuidString) UserNotFoundException(io.gravitee.rest.api.service.exceptions.UserNotFoundException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 63 with ApiEntity

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

the class ApiDuplicatorServiceImpl method updateWithImportedDefinition.

@Override
public ApiEntity updateWithImportedDefinition(String apiId, String apiDefinitionOrURL, String userId, String organizationId, String environmentId) {
    String apiDefinition = fetchApiDefinitionContentFromURL(apiDefinitionOrURL);
    try {
        // Read the whole definition
        final JsonNode jsonNode = objectMapper.readTree(apiDefinition);
        UpdateApiEntity importedApi = convertToEntity(apiDefinition, jsonNode);
        ApiEntity updatedApiEntity = apiService.update(apiId, importedApi, false);
        updateApiReferences(updatedApiEntity, jsonNode, organizationId, environmentId, true);
        return updatedApiEntity;
    } catch (JsonProcessingException e) {
        LOGGER.error("An error occurs while trying to JSON deserialize the API {}", apiDefinition, e);
        throw new TechnicalManagementException("An error occurs while trying to JSON deserialize the API definition.");
    }
}
Also used : UpdateApiEntity(io.gravitee.rest.api.model.api.UpdateApiEntity) UpdateApiEntity(io.gravitee.rest.api.model.api.UpdateApiEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) DuplicateApiEntity(io.gravitee.rest.api.model.api.DuplicateApiEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) UuidString(io.gravitee.rest.api.service.common.UuidString) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 64 with ApiEntity

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

the class AnalyticsServiceImpl method getAPIMetadata.

private Map<String, String> getAPIMetadata(String api) {
    Map<String, String> metadata = new HashMap<>();
    try {
        if (api.equals(UNKNOWN_SERVICE) || api.equals(UNKNOWN_SERVICE_MAPPED)) {
            metadata.put(METADATA_NAME, METADATA_UNKNOWN_API_NAME);
            metadata.put(METADATA_UNKNOWN, Boolean.TRUE.toString());
        } else {
            ApiEntity apiEntity = apiService.findById(api);
            metadata.put(METADATA_NAME, apiEntity.getName());
            metadata.put(METADATA_VERSION, apiEntity.getVersion());
            if (ApiLifecycleState.ARCHIVED.equals(apiEntity.getLifecycleState())) {
                metadata.put(METADATA_DELETED, Boolean.TRUE.toString());
            }
        }
    } catch (ApiNotFoundException anfe) {
        metadata.put(METADATA_DELETED, Boolean.TRUE.toString());
        metadata.put(METADATA_NAME, METADATA_DELETED_API_NAME);
    }
    return metadata;
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity)

Example 65 with ApiEntity

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

the class HealthCheckServiceImpl method getAvailability.

@Override
public ApiMetrics getAvailability(String api, String field) {
    logger.debug("Run health availability query for API '{}'", api);
    try {
        ApiEntity apiEntity = apiService.findById(api);
        AvailabilityResponse response = healthCheckRepository.query(QueryBuilders.availability().api(api).field(AvailabilityQuery.Field.valueOf(field)).build());
        return convert(apiEntity, response.getEndpointAvailabilities(), field);
    } catch (Exception ex) {
        logger.error("An unexpected error occurs while searching for health data.", ex);
        return null;
    }
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) AvailabilityResponse(io.gravitee.repository.healthcheck.query.availability.AvailabilityResponse) InstanceNotFoundException(io.gravitee.rest.api.service.exceptions.InstanceNotFoundException) AnalyticsException(io.gravitee.repository.analytics.AnalyticsException) AnalyticsCalculateException(io.gravitee.rest.api.service.exceptions.AnalyticsCalculateException)

Aggregations

ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)273 Test (org.junit.Test)180 Response (javax.ws.rs.core.Response)65 Before (org.junit.Before)46 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)35 Error (io.gravitee.rest.api.portal.rest.model.Error)32 java.util (java.util)30 Collectors (java.util.stream.Collectors)27 Mockito.doReturn (org.mockito.Mockito.doReturn)27 Mockito (org.mockito.Mockito)25 ArgumentMatchers (org.mockito.ArgumentMatchers)24 UpdateApiEntity (io.gravitee.rest.api.model.api.UpdateApiEntity)23 Assert (org.junit.Assert)22 Collections.singletonList (java.util.Collections.singletonList)21 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)20 IOException (java.io.IOException)20 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)19 Entity (javax.ws.rs.client.Entity)19 HashSet (java.util.HashSet)18 Api (io.gravitee.repository.management.model.Api)17