Search in sources :

Example 6 with MonetizationException

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;
}
Also used : Monetization(org.wso2.carbon.apimgt.api.model.Monetization) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) MonetizationException(org.wso2.carbon.apimgt.api.MonetizationException) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) APIMonetizationUsageDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIMonetizationUsageDTO)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)6 MonetizationException (org.wso2.carbon.apimgt.api.MonetizationException)6 Monetization (org.wso2.carbon.apimgt.api.model.Monetization)5 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)4 API (org.wso2.carbon.apimgt.api.model.API)3 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)3 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)3 APIMonetizationInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIMonetizationInfoDTO)2 Gson (com.google.gson.Gson)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)1 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)1 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)1 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 APIRevision (org.wso2.carbon.apimgt.api.model.APIRevision)1