Search in sources :

Example 6 with ApplicationCount

use of org.wso2.carbon.apimgt.core.models.analytics.ApplicationCount 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());
    }
}
Also used : ArrayList(java.util.ArrayList) ApplicationCount(org.wso2.carbon.apimgt.core.models.analytics.ApplicationCount) ApplicationCountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.ApplicationCountListDTO) Test(org.testng.annotations.Test)

Example 7 with ApplicationCount

use of org.wso2.carbon.apimgt.core.models.analytics.ApplicationCount 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();
    }
}
Also used : ZoneId(java.time.ZoneId) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer) ApplicationCount(org.wso2.carbon.apimgt.core.models.analytics.ApplicationCount) ApplicationCountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.ApplicationCountListDTO)

Example 8 with ApplicationCount

use of org.wso2.carbon.apimgt.core.models.analytics.ApplicationCount in project carbon-apimgt by wso2.

the class AnalyticsMappingUtil method fromApplicationCountToDTO.

private static ApplicationCountDTO fromApplicationCountToDTO(ApplicationCount applicationCount, ZoneId zoneId) {
    ApplicationCountDTO applicationCountDTO = new ApplicationCountDTO();
    applicationCountDTO.setTime(epochToISO8601DateTime(applicationCount.getTimestamp(), zoneId));
    applicationCountDTO.setCount(applicationCount.getCount());
    return applicationCountDTO;
}
Also used : ApplicationCountDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.ApplicationCountDTO)

Aggregations

ApplicationCount (org.wso2.carbon.apimgt.core.models.analytics.ApplicationCount)7 ArrayList (java.util.ArrayList)4 Test (org.testng.annotations.Test)3 ApplicationCountListDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.ApplicationCountListDTO)3 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)2 AnalyticsDAO (org.wso2.carbon.apimgt.core.dao.AnalyticsDAO)2 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)2 ApplicationCountDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.ApplicationCountDTO)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Instant (java.time.Instant)1 ZoneId (java.time.ZoneId)1 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)1 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)1