Search in sources :

Example 6 with DataLoadingException

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

the class SubscriptionDataLoaderImpl method loadAllSubscriptions.

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

Example 7 with DataLoadingException

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

the class SubscriptionDataLoaderImpl method loadAllApis.

@Override
public List<API> loadAllApis(String tenantDomain) throws DataLoadingException {
    Set<String> gatewayLabels = gatewayArtifactSynchronizerProperties.getGatewayLabels();
    List<API> apis = new ArrayList<>();
    if (gatewayLabels != null && gatewayLabels.size() > 0) {
        for (String gatewayLabel : gatewayLabels) {
            String apisEP = APIConstants.SubscriptionValidationResources.APIS + "?gatewayLabel=" + getEncodedLabel(gatewayLabel);
            String responseString = null;
            try {
                responseString = invokeService(apisEP, tenantDomain);
            } catch (IOException e) {
                String msg = "Error while executing the http client " + apisEP;
                log.error(msg, e);
                throw new DataLoadingException(msg, e);
            }
            if (responseString != null && !responseString.isEmpty()) {
                APIList apiList = new Gson().fromJson(responseString, APIList.class);
                apis.addAll(apiList.getList());
            }
            if (log.isDebugEnabled()) {
                log.debug("apis :" + apis.get(0).toString());
            }
        }
    }
    return apis;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) ArrayList(java.util.ArrayList) APIList(org.wso2.carbon.apimgt.keymgt.model.entity.APIList) Gson(com.google.gson.Gson) API(org.wso2.carbon.apimgt.keymgt.model.entity.API) IOException(java.io.IOException)

Example 8 with DataLoadingException

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

the class SubscriptionDataLoaderImpl method getSubscriptionById.

@Override
public Subscription getSubscriptionById(String apiId, String appId) throws DataLoadingException {
    String endPoint = APIConstants.SubscriptionValidationResources.SUBSCRIPTIONS + "?apiId=" + apiId + "&appId=" + appId;
    Subscription subscription = 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()) {
        SubscriptionList list = new Gson().fromJson(responseString, SubscriptionList.class);
        if (list.getList() != null && !list.getList().isEmpty()) {
            subscription = list.getList().get(0);
        }
    }
    return subscription;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) SubscriptionList(org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionList) Gson(com.google.gson.Gson) IOException(java.io.IOException) Subscription(org.wso2.carbon.apimgt.keymgt.model.entity.Subscription)

Example 9 with DataLoadingException

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

the class SubscriptionDataLoaderImpl method loadAllApplications.

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

Example 10 with DataLoadingException

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

the class SubscriptionDataLoaderImpl method loadAllAPIPolicies.

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

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