Search in sources :

Example 26 with SubscriptionDataStore

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

the class ApplicationsApiServiceImpl method applicationsGet.

public Response applicationsGet(String name, String uuid, String tenantDomain, MessageContext messageContext) {
    tenantDomain = GatewayUtils.validateTenantDomain(tenantDomain, messageContext);
    SubscriptionDataStore subscriptionDataStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
    if (subscriptionDataStore == null) {
        log.warn("Subscription data store is not initialized for " + tenantDomain);
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    List<Application> applicationList;
    if (StringUtils.isNotEmpty(name)) {
        applicationList = subscriptionDataStore.getApplicationsByName(name);
    } else if (StringUtils.isNotEmpty(uuid)) {
        applicationList = new ArrayList<>();
        if (subscriptionDataStore.getApplicationByUUID(uuid) != null) {
            applicationList.add(subscriptionDataStore.getApplicationByUUID(uuid));
        }
    } else {
        return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorDTO().moreInfo("required parameters " + "are missing")).build();
    }
    if (applicationList == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    ApplicationListDTO applicationListDTO = GatewayUtils.generateApplicationList(applicationList, subscriptionDataStore);
    return Response.ok().entity(applicationListDTO).build();
}
Also used : ErrorDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO) ArrayList(java.util.ArrayList) SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) Application(org.wso2.carbon.apimgt.keymgt.model.entity.Application) ApplicationListDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.ApplicationListDTO)

Example 27 with SubscriptionDataStore

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

the class GatewayUtils method generateApplicationList.

public static ApplicationListDTO generateApplicationList(List<Application> applicationList, SubscriptionDataStore subscriptionDataStore) {
    ApplicationListDTO applicationListDTO = new ApplicationListDTO();
    List<ApplicationInfoDTO> applicationInfoDTOList = new ArrayList<>();
    for (Application application : applicationList) {
        ApplicationInfoDTO applicationInfoDTO = new ApplicationInfoDTO().id(application.getId()).name(application.getName()).policy(application.getPolicy()).attributes(application.getAttributes()).subName(application.getSubName()).uuid(application.getUUID()).tokenType(application.getTokenType()).keys(convertToApplicationKeyMapping(application.getId(), subscriptionDataStore));
        applicationInfoDTOList.add(applicationInfoDTO);
    }
    applicationListDTO.setList(applicationInfoDTOList);
    applicationListDTO.setCount(applicationInfoDTOList.size());
    return applicationListDTO;
}
Also used : ArrayList(java.util.ArrayList) ApplicationInfoDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.ApplicationInfoDTO) Application(org.wso2.carbon.apimgt.keymgt.model.entity.Application) ApplicationListDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.ApplicationListDTO)

Example 28 with SubscriptionDataStore

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

the class GatewayUtils method generateAPIInfo.

public static APIInfoDTO generateAPIInfo(API api, List<Subscription> subscriptionsByAPIId, SubscriptionDataStore subscriptionDataStore) {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();
    apiInfoDTO.setApiId(api.getApiId());
    apiInfoDTO.setApiType(api.getApiType());
    apiInfoDTO.setName(api.getApiName());
    apiInfoDTO.setApiUUID(api.getUuid());
    apiInfoDTO.setContext(api.getContext());
    apiInfoDTO.setIsDefaultVersion(api.isDefaultVersion());
    apiInfoDTO.setPolicy(api.getApiTier());
    apiInfoDTO.setProvider(api.getApiProvider());
    apiInfoDTO.setUrlMappings(convertUriTemplate(api.getResources()));
    apiInfoDTO.setSubscripitons(convertSubscriptionsToSubscriptionInfo(subscriptionsByAPIId, subscriptionDataStore));
    return apiInfoDTO;
}
Also used : APIInfoDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.APIInfoDTO)

Example 29 with SubscriptionDataStore

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

the class GatewayUtils method convertSubscriptionsToSubscriptionInfo.

private static List<SubscriptionInfoDTO> convertSubscriptionsToSubscriptionInfo(List<Subscription> subscriptions, SubscriptionDataStore subscriptionDataStore) {
    List<SubscriptionInfoDTO> subscriptionInfoDTOList = new ArrayList<>();
    for (Subscription subscription : subscriptions) {
        SubscriptionInfoDTO subscriptionInfoDTO = new SubscriptionInfoDTO();
        subscriptionInfoDTO.setStatus(subscription.getSubscriptionState());
        subscriptionInfoDTO.setSubscriptionUUID(subscription.getSubscriptionUUId());
        subscriptionInfoDTO.setSubscriptionPolicy(subscription.getPolicyId());
        subscriptionInfoDTO.setApplication(convertToApplicationDto(subscription.getAppId(), subscriptionDataStore));
        subscriptionInfoDTOList.add(subscriptionInfoDTO);
    }
    return subscriptionInfoDTOList;
}
Also used : SubscriptionInfoDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.SubscriptionInfoDTO) ArrayList(java.util.ArrayList) Subscription(org.wso2.carbon.apimgt.keymgt.model.entity.Subscription)

Example 30 with SubscriptionDataStore

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

the class ApisApiServiceImpl method apisApiIdGet.

public Response apisApiIdGet(String apiId, String tenantDomain, MessageContext messageContext) {
    tenantDomain = GatewayUtils.validateTenantDomain(tenantDomain, messageContext);
    SubscriptionDataStore subscriptionDataStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
    if (subscriptionDataStore == null) {
        log.warn("Subscription data store is not initialized for " + tenantDomain);
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    API api;
    if (StringUtils.isNotEmpty(apiId)) {
        api = subscriptionDataStore.getAPIByUUID(apiId);
    } else {
        return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorDTO().moreInfo("required parameters " + "are missing")).build();
    }
    if (api == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    List<Subscription> subscriptionsByAPIId = subscriptionDataStore.getSubscriptionsByAPIId(api.getApiId());
    APIInfoDTO apiInfoDTO = GatewayUtils.generateAPIInfo(api, subscriptionsByAPIId, subscriptionDataStore);
    return Response.ok().entity(apiInfoDTO).build();
}
Also used : ErrorDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO) API(org.wso2.carbon.apimgt.keymgt.model.entity.API) SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) Subscription(org.wso2.carbon.apimgt.keymgt.model.entity.Subscription) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.APIInfoDTO)

Aggregations

SubscriptionDataStore (org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)43 API (org.wso2.carbon.apimgt.keymgt.model.entity.API)14 SubscriptionDataHolder (org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder)9 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 ArrayList (java.util.ArrayList)7 Application (org.wso2.carbon.apimgt.keymgt.model.entity.Application)6 Subscription (org.wso2.carbon.apimgt.keymgt.model.entity.Subscription)5 SubscriptionDataLoaderImpl (org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataLoaderImpl)5 MessageContext (org.apache.synapse.MessageContext)4 DataLoadingException (org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException)4 ErrorDTO (org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO)4 ApiPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 URLMapping (org.wso2.carbon.apimgt.api.model.subscription.URLMapping)2 API (org.wso2.carbon.apimgt.common.analytics.publishers.dto.API)2 DeployAPIInGatewayEvent (org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent)2 ApplicationPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationPolicy)2 Scope (org.wso2.carbon.apimgt.keymgt.model.entity.Scope)2 SubscriptionPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy)2