Search in sources :

Example 6 with RatingSummaryEntity

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

the class PortalApisResource method convert.

private ApiListItem convert(ApiEntity api) {
    final ApiListItem apiItem = new ApiListItem();
    apiItem.setId(api.getId());
    apiItem.setName(api.getName());
    apiItem.setVersion(api.getVersion());
    apiItem.setDescription(api.getDescription());
    final UriBuilder ub = uriInfo.getBaseUriBuilder();
    final UriBuilder uriBuilder = ub.path("apis").path(api.getId()).path("picture");
    if (api.getPicture() != null) {
        // force browser to get if updated
        uriBuilder.queryParam("hash", api.getUpdatedAt().getTime());
    }
    apiItem.setPictureUrl(uriBuilder.build().toString());
    apiItem.setCategories(api.getCategories());
    apiItem.setCreatedAt(api.getCreatedAt());
    apiItem.setUpdatedAt(api.getUpdatedAt());
    apiItem.setLabels(api.getLabels());
    apiItem.setCategories(api.getCategories());
    apiItem.setPrimaryOwner(api.getPrimaryOwner());
    if (api.getVisibility() != null) {
        apiItem.setVisibility(io.gravitee.rest.api.model.Visibility.valueOf(api.getVisibility().toString()));
    }
    if (api.getState() != null) {
        apiItem.setState(Lifecycle.State.valueOf(api.getState().toString()));
    }
    if (api.getProxy() != null) {
        apiItem.setVirtualHosts(api.getProxy().getVirtualHosts());
    }
    if (ratingService.isEnabled()) {
        final RatingSummaryEntity ratingSummary = ratingService.findSummaryByApi(api.getId());
        apiItem.setRate(ratingSummary.getAverageRate());
        apiItem.setNumberOfRatings(ratingSummary.getNumberOfRatings());
    }
    apiItem.setTags(api.getTags());
    if (api.getLifecycleState() != null) {
        apiItem.setLifecycleState(ApiLifecycleState.valueOf(api.getLifecycleState().toString()));
    }
    return apiItem;
}
Also used : ApiListItem(io.gravitee.rest.api.model.api.ApiListItem) RatingSummaryEntity(io.gravitee.rest.api.model.RatingSummaryEntity) UriBuilder(javax.ws.rs.core.UriBuilder)

Aggregations

RatingSummaryEntity (io.gravitee.rest.api.model.RatingSummaryEntity)6 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)3 PrimaryOwnerEntity (io.gravitee.rest.api.model.PrimaryOwnerEntity)2 TopApiEntity (io.gravitee.rest.api.model.TopApiEntity)2 ApiEntrypointEntity (io.gravitee.rest.api.model.api.ApiEntrypointEntity)2 Api (io.gravitee.rest.api.portal.rest.model.Api)2 RatingSummary (io.gravitee.rest.api.portal.rest.model.RatingSummary)2 User (io.gravitee.rest.api.portal.rest.model.User)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 Test (org.junit.Test)2 Proxy (io.gravitee.definition.model.Proxy)1 VirtualHost (io.gravitee.definition.model.VirtualHost)1 SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)1 SubscriptionStatus (io.gravitee.rest.api.model.SubscriptionStatus)1 UserEntity (io.gravitee.rest.api.model.UserEntity)1 ApiListItem (io.gravitee.rest.api.model.api.ApiListItem)1 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)1 FilterableItem (io.gravitee.rest.api.model.filtering.FilterableItem)1 FilteredEntities (io.gravitee.rest.api.model.filtering.FilteredEntities)1 SubscriptionQuery (io.gravitee.rest.api.model.subscription.SubscriptionQuery)1