Search in sources :

Example 36 with ApiEntity

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

the class PlatformAnalyticsResource method platformAnalytics.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = MANAGEMENT_PLATFORM, acls = READ) })
public Response platformAnalytics(@BeanParam AnalyticsParam analyticsParam) {
    analyticsParam.validate();
    Analytics analytics = null;
    // add filter by Apis or Applications
    String extraFilter = null;
    if (!isAdmin()) {
        if ("api".equals(analyticsParam.getField())) {
            extraFilter = getExtraFilter(analyticsParam.getField(), apiService.findByUser(getAuthenticatedUser()).stream().filter(api -> permissionService.hasPermission(API_ANALYTICS, api.getId(), READ)).map(ApiEntity::getId).collect(Collectors.toList()));
        } else if ("application".equals(analyticsParam.getField())) {
            extraFilter = getExtraFilter(analyticsParam.getField(), applicationService.findByUser(getAuthenticatedUser()).stream().filter(app -> permissionService.hasPermission(APPLICATION_ANALYTICS, app.getId(), READ)).map(ApplicationEntity::getId).collect(Collectors.toList()));
        }
    }
    switch(analyticsParam.getTypeParam().getValue()) {
        case DATE_HISTO:
            analytics = executeDateHisto(analyticsParam, extraFilter);
            break;
        case GROUP_BY:
            analytics = executeGroupBy(analyticsParam, extraFilter);
            break;
        case COUNT:
            analytics = executeCount(analyticsParam, extraFilter);
            break;
    }
    return Response.ok(analytics).build();
}
Also used : Analytics(io.gravitee.management.model.analytics.Analytics) io.gravitee.management.model.analytics.query(io.gravitee.management.model.analytics.query) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiEntity(io.gravitee.management.model.ApiEntity) ApiService(io.gravitee.management.service.ApiService) RolePermission(io.gravitee.management.model.permissions.RolePermission) Aggregation(io.gravitee.management.rest.resource.param.Aggregation) AnalyticsService(io.gravitee.management.service.AnalyticsService) ApplicationEntity(io.gravitee.management.model.ApplicationEntity) Function(java.util.function.Function) Inject(javax.inject.Inject) Map(java.util.Map) Api(io.swagger.annotations.Api) Permission(io.gravitee.management.rest.security.Permission) AnalyticsParam(io.gravitee.management.rest.resource.param.AnalyticsParam) RolePermissionAction(io.gravitee.management.model.permissions.RolePermissionAction) API_ANALYTICS(io.gravitee.management.model.permissions.RolePermission.API_ANALYTICS) MANAGEMENT_PLATFORM(io.gravitee.management.model.permissions.RolePermission.MANAGEMENT_PLATFORM) Range(io.gravitee.management.rest.resource.param.Range) Permissions(io.gravitee.management.rest.security.Permissions) PermissionService(io.gravitee.management.service.PermissionService) Collectors(java.util.stream.Collectors) ApplicationService(io.gravitee.management.service.ApplicationService) BeanParam(javax.ws.rs.BeanParam) READ(io.gravitee.management.model.permissions.RolePermissionAction.READ) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) Response(javax.ws.rs.core.Response) APPLICATION_ANALYTICS(io.gravitee.management.model.permissions.RolePermission.APPLICATION_ANALYTICS) ApplicationEntity(io.gravitee.management.model.ApplicationEntity) Analytics(io.gravitee.management.model.analytics.Analytics) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Permissions(io.gravitee.management.rest.security.Permissions)

Example 37 with ApiEntity

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

the class TopApiServiceTest method shouldDelete.

@Test
public void shouldDelete() {
    final ApiEntity api1 = new ApiEntity();
    api1.setId("1");
    api1.setName("name");
    api1.setVersion("version");
    api1.setDescription("description");
    final ApiEntity api2 = new ApiEntity();
    api2.setId("2");
    when(parameterService.findAll(eq(PORTAL_TOP_APIS.getKey()), any(), any())).thenReturn(asList(api1, api2));
    topApiService.delete("1");
    verify(parameterService).updateMultipleValue(PORTAL_TOP_APIS.getKey(), singletonList("2"));
}
Also used : ApiEntity(io.gravitee.management.model.ApiEntity) TopApiEntity(io.gravitee.management.model.TopApiEntity) UpdateTopApiEntity(io.gravitee.management.model.UpdateTopApiEntity) NewTopApiEntity(io.gravitee.management.model.NewTopApiEntity) Test(org.junit.Test)

Example 38 with ApiEntity

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

the class TopApiServiceTest method shouldFindAll.

@Test
public void shouldFindAll() {
    final ApiEntity api1 = new ApiEntity();
    api1.setId("1");
    api1.setName("name");
    api1.setVersion("version");
    api1.setDescription("description");
    final ApiEntity api2 = new ApiEntity();
    api2.setId("2");
    when(parameterService.findAll(eq(PORTAL_TOP_APIS.getKey()), any(), any())).thenReturn(asList(api1, api2, api1));
    final List<TopApiEntity> topApis = topApiService.findAll();
    assertEquals("1", topApis.get(0).getApi());
    assertEquals("name", topApis.get(0).getName());
    assertEquals("version", topApis.get(0).getVersion());
    assertEquals("description", topApis.get(0).getDescription());
    assertEquals(0, topApis.get(0).getOrder());
    assertEquals("2", topApis.get(1).getApi());
    assertEquals(1, topApis.get(1).getOrder());
    assertEquals("1", topApis.get(2).getApi());
    assertEquals(2, topApis.get(2).getOrder());
}
Also used : TopApiEntity(io.gravitee.management.model.TopApiEntity) UpdateTopApiEntity(io.gravitee.management.model.UpdateTopApiEntity) NewTopApiEntity(io.gravitee.management.model.NewTopApiEntity) ApiEntity(io.gravitee.management.model.ApiEntity) TopApiEntity(io.gravitee.management.model.TopApiEntity) UpdateTopApiEntity(io.gravitee.management.model.UpdateTopApiEntity) NewTopApiEntity(io.gravitee.management.model.NewTopApiEntity) Test(org.junit.Test)

Example 39 with ApiEntity

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

the class ScheduledSubscriptionsService method run.

@Override
public void run() {
    logger.debug("Refresh subscriptions #{} started at {}", counter.incrementAndGet(), Instant.now().toString());
    Date now = new Date();
    Set<ApiEntity> apis = apiService.findAll();
    for (ApiEntity api : apis) {
        // TODO: this service must be optimized by providing a better way to search for subscription
        // Something like the Event Repository API
        SubscriptionQuery query = new SubscriptionQuery();
        query.setApi(api.getId());
        query.setStatuses(Collections.singleton(SubscriptionStatus.ACCEPTED));
        Collection<SubscriptionEntity> subscriptions = subscriptionService.search(query);
        subscriptions.forEach(subscription -> {
            if (subscription.getEndingAt() != null && subscription.getEndingAt().before(now)) {
                subscriptionService.close(subscription.getId());
            }
        });
    }
    logger.debug("Refresh subscriptions #{} ended at {}", counter.get(), Instant.now().toString());
}
Also used : ApiEntity(io.gravitee.management.model.ApiEntity) SubscriptionEntity(io.gravitee.management.model.SubscriptionEntity) SubscriptionQuery(io.gravitee.management.model.subscription.SubscriptionQuery) Date(java.util.Date)

Example 40 with ApiEntity

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

the class SyncManager method convert.

private ApiEntity convert(Api api) {
    ApiEntity apiEntity = new ApiEntity();
    apiEntity.setId(api.getId());
    apiEntity.setName(api.getName());
    apiEntity.setDeployedAt(api.getDeployedAt());
    apiEntity.setCreatedAt(api.getCreatedAt());
    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());
            apiEntity.setPaths(apiDefinition.getPaths());
            apiEntity.setServices(apiDefinition.getServices());
            apiEntity.setResources(apiDefinition.getResources());
            apiEntity.setProperties(apiDefinition.getProperties());
            apiEntity.setTags(apiDefinition.getTags());
        } catch (IOException ioe) {
            logger.error("Unexpected error while generating API definition", ioe);
        }
    }
    apiEntity.setUpdatedAt(api.getUpdatedAt());
    apiEntity.setVersion(api.getVersion());
    apiEntity.setDescription(api.getDescription());
    apiEntity.setPicture(api.getPicture());
    apiEntity.setViews(api.getViews());
    final LifecycleState lifecycleState = api.getLifecycleState();
    if (lifecycleState != null) {
        apiEntity.setState(Lifecycle.State.valueOf(lifecycleState.name()));
    }
    if (api.getVisibility() != null) {
        apiEntity.setVisibility(io.gravitee.management.model.Visibility.valueOf(api.getVisibility().toString()));
    }
    return apiEntity;
}
Also used : ApiEntity(io.gravitee.management.model.ApiEntity) LifecycleState(io.gravitee.repository.management.model.LifecycleState) IOException(java.io.IOException)

Aggregations

ApiEntity (io.gravitee.management.model.ApiEntity)50 Test (org.junit.Test)34 Response (javax.ws.rs.core.Response)19 UpdateApiEntity (io.gravitee.management.model.UpdateApiEntity)13 PageEntity (io.gravitee.management.model.PageEntity)5 NewApiEntity (io.gravitee.management.model.NewApiEntity)4 NewTopApiEntity (io.gravitee.management.model.NewTopApiEntity)3 TopApiEntity (io.gravitee.management.model.TopApiEntity)3 UpdateTopApiEntity (io.gravitee.management.model.UpdateTopApiEntity)3 Permission (io.gravitee.management.rest.security.Permission)3 HashMap (java.util.HashMap)3 Collectors (java.util.stream.Collectors)3 Proxy (io.gravitee.definition.model.Proxy)2 ApplicationEntity (io.gravitee.management.model.ApplicationEntity)2 MemberEntity (io.gravitee.management.model.MemberEntity)2 SubscriptionEntity (io.gravitee.management.model.SubscriptionEntity)2 UserEntity (io.gravitee.management.model.UserEntity)2 RolePermission (io.gravitee.management.model.permissions.RolePermission)2 RolePermissionAction (io.gravitee.management.model.permissions.RolePermissionAction)2 SubscriptionQuery (io.gravitee.management.model.subscription.SubscriptionQuery)2