use of org.wso2.carbon.apimgt.rest.api.analytics.dto.APIInfoListDTO in project carbon-apimgt by wso2.
the class AnalyticsMappingUtil method fromAPIInfoListToDTO.
/**
* Converts and APIInfoList to APIInfoListDTO.
*
* @param apiInfoList list of ApiInfo objects
* @return corresponding APIInfoListDTO object
*/
public static APIInfoListDTO fromAPIInfoListToDTO(List<APIInfo> apiInfoList, ZoneId zoneId) {
APIInfoListDTO apiInfoListDTO = new APIInfoListDTO();
List<APIInfoDTO> apiInfoDTOList = new ArrayList<>();
apiInfoListDTO.setCount(apiInfoList.size());
for (APIInfo apiInfo : apiInfoList) {
apiInfoDTOList.add(fromAPIInfoToDTO(apiInfo, zoneId));
}
apiInfoListDTO.setList(apiInfoDTOList);
return apiInfoListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.analytics.dto.APIInfoListDTO in project carbon-apimgt by wso2.
the class AnalyticsMappingUtilTestCase method fromAPIInfoListToDTOTest.
@Test
public void fromAPIInfoListToDTOTest() {
List<APIInfo> apiInfoList = new ArrayList<>();
apiInfoList.add(SampleTestObjectCreator.createRandomAPIInfoObject());
apiInfoList.add(SampleTestObjectCreator.createRandomAPIInfoObject());
apiInfoList.add(SampleTestObjectCreator.createRandomAPIInfoObject());
APIInfoListDTO apiInfoListDTO = AnalyticsMappingUtil.fromAPIInfoListToDTO(apiInfoList, ZoneOffset.UTC);
Assert.assertEquals(apiInfoList.size(), apiInfoListDTO.getList().size());
for (int i = 0; i < apiInfoList.size(); i++) {
Assert.assertEquals(epochToISO8601DateTime(apiInfoList.get(i).getCreatedTime(), ZoneOffset.UTC), apiInfoListDTO.getList().get(i).getTime());
Assert.assertEquals(apiInfoList.get(i).getName(), apiInfoListDTO.getList().get(i).getName());
Assert.assertEquals(apiInfoList.get(i).getContext(), apiInfoListDTO.getList().get(i).getContext());
Assert.assertEquals(apiInfoList.get(i).getDescription(), apiInfoListDTO.getList().get(i).getDescription());
Assert.assertEquals(apiInfoList.get(i).getLifeCycleStatus(), apiInfoListDTO.getList().get(i).getLifeCycleStatus());
Assert.assertEquals(apiInfoList.get(i).getProvider(), apiInfoListDTO.getList().get(i).getProvider());
Assert.assertEquals(apiInfoList.get(i).getVersion(), apiInfoListDTO.getList().get(i).getVersion());
Assert.assertEquals(apiInfoList.get(i).getId(), apiInfoListDTO.getList().get(i).getId());
}
}
use of org.wso2.carbon.apimgt.rest.api.analytics.dto.APIInfoListDTO in project carbon-apimgt by wso2.
the class ApiApiServiceImpl method apiListGet.
/**
* Get list of API Info
*
* @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 List
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apiListGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
log.debug("Retrieving API information. [From: {} To: {} Created By:{} ]", startTime, endTime, createdBy);
Analyzer analyzer = RestApiUtil.getAnalyzer(username);
ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
List<APIInfo> apiInfoList = analyzer.getAPIInfo(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
APIInfoListDTO apiInfoListDTO = AnalyticsMappingUtil.fromAPIInfoListToDTO(apiInfoList, requestTimezone);
return Response.ok().entity(apiInfoListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving API information";
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.APIInfoListDTO 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