Search in sources :

Example 21 with APIInfoDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method setThrottlePoliciesAndMonetization.

public static void setThrottlePoliciesAndMonetization(API api, APIInfoDTO apiInfoDTO, Set<String> deniedTiers, Map<String, Tier> tierMap) {
    Set<Tier> throttlingPolicies = new HashSet<Tier>();
    List<String> throttlingPolicyNames = new ArrayList<>();
    Set<Tier> apiTiers = api.getAvailableTiers();
    for (Tier currentTier : apiTiers) {
        if (!deniedTiers.contains(currentTier.getName())) {
            throttlingPolicies.add(currentTier);
            throttlingPolicyNames.add(currentTier.getName());
        }
    }
    int free = 0, commercial = 0;
    for (Tier tier : throttlingPolicies) {
        tier = tierMap.get(tier.getName());
        if (RestApiConstants.FREE.equalsIgnoreCase(tier.getTierPlan())) {
            free = free + 1;
        } else if (RestApiConstants.COMMERCIAL.equalsIgnoreCase(tier.getTierPlan())) {
            commercial = commercial + 1;
        }
    }
    if (free > 0 && commercial == 0) {
        apiInfoDTO.setMonetizationLabel(RestApiConstants.FREE);
    } else if (free == 0 && commercial > 0) {
        apiInfoDTO.setMonetizationLabel(RestApiConstants.PAID);
    } else if (free > 0 && commercial > 0) {
        apiInfoDTO.setMonetizationLabel(RestApiConstants.FREEMIUM);
    }
    apiInfoDTO.setThrottlingPolicies(throttlingPolicyNames);
}
Also used : Tier(org.wso2.carbon.apimgt.api.model.Tier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 22 with APIInfoDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method fromAPIToInfoDTO.

/**
 * Creates a minimal DTO representation of an API object
 *
 * @param api API object
 * @return a minimal representation DTO
 */
static APIInfoDTO fromAPIToInfoDTO(API api) throws APIManagementException {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();
    apiInfoDTO.setDescription(api.getDescription());
    String context = api.getContextTemplate();
    if (context.endsWith("/" + RestApiConstants.API_VERSION_PARAM)) {
        context = context.replace("/" + RestApiConstants.API_VERSION_PARAM, "");
    }
    apiInfoDTO.setContext(context);
    apiInfoDTO.setId(api.getUUID());
    APIIdentifier apiId = api.getId();
    apiInfoDTO.setName(apiId.getApiName());
    apiInfoDTO.setVersion(apiId.getVersion());
    apiInfoDTO.setProvider(apiId.getProviderName());
    apiInfoDTO.setLifeCycleStatus(api.getStatus());
    apiInfoDTO.setType(api.getType());
    apiInfoDTO.setAvgRating(String.valueOf(api.getRating()));
    String providerName = api.getId().getProviderName();
    apiInfoDTO.setProvider(APIUtil.replaceEmailDomainBack(providerName));
    APIBusinessInformationDTO apiBusinessInformationDTO = new APIBusinessInformationDTO();
    apiBusinessInformationDTO.setBusinessOwner(api.getBusinessOwner());
    apiBusinessInformationDTO.setBusinessOwnerEmail(api.getBusinessOwnerEmail());
    apiBusinessInformationDTO.setTechnicalOwner(api.getTechnicalOwner());
    apiBusinessInformationDTO.setTechnicalOwnerEmail(api.getTechnicalOwnerEmail());
    apiInfoDTO.setBusinessInformation(apiBusinessInformationDTO);
    apiInfoDTO.setCreatedTime(api.getCreatedTime());
    // }
    if (!StringUtils.isBlank(api.getThumbnailUrl())) {
        apiInfoDTO.setThumbnailUri(api.getThumbnailUrl());
    }
    apiInfoDTO.setAdvertiseInfo(extractAdvertiseInfo(api));
    String apiTenant = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(api.getId().getProviderName()));
    String subscriptionAvailability = api.getSubscriptionAvailability();
    String subscriptionAllowedTenants = api.getSubscriptionAvailableTenants();
    apiInfoDTO.setIsSubscriptionAvailable(isSubscriptionAvailable(apiTenant, subscriptionAvailability, subscriptionAllowedTenants));
    apiInfoDTO.setGatewayVendor(api.getGatewayVendor());
    return apiInfoDTO;
}
Also used : APIBusinessInformationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIBusinessInformationDTO) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO)

Example 23 with APIInfoDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class ServicesApiServiceImpl method getServiceUsage.

@Override
public Response getServiceUsage(String serviceId, MessageContext messageContext) {
    String userName = RestApiCommonUtil.getLoggedInUsername();
    int tenantId = APIUtil.getTenantId(userName);
    try {
        List<API> apiList = serviceCatalog.getServiceUsage(serviceId, tenantId);
        if (apiList != null) {
            APIListDTO apiListDTO = new APIListDTO();
            List<APIInfoDTO> apiInfoDTOList = new ArrayList<>();
            for (API api : apiList) {
                apiInfoDTOList.add(ServiceEntryMappingUtil.fromAPIToAPIInfoDTO(api));
            }
            apiListDTO.setList(apiInfoDTOList);
            apiListDTO.setCount(apiList.size());
            return Response.ok().entity(apiListDTO).build();
        } else {
            RestApiUtil.handleResourceNotFoundError("Service", serviceId, log);
        }
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API usage of service";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArrayList(java.util.ArrayList) APIListDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.APIListDTO) API(org.wso2.carbon.apimgt.api.model.API) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.APIInfoDTO)

Example 24 with APIInfoDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class ServiceEntryMappingUtil method fromAPIToAPIInfoDTO.

public static APIInfoDTO fromAPIToAPIInfoDTO(API api) {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();
    apiInfoDTO.setName(api.getId().getApiName());
    apiInfoDTO.setVersion(api.getId().getVersion());
    apiInfoDTO.setContext(api.getContext());
    apiInfoDTO.setId(api.getUuid());
    apiInfoDTO.setProvider(api.getId().getProviderName());
    return apiInfoDTO;
}
Also used : APIInfoDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.APIInfoDTO)

Example 25 with APIInfoDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class APIInfoMappingUtil method fromAPIInfoToDTO.

/**
 * Converts a APIIdentifier object into APIInfoDTO
 *
 * @param apiId APIIdentifier object
 * @return APIInfoDTO corresponds to APIIdentifier object
 */
private static APIInfoDTO fromAPIInfoToDTO(APIIdentifier apiId) throws UnsupportedEncodingException {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();
    APIIdentifier apiIdEmailReplacedBack = new APIIdentifier(APIUtil.replaceEmailDomainBack(apiId.getProviderName()).replace(RestApiConstants.API_ID_DELIMITER, RestApiConstants.URL_ENCODED_API_ID_DELIMITER), URLEncoder.encode(apiId.getApiName(), RestApiConstants.CHARSET).replace(RestApiConstants.API_ID_DELIMITER, RestApiConstants.URL_ENCODED_API_ID_DELIMITER), apiId.getVersion().replace(RestApiConstants.API_ID_DELIMITER, RestApiConstants.URL_ENCODED_API_ID_DELIMITER));
    apiInfoDTO.setName(apiIdEmailReplacedBack.getApiName());
    apiInfoDTO.setVersion(apiIdEmailReplacedBack.getVersion());
    apiInfoDTO.setProvider(apiIdEmailReplacedBack.getProviderName());
    return apiInfoDTO;
}
Also used : APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.APIInfoDTO)

Aggregations

ArrayList (java.util.ArrayList)11 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)7 Tier (org.wso2.carbon.apimgt.api.model.Tier)7 APIInfoDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO)7 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)5 API (org.wso2.carbon.apimgt.api.model.API)4 APIInfoDTO (org.wso2.carbon.apimgt.impl.dto.APIInfoDTO)4 JSONObject (org.json.simple.JSONObject)3 API (org.wso2.carbon.apimgt.core.models.API)3 ResourceInfoDTO (org.wso2.carbon.apimgt.impl.dto.ResourceInfoDTO)3 VerbInfoDTO (org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO)3 APIBusinessInformationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIBusinessInformationDTO)3 JsonObject (com.google.gson.JsonObject)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)2 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)2 Application (org.wso2.carbon.apimgt.api.model.Application)2