Search in sources :

Example 6 with APISubscriptionCount

use of org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount in project carbon-apimgt by wso2.

the class ApiApiServiceImpl method apiSubscriberCountByApiGet.

/**
 * Get list of subscriptions for an API
 *
 * @param startTime Filter for start time stamp
 * @param endTime   Filter for end time stamp
 * @param apiId     Filter for apiId
 * @param request   MSF4J request
 * @return API subscriptions count
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response apiSubscriberCountByApiGet(String startTime, String endTime, String apiId, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        log.debug("Retrieving APIs created over time. [From: {} To: {} API Id: {}]");
        Analyzer analyzer = RestApiUtil.getAnalyzer(username);
        List<APISubscriptionCount> apiSubscriptionCountList = analyzer.getAPISubscriptionCount(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), apiId);
        APISubscriptionCountListDTO apiSubscriptionListDTO = AnalyticsMappingUtil.fromAPISubscriptionCountListToDTO(apiSubscriptionCountList);
        return Response.ok().entity(apiSubscriptionListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API subscription info";
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APISubscriptionCountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APISubscriptionCountListDTO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APISubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer)

Example 7 with APISubscriptionCount

use of org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createRandomAPISubscriptionCountObject.

/**
 * Create Random APISubscriptionCount Object.
 *
 * @return Random APISubscriptionCount Object
 */
public static APISubscriptionCount createRandomAPISubscriptionCountObject() {
    APISubscriptionCount apiSubscriptionCount = new APISubscriptionCount();
    apiSubscriptionCount.setId(UUID.randomUUID().toString());
    apiSubscriptionCount.setName(UUID.randomUUID().toString());
    apiSubscriptionCount.setVersion(UUID.randomUUID().toString());
    apiSubscriptionCount.setProvider(UUID.randomUUID().toString());
    apiSubscriptionCount.setCount(new Random().nextInt());
    return apiSubscriptionCount;
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Random(java.util.Random) APISubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount)

Aggregations

APISubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount)7 ArrayList (java.util.ArrayList)4 Test (org.testng.annotations.Test)3 APISubscriptionCountListDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APISubscriptionCountListDTO)3 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)2 AnalyticsDAO (org.wso2.carbon.apimgt.core.dao.AnalyticsDAO)2 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Instant (java.time.Instant)1 Random (java.util.Random)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)1 API (org.wso2.carbon.apimgt.core.models.API)1 Application (org.wso2.carbon.apimgt.core.models.Application)1 APISubscriptionCountDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APISubscriptionCountDTO)1 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)1