Search in sources :

Example 1 with PageRevisionId

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();
}
Also used : PageRevisionId(io.gravitee.rest.api.model.PageEntity.PageRevisionId) 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)

Aggregations

PageRevisionId (io.gravitee.rest.api.model.PageEntity.PageRevisionId)1 Key (io.gravitee.rest.api.portal.rest.model.Key)1 Subscription (io.gravitee.rest.api.portal.rest.model.Subscription)1 ForbiddenAccessException (io.gravitee.rest.api.service.exceptions.ForbiddenAccessException)1