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;
}
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;
}
Aggregations