Search in sources :

Example 6 with SubscriptionCount

use of org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount 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 7 with SubscriptionCount

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

the class AnalyticsMappingUtil method fromSubscriptionCountListToDTO.

/**
 * Converts and SubscriptionInfoList to SubscriptionInfoListDTO.
 *
 * @param subscriptionCountList list of SubscriptionCount objects
 * @return corresponding APIInfoListDTO object
 */
public static SubscriptionCountListDTO fromSubscriptionCountListToDTO(List<SubscriptionCount> subscriptionCountList, ZoneId zoneId) {
    SubscriptionCountListDTO subscriptionCountListDTO = new SubscriptionCountListDTO();
    List<SubscriptionCountDTO> subscriptionCountDTOList = new ArrayList<>();
    subscriptionCountListDTO.setCount(subscriptionCountList.size());
    for (SubscriptionCount subscriptionCount : subscriptionCountList) {
        SubscriptionCountDTO subscriptionCountDTO = new SubscriptionCountDTO();
        subscriptionCountDTO.setTime(epochToISO8601DateTime(subscriptionCount.getTimestamp(), zoneId));
        subscriptionCountDTO.setCount(subscriptionCount.getCount());
        subscriptionCountDTOList.add(subscriptionCountDTO);
    }
    subscriptionCountListDTO.setList(subscriptionCountDTOList);
    return subscriptionCountListDTO;
}
Also used : SubscriptionCountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionCountListDTO) APISubscriptionCountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APISubscriptionCountListDTO) ArrayList(java.util.ArrayList) APISubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount) SubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount) SubscriptionCountDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionCountDTO) APISubscriptionCountDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APISubscriptionCountDTO)

Example 8 with SubscriptionCount

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

the class SampleTestObjectCreator method createRandomSubscriptionCountObject.

/**
 * Create Random SubscriptionCount Object.
 *
 * @return Random SubscriptionCount Object
 */
public static SubscriptionCount createRandomSubscriptionCountObject() {
    SubscriptionCount subscriptionCount = new SubscriptionCount();
    subscriptionCount.setCount(new Random().nextInt());
    subscriptionCount.setTimestamp(ThreadLocalRandom.current().nextLong());
    return subscriptionCount;
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Random(java.util.Random) SubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount) APISubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount)

Aggregations

APISubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount)7 SubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount)7 ArrayList (java.util.ArrayList)4 Test (org.testng.annotations.Test)4 AnalyticsDAO (org.wso2.carbon.apimgt.core.dao.AnalyticsDAO)3 SubscriptionCountListDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionCountListDTO)3 Instant (java.time.Instant)2 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)2 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)2 API (org.wso2.carbon.apimgt.core.models.API)2 Application (org.wso2.carbon.apimgt.core.models.Application)2 APISubscriptionCountListDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APISubscriptionCountListDTO)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 ZoneId (java.time.ZoneId)1 Random (java.util.Random)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1