Search in sources :

Example 6 with APIInfoListDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoListDTO in project carbon-apimgt by wso2.

the class ApiApiServiceImpl method apiListGet.

/**
 * Get list of API Info
 *
 * @param startTime Filter for start time stamp
 * @param endTime   Filter for end time stamp
 * @param createdBy Filter for created user
 * @param request   MSF4J request
 * @return API List
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response apiListGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        log.debug("Retrieving API information. [From: {} To: {} Created By:{} ]", startTime, endTime, createdBy);
        Analyzer analyzer = RestApiUtil.getAnalyzer(username);
        ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
        List<APIInfo> apiInfoList = analyzer.getAPIInfo(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
        APIInfoListDTO apiInfoListDTO = AnalyticsMappingUtil.fromAPIInfoListToDTO(apiInfoList, requestTimezone);
        return Response.ok().entity(apiInfoListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API information";
        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) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIInfo(org.wso2.carbon.apimgt.core.models.analytics.APIInfo) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer) APIInfoListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APIInfoListDTO)

Example 7 with APIInfoListDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoListDTO 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)

Aggregations

ArrayList (java.util.ArrayList)4 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)3 APIInfo (org.wso2.carbon.apimgt.core.models.analytics.APIInfo)3 APIInfoListDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APIInfoListDTO)3 APIInfoListDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoListDTO)2 Gson (com.google.gson.Gson)1 JsonElement (com.google.gson.JsonElement)1 JsonParser (com.google.gson.JsonParser)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ZoneId (java.time.ZoneId)1 Test (org.testng.annotations.Test)1 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 Application (org.wso2.carbon.apimgt.api.model.Application)1 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)1 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1 APISubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount)1