Search in sources :

Example 6 with APIInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method fromAPIListToInfoDTO.

/**
 * Converts a List object of APIs into Info DTO List.
 *
 * @param apiList List of APIs
 * @return APIListDTO object containing APIDTOs
 */
public static APIListDTO fromAPIListToInfoDTO(List<API> apiList) throws APIManagementException {
    APIListDTO apiListDTO = new APIListDTO();
    List<APIInfoDTO> apiInfoDTOs = apiListDTO.getList();
    for (API api : apiList) {
        apiInfoDTOs.add(fromAPIToInfoDTO(api));
    }
    apiListDTO.setCount(apiInfoDTOs.size());
    return apiListDTO;
}
Also used : APIListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIListDTO) API(org.wso2.carbon.apimgt.api.model.API) APIRevisionAPIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionAPIInfoDTO) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoDTO)

Example 7 with APIInfoDTO

use of org.wso2.carbon.apimgt.impl.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
 */
public static APIInfoDTO fromAPIToInfoDTO(API api) {
    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.setType(api.getType());
    String providerName = api.getId().getProviderName();
    apiInfoDTO.setProvider(APIUtil.replaceEmailDomainBack(providerName));
    apiInfoDTO.setLifeCycleStatus(api.getStatus());
    apiInfoDTO.setHasThumbnail(!StringUtils.isBlank(api.getThumbnailUrl()));
    if (api.getAudience() != null) {
        apiInfoDTO.setAudience(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoDTO.AudienceEnum.valueOf(api.getAudience()));
    }
    if (api.getCreatedTime() != null) {
        Date createdTime = new Date(Long.parseLong(api.getCreatedTime()));
        apiInfoDTO.setCreatedTime(String.valueOf(createdTime.getTime()));
    }
    if (api.getLastUpdated() != null) {
        Date lastUpdatedTime = api.getLastUpdated();
        apiInfoDTO.setUpdatedTime(String.valueOf(lastUpdatedTime.getTime()));
    }
    apiInfoDTO.setAdvertiseOnly(api.isAdvertiseOnly());
    if (api.getAdditionalProperties() != null) {
        JSONObject additionalProperties = api.getAdditionalProperties();
        List<APIInfoAdditionalPropertiesDTO> additionalPropertiesList = new ArrayList<>();
        Map<String, APIInfoAdditionalPropertiesMapDTO> additionalPropertiesMap = new HashMap<>();
        for (Object propertyKey : additionalProperties.keySet()) {
            APIInfoAdditionalPropertiesDTO additionalPropertiesDTO = new APIInfoAdditionalPropertiesDTO();
            APIInfoAdditionalPropertiesMapDTO apiInfoAdditionalPropertiesMapDTO = new APIInfoAdditionalPropertiesMapDTO();
            String key = (String) propertyKey;
            int index = key.lastIndexOf(APIConstants.API_RELATED_CUSTOM_PROPERTIES_SURFIX);
            additionalPropertiesDTO.setValue((String) additionalProperties.get(key));
            apiInfoAdditionalPropertiesMapDTO.setValue((String) additionalProperties.get(key));
            if (index > 0) {
                additionalPropertiesDTO.setName(key.substring(0, index));
                apiInfoAdditionalPropertiesMapDTO.setName(key.substring(0, index));
                additionalPropertiesDTO.setDisplay(true);
            } else {
                additionalPropertiesDTO.setName(key);
                apiInfoAdditionalPropertiesMapDTO.setName(key);
                additionalPropertiesDTO.setDisplay(false);
            }
            apiInfoAdditionalPropertiesMapDTO.setDisplay(false);
            additionalPropertiesMap.put(key, apiInfoAdditionalPropertiesMapDTO);
            additionalPropertiesList.add(additionalPropertiesDTO);
        }
        apiInfoDTO.setAdditionalProperties(additionalPropertiesList);
        apiInfoDTO.setAdditionalPropertiesMap(additionalPropertiesMap);
        apiInfoDTO.setGatewayVendor(api.getGatewayVendor());
    }
    return apiInfoDTO;
}
Also used : APIInfoAdditionalPropertiesMapDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoAdditionalPropertiesMapDTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) JSONObject(org.json.simple.JSONObject) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) JSONObject(org.json.simple.JSONObject) APIRevisionAPIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionAPIInfoDTO) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoDTO) APIInfoAdditionalPropertiesDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoAdditionalPropertiesDTO)

Example 8 with APIInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class APIInfoMappingUtil method fromAPIInfoListToDTO.

/**
 * Converts a List object of APIIdentifiers into a DTO
 *
 * @param apiIds a list of APIIdentifier objects
 * @return APIInfoListDTO object containing APIInfoDTOs
 */
public static APIInfoListDTO fromAPIInfoListToDTO(List<APIIdentifier> apiIds) throws UnsupportedEncodingException {
    APIInfoListDTO apiInfoListDTO = new APIInfoListDTO();
    List<APIInfoDTO> apiInfoDTOs = apiInfoListDTO.getList();
    if (apiInfoDTOs == null) {
        apiInfoDTOs = new ArrayList<>();
        apiInfoListDTO.setList(apiInfoDTOs);
    }
    for (APIIdentifier apiId : apiIds) {
        apiInfoDTOs.add(fromAPIInfoToDTO(apiId));
    }
    apiInfoListDTO.setCount(apiInfoDTOs.size());
    return apiInfoListDTO;
}
Also used : APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO) APIInfoListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoListDTO)

Example 9 with APIInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method fromAPIListToDTO.

/**
 * Converts a List object of APIs into a DTO
 *
 * @param apiList List of APIs
 * @return APIListDTO object containing APIDTOs
 * @throws APIManagementException
 */
public static APIListDTO fromAPIListToDTO(List<Object> apiList, String organization) throws APIManagementException {
    APIListDTO apiListDTO = new APIListDTO();
    APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
    Set<String> deniedTiers = apiConsumer.getDeniedTiers(organization);
    Map<String, Tier> tierMap = APIUtil.getTiers(organization);
    List<APIInfoDTO> apiInfoDTOs = apiListDTO.getList();
    if (apiList != null) {
        for (Object api : apiList) {
            APIInfoDTO apiInfoDTO = null;
            if (api instanceof API) {
                API api1 = (API) api;
                apiInfoDTO = fromAPIToInfoDTO((API) api);
                setThrottlePoliciesAndMonetization(api1, apiInfoDTO, deniedTiers, tierMap);
            } else if (api instanceof APIProduct) {
                APIProduct api1 = (APIProduct) api;
                apiInfoDTO = fromAPIToInfoDTO((API) api);
                setThrottlePoliciesAndMonetization(api1, apiInfoDTO, deniedTiers, tierMap);
            }
            apiInfoDTOs.add(apiInfoDTO);
        }
    }
    apiListDTO.setCount(apiInfoDTOs.size());
    return apiListDTO;
}
Also used : APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) Tier(org.wso2.carbon.apimgt.api.model.Tier) APIListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIListDTO) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.simple.JSONObject) API(org.wso2.carbon.apimgt.api.model.API) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO)

Example 10 with APIInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method setThrottlePoliciesAndMonetization.

public static void setThrottlePoliciesAndMonetization(APIProduct apiProduct, APIInfoDTO apiInfoDTO, Set<String> deniedTiers, Map<String, Tier> tierMap) {
    Set<Tier> throttlingPolicies = new HashSet<Tier>();
    List<String> throttlingPolicyNames = new ArrayList<>();
    Set<Tier> apiTiers = apiProduct.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)

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