Search in sources :

Example 21 with DataLoadingException

use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.

the class SubscriptionDataLoaderImpl method loadAllSubscriptionPolicies.

@Override
public List<SubscriptionPolicy> loadAllSubscriptionPolicies(String tenantDomain) throws DataLoadingException {
    String subscriptionPoliciesEP = APIConstants.SubscriptionValidationResources.SUBSCRIPTION_POLICIES;
    List<SubscriptionPolicy> subscriptionPolicies = new ArrayList<>();
    String responseString = null;
    try {
        responseString = invokeService(subscriptionPoliciesEP, tenantDomain);
    } catch (IOException e) {
        String msg = "Error while executing the http client " + subscriptionPoliciesEP;
        log.error(msg, e);
        throw new DataLoadingException(msg, e);
    }
    if (responseString != null && !responseString.isEmpty()) {
        subscriptionPolicies = (new Gson().fromJson(responseString, SubscriptionPolicyList.class)).getList();
    }
    return subscriptionPolicies;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) SubscriptionPolicy(org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy) ArrayList(java.util.ArrayList) SubscriptionPolicyList(org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicyList) Gson(com.google.gson.Gson) IOException(java.io.IOException)

Example 22 with DataLoadingException

use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.

the class SubscriptionDataLoaderImpl method getApplicationById.

@Override
public Application getApplicationById(int appId) throws DataLoadingException {
    String endPoint = APIConstants.SubscriptionValidationResources.APPLICATIONS + "?appId=" + appId;
    Application application = null;
    String responseString;
    try {
        responseString = invokeService(endPoint, null);
    } catch (IOException e) {
        String msg = "Error while executing the http client " + endPoint;
        log.error(msg, e);
        throw new DataLoadingException(msg, e);
    }
    if (responseString != null && !responseString.isEmpty()) {
        ApplicationList list = new Gson().fromJson(responseString, ApplicationList.class);
        if (list.getList() != null && !list.getList().isEmpty()) {
            application = list.getList().get(0);
        }
    }
    return application;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) ApplicationList(org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationList) Gson(com.google.gson.Gson) IOException(java.io.IOException) Application(org.wso2.carbon.apimgt.keymgt.model.entity.Application)

Example 23 with DataLoadingException

use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.

the class SubscriptionDataLoaderImpl method getSubscriptionPolicy.

@Override
public SubscriptionPolicy getSubscriptionPolicy(String policyName, String tenantDomain) throws DataLoadingException {
    String endPoint = APIConstants.SubscriptionValidationResources.SUBSCRIPTION_POLICIES + "?policyName=" + policyName;
    SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy();
    if (log.isDebugEnabled()) {
        log.debug("getSubscriptionPolicy for " + policyName + " for tenant " + tenantDomain);
    }
    String responseString;
    try {
        responseString = invokeService(endPoint, tenantDomain);
    } catch (IOException e) {
        String msg = "Error while executing the http client " + endPoint;
        log.error(msg, e);
        throw new DataLoadingException(msg, e);
    }
    if (responseString != null && !responseString.isEmpty()) {
        SubscriptionPolicyList list = new Gson().fromJson(responseString, SubscriptionPolicyList.class);
        if (list.getList() != null && !list.getList().isEmpty()) {
            subscriptionPolicy = list.getList().get(0);
        }
    }
    return subscriptionPolicy;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) SubscriptionPolicy(org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy) SubscriptionPolicyList(org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicyList) Gson(com.google.gson.Gson) IOException(java.io.IOException)

Example 24 with DataLoadingException

use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.

the class SubscriptionDataStoreImpl method getSubscriptionById.

@Override
public Subscription getSubscriptionById(int appId, int apiId) {
    String subscriptionCacheKey = SubscriptionDataStoreUtil.getSubscriptionCacheKey(appId, apiId);
    String synchronizeKey = "SubscriptionDataStoreImpl-Subscription-" + subscriptionCacheKey;
    Subscription subscription = subscriptionMap.get(subscriptionCacheKey);
    if (subscription == null) {
        synchronized (synchronizeKey.intern()) {
            subscription = subscriptionMap.get(subscriptionCacheKey);
            if (subscription != null) {
                return subscription;
            }
            try {
                subscription = new SubscriptionDataLoaderImpl().getSubscriptionById(Integer.toString(apiId), Integer.toString(appId));
            } catch (DataLoadingException e) {
                log.error("Error while Retrieving Subscription Data From Internal API", e);
            }
            if (subscription != null && !StringUtils.isEmpty(subscription.getSubscriptionId())) {
                // load to the memory
                log.debug("Loading Subscription to the in-memory datastore.");
                subscriptionMap.put(subscription.getCacheKey(), subscription);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Retrieving API Subscription with Application " + appId + " and APIId : " + apiId);
        if (subscription != null) {
            log.debug("Retrieved API Subscription with Application " + appId + " and APIId : " + apiId + " is " + subscription.toString());
        } else {
            log.debug("Retrieved API Subscription with Application " + appId + " and APIId : " + apiId + " is " + "empty.");
        }
    }
    return subscription;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) Subscription(org.wso2.carbon.apimgt.keymgt.model.entity.Subscription)

Example 25 with DataLoadingException

use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.

the class SubscriptionDataStoreImpl method getKeyMappingByKeyAndKeyManager.

@Override
public ApplicationKeyMapping getKeyMappingByKeyAndKeyManager(String key, String keyManager) {
    ApplicationKeyMappingCacheKey applicationKeyMappingCacheKey = new ApplicationKeyMappingCacheKey(key, keyManager);
    String synchronizeKey = "SubscriptionDataStoreImpl-KeyMapping-" + applicationKeyMappingCacheKey;
    ApplicationKeyMapping applicationKeyMapping = applicationKeyMappingMap.get(applicationKeyMappingCacheKey);
    if (applicationKeyMapping == null) {
        synchronized (synchronizeKey.intern()) {
            applicationKeyMapping = applicationKeyMappingMap.get(applicationKeyMappingCacheKey);
            if (applicationKeyMapping != null) {
                return applicationKeyMapping;
            }
            try {
                applicationKeyMapping = new SubscriptionDataLoaderImpl().getKeyMapping(key, keyManager, tenantDomain);
            } catch (DataLoadingException e) {
                log.error("Error while Loading KeyMapping Information from Internal API.", e);
            }
            if (applicationKeyMapping != null && !StringUtils.isEmpty(applicationKeyMapping.getConsumerKey())) {
                // load to the memory
                log.debug("Loading Keymapping to the in-memory datastore.");
                addOrUpdateApplicationKeyMapping(applicationKeyMapping);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Retrieving Application information with Consumer Key : " + key + " and keymanager : " + keyManager);
        if (applicationKeyMapping != null) {
            log.debug("Retrieved Application information with Consumer Key : " + key + " and keymanager : " + keyManager + " is " + applicationKeyMapping.toString());
        } else {
            log.debug("Retrieving Application information with Consumer Key : " + key + " and keymanager : " + keyManager + " is empty");
        }
    }
    return applicationKeyMapping;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) ApplicationKeyMappingCacheKey(org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMappingCacheKey) ApplicationKeyMapping(org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMapping)

Aggregations

DataLoadingException (org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException)26 IOException (java.io.IOException)16 Gson (com.google.gson.Gson)15 ArrayList (java.util.ArrayList)10 ApiPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy)5 API (org.wso2.carbon.apimgt.keymgt.model.entity.API)4 ApplicationPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationPolicy)4 SubscriptionPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy)4 SubscriptionDataLoaderImpl (org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataLoaderImpl)4 Application (org.wso2.carbon.apimgt.keymgt.model.entity.Application)3 ApplicationKeyMapping (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMapping)3 Subscription (org.wso2.carbon.apimgt.keymgt.model.entity.Subscription)3 API (org.wso2.carbon.apimgt.common.analytics.publishers.dto.API)2 SubscriptionDataStore (org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)2 APIList (org.wso2.carbon.apimgt.keymgt.model.entity.APIList)2 APIPolicyList (org.wso2.carbon.apimgt.keymgt.model.entity.APIPolicyList)2 ApplicationKeyMappingList (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMappingList)2 ApplicationList (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationList)2 ApplicationPolicyList (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationPolicyList)2 SubscriptionList (org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionList)2