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