Search in sources :

Example 1 with APICountListDTO

use of org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO in project carbon-apimgt by wso2.

the class ApiApiServiceImpl method apiCountOverTimeGet.

/**
 * Get list of API count information
 *
 * @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 Count information
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response apiCountOverTimeGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        log.debug("Retrieving APIs created over time. [From: {}  To: {} Created By: {}]", startTime, endTime, createdBy);
        Analyzer analyzer = RestApiUtil.getAnalyzer(username);
        ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
        List<APICount> apiCountList = analyzer.getAPICount(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
        APICountListDTO apiCountListDTO = AnalyticsMappingUtil.fromAPICountToListDTO(apiCountList, requestTimezone);
        return Response.ok().entity(apiCountListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API created over time info";
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APICount(org.wso2.carbon.apimgt.core.models.analytics.APICount) ZoneId(java.time.ZoneId) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APICountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer)

Example 2 with APICountListDTO

use of org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO in project carbon-apimgt by wso2.

the class AnalyticsMappingUtil method fromAPICountToListDTO.

/**
 * Converts and APICountList to APICountDTO.
 *
 * @param apiCountList list of APICount objects
 * @return corresponding APICountListDTO object
 */
public static APICountListDTO fromAPICountToListDTO(List<APICount> apiCountList, ZoneId zoneId) {
    APICountListDTO apiCountListDTO = new APICountListDTO();
    List<APICountDTO> apiCountDTOList = new ArrayList<>();
    apiCountListDTO.setCount(apiCountList.size());
    for (APICount apiInfo : apiCountList) {
        apiCountDTOList.add(fromAPICountToDTO(apiInfo, zoneId));
    }
    apiCountListDTO.setList(apiCountDTOList);
    return apiCountListDTO;
}
Also used : APICount(org.wso2.carbon.apimgt.core.models.analytics.APICount) APICountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO) ArrayList(java.util.ArrayList) APICountDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountDTO)

Example 3 with APICountListDTO

use of org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO in project carbon-apimgt by wso2.

the class AnalyticsMappingUtilTestCase method fromAPICountToListDTOTest.

@Test
public void fromAPICountToListDTOTest() {
    List<APICount> apiCountList = new ArrayList<>();
    apiCountList.add(SampleTestObjectCreator.createRandomAPICountObject());
    apiCountList.add(SampleTestObjectCreator.createRandomAPICountObject());
    apiCountList.add(SampleTestObjectCreator.createRandomAPICountObject());
    APICountListDTO apiCountListDTO = AnalyticsMappingUtil.fromAPICountToListDTO(apiCountList, ZoneOffset.UTC);
    Assert.assertEquals(apiCountList.size(), apiCountListDTO.getList().size());
    for (int i = 0; i < apiCountList.size(); i++) {
        Assert.assertEquals(epochToISO8601DateTime(apiCountList.get(i).getTimestamp(), ZoneOffset.UTC), apiCountListDTO.getList().get(i).getTime());
    }
}
Also used : APICount(org.wso2.carbon.apimgt.core.models.analytics.APICount) APICountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Aggregations

APICount (org.wso2.carbon.apimgt.core.models.analytics.APICount)3 APICountListDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO)3 ArrayList (java.util.ArrayList)2 ZoneId (java.time.ZoneId)1 Test (org.testng.annotations.Test)1 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)1 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1 APICountDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountDTO)1 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)1