use of io.gravitee.rest.api.portal.rest.model.Key in project gravitee-management-rest-api by gravitee-io.
the class KeyMapperTest method testConvert.
@Test
public void testConvert() {
// Test
Key key = keyMapper.convert(apiKeyEntity);
assertNotNull(key);
assertEquals(API, key.getApi());
assertEquals(APPLICATION, key.getApplication());
assertEquals(now.toEpochMilli(), key.getCreatedAt().toInstant().toEpochMilli());
assertEquals(KEY, key.getId());
assertEquals(Boolean.FALSE, key.getPaused());
assertEquals(PLAN, key.getPlan());
assertEquals(Boolean.FALSE, key.getRevoked());
assertNull(key.getRevokedAt());
}
use of io.gravitee.rest.api.portal.rest.model.Key in project gravitee-management-rest-api by gravitee-io.
the class KeyMapperTest method testConvertWithoutPlan.
@Test
public void testConvertWithoutPlan() {
apiKeyEntity.setPlan(UNKNOWN_PLAN);
// Test
Key key = keyMapper.convert(apiKeyEntity);
assertNotNull(key);
assertNull(key.getApi());
assertEquals(APPLICATION, key.getApplication());
assertEquals(now.toEpochMilli(), key.getCreatedAt().toInstant().toEpochMilli());
assertEquals(KEY, key.getId());
assertEquals(Boolean.FALSE, key.getPaused());
assertEquals(UNKNOWN_PLAN, key.getPlan());
assertEquals(Boolean.FALSE, key.getRevoked());
assertNull(key.getRevokedAt());
}
use of io.gravitee.rest.api.portal.rest.model.Key in project gravitee-management-rest-api by gravitee-io.
the class KeyMapper method convert.
public Key convert(ApiKeyEntity apiKeyEntity) {
final Key keyItem = new Key();
final String plan = apiKeyEntity.getPlan();
try {
PlanEntity planEntity = planService.findById(plan);
keyItem.setApi(planEntity.getApi());
} catch (PlanNotFoundException e) {
LOGGER.warn("plan does not exist : {}", plan);
}
keyItem.setApplication(apiKeyEntity.getApplication());
keyItem.setCreatedAt(apiKeyEntity.getCreatedAt().toInstant().atOffset(ZoneOffset.UTC));
keyItem.setId(apiKeyEntity.getKey());
keyItem.setPaused(apiKeyEntity.isPaused());
keyItem.setPlan(plan);
keyItem.setRevoked(apiKeyEntity.isRevoked());
if (apiKeyEntity.isRevoked()) {
keyItem.setRevokedAt(apiKeyEntity.getRevokedAt().toInstant().atOffset(ZoneOffset.UTC));
}
keyItem.setExpired(apiKeyEntity.isExpired());
if (apiKeyEntity.getExpireAt() != null) {
keyItem.setExpireAt(apiKeyEntity.getExpireAt().toInstant().atOffset(ZoneOffset.UTC));
}
return keyItem;
}
use of io.gravitee.rest.api.portal.rest.model.Key in project gravitee-management-rest-api by gravitee-io.
the class SubscriptionsResource method createSubscription.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createSubscription(@Valid @NotNull(message = "Input must not be null.") SubscriptionInput subscriptionInput) {
if (hasPermission(RolePermission.APPLICATION_SUBSCRIPTION, subscriptionInput.getApplication(), RolePermissionAction.CREATE)) {
NewSubscriptionEntity newSubscriptionEntity = new NewSubscriptionEntity();
newSubscriptionEntity.setApplication(subscriptionInput.getApplication());
newSubscriptionEntity.setPlan(subscriptionInput.getPlan());
newSubscriptionEntity.setRequest(subscriptionInput.getRequest());
newSubscriptionEntity.setGeneralConditionsAccepted(subscriptionInput.getGeneralConditionsAccepted());
if (subscriptionInput.getGeneralConditionsContentRevision() != null) {
final PageRevisionId generalConditionsContentRevision = new PageRevisionId(subscriptionInput.getGeneralConditionsContentRevision().getPageId(), subscriptionInput.getGeneralConditionsContentRevision().getRevision());
newSubscriptionEntity.setGeneralConditionsContentRevision(generalConditionsContentRevision);
}
SubscriptionEntity createdSubscription = subscriptionService.create(newSubscriptionEntity);
// For consumer convenience, fetch the keys just after the subscription has been created.
List<Key> keys = apiKeyService.findBySubscription(createdSubscription.getId()).stream().sorted((o1, o2) -> o2.getCreatedAt().compareTo(o1.getCreatedAt())).map(keyMapper::convert).collect(Collectors.toList());
final Subscription subscription = subscriptionMapper.convert(createdSubscription);
subscription.setKeys(keys);
return Response.ok(subscription).build();
}
throw new ForbiddenAccessException();
}
use of io.gravitee.rest.api.portal.rest.model.Key in project gravitee-management-rest-api by gravitee-io.
the class SubscriptionKeysResourceTest method shouldRenewSubscription.
@Test
public void shouldRenewSubscription() {
final Response response = target(SUBSCRIPTION).path("keys/_renew").request().post(null);
assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
assertNull(response.getHeaders().getFirst(HttpHeaders.LOCATION));
Mockito.verify(apiKeyService).renew(SUBSCRIPTION);
Key key = response.readEntity(Key.class);
assertNotNull(key);
assertEquals(KEY, key.getId());
}
Aggregations