use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionListDTO in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method subscriptionsGetTest.
@Test
public void subscriptionsGetTest() throws Exception {
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
Mockito.when(apiMgtAdminService.getAPISubscriptionsOfApi(API_CONTEXT, API_VERSION)).thenReturn(createSubscriptionValidationDataList());
Response response = subscriptionsApiService.subscriptionsGet(API_CONTEXT, API_VERSION, LIMIT, null, getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertEquals(((SubscriptionListDTO) response.getEntity()).getList().size(), 2);
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionListDTO in project carbon-apimgt by wso2.
the class SubscriptionApiServiceImpl method subscriptionCountOverTimeGet.
/**
* Get list of subscriptions created over time
*
* @param startTime Filter for start time stamp
* @param endTime Filter for end time stamp
* @param createdBy Filter for createdBy
* @param request MSF4J request
* @return Subscriptions count over time
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response subscriptionCountOverTimeGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
log.debug("Retrieving subscriptions created over time. [From: {} To: {} Created By: {}]", startTime, endTime, createdBy);
Analyzer analyzer = RestApiUtil.getAnalyzer(username);
ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
List<SubscriptionCount> subscriptionCount = analyzer.getSubscriptionCount(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
SubscriptionCountListDTO subscriptionListDTO = AnalyticsMappingUtil.fromSubscriptionCountListToDTO(subscriptionCount, requestTimezone);
return Response.ok().entity(subscriptionListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving Subscription Count";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionListDTO in project carbon-apimgt by wso2.
the class MappingUtil method fromSubscriptionListToDTO.
/**
* Converts Subscription model into SubscriptionListDTO object
*
* @param subscriptionList list of subscriptions
* @param limit no of items to return
* @param offset value to offset
* @return SubscriptionListDTO containing subscriptions
*/
public static SubscriptionListDTO fromSubscriptionListToDTO(List<Subscription> subscriptionList, Integer limit, Integer offset) {
SubscriptionListDTO subscriptionListDTO = new SubscriptionListDTO();
for (Subscription subscription : subscriptionList) {
subscriptionListDTO.addListItem(fromSubscription(subscription));
}
// TODO need to change when pagination implementation goes on
subscriptionListDTO.count(subscriptionList.size());
return subscriptionListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.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);
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionListDTO in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method fromSubscriptionListToDTO.
/**
* 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
* @return SubscriptionListDTO object containing SubscriptionDTOs
*/
public static SubscriptionListDTO fromSubscriptionListToDTO(List<SubscribedAPI> subscriptions, Integer limit, Integer offset) throws APIManagementException {
SubscriptionListDTO subscriptionListDTO = new SubscriptionListDTO();
List<SubscriptionDTO> subscriptionDTOs = subscriptionListDTO.getList();
if (subscriptionDTOs == null) {
subscriptionDTOs = new ArrayList<>();
subscriptionListDTO.setList(subscriptionDTOs);
}
// 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++) {
SubscribedAPI subscription = subscriptions.get(i);
subscriptionDTOs.add(fromSubscriptionToDTO(subscription));
}
subscriptionListDTO.setCount(subscriptionDTOs.size());
return subscriptionListDTO;
}
Aggregations