Search in sources :

Example 1 with ApiListItem

use of io.gravitee.rest.api.model.api.ApiListItem 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)1 ApiListItem (io.gravitee.rest.api.model.api.ApiListItem)1 UriBuilder (javax.ws.rs.core.UriBuilder)1