Search in sources :

Example 21 with Analyzer

use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.

the class AnalyzerImplTestCase method testGetAPISubscrptionCount.

@Test(description = "Get Subscription count for API test")
public void testGetAPISubscrptionCount() throws APIManagementException {
    AnalyticsDAO analyticsDAO = Mockito.mock(AnalyticsDAO.class);
    APISubscriptionCount apiSubscriptionCount = new APISubscriptionCount();
    List<APISubscriptionCount> apiSubscriptionCountList = new ArrayList<>();
    apiSubscriptionCountList.add(apiSubscriptionCount);
    Analyzer analyzer = getAnalyzerImpl(analyticsDAO);
    when(analyticsDAO.getAPISubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenReturn(apiSubscriptionCountList);
    List<APISubscriptionCount> apiSubscriptionCountResult = analyzer.getAPISubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
    Assert.assertNotNull(apiSubscriptionCountResult);
    verify(analyticsDAO, Mockito.times(1)).getAPISubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
    // Error path
    Mockito.when(analyticsDAO.getAPISubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenThrow(APIMgtDAOException.class);
    try {
        analyzer.getAPISubscriptionCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Error occurred while fetching API subscription count information");
    }
}
Also used : AnalyticsDAO(org.wso2.carbon.apimgt.core.dao.AnalyticsDAO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APISubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount) ArrayList(java.util.ArrayList) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer) Test(org.testng.annotations.Test)

Example 22 with Analyzer

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

Example 23 with Analyzer

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

Example 24 with Analyzer

use of org.wso2.carbon.apimgt.core.api.Analyzer 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 25 with Analyzer

use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.

the class SubscriptionApiServiceImpl method subscriptionCountOverTimeGet.

/**
 * Get list of subscriptions created over time
 *
 * @param startTime Filter for start time stamp
 * @param endTime   Filter for end time stamp
 * @param createdBy Filter for createdBy
 * @param request   MSF4J request
 * @return Subscriptions count over time
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response subscriptionCountOverTimeGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        log.debug("Retrieving subscriptions created over time. [From: {} To: {} Created By: {}]", startTime, endTime, createdBy);
        Analyzer analyzer = RestApiUtil.getAnalyzer(username);
        ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
        List<SubscriptionCount> subscriptionCount = analyzer.getSubscriptionCount(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
        SubscriptionCountListDTO subscriptionListDTO = AnalyticsMappingUtil.fromSubscriptionCountListToDTO(subscriptionCount, requestTimezone);
        return Response.ok().entity(subscriptionListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving Subscription Count";
        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) SubscriptionCountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionCountListDTO) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer) SubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount)

Aggregations

Test (org.testng.annotations.Test)27 JSONConfig (org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig)15 JSONAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer)14 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)13 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)12 BeforeTest (org.testng.annotations.BeforeTest)7 XMLAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.XMLAnalyzer)7 ArrayList (java.util.ArrayList)6 AnalyticsDAO (org.wso2.carbon.apimgt.core.dao.AnalyticsDAO)6 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)6 ZoneId (java.time.ZoneId)5 APISubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount)3 BBoolean (org.ballerinalang.model.values.BBoolean)2 APIMThreatAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.APIMThreatAnalyzer)2 XMLConfig (org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.XMLConfig)2 APICount (org.wso2.carbon.apimgt.core.models.analytics.APICount)2 APIInfo (org.wso2.carbon.apimgt.core.models.analytics.APIInfo)2 ApplicationCount (org.wso2.carbon.apimgt.core.models.analytics.ApplicationCount)2 SubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount)2 SubscriptionInfo (org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo)2