use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoListDTO in project carbon-apimgt by wso2.
the class AdditionalSubscriptionInfoMappingUtil method fromAdditionalSubscriptionInfoListToDTO.
/**
* Converts a List object of SubscribedAPIs into a DTO
*
* @param subscriptions a list of SubscribedAPI objects
* @param limit max number of objects returned
* @param offset starting index
* @param organization identifier of the organization
* @return SubscriptionListDTO object containing SubscriptionDTOs
* @throws APIManagementException if error occurred when creating AdditionalSubscriptionInfoListDTO
*/
public static AdditionalSubscriptionInfoListDTO fromAdditionalSubscriptionInfoListToDTO(List<SubscribedAPI> subscriptions, Integer limit, Integer offset, String organization) throws APIManagementException {
AdditionalSubscriptionInfoListDTO additionalSubscriptionInfoListDTO = new AdditionalSubscriptionInfoListDTO();
List<AdditionalSubscriptionInfoDTO> additionalSubscriptionInfoDTOs = additionalSubscriptionInfoListDTO.getList();
if (additionalSubscriptionInfoDTOs == null) {
additionalSubscriptionInfoDTOs = new ArrayList<>();
additionalSubscriptionInfoListDTO.setList(additionalSubscriptionInfoDTOs);
}
// Identifying the proper start and end indexes
int size = subscriptions.size();
int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
for (int i = start; i <= end; i++) {
try {
SubscribedAPI subscription = subscriptions.get(i);
additionalSubscriptionInfoDTOs.add(fromAdditionalSubscriptionInfoToDTO(subscription, organization));
} catch (APIManagementException e) {
log.error("Error while obtaining additional info of subscriptions", e);
}
}
// Set count for list
additionalSubscriptionInfoListDTO.setCount(additionalSubscriptionInfoDTOs.size());
return additionalSubscriptionInfoListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoListDTO in project carbon-apimgt by wso2.
the class AdditionalSubscriptionInfoMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a AdditionalSubscriptionInfoListDTO object given pagination parameters and url
* parameters
*
* @param additionalSubscriptionInfoListDTO a AdditionalSubscriptionInfoListDTO 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(AdditionalSubscriptionInfoListDTO additionalSubscriptionInfoListDTO, 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);
additionalSubscriptionInfoListDTO.setPagination(pagination);
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoListDTO in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method getAdditionalInfoOfAPISubscriptions.
/**
* Get additional Info details of subscriptions attached with given API
*
* @param apiId apiId
* @param offset starting index of the subscription list
* @param limit max num of subscriptions returned
* @param ifNoneMatch If-None-Match header value
* @param messageContext message context
* @return Response with additional Info of the GraphQL API
*/
@Override
public Response getAdditionalInfoOfAPISubscriptions(String apiId, 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<>();
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
AdditionalSubscriptionInfoListDTO additionalSubscriptionInfoListDTO;
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 subscriptions by application name
subscribedAPIList.addAll(subscriptions);
subscribedAPIList.sort(Comparator.comparing(o -> o.getApplication().getName()));
additionalSubscriptionInfoListDTO = AdditionalSubscriptionInfoMappingUtil.fromAdditionalSubscriptionInfoListToDTO(subscribedAPIList, limit, offset, organization);
AdditionalSubscriptionInfoMappingUtil.setPaginationParams(additionalSubscriptionInfoListDTO, apiId, "", limit, offset, subscribedAPIList.size());
return Response.ok().entity(additionalSubscriptionInfoListDTO).build();
} catch (APIManagementException e) {
// to expose the existence of the resource
if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else if (RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure("Authorization failure while retrieving additional information details of the API : " + apiId, e, log);
} else {
String msg = "Error while retrieving additional information details of the API " + apiId;
RestApiUtil.handleInternalServerError(msg, e, log);
}
}
return null;
}
Aggregations