use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIMonetizationUsageDTO in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method getSubscriptionUsage.
/**
* Get monetization usage data for a subscription
*
* @param subscriptionId subscription Id
* @param messageContext message context
* @return monetization usage data for a subscription
*/
@Override
public Response getSubscriptionUsage(String subscriptionId, MessageContext messageContext) {
if (StringUtils.isBlank(subscriptionId)) {
String errorMessage = "Subscription ID cannot be empty or null when getting monetization usage.";
RestApiUtil.handleBadRequest(errorMessage, log);
}
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
Monetization monetizationImplementation = apiProvider.getMonetizationImplClass();
Map<String, String> billingEngineUsageData = monetizationImplementation.getCurrentUsageForSubscription(subscriptionId, apiProvider);
if (MapUtils.isEmpty(billingEngineUsageData)) {
String errorMessage = "Billing engine usage data was not found for subscription ID : " + subscriptionId;
RestApiUtil.handleBadRequest(errorMessage, log);
}
APIMonetizationUsageDTO apiMonetizationUsageDTO = new APIMonetizationUsageDTO();
apiMonetizationUsageDTO.setProperties(billingEngineUsageData);
return Response.ok().entity(apiMonetizationUsageDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Failed to retrieve billing engine usage data for subscription ID : " + subscriptionId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
} catch (MonetizationException e) {
String errorMessage = "Failed to get current usage for subscription ID : " + subscriptionId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIMonetizationUsageDTO in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method subscriptionsSubscriptionIdUsageGet.
@Override
public Response subscriptionsSubscriptionIdUsageGet(String subscriptionId, MessageContext messageContext) {
if (StringUtils.isBlank(subscriptionId)) {
String errorMessage = "Subscription ID cannot be empty or null when getting monetization usage.";
RestApiUtil.handleBadRequest(errorMessage, log);
}
try {
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
Monetization monetizationImplementation = apiConsumer.getMonetizationImplClass();
Map<String, String> billingEngineUsageData = monetizationImplementation.getCurrentUsageForSubscription(subscriptionId, RestApiCommonUtil.getLoggedInUserProvider());
if (MapUtils.isEmpty(billingEngineUsageData)) {
String errorMessage = "Billing engine usage data was not found for subscription ID : " + subscriptionId;
RestApiUtil.handleBadRequest(errorMessage, log);
}
APIMonetizationUsageDTO apiMonetizationUsageDTO = new APIMonetizationUsageDTO();
apiMonetizationUsageDTO.setProperties(billingEngineUsageData);
return Response.ok().entity(apiMonetizationUsageDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Failed to retrieve billing engine usage data for subscription ID : " + subscriptionId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
} catch (MonetizationException e) {
String errorMessage = "Failed to get current usage for subscription ID : " + subscriptionId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
Aggregations