use of org.wso2.carbon.apimgt.rest.api.analytics.dto.ApplicationCountListDTO in project carbon-apimgt by wso2.
the class AnalyticsMappingUtil method fromApplicationCountToListDTO.
/**
* Converts and ApplicationCountList to ApplicationCountListDTO.
*
* @param applicationCountList list of ApplicationCount objects
* @return corresponding ApplicationCountListDTO object
*/
public static ApplicationCountListDTO fromApplicationCountToListDTO(List<ApplicationCount> applicationCountList, ZoneId zoneId) {
ApplicationCountListDTO applicationCountListDTO = new ApplicationCountListDTO();
List<ApplicationCountDTO> applicationCountDTOList = new ArrayList<>();
applicationCountListDTO.setCount(applicationCountList.size());
for (ApplicationCount applicationCount : applicationCountList) {
applicationCountDTOList.add(fromApplicationCountToDTO(applicationCount, zoneId));
}
applicationCountListDTO.setList(applicationCountDTOList);
return applicationCountListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.analytics.dto.ApplicationCountListDTO in project carbon-apimgt by wso2.
the class AnalyticsMappingUtilTestCase method fromApplicationCountToListDTOTest.
@Test
public void fromApplicationCountToListDTOTest() {
List<ApplicationCount> applicationCountList = new ArrayList<>();
applicationCountList.add(SampleTestObjectCreator.createRandomApplicationCountObject());
applicationCountList.add(SampleTestObjectCreator.createRandomApplicationCountObject());
applicationCountList.add(SampleTestObjectCreator.createRandomApplicationCountObject());
ApplicationCountListDTO applicationCountListDTO = AnalyticsMappingUtil.fromApplicationCountToListDTO(applicationCountList, ZoneOffset.UTC);
Assert.assertEquals(applicationCountList.size(), applicationCountListDTO.getList().size());
for (int i = 0; i < applicationCountList.size(); i++) {
Assert.assertEquals(epochToISO8601DateTime(applicationCountList.get(i).getTimestamp(), ZoneOffset.UTC), applicationCountListDTO.getList().get(i).getTime());
}
}
use of org.wso2.carbon.apimgt.rest.api.analytics.dto.ApplicationCountListDTO in project carbon-apimgt by wso2.
the class ApplicationApiServiceImpl method applicationCountOverTimeGet.
/**
* Get list of Application count information
*
* @param startTime Filter for start time stamp
* @param endTime Filter for end time stamp
* @param createdBy Filter for application creator
* @param request MSF4J request
* @return Application count over time
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response applicationCountOverTimeGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
log.debug("Retrieving applications created over time. [From: {} to: {} Created By: {}]", startTime, endTime, createdBy);
Analyzer analyzer = RestApiUtil.getAnalyzer(username);
ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
List<ApplicationCount> applicationCountList = analyzer.getApplicationCount(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
ApplicationCountListDTO applicationCountListDTO = AnalyticsMappingUtil.fromApplicationCountToListDTO(applicationCountList, requestTimezone);
return Response.ok().entity(applicationCountListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving application created over time info";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations