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.");
}
}
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 "";
}
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.");
}
}
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;
}
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;
}
}
Aggregations