use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPagesResource method getApiPages.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List pages", notes = "User must have the READ permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "List of pages", response = PageEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
public List<PageEntity> getApiPages(@HeaderParam("Accept-Language") String acceptLang, @QueryParam("homepage") Boolean homepage, @QueryParam("type") PageType type, @QueryParam("parent") String parent, @QueryParam("name") String name, @QueryParam("root") Boolean rootParent, @QueryParam("translated") boolean translated) {
final String acceptedLocale = HttpHeadersUtil.getFirstAcceptedLocaleName(acceptLang);
final ApiEntity apiEntity = apiService.findById(api);
if (Visibility.PUBLIC.equals(apiEntity.getVisibility()) || hasPermission(RolePermission.API_DOCUMENTATION, api, RolePermissionAction.READ)) {
return pageService.search(new PageQuery.Builder().api(api).homepage(homepage).type(type).parent(parent).name(name).rootParent(rootParent).build(), translated ? acceptedLocale : null, GraviteeContext.getCurrentEnvironment()).stream().filter(page -> isDisplayable(apiEntity, page)).map(page -> {
// check if the page is used as GeneralCondition by an active Plan
// and update the PageEntity to transfer the information to the FrontEnd
page.setGeneralConditions(pageService.isPageUsedAsGeneralConditions(page, api));
return page;
}).collect(Collectors.toList());
}
throw new ForbiddenAccessException();
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationSubscriptionsResource method convert.
private Subscription convert(SubscriptionEntity subscriptionEntity) {
Subscription subscription = new Subscription();
subscription.setId(subscriptionEntity.getId());
subscription.setCreatedAt(subscriptionEntity.getCreatedAt());
subscription.setUpdatedAt(subscriptionEntity.getUpdatedAt());
subscription.setStartingAt(subscriptionEntity.getStartingAt());
subscription.setEndingAt(subscriptionEntity.getEndingAt());
subscription.setProcessedAt(subscriptionEntity.getProcessedAt());
subscription.setProcessedBy(subscriptionEntity.getProcessedBy());
subscription.setReason(subscriptionEntity.getReason());
subscription.setRequest(subscriptionEntity.getRequest());
subscription.setStatus(subscriptionEntity.getStatus());
subscription.setSubscribedBy(new Subscription.User(subscriptionEntity.getSubscribedBy(), userService.findById(subscriptionEntity.getSubscribedBy(), true).getDisplayName()));
PlanEntity plan = planService.findById(subscriptionEntity.getPlan());
subscription.setPlan(new Subscription.Plan(plan.getId(), plan.getName()));
subscription.getPlan().setSecurity(plan.getSecurity());
ApiEntity api = apiService.findById(subscriptionEntity.getApi());
subscription.setApi(new Subscription.Api(api.getId(), api.getName(), api.getVersion(), new Subscription.User(api.getPrimaryOwner().getId(), api.getPrimaryOwner().getDisplayName())));
subscription.setClosedAt(subscriptionEntity.getClosedAt());
subscription.setPausedAt(subscriptionEntity.getPausedAt());
return subscription;
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PlatformEventsResource method getPlatformEvents.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List platform events", notes = "User must have the MANAGEMENT_PLATFORM[READ] permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Platform events", response = EventEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_PLATFORM, acls = RolePermissionAction.READ) })
public Page<EventEntity> getPlatformEvents(@BeanParam EventSearchParam eventSearchParam) {
eventSearchParam.validate();
Map<String, Object> properties = new HashMap<>();
if (eventSearchParam.getApiIdsParam() != null && eventSearchParam.getApiIdsParam().getIds() != null && !eventSearchParam.getApiIdsParam().getIds().isEmpty()) {
properties.put(Event.EventProperties.API_ID.getValue(), eventSearchParam.getApiIdsParam().getIds());
} else if (!isAdmin()) {
properties.put(Event.EventProperties.API_ID.getValue(), apiService.findByUser(getAuthenticatedUser(), null, false).stream().filter(api -> permissionService.hasPermission(API_ANALYTICS, api.getId(), READ)).map(ApiEntity::getId).collect(Collectors.joining(",")));
}
Page<EventEntity> events = eventService.search(eventSearchParam.getEventTypeListParam().getEventTypes(), properties, eventSearchParam.getFrom(), eventSearchParam.getTo(), eventSearchParam.getPage(), eventSearchParam.getSize());
events.getContent().forEach(event -> {
Map<String, String> properties1 = event.getProperties();
// Event relative to API
if (properties1 != null && properties1.containsKey(Event.EventProperties.API_ID.getValue())) {
// Remove payload content from response since it's not required anymore
event.setPayload(null);
// Retrieve additional data
String apiId = properties1.get(Event.EventProperties.API_ID.getValue());
try {
ApiEntity api = apiService.findById(apiId);
properties1.put("api_name", api.getName());
properties1.put("api_version", api.getVersion());
} catch (ApiNotFoundException anfe) {
properties1.put("deleted", Boolean.TRUE.toString());
properties1.put("api_name", "Deleted API");
}
}
});
return events;
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class TaskServiceImpl method getMetadata.
@Override
public Metadata getMetadata(List<TaskEntity> tasks) {
final Metadata metadata = new Metadata();
tasks.forEach(task -> {
final Object data = task.getData();
if (data instanceof SubscriptionEntity) {
final SubscriptionEntity subscription = (SubscriptionEntity) data;
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());
String apiId = planEntity.getApi();
ApiEntity api = apiService.findById(apiId);
metadata.put(subscription.getPlan(), "name", planEntity.getName());
metadata.put(subscription.getPlan(), "api", apiId);
metadata.put(apiId, "name", api.getName());
}
} else if (data instanceof Workflow) {
final Workflow workflow = (Workflow) data;
if (API.name().equals(workflow.getReferenceType()) && !metadata.containsKey(workflow.getReferenceId())) {
ApiEntity api = apiService.findById(workflow.getReferenceId());
metadata.put(api.getId(), "name", api.getName());
}
}
});
return metadata;
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class FilteringServiceImpl method getRatedApis.
private FilteredEntities<ApiEntity> getRatedApis(Collection<ApiEntity> apis, boolean excluded) {
// keep apis with ratings
Map<ApiEntity, RatingSummaryEntity> ratings = new HashMap<>();
// APIPortal: should create a specific service to retrieve all the information
// in one call to the repository
apis.forEach(api -> {
RatingSummaryEntity apiRatingSummary = ratingService.findSummaryByApi(api.getId());
if (apiRatingSummary != null && apiRatingSummary.getNumberOfRatings() > 0) {
ratings.put(api, apiRatingSummary);
}
});
if (excluded) {
return new FilteredEntities<>(apis.stream().filter(api -> !ratings.containsKey(api)).collect(Collectors.toList()), null);
} else {
// sort apis by ratings, nb of ratings, and name
return new FilteredEntities<>(ratings.entrySet().stream().sorted((e1, e2) -> {
RatingSummaryEntity o1 = e1.getValue();
RatingSummaryEntity o2 = e2.getValue();
int averageRateComparaison = Double.compare(o2.getAverageRate(), o1.getAverageRate());
if (averageRateComparaison != 0) {
return averageRateComparaison;
}
int nbRatingsComparaison = Integer.compare(o2.getNumberOfRatings(), o1.getNumberOfRatings());
if (nbRatingsComparaison != 0) {
return nbRatingsComparaison;
}
return String.CASE_INSENSITIVE_ORDER.compare(e1.getKey().getName(), e2.getKey().getName());
}).map(Map.Entry::getKey).collect(Collectors.toList()), null);
}
}
Aggregations