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