use of org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionCountListDTO 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;
}
use of org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionCountListDTO in project carbon-apimgt by wso2.
the class AnalyticsMappingUtilTestCase method fromSubscriptionCountListToDTOTest.
@Test
public void fromSubscriptionCountListToDTOTest() {
List<SubscriptionCount> subscriptionCountList = new ArrayList<>();
subscriptionCountList.add(SampleTestObjectCreator.createRandomSubscriptionCountObject());
subscriptionCountList.add(SampleTestObjectCreator.createRandomSubscriptionCountObject());
subscriptionCountList.add(SampleTestObjectCreator.createRandomSubscriptionCountObject());
SubscriptionCountListDTO subscriptionCountListToDTO = AnalyticsMappingUtil.fromSubscriptionCountListToDTO(subscriptionCountList, ZoneOffset.UTC);
Assert.assertEquals(subscriptionCountList.size(), subscriptionCountListToDTO.getList().size());
for (int i = 0; i < subscriptionCountList.size(); i++) {
Assert.assertEquals(Long.valueOf(subscriptionCountList.get(i).getCount()), Long.valueOf(subscriptionCountListToDTO.getList().get(i).getCount()));
Assert.assertEquals(epochToISO8601DateTime(subscriptionCountList.get(i).getTimestamp(), ZoneOffset.UTC), subscriptionCountListToDTO.getList().get(i).getTime());
}
}
use of org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionCountListDTO 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();
}
}
use of org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionCountListDTO 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;
}
Aggregations