use of io.gravitee.rest.api.model.PageEntity.PageRevisionId 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();
}
Aggregations