Search in sources :

Example 86 with ApiEntity

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

the class TicketServiceImpl method getApiNameAndApplicationName.

private Ticket getApiNameAndApplicationName(Ticket ticket) {
    // Retrieve application name
    if (StringUtils.isNotEmpty(ticket.getApplication())) {
        ApplicationEntity application = applicationService.findById(ticket.getApplication());
        ticket.setApplication(application.getName());
    }
    // Retrieve api name
    if (StringUtils.isNotEmpty(ticket.getApi())) {
        ApiEntity api = apiService.findById(ticket.getApi());
        ticket.setApi(api.getName());
    }
    return ticket;
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity)

Example 87 with ApiEntity

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

the class VirtualHostServiceImpl method convert.

private ApiEntity convert(Api api) {
    ApiEntity apiEntity = new ApiEntity();
    apiEntity.setId(api.getId());
    if (api.getDefinition() != null) {
        try {
            io.gravitee.definition.model.Api apiDefinition = objectMapper.readValue(api.getDefinition(), io.gravitee.definition.model.Api.class);
            apiEntity.setProxy(apiDefinition.getProxy());
            // Sanitize virtual hosts
            apiEntity.getProxy().setVirtualHosts(apiEntity.getProxy().getVirtualHosts().stream().map(this::sanitize).collect(Collectors.toList()));
        } catch (IOException ioe) {
            LOGGER.error("Unexpected error while getting API definition", ioe);
        }
    }
    return apiEntity;
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) IOException(java.io.IOException)

Example 88 with ApiEntity

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

the class SubscriptionServiceImpl method getMetadata.

@Override
public Metadata getMetadata(List<SubscriptionEntity> subscriptions) {
    Metadata metadata = new Metadata();
    subscriptions.forEach(subscription -> {
        if (!metadata.containsKey(subscription.getApplication())) {
            ApplicationEntity applicationEntity = applicationService.findById(subscription.getApplication());
            metadata.put(subscription.getApplication(), "name", applicationEntity.getName());
        }
        if (!metadata.containsKey(subscription.getPlan())) {
            PlanEntity planEntity = planService.findById(subscription.getPlan());
            metadata.put(subscription.getPlan(), "name", planEntity.getName());
        }
        if (!metadata.containsKey(subscription.getApi())) {
            ApiEntity api = apiService.findById(subscription.getApi());
            metadata.put(subscription.getApi(), "name", api.getName());
        }
    });
    return metadata;
}
Also used : Metadata(io.gravitee.rest.api.model.pagedresult.Metadata) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity)

Example 89 with ApiEntity

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

the class ScheduledSubscriptionPreExpirationNotificationService method notifySubscription.

private SubscriptionEntity notifySubscription(Integer daysToExpiration, SubscriptionEntity subscription) {
    ApiEntity api = apiService.findById(subscription.getApi());
    PlanEntity plan = planService.findById(subscription.getPlan());
    ApplicationEntity application = applicationService.findById(subscription.getApplication());
    findEmailsToNotify(subscription, application).forEach(email -> this.sendEmail(email, daysToExpiration, api, plan, application, null));
    return subscriptionService.updateDaysToExpirationOnLastNotification(subscription.getId(), daysToExpiration);
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity)

Example 90 with ApiEntity

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

the class ScheduledSubscriptionPreExpirationNotificationService method notificationApiKeyExpiration.

private ApiKeyEntity notificationApiKeyExpiration(Integer daysToExpiration, ApiKeyEntity apiKey) {
    SubscriptionEntity subscription = subscriptionService.findById(apiKey.getSubscription());
    ApiEntity api = apiService.findById(subscription.getApi());
    PlanEntity plan = planService.findById(subscription.getPlan());
    ApplicationEntity application = applicationService.findById(subscription.getApplication());
    findEmailsToNotify(subscription, application).forEach(email -> this.sendEmail(email, daysToExpiration, api, plan, application, apiKey));
    return apiKeyService.updateDaysToExpirationOnLastNotification(apiKey.getKey(), daysToExpiration);
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity)

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