Search in sources :

Example 1 with SubscriptionInfoListDTO

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

the class AnalyticsMappingUtil method fromSubscriptionInfoListToDTO.

public static SubscriptionInfoListDTO fromSubscriptionInfoListToDTO(List<SubscriptionInfo> subscriptionInfoList, ZoneId zoneId) {
    SubscriptionInfoListDTO subscriptionCountListDTO = new SubscriptionInfoListDTO();
    List<SubscriptionInfoDTO> subscriptionInfoDTOList = new ArrayList<>();
    subscriptionCountListDTO.setCount(subscriptionInfoList.size());
    for (SubscriptionInfo subscriptionInfo : subscriptionInfoList) {
        SubscriptionInfoDTO subscriptionInfoDTO = new SubscriptionInfoDTO();
        subscriptionInfoDTO.setId(subscriptionInfo.getId());
        subscriptionInfoDTO.setName(subscriptionInfo.getName());
        subscriptionInfoDTO.setVersion(subscriptionInfo.getVersion());
        subscriptionInfoDTO.setAppName(subscriptionInfo.getAppName());
        subscriptionInfoDTO.setDescription(subscriptionInfo.getDescription());
        subscriptionInfoDTO.setCreatedTime(epochToISO8601DateTime(subscriptionInfo.getCreatedTime(), zoneId));
        subscriptionInfoDTO.setSubscriptionStatus(subscriptionInfo.getSubscriptionStatus());
        subscriptionInfoDTO.setSubscriptionTier(subscriptionInfo.getSubscriptionTier());
        subscriptionInfoDTOList.add(subscriptionInfoDTO);
    }
    subscriptionCountListDTO.setList(subscriptionInfoDTOList);
    return subscriptionCountListDTO;
}
Also used : SubscriptionInfoDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionInfoDTO) SubscriptionInfoListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionInfoListDTO) ArrayList(java.util.ArrayList) SubscriptionInfo(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo)

Example 2 with SubscriptionInfoListDTO

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

the class AnalyticsMappingUtilTestCase method fromSubscriptionInfoListToDTOTest.

@Test
public void fromSubscriptionInfoListToDTOTest() {
    List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>();
    subscriptionInfoList.add(SampleTestObjectCreator.createRandomSubscriptionInfoObject());
    subscriptionInfoList.add(SampleTestObjectCreator.createRandomSubscriptionInfoObject());
    subscriptionInfoList.add(SampleTestObjectCreator.createRandomSubscriptionInfoObject());
    SubscriptionInfoListDTO subscriptionInfoListDTO = AnalyticsMappingUtil.fromSubscriptionInfoListToDTO(subscriptionInfoList, ZoneOffset.UTC);
    Assert.assertEquals(subscriptionInfoList.size(), subscriptionInfoListDTO.getList().size());
    for (int i = 0; i < subscriptionInfoList.size(); i++) {
        Assert.assertEquals(subscriptionInfoList.get(i).getName(), subscriptionInfoListDTO.getList().get(i).getName());
        Assert.assertEquals(subscriptionInfoList.get(i).getId(), subscriptionInfoListDTO.getList().get(i).getId());
        Assert.assertEquals(subscriptionInfoList.get(i).getDescription(), subscriptionInfoListDTO.getList().get(i).getDescription());
        Assert.assertEquals(subscriptionInfoList.get(i).getAppName(), subscriptionInfoListDTO.getList().get(i).getAppName());
        Assert.assertEquals(subscriptionInfoList.get(i).getVersion(), subscriptionInfoListDTO.getList().get(i).getVersion());
        Assert.assertEquals(subscriptionInfoList.get(i).getSubscriptionStatus(), subscriptionInfoListDTO.getList().get(i).getSubscriptionStatus());
        Assert.assertEquals(subscriptionInfoList.get(i).getSubscriptionTier(), subscriptionInfoListDTO.getList().get(i).getSubscriptionTier());
        Assert.assertEquals(epochToISO8601DateTime(subscriptionInfoList.get(i).getCreatedTime(), ZoneOffset.UTC), subscriptionInfoListDTO.getList().get(i).getCreatedTime());
    }
}
Also used : SubscriptionInfoListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionInfoListDTO) ArrayList(java.util.ArrayList) SubscriptionInfo(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo) Test(org.testng.annotations.Test)

Example 3 with SubscriptionInfoListDTO

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

the class SubscriptionApiServiceImpl method subscriptionListGet.

/**
 * Get list of subscriptions info 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 information over time
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response subscriptionListGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        log.debug("Retrieving subscriptions info. [From: {}  To: {} Created By: {}]", startTime, endTime, createdBy);
        Analyzer analyzer = RestApiUtil.getAnalyzer(username);
        ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
        List<SubscriptionInfo> subscriptionInfoList = analyzer.getSubscriptionInfo(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
        SubscriptionInfoListDTO subscriptionInfoListDTO = AnalyticsMappingUtil.fromSubscriptionInfoListToDTO(subscriptionInfoList, requestTimezone);
        return Response.ok().entity(subscriptionInfoListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving subscription 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) SubscriptionInfoListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionInfoListDTO) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) SubscriptionInfo(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer)

Example 4 with SubscriptionInfoListDTO

use of org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionInfoListDTO 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)3 SubscriptionInfo (org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo)3 SubscriptionInfoListDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionInfoListDTO)3 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 APISubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount)1 SubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount)1 APISubscriptionCountDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APISubscriptionCountDTO)1 APISubscriptionCountListDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APISubscriptionCountListDTO)1 SubscriptionCountDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionCountDTO)1 SubscriptionCountListDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionCountListDTO)1 SubscriptionInfoDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionInfoDTO)1 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)1