Search in sources :

Example 16 with SubscriptionListDTO

use of org.wso2.carbon.apimgt.internal.service.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);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) SubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionListDTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with SubscriptionListDTO

use of org.wso2.carbon.apimgt.internal.service.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();
    }
}
Also used : ZoneId(java.time.ZoneId) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) SubscriptionCountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionCountListDTO) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer) SubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount)

Example 18 with SubscriptionListDTO

use of org.wso2.carbon.apimgt.internal.service.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;
}
Also used : Subscription(org.wso2.carbon.apimgt.core.models.Subscription) SubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.SubscriptionListDTO)

Example 19 with SubscriptionListDTO

use of org.wso2.carbon.apimgt.internal.service.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);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)

Example 20 with SubscriptionListDTO

use of org.wso2.carbon.apimgt.internal.service.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;
}
Also used : SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO) SubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionListDTO)

Aggregations

SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)6 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)6 ArrayList (java.util.ArrayList)4 Response (javax.ws.rs.core.Response)4 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)4 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)4 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Test (org.testng.annotations.Test)3 SubscriptionListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionListDTO)3 SubscriptionListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionListDTO)3 SubscriptionListDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.SubscriptionListDTO)2 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO)2 SubscriptionListDTO (org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionListDTO)2 PaginationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ZoneId (java.time.ZoneId)1