Search in sources :

Example 11 with DevPortalAPI

use of org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI in project carbon-apimgt by wso2.

the class APIConsumerImpl method getAPIorAPIProductByUUIDWithoutPermissionCheck.

/**
 * Used to retrieve API/API Products without performing the visibility permission checks
 * @param uuid
 * @param organization
 * @return
 * @throws APIManagementException
 */
private ApiTypeWrapper getAPIorAPIProductByUUIDWithoutPermissionCheck(String uuid, String organization) throws APIManagementException {
    try {
        Organization org = new Organization(organization);
        DevPortalAPI devPortalApi = apiPersistenceInstance.getDevPortalAPI(org, uuid);
        if (devPortalApi != null) {
            if (APIConstants.API_PRODUCT.equalsIgnoreCase(devPortalApi.getType())) {
                APIProduct apiProduct = APIMapper.INSTANCE.toApiProduct(devPortalApi);
                apiProduct.setID(new APIProductIdentifier(devPortalApi.getProviderName(), devPortalApi.getApiName(), devPortalApi.getVersion()));
                populateAPIProductInformation(uuid, organization, apiProduct);
                return new ApiTypeWrapper(apiProduct);
            } else {
                API api = APIMapper.INSTANCE.toApi(devPortalApi);
                populateDevPortalAPIInformation(uuid, organization, api);
                populateDefaultVersion(api);
                api = addTiersToAPI(api, organization);
                return new ApiTypeWrapper(api);
            }
        } else {
            String msg = "Failed to get API. API artifact corresponding to artifactId " + uuid + " does not exist";
            throw new APIMgtResourceNotFoundException(msg);
        }
    } catch (APIPersistenceException | OASPersistenceException | ParseException e) {
        String msg = "Failed to get API";
        throw new APIManagementException(msg, e);
    }
}
Also used : APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) OASPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.OASPersistenceException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) API(org.wso2.carbon.apimgt.api.model.API) ParseException(org.json.simple.parser.ParseException)

Aggregations

DevPortalAPI (org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI)11 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)7 API (org.wso2.carbon.apimgt.api.model.API)6 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)6 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)5 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)5 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)4 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)4 Registry (org.wso2.carbon.registry.core.Registry)3 Resource (org.wso2.carbon.registry.core.Resource)3 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)3 ParseException (org.json.simple.parser.ParseException)2 Matchers.anyString (org.mockito.Matchers.anyString)2 APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)2 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)2 ApiTypeWrapper (org.wso2.carbon.apimgt.api.model.ApiTypeWrapper)2 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)2 OASPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.OASPersistenceException)2