Search in sources :

Example 11 with SubscriptionListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.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 12 with SubscriptionListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.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)

Aggregations

Subscription (org.wso2.carbon.apimgt.core.models.Subscription)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)4 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)4 SubscriptionListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionListDTO)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Response (javax.ws.rs.core.Response)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.publisher.dto.SubscriptionListDTO)3 SubscriptionListDTO (org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionListDTO)3 Application (org.wso2.carbon.apimgt.core.models.Application)2 SubscriptionValidationData (org.wso2.carbon.apimgt.core.models.SubscriptionValidationData)2 ZoneId (java.time.ZoneId)1 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)1 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)1 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)1 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)1 ApiType (org.wso2.carbon.apimgt.core.dao.ApiType)1