use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.SubscriptionListDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method setPaginationParamsWithSortParams.
/**
* Sets pagination urls for a ApplicationListDTO object given pagination parameters and url parameters with
* sortOrder and sortBy params.
*
* @param applicationListDTO a SubscriptionListDTO object
* @param groupId group id of the applications to be returned
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
* @param sortOrder sorting order
* @param sortBy specified sort param
*/
public static void setPaginationParamsWithSortParams(ApplicationListDTO applicationListDTO, String groupId, int limit, int offset, int size, String sortOrder, String sortBy) {
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
String paginatedPrevious = "";
String paginatedNext = "";
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = RestApiCommonUtil.getApplicationPaginatedURLWithSortParams(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), groupId, sortOrder, sortBy);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getApplicationPaginatedURLWithSortParams(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), groupId, sortOrder, sortBy);
}
PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
applicationListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.SubscriptionListDTO in project carbon-apimgt by wso2.
the class SubscriptionValidationDataUtil method fromSubscriptionToSubscriptionListDTO.
public static SubscriptionListDTO fromSubscriptionToSubscriptionListDTO(List<Subscription> model) {
SubscriptionListDTO subscriptionListDTO = new SubscriptionListDTO();
if (model != null) {
for (Subscription subsModel : model) {
SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
subscriptionDTO.setSubscriptionUUID(subsModel.getSubscriptionUUID());
subscriptionDTO.setApplicationUUID(subsModel.getApplicationUUID());
subscriptionDTO.setApiUUID(subsModel.getApiUUID());
subscriptionDTO.setApiId(subsModel.getApiId());
subscriptionDTO.setAppId(subsModel.getAppId());
subscriptionDTO.setSubscriptionId(subsModel.getSubscriptionId());
subscriptionDTO.setPolicyId(subsModel.getPolicyId());
subscriptionDTO.setSubscriptionState(subsModel.getSubscriptionState());
subscriptionListDTO.getList().add(subscriptionDTO);
}
subscriptionListDTO.setCount(model.size());
} else {
subscriptionListDTO.setCount(0);
}
return subscriptionListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.SubscriptionListDTO in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method subscriptionsGet.
/**
* Get all subscriptions that are of user or shared subscriptions of the user's group.
* <p/>
* If apiId is specified this will return the subscribed applications of that api
* If application id is specified this will return the api subscriptions of that application
*
* @param apiId api identifier
* @param applicationId application identifier
* @param offset starting index of the subscription list
* @param limit max num of subscriptions returned
* @param ifNoneMatch If-None-Match header value
* @return matched subscriptions as a list of SubscriptionDTOs
*/
@Override
public Response subscriptionsGet(String apiId, String applicationId, String groupId, String xWSO2Tenant, Integer offset, Integer limit, String ifNoneMatch, MessageContext messageContext) {
String username = RestApiCommonUtil.getLoggedInUsername();
Subscriber subscriber = new Subscriber(username);
Set<SubscribedAPI> subscriptions;
List<SubscribedAPI> subscribedAPIList = new ArrayList<>();
// pre-processing
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
// currently groupId is taken from the user so that groupId coming as a query parameter is not honored.
// As a improvement, we can check admin privileges of the user and honor groupId.
groupId = RestApiUtil.getLoggedInUserGroupId();
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
SubscriptionListDTO subscriptionListDTO;
if (!StringUtils.isEmpty(apiId)) {
// todo : FIX properly, need to done properly with backend side pagination.
// todo : getSubscribedIdentifiers() method should NOT be used. Appears to be too slow.
// This will fail with an authorization failed exception if user does not have permission to access the API
ApiTypeWrapper apiTypeWrapper = apiConsumer.getAPIorAPIProductByUUID(apiId, organization);
if (apiTypeWrapper.isAPIProduct()) {
subscriptions = apiConsumer.getSubscribedIdentifiers(subscriber, apiTypeWrapper.getApiProduct().getId(), groupId, organization);
} else {
subscriptions = apiConsumer.getSubscribedIdentifiers(subscriber, apiTypeWrapper.getApi().getId(), groupId, organization);
}
// sort by application name
subscribedAPIList.addAll(subscriptions);
subscribedAPIList.sort(Comparator.comparing(o -> o.getApplication().getName()));
subscriptionListDTO = SubscriptionMappingUtil.fromSubscriptionListToDTO(subscribedAPIList, limit, offset, organization);
SubscriptionMappingUtil.setPaginationParams(subscriptionListDTO, apiId, "", limit, offset, subscribedAPIList.size());
return Response.ok().entity(subscriptionListDTO).build();
} else if (!StringUtils.isEmpty(applicationId)) {
Application application = apiConsumer.getApplicationByUUID(applicationId);
if (application == null) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_APPLICATION, applicationId, log);
return null;
}
if (!RestAPIStoreUtils.isUserAccessAllowedForApplication(application)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_APPLICATION, applicationId, log);
}
subscriptions = apiConsumer.getPaginatedSubscribedAPIsByApplication(application, offset, limit, organization);
subscribedAPIList.addAll(subscriptions);
subscriptionListDTO = SubscriptionMappingUtil.fromSubscriptionListToDTO(subscribedAPIList, limit, offset, organization);
return Response.ok().entity(subscriptionListDTO).build();
} else {
// neither apiId nor applicationId is given
RestApiUtil.handleBadRequest("Either applicationId or apiId should be available", log);
return null;
}
} catch (APIManagementException e) {
if (RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_API, apiId, log);
} else if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else {
RestApiUtil.handleInternalServerError("Error while getting subscriptions of the user " + username, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.SubscriptionListDTO 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;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.SubscriptionListDTO in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a SubscriptionListDTO object given pagination parameters and url parameters
*
* @param subscriptionListDTO a SubscriptionListDTO object
* @param apiId uuid/id of API
* @param groupId group id of the applications to be returned
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setPaginationParams(SubscriptionListDTO subscriptionListDTO, String apiId, String groupId, int limit, int offset, int size) {
String paginatedPrevious = "";
String paginatedNext = "";
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = RestApiCommonUtil.getSubscriptionPaginatedURLForAPIId(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), apiId, groupId);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getSubscriptionPaginatedURLForAPIId(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), apiId, groupId);
}
PaginationDTO pagination = new PaginationDTO();
pagination.setOffset(offset);
pagination.setLimit(limit);
pagination.setNext(paginatedNext);
pagination.setPrevious(paginatedPrevious);
pagination.setTotal(size);
subscriptionListDTO.setPagination(pagination);
}
Aggregations