Search in sources :

Example 1 with APISubscriptionCountListDTO

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

the class AnalyticsMappingUtil method fromAPISubscriptionCountListToDTO.

/**
 * Converts and APISubscriptionCountList to APISubscriptionCountListDTO.
 *
 * @param apiSubscriptionCountList list of APISubscriptionCount objects
 * @return corresponding APISubscriptionCountListDTO object
 */
public static APISubscriptionCountListDTO fromAPISubscriptionCountListToDTO(List<APISubscriptionCount> apiSubscriptionCountList) {
    APISubscriptionCountListDTO apiSubscriptionListDTO = new APISubscriptionCountListDTO();
    List<APISubscriptionCountDTO> apiSubscriptionDTOList = new ArrayList<>();
    apiSubscriptionListDTO.setCount(apiSubscriptionCountList.size());
    for (APISubscriptionCount apiSubscriptionCount : apiSubscriptionCountList) {
        APISubscriptionCountDTO apiSubscriptionDTO = new APISubscriptionCountDTO();
        apiSubscriptionDTO.setId(apiSubscriptionCount.getId());
        apiSubscriptionDTO.setName(apiSubscriptionCount.getName());
        apiSubscriptionDTO.setVersion(apiSubscriptionCount.getVersion());
        apiSubscriptionDTO.setProvider(apiSubscriptionCount.getProvider());
        apiSubscriptionDTO.setCount(apiSubscriptionCount.getCount());
        apiSubscriptionDTOList.add(apiSubscriptionDTO);
    }
    apiSubscriptionListDTO.setList(apiSubscriptionDTOList);
    return apiSubscriptionListDTO;
}
Also used : APISubscriptionCountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APISubscriptionCountListDTO) APISubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount) APISubscriptionCountDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APISubscriptionCountDTO) ArrayList(java.util.ArrayList)

Example 2 with APISubscriptionCountListDTO

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

the class AnalyticsMappingUtilTestCase method fromAPISubscriptionCountListToDTOTest.

@Test
public void fromAPISubscriptionCountListToDTOTest() {
    List<APISubscriptionCount> apiSubscriptionCountList = new ArrayList<>();
    apiSubscriptionCountList.add(SampleTestObjectCreator.createRandomAPISubscriptionCountObject());
    apiSubscriptionCountList.add(SampleTestObjectCreator.createRandomAPISubscriptionCountObject());
    apiSubscriptionCountList.add(SampleTestObjectCreator.createRandomAPISubscriptionCountObject());
    APISubscriptionCountListDTO apiSubscriptionCountListDTO = AnalyticsMappingUtil.fromAPISubscriptionCountListToDTO(apiSubscriptionCountList);
    Assert.assertEquals(apiSubscriptionCountList.size(), apiSubscriptionCountListDTO.getList().size());
    for (int i = 0; i < apiSubscriptionCountList.size(); i++) {
        Assert.assertEquals(apiSubscriptionCountList.get(i).getProvider(), apiSubscriptionCountListDTO.getList().get(i).getProvider());
        Assert.assertEquals(apiSubscriptionCountList.get(i).getVersion(), apiSubscriptionCountListDTO.getList().get(i).getVersion());
        Assert.assertEquals(apiSubscriptionCountList.get(i).getId(), apiSubscriptionCountListDTO.getList().get(i).getId());
    }
}
Also used : APISubscriptionCountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APISubscriptionCountListDTO) APISubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 3 with APISubscriptionCountListDTO

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

Aggregations

APISubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount)3 APISubscriptionCountListDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APISubscriptionCountListDTO)3 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)1 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)1 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1 APISubscriptionCountDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APISubscriptionCountDTO)1 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)1