Search in sources :

Example 1 with WebhookSubscriptionListDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.WebhookSubscriptionListDTO in project carbon-apimgt by wso2.

the class WebhooksApiServiceImpl method webhooksSubscriptionsGet.

public Response webhooksSubscriptionsGet(String applicationId, String apiId, String xWSO2Tenant, MessageContext messageContext) {
    if (StringUtils.isNotEmpty(applicationId)) {
        String username = RestApiCommonUtil.getLoggedInUsername();
        try {
            APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
            WebhookSubscriptionListDTO WebhookSubscriptionListDTO;
            Set<Subscription> subscriptionSet = apiConsumer.getTopicSubscriptions(applicationId, apiId);
            WebhookSubscriptionListDTO = AsyncAPIMappingUtil.fromSubscriptionListToDTO(subscriptionSet);
            return Response.ok().entity(WebhookSubscriptionListDTO).build();
        } catch (APIManagementException e) {
            if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
                RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
            } else {
                RestApiUtil.handleInternalServerError("Failed to get topic subscriptions of Async API " + apiId, e, log);
            }
        }
    } else {
        RestApiUtil.handleBadRequest("Application Id cannot be empty", log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) WebhookSubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.WebhookSubscriptionListDTO) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) Subscription(org.wso2.carbon.apimgt.api.model.webhooks.Subscription)

Example 2 with WebhookSubscriptionListDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.WebhookSubscriptionListDTO in project carbon-apimgt by wso2.

the class AsyncAPIMappingUtil method fromSubscriptionListToDTO.

/**
 * Converts Set of Subscription objects to SubscriptionListDTO.
 *
 * @param subscriptions Set of Subscription objects
 * @return WebhookSubscriptionListDTO containing SubscriptionDTOs
 */
public static WebhookSubscriptionListDTO fromSubscriptionListToDTO(Set<Subscription> subscriptions) {
    WebhookSubscriptionListDTO webhookSubscriptionListDTO = new WebhookSubscriptionListDTO();
    List<WebhookSubscriptionDTO> subscriptionDTOs = webhookSubscriptionListDTO.getList();
    webhookSubscriptionListDTO.setCount(subscriptions.size());
    if (subscriptionDTOs == null) {
        subscriptionDTOs = new ArrayList<>();
        webhookSubscriptionListDTO.setList(subscriptionDTOs);
    }
    for (Subscription subscription : subscriptions) {
        subscriptionDTOs.add(fromSubscriptionToDTO(subscription));
    }
    return webhookSubscriptionListDTO;
}
Also used : WebhookSubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.WebhookSubscriptionListDTO) WebhookSubscriptionDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.WebhookSubscriptionDTO) Subscription(org.wso2.carbon.apimgt.api.model.webhooks.Subscription)

Aggregations

Subscription (org.wso2.carbon.apimgt.api.model.webhooks.Subscription)2 WebhookSubscriptionListDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.WebhookSubscriptionListDTO)2 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 WebhookSubscriptionDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.WebhookSubscriptionDTO)1