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");
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations