Search in sources :

Example 21 with APIInfo

use of org.wso2.carbon.apimgt.api.model.APIInfo 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 22 with APIInfo

use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.

the class RegistryPersistenceImpl method searchPaginatedDevPortalAPIs.

private DevPortalAPISearchResult searchPaginatedDevPortalAPIs(Registry userRegistry, int tenantIDLocal, String searchQuery, int start, int offset) throws APIManagementException {
    int totalLength = 0;
    DevPortalAPISearchResult searchResults = new DevPortalAPISearchResult();
    try {
        final int maxPaginationLimit = getMaxPaginationLimit();
        PaginationContext.init(start, offset, "ASC", APIConstants.API_OVERVIEW_NAME, maxPaginationLimit);
        log.debug("Dev portal list apis query " + searchQuery);
        List<GovernanceArtifact> governanceArtifacts = GovernanceUtils.findGovernanceArtifacts(searchQuery, userRegistry, APIConstants.API_RXT_MEDIA_TYPE, true);
        totalLength = PaginationContext.getInstance().getLength();
        boolean isFound = true;
        if (governanceArtifacts == null || governanceArtifacts.size() == 0) {
            if (searchQuery.contains(APIConstants.API_OVERVIEW_PROVIDER)) {
                searchQuery = searchQuery.replaceAll(APIConstants.API_OVERVIEW_PROVIDER, APIConstants.API_OVERVIEW_OWNER);
                governanceArtifacts = GovernanceUtils.findGovernanceArtifacts(searchQuery, userRegistry, APIConstants.API_RXT_MEDIA_TYPE, true);
                if (governanceArtifacts == null || governanceArtifacts.size() == 0) {
                    isFound = false;
                }
            } else {
                isFound = false;
            }
        }
        if (!isFound) {
            return searchResults;
        }
        // Check to see if we can speculate that there are more APIs to be loaded
        if (maxPaginationLimit == totalLength) {
            // Remove the additional 1 added earlier when setting max pagination limit
            --totalLength;
        }
        List<DevPortalAPIInfo> devPortalAPIInfoList = new ArrayList<DevPortalAPIInfo>();
        int tempLength = 0;
        for (GovernanceArtifact artifact : governanceArtifacts) {
            DevPortalAPIInfo apiInfo = new DevPortalAPIInfo();
            // devPortalAPIInfoList apiInfo = new devPortalAPIInfoList();
            apiInfo.setType(artifact.getAttribute(APIConstants.API_OVERVIEW_TYPE));
            apiInfo.setId(artifact.getId());
            apiInfo.setApiName(artifact.getAttribute(APIConstants.API_OVERVIEW_NAME));
            apiInfo.setDescription(artifact.getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION));
            apiInfo.setContext(artifact.getAttribute(APIConstants.API_OVERVIEW_CONTEXT_TEMPLATE));
            apiInfo.setProviderName(artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER));
            apiInfo.setStatus(artifact.getAttribute(APIConstants.API_OVERVIEW_STATUS));
            apiInfo.setThumbnail(artifact.getAttribute(APIConstants.API_OVERVIEW_THUMBNAIL_URL));
            apiInfo.setBusinessOwner(artifact.getAttribute(APIConstants.API_OVERVIEW_BUSS_OWNER));
            apiInfo.setVersion(artifact.getAttribute(APIConstants.API_OVERVIEW_VERSION));
            String tiers = artifact.getAttribute(APIConstants.API_OVERVIEW_TIER);
            Set<String> availableTiers = new HashSet<String>();
            if (tiers != null) {
                String[] tiersArray = tiers.split("\\|\\|");
                for (String tierName : tiersArray) {
                    availableTiers.add(tierName);
                }
            }
            apiInfo.setAvailableTierNames(availableTiers);
            apiInfo.setSubscriptionAvailability(artifact.getAttribute(APIConstants.API_OVERVIEW_SUBSCRIPTION_AVAILABILITY));
            apiInfo.setSubscriptionAvailableOrgs(artifact.getAttribute(APIConstants.API_OVERVIEW_SUBSCRIPTION_AVAILABLE_TENANTS));
            apiInfo.setGatewayVendor(artifact.getAttribute(APIConstants.API_GATEWAY_VENDOR));
            devPortalAPIInfoList.add(apiInfo);
            // Ensure the APIs returned matches the length, there could be an additional API
            // returned due incrementing the pagination limit when getting from registry
            tempLength++;
            if (tempLength >= totalLength) {
                break;
            }
        }
        searchResults.setDevPortalAPIInfoList(devPortalAPIInfoList);
        searchResults.setReturnedAPIsCount(devPortalAPIInfoList.size());
        searchResults.setTotalAPIsCount(totalLength);
    } catch (RegistryException e) {
        String msg = "Failed to search APIs with type";
        throw new APIManagementException(msg, e);
    } finally {
        PaginationContext.destroy();
    }
    return searchResults;
}
Also used : GovernanceArtifact(org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact) DevPortalAPIInfo(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPIInfo) ArrayList(java.util.ArrayList) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) DevPortalAPISearchResult(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPISearchResult) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HashSet(java.util.HashSet)

Example 23 with APIInfo

use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method getAPISubscriptionPolicies.

@Override
public Response getAPISubscriptionPolicies(String apiId, String ifNoneMatch, String xWSO2Tenant, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    APIDTO apiInfo = getAPIByID(apiId, apiProvider, organization);
    List<Tier> availableThrottlingPolicyList = new ThrottlingPoliciesApiServiceImpl().getThrottlingPolicyList(ThrottlingPolicyDTO.PolicyLevelEnum.SUBSCRIPTION.toString(), true);
    if (apiInfo != null) {
        List<String> apiPolicies = apiInfo.getPolicies();
        if (apiPolicies != null && !apiPolicies.isEmpty()) {
            List<Tier> apiThrottlingPolicies = new ArrayList<>();
            for (Tier tier : availableThrottlingPolicyList) {
                if (apiPolicies.contains(tier.getName())) {
                    apiThrottlingPolicies.add(tier);
                }
            }
            return Response.ok().entity(apiThrottlingPolicies).build();
        }
    }
    return null;
}
Also used : APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO) Tier(org.wso2.carbon.apimgt.api.model.Tier) ArrayList(java.util.ArrayList) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 24 with APIInfo

use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method restoreAPIRevision.

/**
 * Restore a revision to the working copy of the API
 *
 * @param apiId          UUID of the API
 * @param revisionId  Revision ID of the API
 * @param messageContext message context object
 * @return response with 200 status code
 */
@Override
public Response restoreAPIRevision(String apiId, String revisionId, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    // validate if api exists
    APIInfo apiInfo = validateAPIExistence(apiId);
    // validate API update operation permitted based on the LC state
    validateAPIOperationsPerLC(apiInfo.getStatus().toString());
    apiProvider.restoreAPIRevision(apiId, revisionId, organization);
    APIDTO apiToReturn = getAPIByID(apiId, apiProvider, organization);
    Response.Status status = Response.Status.CREATED;
    return Response.status(status).entity(apiToReturn).build();
}
Also used : HttpResponse(org.apache.http.HttpResponse) WSDLValidationResponse(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse) Response(javax.ws.rs.core.Response) APIDefinitionValidationResponse(org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse) APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO) APIInfo(org.wso2.carbon.apimgt.api.model.APIInfo) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 25 with APIInfo

use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method updateWSDLOfAPI.

/**
 * Update the WSDL of an API
 *
 * @param apiId UUID of the API
 * @param fileInputStream file data as input stream
 * @param fileDetail file details
 * @param url URL of the WSDL
 * @return 200 OK response if the operation is successful. 400 if the provided inputs are invalid. 500 if a server
 *  error occurred.
 * @throws APIManagementException when error occurred while trying to retrieve the WSDL
 */
@Override
public Response updateWSDLOfAPI(String apiId, String ifMatch, InputStream fileInputStream, Attachment fileDetail, String url, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    // validate if api exists
    APIInfo apiInfo = validateAPIExistence(apiId);
    // validate API update operation permitted based on the LC state
    validateAPIOperationsPerLC(apiInfo.getStatus().toString());
    WSDLValidationResponse validationResponse = validateWSDLAndReset(fileInputStream, fileDetail, url);
    if (StringUtils.isNotBlank(url)) {
        apiProvider.addWSDLResource(apiId, null, url, organization);
    } else {
        ResourceFile wsdlResource;
        if (APIConstants.APPLICATION_ZIP.equals(fileDetail.getContentType().toString()) || APIConstants.APPLICATION_X_ZIP_COMPRESSED.equals(fileDetail.getContentType().toString())) {
            wsdlResource = new ResourceFile(validationResponse.getWsdlProcessor().getWSDL(), APIConstants.APPLICATION_ZIP);
        } else {
            wsdlResource = new ResourceFile(validationResponse.getWsdlProcessor().getWSDL(), fileDetail.getContentType().toString());
        }
        apiProvider.addWSDLResource(apiId, wsdlResource, null, organization);
    }
    return Response.ok().build();
}
Also used : ResourceFile(org.wso2.carbon.apimgt.api.model.ResourceFile) WSDLValidationResponse(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse) APIInfo(org.wso2.carbon.apimgt.api.model.APIInfo) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Aggregations

APIInfo (org.wso2.carbon.apimgt.api.model.APIInfo)20 ArrayList (java.util.ArrayList)17 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)17 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)16 HashMap (java.util.HashMap)7 APIDefinitionValidationResponse (org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse)7 APIInfo (org.wso2.carbon.apimgt.core.models.analytics.APIInfo)7 API (org.wso2.carbon.apimgt.core.models.API)5 WSDLValidationResponse (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse)5 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 Response (javax.ws.rs.core.Response)4 HttpResponse (org.apache.http.HttpResponse)4 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 APIStateChangeResponse (org.wso2.carbon.apimgt.api.model.APIStateChangeResponse)4 Documentation (org.wso2.carbon.apimgt.api.model.Documentation)4 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)4 Tier (org.wso2.carbon.apimgt.api.model.Tier)4 APIDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO)4 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3