Search in sources :

Example 1 with Subscription

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

the class ApplicationSubscriptionsResource method convert.

private Subscription convert(SubscriptionEntity subscriptionEntity) {
    Subscription subscription = new Subscription();
    subscription.setId(subscriptionEntity.getId());
    subscription.setCreatedAt(subscriptionEntity.getCreatedAt());
    subscription.setUpdatedAt(subscriptionEntity.getUpdatedAt());
    subscription.setStartingAt(subscriptionEntity.getStartingAt());
    subscription.setEndingAt(subscriptionEntity.getEndingAt());
    subscription.setProcessedAt(subscriptionEntity.getProcessedAt());
    subscription.setProcessedBy(subscriptionEntity.getProcessedBy());
    subscription.setReason(subscriptionEntity.getReason());
    subscription.setRequest(subscriptionEntity.getRequest());
    subscription.setStatus(subscriptionEntity.getStatus());
    subscription.setSubscribedBy(new Subscription.User(subscriptionEntity.getSubscribedBy(), userService.findById(subscriptionEntity.getSubscribedBy(), true).getDisplayName()));
    PlanEntity plan = planService.findById(subscriptionEntity.getPlan());
    subscription.setPlan(new Subscription.Plan(plan.getId(), plan.getName()));
    subscription.getPlan().setSecurity(plan.getSecurity());
    ApiEntity api = apiService.findById(subscriptionEntity.getApi());
    subscription.setApi(new Subscription.Api(api.getId(), api.getName(), api.getVersion(), new Subscription.User(api.getPrimaryOwner().getId(), api.getPrimaryOwner().getDisplayName())));
    subscription.setClosedAt(subscriptionEntity.getClosedAt());
    subscription.setPausedAt(subscriptionEntity.getPausedAt());
    return subscription;
}
Also used : PlanEntity(io.gravitee.rest.api.model.PlanEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Subscription(io.gravitee.rest.api.management.rest.model.Subscription)

Example 2 with Subscription

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

the class ApiSubscriptionsResource method convert.

private Subscription convert(SubscriptionEntity subscriptionEntity) {
    Subscription subscription = new Subscription();
    subscription.setId(subscriptionEntity.getId());
    subscription.setCreatedAt(subscriptionEntity.getCreatedAt());
    subscription.setUpdatedAt(subscriptionEntity.getUpdatedAt());
    subscription.setStartingAt(subscriptionEntity.getStartingAt());
    subscription.setEndingAt(subscriptionEntity.getEndingAt());
    subscription.setProcessedAt(subscriptionEntity.getProcessedAt());
    subscription.setProcessedBy(subscriptionEntity.getProcessedBy());
    subscription.setReason(subscriptionEntity.getReason());
    subscription.setStatus(subscriptionEntity.getStatus());
    subscription.setSubscribedBy(new Subscription.User(subscriptionEntity.getSubscribedBy(), userService.findById(subscriptionEntity.getSubscribedBy()).getDisplayName()));
    PlanEntity plan = planService.findById(subscriptionEntity.getPlan());
    subscription.setPlan(new Subscription.Plan(plan.getId(), plan.getName()));
    ApplicationEntity application = applicationService.findById(subscriptionEntity.getApplication());
    subscription.setApplication(new Subscription.Application(application.getId(), application.getName(), application.getType(), application.getDescription(), new Subscription.User(application.getPrimaryOwner().getId(), application.getPrimaryOwner().getDisplayName())));
    subscription.setClosedAt(subscriptionEntity.getClosedAt());
    return subscription;
}
Also used : Subscription(io.gravitee.rest.api.management.rest.model.Subscription)

Example 3 with Subscription

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

the class ApiSubscriptionResource method convert.

private Subscription convert(SubscriptionEntity subscriptionEntity) {
    Subscription subscription = new Subscription();
    subscription.setId(subscriptionEntity.getId());
    subscription.setCreatedAt(subscriptionEntity.getCreatedAt());
    subscription.setUpdatedAt(subscriptionEntity.getUpdatedAt());
    subscription.setStartingAt(subscriptionEntity.getStartingAt());
    subscription.setEndingAt(subscriptionEntity.getEndingAt());
    subscription.setProcessedAt(subscriptionEntity.getProcessedAt());
    subscription.setProcessedBy(subscriptionEntity.getProcessedBy());
    subscription.setRequest(subscriptionEntity.getRequest());
    subscription.setReason(subscriptionEntity.getReason());
    subscription.setRequest(subscriptionEntity.getRequest());
    subscription.setStatus(subscriptionEntity.getStatus());
    subscription.setSubscribedBy(new Subscription.User(subscriptionEntity.getSubscribedBy(), userService.findById(subscriptionEntity.getSubscribedBy(), true).getDisplayName()));
    subscription.setClientId(subscriptionEntity.getClientId());
    PlanEntity plan = planService.findById(subscriptionEntity.getPlan());
    subscription.setPlan(new Subscription.Plan(plan.getId(), plan.getName()));
    subscription.getPlan().setSecurity(plan.getSecurity());
    ApplicationEntity application = applicationService.findById(subscriptionEntity.getApplication());
    subscription.setApplication(new Subscription.Application(application.getId(), application.getName(), application.getType(), application.getDescription(), new Subscription.User(application.getPrimaryOwner().getId(), application.getPrimaryOwner().getDisplayName())));
    subscription.setClosedAt(subscriptionEntity.getClosedAt());
    subscription.setPausedAt(subscriptionEntity.getPausedAt());
    return subscription;
}
Also used : Subscription(io.gravitee.rest.api.management.rest.model.Subscription)

Example 4 with Subscription

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

the class ApplicationSubscriptionsResource method createSubscriptionWithApplication.

@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Subscribe to a plan", notes = "User must have the MANAGE_SUBSCRIPTIONS permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Subscription successfully created", response = Subscription.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_SUBSCRIPTION, acls = RolePermissionAction.CREATE) })
public Response createSubscriptionWithApplication(@ApiParam(name = "plan", required = true) @NotNull @QueryParam("plan") String plan, NewSubscriptionEntity newSubscriptionEntity) {
    // If no request message has been passed, the entity is not created
    if (newSubscriptionEntity == null) {
        newSubscriptionEntity = new NewSubscriptionEntity();
    }
    PlanEntity planEntity = planService.findById(plan);
    if (planEntity.isCommentRequired() && (newSubscriptionEntity.getRequest() == null || newSubscriptionEntity.getRequest().isEmpty())) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Plan requires a consumer comment when subscribing").build();
    }
    newSubscriptionEntity.setApplication(application);
    newSubscriptionEntity.setPlan(plan);
    Subscription subscription = convert(subscriptionService.create(newSubscriptionEntity));
    return Response.created(this.getRequestUriBuilder().path(subscription.getId()).replaceQueryParam("plan", null).build()).entity(subscription).build();
}
Also used : NewSubscriptionEntity(io.gravitee.rest.api.model.NewSubscriptionEntity) PlanEntity(io.gravitee.rest.api.model.PlanEntity) Subscription(io.gravitee.rest.api.management.rest.model.Subscription) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 5 with Subscription

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

the class SubscriptionsResource method convert.

private Subscription convert(SubscriptionEntity subscriptionEntity) {
    Subscription subscription = new Subscription();
    subscription.setId(subscriptionEntity.getId());
    subscription.setCreatedAt(subscriptionEntity.getCreatedAt());
    subscription.setUpdatedAt(subscriptionEntity.getUpdatedAt());
    subscription.setStartingAt(subscriptionEntity.getStartingAt());
    subscription.setEndingAt(subscriptionEntity.getEndingAt());
    subscription.setProcessedAt(subscriptionEntity.getProcessedAt());
    subscription.setProcessedBy(subscriptionEntity.getProcessedBy());
    subscription.setReason(subscriptionEntity.getReason());
    subscription.setStatus(subscriptionEntity.getStatus());
    ApplicationEntity application = applicationService.findById(subscriptionEntity.getApplication());
    subscription.setApplication(new Subscription.Application(application.getId(), application.getName(), application.getType(), application.getDescription(), new Subscription.User(application.getPrimaryOwner().getId(), application.getPrimaryOwner().getDisplayName())));
    PlanEntity plan = planService.findById(subscriptionEntity.getPlan());
    subscription.setPlan(new Subscription.Plan(plan.getId(), plan.getName()));
    subscription.setClosedAt(subscriptionEntity.getClosedAt());
    return subscription;
}
Also used : ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) PlanEntity(io.gravitee.rest.api.model.PlanEntity) Subscription(io.gravitee.rest.api.management.rest.model.Subscription)

Aggregations

Subscription (io.gravitee.rest.api.management.rest.model.Subscription)5 PlanEntity (io.gravitee.rest.api.model.PlanEntity)3 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)1 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)1 NewSubscriptionEntity (io.gravitee.rest.api.model.NewSubscriptionEntity)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1