use of org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo in project carbon-apimgt by wso2.
the class AnalyticsDAOImpl method getSubscriptionInfo.
/**
* @see AnalyticsDAO#getSubscriptionInfo(Instant, Instant, String)
*/
@Override
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
public List<SubscriptionInfo> getSubscriptionInfo(Instant fromTimestamp, Instant toTimestamp, String createdBy) throws APIMgtDAOException {
final String query;
if (StringUtils.isNotEmpty(createdBy)) {
query = "SELECT sub.UUID, api.NAME as API_NAME, api.VERSION as API_VERSION, app.NAME " + "as APP_NAME, app.DESCRIPTION, sub.CREATED_TIME , policy.DISPLAY_NAME , sub.SUB_STATUS " + "FROM AM_API api, AM_SUBSCRIPTION sub, AM_APPLICATION app, AM_SUBSCRIPTION_POLICY policy " + "WHERE (sub.CREATED_TIME BETWEEN ? AND ?) " + "AND api.UUID = sub.API_ID " + "AND sub.APPLICATION_ID = app.UUID " + "AND sub.CREATED_BY= ? " + "AND sub.TIER_ID = policy.UUID ";
} else {
query = "SELECT sub.UUID, api.NAME as API_NAME, api.VERSION as API_VERSION, app.NAME " + "as APP_NAME, app.DESCRIPTION, sub.CREATED_TIME , policy.DISPLAY_NAME , sub.SUB_STATUS " + "FROM AM_API api, AM_SUBSCRIPTION sub, AM_APPLICATION app, AM_SUBSCRIPTION_POLICY policy " + "WHERE (sub.CREATED_TIME BETWEEN ? AND ?) " + "AND api.UUID = sub.API_ID " + "AND sub.APPLICATION_ID = app.UUID " + "AND sub.TIER_ID = policy.UUID ";
}
List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>();
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setTimestamp(1, Timestamp.from(fromTimestamp));
statement.setTimestamp(2, Timestamp.from(toTimestamp));
if (StringUtils.isNotEmpty(createdBy)) {
statement.setString(3, createdBy);
}
log.debug("Executing query: {} ", query);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
while (rs.next()) {
SubscriptionInfo subscriptionInfo = new SubscriptionInfo();
subscriptionInfo.setId(rs.getString("UUID"));
subscriptionInfo.setName(rs.getString("API_NAME"));
subscriptionInfo.setVersion(rs.getString("API_VERSION"));
subscriptionInfo.setAppName(rs.getString("APP_NAME"));
subscriptionInfo.setDescription(rs.getString("DESCRIPTION"));
subscriptionInfo.setCreatedTime(rs.getTimestamp("CREATED_TIME").getTime());
subscriptionInfo.setSubscriptionStatus(rs.getString("SUB_STATUS"));
subscriptionInfo.setSubscriptionTier(rs.getString("DISPLAY_NAME"));
subscriptionInfoList.add(subscriptionInfo);
}
}
} catch (SQLException e) {
throw new APIMgtDAOException("Error while creating database connection/prepared-statement", e);
}
return subscriptionInfoList;
}
use of org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo in project carbon-apimgt by wso2.
the class SubscriptionApiServiceImpl method subscriptionListGet.
/**
* Get list of subscriptions info 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 information over time
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response subscriptionListGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
log.debug("Retrieving subscriptions info. [From: {} To: {} Created By: {}]", startTime, endTime, createdBy);
Analyzer analyzer = RestApiUtil.getAnalyzer(username);
ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
List<SubscriptionInfo> subscriptionInfoList = analyzer.getSubscriptionInfo(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
SubscriptionInfoListDTO subscriptionInfoListDTO = AnalyticsMappingUtil.fromSubscriptionInfoListToDTO(subscriptionInfoList, requestTimezone);
return Response.ok().entity(subscriptionInfoListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving subscription information";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations