Search in sources :

Example 6 with Subscription

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

the class SubscriptionResource method getSubscriptionBySubscriptionId.

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getSubscriptionBySubscriptionId(@PathParam("subscriptionId") String subscriptionId, @QueryParam("include") List<String> include) {
    SubscriptionEntity subscriptionEntity = subscriptionService.findById(subscriptionId);
    if (hasPermission(RolePermission.API_SUBSCRIPTION, subscriptionEntity.getApi(), RolePermissionAction.READ) || hasPermission(RolePermission.APPLICATION_SUBSCRIPTION, subscriptionEntity.getApplication(), RolePermissionAction.READ)) {
        Subscription subscription = subscriptionMapper.convert(subscriptionEntity);
        if (include.contains(INCLUDE_KEYS)) {
            List<Key> keys = apiKeyService.findBySubscription(subscriptionId).stream().sorted((o1, o2) -> o2.getCreatedAt().compareTo(o1.getCreatedAt())).map(keyMapper::convert).collect(Collectors.toList());
            subscription.setKeys(keys);
        }
        return Response.ok(subscription).build();
    }
    throw new ForbiddenAccessException();
}
Also used : SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) Subscription(io.gravitee.rest.api.portal.rest.model.Subscription) ForbiddenAccessException(io.gravitee.rest.api.service.exceptions.ForbiddenAccessException) Key(io.gravitee.rest.api.portal.rest.model.Key)

Example 7 with Subscription

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

the class SubscriptionResourceTest method init.

@Before
public void init() {
    resetAllMocks();
    subscriptionEntity = new SubscriptionEntity();
    subscriptionEntity.setId(SUBSCRIPTION);
    subscriptionEntity.setApi(API);
    subscriptionEntity.setApplication(APPLICATION);
    doReturn(subscriptionEntity).when(subscriptionService).findById(SUBSCRIPTION);
    doThrow(SubscriptionNotFoundException.class).when(subscriptionService).findById(UNKNOWN_SUBSCRIPTION);
    doReturn(Arrays.asList(new ApiKeyEntity())).when(apiKeyService).findBySubscription(SUBSCRIPTION);
    doReturn(new Subscription()).when(subscriptionMapper).convert(any());
    doReturn(new Key()).when(keyMapper).convert(any());
    doReturn(true).when(permissionService).hasPermission(any(), any(), any());
}
Also used : ApiKeyEntity(io.gravitee.rest.api.model.ApiKeyEntity) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) Subscription(io.gravitee.rest.api.portal.rest.model.Subscription) Key(io.gravitee.rest.api.portal.rest.model.Key) Before(org.junit.Before)

Example 8 with Subscription

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

the class SubscriptionResourceTest method shouldGetSubscriptionWithKeys.

@Test
public void shouldGetSubscriptionWithKeys() {
    doReturn(true).when(permissionService).hasPermission(RolePermission.API_SUBSCRIPTION, API, RolePermissionAction.READ);
    doReturn(true).when(permissionService).hasPermission(RolePermission.APPLICATION_SUBSCRIPTION, APPLICATION, RolePermissionAction.READ);
    final Response response = target(SUBSCRIPTION).queryParam("include", "keys").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    Mockito.verify(subscriptionMapper).convert(subscriptionEntity);
    Subscription subscription = response.readEntity(Subscription.class);
    assertNotNull(subscription);
    assertNotNull(subscription.getKeys());
    assertFalse(subscription.getKeys().isEmpty());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) Subscription(io.gravitee.rest.api.portal.rest.model.Subscription) Test(org.junit.Test)

Aggregations

Subscription (io.gravitee.rest.api.portal.rest.model.Subscription)8 SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)3 Key (io.gravitee.rest.api.portal.rest.model.Key)3 ForbiddenAccessException (io.gravitee.rest.api.service.exceptions.ForbiddenAccessException)3 Test (org.junit.Test)3 ErrorResponse (io.gravitee.rest.api.portal.rest.model.ErrorResponse)2 Response (javax.ws.rs.core.Response)2 ApiKeyEntity (io.gravitee.rest.api.model.ApiKeyEntity)1 PageRevisionId (io.gravitee.rest.api.model.PageEntity.PageRevisionId)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)1 PageableImpl (io.gravitee.rest.api.model.common.PageableImpl)1 SubscriptionQuery (io.gravitee.rest.api.model.subscription.SubscriptionQuery)1 Instant (java.time.Instant)1 Date (java.util.Date)1 Before (org.junit.Before)1