use of org.wso2.carbon.apimgt.api.dto.UserApplicationAPIUsage in project carbon-apimgt by wso2.
the class ApiMgtDAO method getAllAPIUsageByProviderAndApiId.
/**
* @param uuid API uuid
* @param organization Organization of the API
* @return UserApplicationAPIUsage of given provider
* @throws org.wso2.carbon.apimgt.api.APIManagementException if failed to get
* UserApplicationAPIUsage for given provider
*/
public UserApplicationAPIUsage[] getAllAPIUsageByProviderAndApiId(String uuid, String organization) throws APIManagementException {
Connection connection = null;
PreparedStatement ps = null;
ResultSet result = null;
try {
String sqlQuery = SQLConstants.GET_APP_API_USAGE_BY_UUID_SQL;
connection = APIMgtDBUtil.getConnection();
ps = connection.prepareStatement(sqlQuery);
ps.setString(1, uuid);
ps.setString(2, organization);
result = ps.executeQuery();
Map<String, UserApplicationAPIUsage> userApplicationUsages = new TreeMap<String, UserApplicationAPIUsage>();
while (result.next()) {
int subId = result.getInt("SUBSCRIPTION_ID");
String userId = result.getString("USER_ID");
String application = result.getString("APPNAME");
int appId = result.getInt("APPLICATION_ID");
String subStatus = result.getString("SUB_STATUS");
String subsCreateState = result.getString("SUBS_CREATE_STATE");
String key = userId + "::" + application;
UserApplicationAPIUsage usage = userApplicationUsages.get(key);
if (usage == null) {
usage = new UserApplicationAPIUsage();
usage.setUserId(userId);
usage.setApplicationName(application);
usage.setAppId(appId);
userApplicationUsages.put(key, usage);
}
APIIdentifier apiId = new APIIdentifier(result.getString("API_PROVIDER"), result.getString("API_NAME"), result.getString("API_VERSION"));
SubscribedAPI apiSubscription = new SubscribedAPI(new Subscriber(userId), apiId);
apiSubscription.setSubStatus(subStatus);
apiSubscription.setSubCreatedStatus(subsCreateState);
apiSubscription.setUUID(result.getString("SUB_UUID"));
apiSubscription.setTier(new Tier(result.getString("SUB_TIER_ID")));
Application applicationObj = new Application(result.getString("APP_UUID"));
apiSubscription.setApplication(applicationObj);
usage.addApiSubscriptions(apiSubscription);
}
return userApplicationUsages.values().toArray(new UserApplicationAPIUsage[userApplicationUsages.size()]);
} catch (SQLException e) {
handleException("Failed to find API Usage for API with UUID :" + uuid, e);
return null;
} finally {
APIMgtDBUtil.closeAllConnections(ps, connection, result);
}
}
use of org.wso2.carbon.apimgt.api.dto.UserApplicationAPIUsage in project carbon-apimgt by wso2.
the class APIProviderImpl method getAPIUsageByAPIId.
/**
* Returns usage details of a particular API
*
* @param uuid API uuid
* @param organization identifier of the organization
* @return UserApplicationAPIUsages for given provider
* @throws org.wso2.carbon.apimgt.api.APIManagementException If failed to get UserApplicationAPIUsage
*/
@Override
public List<SubscribedAPI> getAPIUsageByAPIId(String uuid, String organization) throws APIManagementException {
APIIdentifier identifier = apiMgtDAO.getAPIIdentifierFromUUID(uuid);
List<SubscribedAPI> subscribedAPIs = new ArrayList<>();
if (identifier != null) {
APIIdentifier apiIdEmailReplaced = new APIIdentifier(APIUtil.replaceEmailDomain(identifier.getProviderName()), identifier.getApiName(), identifier.getVersion());
UserApplicationAPIUsage[] allApiResult = apiMgtDAO.getAllAPIUsageByProviderAndApiId(uuid, organization);
for (UserApplicationAPIUsage usage : allApiResult) {
for (SubscribedAPI apiSubscription : usage.getApiSubscriptions()) {
APIIdentifier subsApiId = apiSubscription.getApiId();
APIIdentifier subsApiIdEmailReplaced = new APIIdentifier(APIUtil.replaceEmailDomain(subsApiId.getProviderName()), subsApiId.getApiName(), subsApiId.getVersion());
if (subsApiIdEmailReplaced.equals(apiIdEmailReplaced)) {
subscribedAPIs.add(apiSubscription);
}
}
}
}
return subscribedAPIs;
}
Aggregations