use of org.wso2.carbon.apimgt.api.MonetizationException 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