Search in sources :

Example 6 with ApplicationInfoDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ApplicationInfoDTO in project carbon-apimgt by wso2.

the class SubscriptionMappingUtil method fromApplicationToApplicationInfoDTO.

/**
 * Convert Application to an ApplicationInfoDTO
 *
 * @param application the application to be converted
 * @return ApplicationInfoDTO corresponding to the application
 * @throws APIManagementException If an error occurs when getting logged in provider or when getting lightweight API
 */
private static ApplicationInfoDTO fromApplicationToApplicationInfoDTO(Application application) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    application = apiProvider.getLightweightApplicationByUUID(application.getUUID());
    return ApplicationMappingUtil.fromApplicationToInfoDTO(application);
}
Also used : APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 7 with ApplicationInfoDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ApplicationInfoDTO in project carbon-apimgt by wso2.

the class SubscriptionMappingUtil method fromSubscriptionToDTO.

/**
 * Converts a SubscribedAPI object into SubscriptionDTO
 *
 * @param subscription SubscribedAPI object
 * @param organization Identifier of the organization
 * @return SubscriptionDTO corresponds to SubscribedAPI object
 */
public static SubscriptionDTO fromSubscriptionToDTO(SubscribedAPI subscription, String organization) throws APIManagementException {
    String username = RestApiCommonUtil.getLoggedInUsername();
    APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
    SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
    subscriptionDTO.setSubscriptionId(subscription.getUUID());
    APIInfoDTO apiInfo;
    Identifier apiId = subscription.getIdentifier();
    ApiTypeWrapper apiTypeWrapper;
    try {
        apiTypeWrapper = apiConsumer.getAPIorAPIProductByUUID(subscription.getIdentifier().getUUID(), organization);
        subscriptionDTO.setApiId(subscription.getIdentifier().getUUID());
        Set<String> deniedTiers = apiConsumer.getDeniedTiers(organization);
        Map<String, Tier> tierMap = APIUtil.getTiers(organization);
        if (apiTypeWrapper.isAPIProduct()) {
            apiInfo = APIMappingUtil.fromAPIToInfoDTO(apiTypeWrapper.getApiProduct(), organization);
            APIMappingUtil.setThrottlePoliciesAndMonetization(apiTypeWrapper.getApiProduct(), apiInfo, deniedTiers, tierMap);
        } else {
            apiInfo = APIMappingUtil.fromAPIToInfoDTO(apiTypeWrapper.getApi());
            APIMappingUtil.setThrottlePoliciesAndMonetization(apiTypeWrapper.getApi(), apiInfo, deniedTiers, tierMap);
        }
        subscriptionDTO.setApiInfo(apiInfo);
    } catch (APIManagementException e) {
        if (log.isDebugEnabled()) {
            log.debug("User :" + username + " does not have access to the API " + apiId);
        }
        apiInfo = new APIInfoDTO();
        apiInfo.setName(apiId.getName());
        apiInfo.setVersion(apiId.getVersion());
        subscriptionDTO.setApiInfo(apiInfo);
    }
    Application application = subscription.getApplication();
    application = apiConsumer.getLightweightApplicationByUUID(application.getUUID());
    subscriptionDTO.setApplicationId(subscription.getApplication().getUUID());
    subscriptionDTO.setStatus(SubscriptionDTO.StatusEnum.valueOf(subscription.getSubStatus()));
    subscriptionDTO.setThrottlingPolicy(subscription.getTier().getName());
    subscriptionDTO.setRequestedThrottlingPolicy(subscription.getRequestedTier().getName());
    ApplicationInfoDTO applicationInfoDTO = ApplicationMappingUtil.fromApplicationToInfoDTO(application);
    subscriptionDTO.setApplicationInfo(applicationInfoDTO);
    return subscriptionDTO;
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) Identifier(org.wso2.carbon.apimgt.api.model.Identifier) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) Tier(org.wso2.carbon.apimgt.api.model.Tier) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) ApplicationInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationInfoDTO) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.SubscriptionDTO) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 8 with ApplicationInfoDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ApplicationInfoDTO in project carbon-apimgt by wso2.

the class SubscriptionMappingUtil method fromSubscriptionToDTO.

public static SubscriptionDTO fromSubscriptionToDTO(SubscribedAPI subscription, ApiTypeWrapper apiTypeWrapper, String organization) throws APIManagementException {
    SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
    subscriptionDTO.setSubscriptionId(subscription.getUUID());
    APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
    Set<String> deniedTiers = apiConsumer.getDeniedTiers(organization);
    Map<String, Tier> tierMap = APIUtil.getTiers(organization);
    if (apiTypeWrapper != null && !apiTypeWrapper.isAPIProduct()) {
        API api = apiTypeWrapper.getApi();
        subscriptionDTO.setApiId(api.getUUID());
        APIInfoDTO apiInfo = APIMappingUtil.fromAPIToInfoDTO(api);
        APIMappingUtil.setThrottlePoliciesAndMonetization(api, apiInfo, deniedTiers, tierMap);
        subscriptionDTO.setApiInfo(apiInfo);
    } else {
        APIProduct apiProduct = apiTypeWrapper.getApiProduct();
        subscriptionDTO.setApiId(apiProduct.getUuid());
        APIInfoDTO apiInfo = APIMappingUtil.fromAPIToInfoDTO(apiProduct, organization);
        APIMappingUtil.setThrottlePoliciesAndMonetization(apiProduct, apiInfo, deniedTiers, tierMap);
        subscriptionDTO.setApiInfo(apiInfo);
    }
    Application application = subscription.getApplication();
    subscriptionDTO.setApplicationId(subscription.getApplication().getUUID());
    subscriptionDTO.setStatus(SubscriptionDTO.StatusEnum.valueOf(subscription.getSubStatus()));
    subscriptionDTO.setThrottlingPolicy(subscription.getTier().getName());
    subscriptionDTO.setRequestedThrottlingPolicy(subscription.getRequestedTier().getName());
    ApplicationInfoDTO applicationInfoDTO = ApplicationMappingUtil.fromApplicationToInfoDTO(application);
    subscriptionDTO.setApplicationInfo(applicationInfoDTO);
    return subscriptionDTO;
}
Also used : APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) Tier(org.wso2.carbon.apimgt.api.model.Tier) API(org.wso2.carbon.apimgt.api.model.API) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) ApplicationInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationInfoDTO) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.SubscriptionDTO) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 9 with ApplicationInfoDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ApplicationInfoDTO in project carbon-apimgt by wso2.

the class ApplicationMappingUtil method fromApplicationToInfoDTO.

public static ApplicationInfoDTO fromApplicationToInfoDTO(Application application) {
    ApplicationInfoDTO applicationInfoDTO = new ApplicationInfoDTO();
    applicationInfoDTO.setApplicationId(application.getId());
    applicationInfoDTO.setThrottlingTier(application.getPolicy().getPolicyName());
    applicationInfoDTO.setDescription(application.getDescription());
    applicationInfoDTO.setLifeCycleStatus(application.getStatus());
    applicationInfoDTO.setName(application.getName());
    applicationInfoDTO.setSubscriber(application.getCreatedUser());
    return applicationInfoDTO;
}
Also used : ApplicationInfoDTO(org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationInfoDTO)

Example 10 with ApplicationInfoDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ApplicationInfoDTO in project carbon-apimgt by wso2.

the class ApplicationMappingUtil method fromApplicationToInfoDTO.

public static ApplicationInfoDTO fromApplicationToInfoDTO(Application application) {
    ApplicationInfoDTO applicationInfoDTO = new ApplicationInfoDTO();
    applicationInfoDTO.setApplicationId(application.getUUID());
    applicationInfoDTO.setThrottlingPolicy(application.getTier());
    applicationInfoDTO.setDescription(application.getDescription());
    applicationInfoDTO.setStatus(application.getStatus());
    applicationInfoDTO.setName(application.getName());
    if (StringUtils.isNotEmpty(application.getGroupId())) {
        applicationInfoDTO.setGroups(Arrays.asList(application.getGroupId().split(",")));
    }
    Map<String, String> applicationAttributes = application.getApplicationAttributes();
    applicationInfoDTO.setAttributes(applicationAttributes);
    applicationInfoDTO.setSubscriptionCount(application.getSubscriptionCount());
    applicationInfoDTO.setOwner(application.getOwner());
    return applicationInfoDTO;
}
Also used : ApplicationInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationInfoDTO)

Aggregations

Application (org.wso2.carbon.apimgt.api.model.Application)5 ApplicationInfoDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationInfoDTO)5 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)3 ArrayList (java.util.ArrayList)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)2 Tier (org.wso2.carbon.apimgt.api.model.Tier)2 Application (org.wso2.carbon.apimgt.keymgt.model.entity.Application)2 ApplicationInfoDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationInfoDTO)2 ApplicationInfoDTO (org.wso2.carbon.apimgt.rest.api.gateway.dto.ApplicationInfoDTO)2 ApplicationInfoDTO (org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationInfoDTO)2 APIInfoDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO)2 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.SubscriptionDTO)2 Gson (com.google.gson.Gson)1 JsonElement (com.google.gson.JsonElement)1 JsonParser (com.google.gson.JsonParser)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1