Search in sources :

Example 1 with APIBusinessInformationDTO

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

the class MappingUtil method toAPI.

/**
 * This method converts the API model object from the DTO object.
 *
 * @param apidto APIDTO object with API data
 * @return APIBuilder object
 */
public static API.APIBuilder toAPI(APIDTO apidto) throws JsonProcessingException {
    BusinessInformation businessInformation = new BusinessInformation();
    API_businessInformationDTO apiBusinessInformationDTO = apidto.getBusinessInformation();
    if (apiBusinessInformationDTO != null) {
        businessInformation.setBusinessOwner(apiBusinessInformationDTO.getBusinessOwner());
        businessInformation.setBusinessOwnerEmail(apiBusinessInformationDTO.getBusinessOwnerEmail());
        businessInformation.setTechnicalOwner(apiBusinessInformationDTO.getTechnicalOwner());
        businessInformation.setTechnicalOwnerEmail(apiBusinessInformationDTO.getTechnicalOwnerEmail());
    }
    API_corsConfigurationDTO apiCorsConfigurationDTO = apidto.getCorsConfiguration();
    CorsConfiguration corsConfiguration = new CorsConfiguration();
    if (apiCorsConfigurationDTO != null) {
        corsConfiguration.setAllowCredentials(apiCorsConfigurationDTO.getAccessControlAllowCredentials());
        corsConfiguration.setAllowHeaders(apiCorsConfigurationDTO.getAccessControlAllowHeaders());
        corsConfiguration.setAllowMethods(apiCorsConfigurationDTO.getAccessControlAllowMethods());
        corsConfiguration.setAllowOrigins(apiCorsConfigurationDTO.getAccessControlAllowOrigins());
        corsConfiguration.setEnabled(apiCorsConfigurationDTO.getCorsConfigurationEnabled());
    }
    List<API_operationsDTO> operationList = apidto.getOperations();
    Map<String, UriTemplate> uriTemplateList = new HashMap<>();
    for (API_operationsDTO operationsDTO : operationList) {
        UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder();
        uriTemplateBuilder.uriTemplate(operationsDTO.getUritemplate());
        uriTemplateBuilder.authType(operationsDTO.getAuthType());
        uriTemplateBuilder.httpVerb(operationsDTO.getHttpVerb());
        uriTemplateBuilder.policy(new APIPolicy(operationsDTO.getPolicy()));
        uriTemplateBuilder.scopes(operationsDTO.getScopes());
        if (operationsDTO.getEndpoint() != null && !operationsDTO.getEndpoint().isEmpty()) {
            uriTemplateBuilder.endpoint(fromEndpointListToMap(operationsDTO.getEndpoint()));
        }
        if (operationsDTO.getId() != null) {
            uriTemplateBuilder.templateId(operationsDTO.getId());
        } else {
            uriTemplateBuilder.templateId(APIUtils.generateOperationIdFromPath(operationsDTO.getUritemplate(), operationsDTO.getHttpVerb()));
        }
        uriTemplateList.put(uriTemplateBuilder.getTemplateId(), uriTemplateBuilder.build());
    }
    Set<Policy> subscriptionPolicies = new HashSet<>();
    apidto.getPolicies().forEach(v -> subscriptionPolicies.add(new SubscriptionPolicy(v)));
    API.APIBuilder apiBuilder = new API.APIBuilder(apidto.getProvider(), apidto.getName(), apidto.getVersion()).id(apidto.getId()).context(apidto.getContext()).description(apidto.getDescription()).lifeCycleStatus(apidto.getLifeCycleStatus()).endpoint(fromEndpointListToMap(apidto.getEndpoint())).visibleRoles(new HashSet<>(apidto.getVisibleRoles())).policies(subscriptionPolicies).apiPermission(apidto.getPermission()).tags(new HashSet<>(apidto.getTags())).labels(new ArrayList<>(apidto.getLabels())).transport(new HashSet<>(apidto.getTransport())).isResponseCachingEnabled(Boolean.valueOf(apidto.getResponseCaching())).businessInformation(businessInformation).uriTemplates(uriTemplateList).corsConfiguration(corsConfiguration).wsdlUri(apidto.getWsdlUri()).scopes(apidto.getScopes()).securityScheme(mapSecuritySchemeListToInt(apidto.getSecurityScheme()));
    if (apidto.getIsDefaultVersion() != null) {
        apiBuilder.isDefaultVersion(apidto.getIsDefaultVersion());
    }
    if (apidto.getVisibility() != null) {
        apiBuilder.visibility(API.Visibility.valueOf(apidto.getVisibility().toString()));
    }
    if (apidto.getCacheTimeout() != null) {
        apiBuilder.cacheTimeout(apidto.getCacheTimeout());
    }
    if (apidto.getApiPolicy() != null) {
        Policy policy = new APIPolicy(apidto.getApiPolicy());
        apiBuilder.apiPolicy(policy);
    }
    if (apidto.getHasOwnGateway() != null) {
        apiBuilder.hasOwnGateway(apidto.getHasOwnGateway());
    }
    if (apidto.getThreatProtectionPolicies() != null) {
        API_threatProtectionPoliciesDTO threatProtectionPoliciesDTO = apidto.getThreatProtectionPolicies();
        List<API_threatProtectionPolicies_listDTO> threatProtectionPolicies_listDTO = threatProtectionPoliciesDTO.getList();
        Set<String> policyIdSet = new HashSet<>();
        for (API_threatProtectionPolicies_listDTO listDTO : threatProtectionPolicies_listDTO) {
            policyIdSet.add(listDTO.getPolicyId());
        }
        apiBuilder.threatProtectionPolicies(policyIdSet);
    }
    return apiBuilder;
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) BusinessInformation(org.wso2.carbon.apimgt.core.models.BusinessInformation) HashMap(java.util.HashMap) API_threatProtectionPolicies_listDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_threatProtectionPolicies_listDTO) API_operationsDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_operationsDTO) API_threatProtectionPoliciesDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_threatProtectionPoliciesDTO) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) API_businessInformationDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_businessInformationDTO) API_corsConfigurationDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_corsConfigurationDTO) HashSet(java.util.HashSet) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) CorsConfiguration(org.wso2.carbon.apimgt.core.models.CorsConfiguration) API(org.wso2.carbon.apimgt.core.models.API) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy)

Example 2 with APIBusinessInformationDTO

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

the class APIMappingUtil method fromAPIToInfoDTO.

/**
 * Creates a minimal DTO representation of an API Product object
 *
 * @param apiProduct API Product object
 * @return a minimal representation DTO
 * @throws APIManagementException
 */
static APIInfoDTO fromAPIToInfoDTO(APIProduct apiProduct, String organization) throws APIManagementException {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();
    apiInfoDTO.setDescription(apiProduct.getDescription());
    apiInfoDTO.setContext(apiProduct.getContext());
    apiInfoDTO.setId(apiProduct.getUuid());
    APIProductIdentifier apiId = apiProduct.getId();
    apiInfoDTO.setName(apiId.getName());
    apiInfoDTO.setVersion(apiId.getVersion());
    apiInfoDTO.setProvider(apiId.getProviderName());
    apiInfoDTO.setLifeCycleStatus(apiProduct.getState());
    apiInfoDTO.setType(APIType.API_PRODUCT.toString());
    apiInfoDTO.setAvgRating(String.valueOf(apiProduct.getRating()));
    String providerName = apiProduct.getId().getProviderName();
    apiInfoDTO.setProvider(APIUtil.replaceEmailDomainBack(providerName));
    APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
    Set<String> deniedTiers = apiConsumer.getDeniedTiers(organization);
    Map<String, Tier> tierMap = APIUtil.getTiers(organization);
    setThrottlePoliciesAndMonetization(apiProduct, apiInfoDTO, deniedTiers, tierMap);
    APIBusinessInformationDTO apiBusinessInformationDTO = new APIBusinessInformationDTO();
    apiBusinessInformationDTO.setBusinessOwner(apiProduct.getBusinessOwner());
    apiBusinessInformationDTO.setBusinessOwnerEmail(apiProduct.getBusinessOwnerEmail());
    apiBusinessInformationDTO.setTechnicalOwner(apiProduct.getTechnicalOwner());
    apiBusinessInformationDTO.setTechnicalOwnerEmail(apiProduct.getTechnicalOwnerEmail());
    apiInfoDTO.setBusinessInformation(apiBusinessInformationDTO);
    if (!StringUtils.isBlank(apiProduct.getThumbnailUrl())) {
        apiInfoDTO.setThumbnailUri(apiProduct.getThumbnailUrl());
    }
    // Since same APIInfoDTO is used for listing APIProducts in StoreUI set default AdvertisedInfo to the DTO
    AdvertiseInfoDTO advertiseInfoDTO = new AdvertiseInfoDTO();
    advertiseInfoDTO.setAdvertised(false);
    apiInfoDTO.setAdvertiseInfo(advertiseInfoDTO);
    String apiTenant = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(apiProduct.getId().getProviderName()));
    String subscriptionAvailability = apiProduct.getSubscriptionAvailability();
    String subscriptionAllowedTenants = apiProduct.getSubscriptionAvailableTenants();
    apiInfoDTO.setIsSubscriptionAvailable(isSubscriptionAvailable(apiTenant, subscriptionAvailability, subscriptionAllowedTenants));
    return apiInfoDTO;
}
Also used : APIBusinessInformationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIBusinessInformationDTO) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) AdvertiseInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdvertiseInfoDTO) Tier(org.wso2.carbon.apimgt.api.model.Tier) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO)

Example 3 with APIBusinessInformationDTO

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

the class APIMappingUtil method fromAPItoDTO.

public static APIDTO fromAPItoDTO(APIProduct model, String organization) throws APIManagementException {
    APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
    APIDTO dto = new APIDTO();
    dto.setName(model.getId().getName());
    dto.setVersion(model.getId().getVersion());
    String providerName = model.getId().getProviderName();
    dto.setProvider(APIUtil.replaceEmailDomainBack(providerName));
    dto.setId(model.getUuid());
    dto.setContext(model.getContext());
    dto.setDescription(model.getDescription());
    dto.setLifeCycleStatus(model.getState());
    dto.setType(model.getType());
    dto.setAvgRating(String.valueOf(model.getRating()));
    /* todo: created and last updated times
        if (null != model.getLastUpdated()) {
            Date lastUpdateDate = model.getLastUpdated();
            Timestamp timeStamp = new Timestamp(lastUpdateDate.getTime());
            dto.setLastUpdatedTime(String.valueOf(timeStamp));
        }

        String createdTimeStamp = model.getCreatedTime();
        if (null != createdTimeStamp) {
            Date date = new Date(Long.valueOf(createdTimeStamp));
            DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            String dateFormatted = formatter.format(date);
            dto.setCreatedTime(dateFormatted);
        } */
    String apiDefinition = null;
    if (model.isAsync()) {
        // for asyncAPI retrieve asyncapi.yml specification
        apiDefinition = apiConsumer.getAsyncAPIDefinition(model.getUuid(), organization);
    } else {
        // retrieve open API definition
        if (model.getDefinition() != null) {
            apiDefinition = model.getDefinition();
        } else {
            apiDefinition = apiConsumer.getOpenAPIDefinition(model.getUuid(), organization);
        }
    }
    dto.setApiDefinition(apiDefinition);
    Set<String> apiTags = model.getTags();
    List<String> tagsToReturn = new ArrayList<>();
    tagsToReturn.addAll(apiTags);
    dto.setTags(tagsToReturn);
    Set<org.wso2.carbon.apimgt.api.model.Tier> apiTiers = model.getAvailableTiers();
    List<APITiersDTO> tiersToReturn = new ArrayList<>();
    // set the monetization status of this API (enabled or disabled)
    APIMonetizationInfoDTO monetizationInfoDTO = new APIMonetizationInfoDTO();
    monetizationInfoDTO.enabled(model.getMonetizationStatus());
    dto.setMonetization(monetizationInfoDTO);
    for (org.wso2.carbon.apimgt.api.model.Tier currentTier : apiTiers) {
        APITiersDTO apiTiersDTO = new APITiersDTO();
        apiTiersDTO.setTierName(currentTier.getName());
        apiTiersDTO.setTierPlan(currentTier.getTierPlan());
        // monetization attributes are applicable only for commercial tiers
        if (APIConstants.COMMERCIAL_TIER_PLAN.equalsIgnoreCase(currentTier.getTierPlan())) {
            APIMonetizationAttributesDTO monetizationAttributesDTO = new APIMonetizationAttributesDTO();
            if (MapUtils.isNotEmpty(currentTier.getMonetizationAttributes())) {
                Map<String, String> monetizationAttributes = currentTier.getMonetizationAttributes();
                // check the billing plan (fixed or price per request)
                if (!StringUtils.isBlank(monetizationAttributes.get(APIConstants.Monetization.FIXED_PRICE))) {
                    monetizationAttributesDTO.setFixedPrice(monetizationAttributes.get(APIConstants.Monetization.FIXED_PRICE));
                } else if (!StringUtils.isBlank(monetizationAttributes.get(APIConstants.Monetization.PRICE_PER_REQUEST))) {
                    monetizationAttributesDTO.setPricePerRequest(monetizationAttributes.get(APIConstants.Monetization.PRICE_PER_REQUEST));
                }
                monetizationAttributesDTO.setCurrencyType(monetizationAttributes.get(APIConstants.Monetization.CURRENCY) != null ? monetizationAttributes.get(APIConstants.Monetization.CURRENCY) : StringUtils.EMPTY);
                monetizationAttributesDTO.setBillingCycle(monetizationAttributes.get(APIConstants.Monetization.BILLING_CYCLE) != null ? monetizationAttributes.get(APIConstants.Monetization.BILLING_CYCLE) : StringUtils.EMPTY);
            }
            apiTiersDTO.setMonetizationAttributes(monetizationAttributesDTO);
        }
        tiersToReturn.add(apiTiersDTO);
    }
    dto.setTiers(tiersToReturn);
    List<APIOperationsDTO> operationList = new ArrayList<>();
    Map<String, ScopeInfoDTO> uniqueScopes = new HashMap<>();
    for (APIProductResource productResource : model.getProductResources()) {
        URITemplate uriTemplate = productResource.getUriTemplate();
        APIOperationsDTO operation = new APIOperationsDTO();
        operation.setTarget(uriTemplate.getUriTemplate());
        operation.setVerb(uriTemplate.getHTTPVerb());
        operationList.add(operation);
        List<Scope> scopes = uriTemplate.retrieveAllScopes();
        for (Scope scope : scopes) {
            if (!uniqueScopes.containsKey(scope.getKey())) {
                ScopeInfoDTO scopeInfoDTO = new ScopeInfoDTO().key(scope.getKey()).name(scope.getName()).description(scope.getDescription());
                if (StringUtils.isNotBlank(scope.getRoles())) {
                    scopeInfoDTO.roles(Arrays.asList(scope.getRoles().trim().split(",")));
                }
                uniqueScopes.put(scope.getKey(), scopeInfoDTO);
            }
        }
    }
    dto.setOperations(operationList);
    dto.setScopes(new ArrayList<>(uniqueScopes.values()));
    dto.setTransport(Arrays.asList(model.getTransports().split(",")));
    APIBusinessInformationDTO apiBusinessInformationDTO = new APIBusinessInformationDTO();
    apiBusinessInformationDTO.setBusinessOwner(model.getBusinessOwner());
    apiBusinessInformationDTO.setBusinessOwnerEmail(model.getBusinessOwnerEmail());
    apiBusinessInformationDTO.setTechnicalOwner(model.getTechnicalOwner());
    apiBusinessInformationDTO.setTechnicalOwnerEmail(model.getTechnicalOwnerEmail());
    dto.setBusinessInformation(apiBusinessInformationDTO);
    if (!StringUtils.isBlank(model.getThumbnailUrl())) {
        dto.setHasThumbnail(true);
    }
    if (model.getAdditionalProperties() != null) {
        JSONObject additionalProperties = model.getAdditionalProperties();
        List<APIAdditionalPropertiesDTO> additionalPropertiesList = new ArrayList<>();
        for (Object propertyKey : additionalProperties.keySet()) {
            APIAdditionalPropertiesDTO additionalPropertiesDTO = new APIAdditionalPropertiesDTO();
            String key = (String) propertyKey;
            int index = key.lastIndexOf(APIConstants.API_RELATED_CUSTOM_PROPERTIES_SURFIX);
            additionalPropertiesDTO.setValue((String) additionalProperties.get(key));
            if (index > 0) {
                additionalPropertiesDTO.setName(key.substring(0, index));
                additionalPropertiesDTO.setDisplay(true);
                additionalPropertiesList.add(additionalPropertiesDTO);
            }
        }
        dto.setAdditionalProperties(additionalPropertiesList);
    }
    if (model.getEnvironments() != null) {
        List<String> environmentListToReturn = new ArrayList<>(model.getEnvironments());
        dto.setEnvironmentList(environmentListToReturn);
    }
    dto.setAuthorizationHeader(model.getAuthorizationHeader());
    if (model.getApiSecurity() != null) {
        dto.setSecurityScheme(Arrays.asList(model.getApiSecurity().split(",")));
    }
    // Since same APIInfoDTO is used for APIProduct in StoreUI set default AdvertisedInfo to the DTO
    AdvertiseInfoDTO advertiseInfoDTO = new AdvertiseInfoDTO();
    advertiseInfoDTO.setAdvertised(false);
    dto.setAdvertiseInfo(advertiseInfoDTO);
    String apiTenant = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(model.getId().getProviderName()));
    String subscriptionAvailability = model.getSubscriptionAvailability();
    String subscriptionAllowedTenants = model.getSubscriptionAvailableTenants();
    dto.setIsSubscriptionAvailable(isSubscriptionAvailable(apiTenant, subscriptionAvailability, subscriptionAllowedTenants));
    return dto;
}
Also used : AdvertiseInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdvertiseInfoDTO) HashMap(java.util.HashMap) APITiersDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APITiersDTO) ArrayList(java.util.ArrayList) APIAdditionalPropertiesDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIAdditionalPropertiesDTO) APIBusinessInformationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIBusinessInformationDTO) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) APIMonetizationInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIMonetizationInfoDTO) Tier(org.wso2.carbon.apimgt.api.model.Tier) Tier(org.wso2.carbon.apimgt.api.model.Tier) ScopeInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ScopeInfoDTO) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) APIDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIDTO) Scope(org.wso2.carbon.apimgt.api.model.Scope) JSONObject(org.json.simple.JSONObject) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) APIOperationsDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIOperationsDTO) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.simple.JSONObject) APIMonetizationAttributesDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIMonetizationAttributesDTO)

Example 4 with APIBusinessInformationDTO

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

the class SearchResultMappingUtil method fromAPIToAPIResultDTO.

/**
 * Get API result representation for content search
 * @param apiProduct API product
 * @return APISearchResultDTO
 */
public static APISearchResultDTO fromAPIToAPIResultDTO(APIProduct apiProduct) {
    APISearchResultDTO apiResultDTO = new APISearchResultDTO();
    apiResultDTO.setId(apiProduct.getUuid());
    APIProductIdentifier apiId = apiProduct.getId();
    apiResultDTO.setName(apiId.getName());
    apiResultDTO.setVersion(apiId.getVersion());
    apiResultDTO.setProvider(APIUtil.replaceEmailDomainBack(apiId.getProviderName()));
    String context = apiProduct.getContextTemplate();
    if (context.endsWith("/" + RestApiConstants.API_VERSION_PARAM)) {
        context = context.replace("/" + RestApiConstants.API_VERSION_PARAM, "");
    }
    apiResultDTO.setContext(context);
    apiResultDTO.setAvgRating(String.valueOf(apiProduct.getRating()));
    APIBusinessInformationDTO apiBusinessInformationDTO = new APIBusinessInformationDTO();
    apiBusinessInformationDTO.setBusinessOwner(apiProduct.getBusinessOwner());
    apiBusinessInformationDTO.setBusinessOwnerEmail(apiProduct.getBusinessOwnerEmail());
    apiBusinessInformationDTO.setTechnicalOwner(apiProduct.getTechnicalOwner());
    apiBusinessInformationDTO.setTechnicalOwnerEmail(apiProduct.getTechnicalOwnerEmail());
    apiResultDTO.setBusinessInformation(apiBusinessInformationDTO);
    apiResultDTO.setType(SearchResultDTO.TypeEnum.API);
    apiResultDTO.setTransportType(apiProduct.getType());
    apiResultDTO.setDescription(apiProduct.getDescription());
    apiResultDTO.setStatus(apiProduct.getState());
    apiResultDTO.setThumbnailUri(apiProduct.getThumbnailUrl());
    return apiResultDTO;
}
Also used : APIBusinessInformationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIBusinessInformationDTO) APISearchResultDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APISearchResultDTO) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier)

Example 5 with APIBusinessInformationDTO

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

the class MappingUtil method toAPIDto.

/**
 * This method converts the API Object from models into APIDTO object.
 *
 * @param api API object
 * @return APIDTO object with provided API object
 */
public static APIDTO toAPIDto(API api) throws IOException {
    APIDTO apidto = new APIDTO();
    apidto.setId(api.getId());
    apidto.setName(api.getName());
    apidto.version(api.getVersion());
    apidto.setContext(api.getContext());
    apidto.setDescription(api.getDescription());
    apidto.setIsDefaultVersion(api.isDefaultVersion());
    apidto.setVisibility(APIDTO.VisibilityEnum.valueOf(api.getVisibility().toString()));
    apidto.setResponseCaching(Boolean.toString(api.isResponseCachingEnabled()));
    apidto.setCacheTimeout(api.getCacheTimeout());
    apidto.setVisibleRoles(new ArrayList<>(api.getVisibleRoles()));
    apidto.setProvider(api.getProvider());
    apidto.setPermission(api.getApiPermission());
    apidto.setLifeCycleStatus(api.getLifeCycleStatus());
    apidto.setWorkflowStatus(api.getWorkflowStatus());
    apidto.setTags(new ArrayList<>(api.getTags()));
    apidto.hasOwnGateway(api.hasOwnGateway());
    apidto.setLabels(new ArrayList<>(api.getLabels()));
    apidto.setTransport(new ArrayList<>(api.getTransport()));
    apidto.setUserPermissionsForApi(api.getUserSpecificApiPermissions());
    apidto.setSecurityScheme(mapSecuritySchemeIntToList(api.getSecurityScheme()));
    for (Policy policy : api.getPolicies()) {
        apidto.addPoliciesItem(policy.getPolicyName());
    }
    apidto.setScopes(api.getScopes());
    BusinessInformation businessInformation = api.getBusinessInformation();
    API_businessInformationDTO apiBusinessInformationDTO = new API_businessInformationDTO();
    apiBusinessInformationDTO.setBusinessOwner(businessInformation.getBusinessOwner());
    apiBusinessInformationDTO.setBusinessOwnerEmail(businessInformation.getBusinessOwnerEmail());
    apiBusinessInformationDTO.setTechnicalOwner(businessInformation.getTechnicalOwner());
    apiBusinessInformationDTO.setTechnicalOwnerEmail(businessInformation.getTechnicalOwnerEmail());
    apidto.setBusinessInformation(apiBusinessInformationDTO);
    CorsConfiguration corsConfiguration = api.getCorsConfiguration();
    API_corsConfigurationDTO apiCorsConfigurationDTO = new API_corsConfigurationDTO();
    apiCorsConfigurationDTO.setAccessControlAllowCredentials(corsConfiguration.isAllowCredentials());
    apiCorsConfigurationDTO.setAccessControlAllowHeaders(corsConfiguration.getAllowHeaders());
    apiCorsConfigurationDTO.setAccessControlAllowMethods(corsConfiguration.getAllowMethods());
    apiCorsConfigurationDTO.setAccessControlAllowOrigins(corsConfiguration.getAllowOrigins());
    apiCorsConfigurationDTO.setCorsConfigurationEnabled(corsConfiguration.isEnabled());
    apidto.setCorsConfiguration(apiCorsConfigurationDTO);
    apidto.setEndpoint(fromEndpointToList(api.getEndpoint()));
    for (UriTemplate uriTemplate : api.getUriTemplates().values()) {
        API_operationsDTO apiOperationsDTO = new API_operationsDTO();
        apiOperationsDTO.setId(uriTemplate.getTemplateId());
        apiOperationsDTO.setUritemplate(uriTemplate.getUriTemplate());
        apiOperationsDTO.setAuthType(uriTemplate.getAuthType());
        apiOperationsDTO.setEndpoint(fromEndpointToList(uriTemplate.getEndpoint()));
        apiOperationsDTO.setHttpVerb(uriTemplate.getHttpVerb());
        apiOperationsDTO.setPolicy(uriTemplate.getPolicy().getPolicyName());
        apiOperationsDTO.setScopes(uriTemplate.getScopes());
        apidto.addOperationsItem(apiOperationsDTO);
    }
    if (api.getApiPolicy() != null) {
        apidto.setApiPolicy(api.getApiPolicy().getPolicyName());
    }
    apidto.setCreatedTime(api.getCreatedTime().toString());
    apidto.setLastUpdatedTime(api.getLastUpdatedTime().toString());
    if (api.getThreatProtectionPolicies() != null) {
        List<String> policyIdList = new ArrayList<>(api.getThreatProtectionPolicies());
        List<API_threatProtectionPolicies_listDTO> listDTOS = new ArrayList<>();
        for (String policyId : policyIdList) {
            API_threatProtectionPolicies_listDTO threatProtectionPoliciesListDTO = new API_threatProtectionPolicies_listDTO();
            threatProtectionPoliciesListDTO.setPolicyId(policyId);
            // set priority when implementing
            // threatProtectionPoliciesListDTO.setPriority(10);
            listDTOS.add(threatProtectionPoliciesListDTO);
        }
        API_threatProtectionPoliciesDTO threatProtectionPoliciesDTO = new API_threatProtectionPoliciesDTO();
        threatProtectionPoliciesDTO.setList(listDTOS);
        apidto.setThreatProtectionPolicies(threatProtectionPoliciesDTO);
    }
    return apidto;
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) BusinessInformation(org.wso2.carbon.apimgt.core.models.BusinessInformation) ArrayList(java.util.ArrayList) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) API_threatProtectionPolicies_listDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_threatProtectionPolicies_listDTO) API_operationsDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_operationsDTO) APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIDTO) API_threatProtectionPoliciesDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_threatProtectionPoliciesDTO) CorsConfiguration(org.wso2.carbon.apimgt.core.models.CorsConfiguration) API_businessInformationDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_businessInformationDTO) API_corsConfigurationDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.API_corsConfigurationDTO)

Aggregations

APIBusinessInformationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIBusinessInformationDTO)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Tier (org.wso2.carbon.apimgt.api.model.Tier)5 JSONObject (org.json.simple.JSONObject)4 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)3 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)3 Scope (org.wso2.carbon.apimgt.api.model.Scope)3 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)3 JsonObject (com.google.gson.JsonObject)2 Timestamp (java.sql.Timestamp)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 JSONParser (org.json.simple.parser.JSONParser)2 ParseException (org.json.simple.parser.ParseException)2 APICategory (org.wso2.carbon.apimgt.api.model.APICategory)2 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)2 CORSConfiguration (org.wso2.carbon.apimgt.api.model.CORSConfiguration)2 WebsubSubscriptionConfiguration (org.wso2.carbon.apimgt.api.model.WebsubSubscriptionConfiguration)2 APIUtil.getDefaultWebsubSubscriptionConfiguration (org.wso2.carbon.apimgt.impl.utils.APIUtil.getDefaultWebsubSubscriptionConfiguration)2