use of org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO in project carbon-apimgt by wso2.
the class ApiApiServiceImpl method apiCountOverTimeGet.
/**
* Get list of API count information
*
* @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 Count information
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apiCountOverTimeGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
log.debug("Retrieving APIs created over time. [From: {} To: {} Created By: {}]", startTime, endTime, createdBy);
Analyzer analyzer = RestApiUtil.getAnalyzer(username);
ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
List<APICount> apiCountList = analyzer.getAPICount(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
APICountListDTO apiCountListDTO = AnalyticsMappingUtil.fromAPICountToListDTO(apiCountList, requestTimezone);
return Response.ok().entity(apiCountListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving API created over time info";
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.APICountListDTO in project carbon-apimgt by wso2.
the class AnalyticsMappingUtil method fromAPICountToListDTO.
/**
* Converts and APICountList to APICountDTO.
*
* @param apiCountList list of APICount objects
* @return corresponding APICountListDTO object
*/
public static APICountListDTO fromAPICountToListDTO(List<APICount> apiCountList, ZoneId zoneId) {
APICountListDTO apiCountListDTO = new APICountListDTO();
List<APICountDTO> apiCountDTOList = new ArrayList<>();
apiCountListDTO.setCount(apiCountList.size());
for (APICount apiInfo : apiCountList) {
apiCountDTOList.add(fromAPICountToDTO(apiInfo, zoneId));
}
apiCountListDTO.setList(apiCountDTOList);
return apiCountListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO in project carbon-apimgt by wso2.
the class AnalyticsMappingUtilTestCase method fromAPICountToListDTOTest.
@Test
public void fromAPICountToListDTOTest() {
List<APICount> apiCountList = new ArrayList<>();
apiCountList.add(SampleTestObjectCreator.createRandomAPICountObject());
apiCountList.add(SampleTestObjectCreator.createRandomAPICountObject());
apiCountList.add(SampleTestObjectCreator.createRandomAPICountObject());
APICountListDTO apiCountListDTO = AnalyticsMappingUtil.fromAPICountToListDTO(apiCountList, ZoneOffset.UTC);
Assert.assertEquals(apiCountList.size(), apiCountListDTO.getList().size());
for (int i = 0; i < apiCountList.size(); i++) {
Assert.assertEquals(epochToISO8601DateTime(apiCountList.get(i).getTimestamp(), ZoneOffset.UTC), apiCountListDTO.getList().get(i).getTime());
}
}
Aggregations