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;
}
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());
}
}
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();
}
}
Aggregations