Search in sources :

Example 46 with GovernanceException

use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.

the class RegistryPersistenceUtilTestCase method testAPIProductGet.

@Test
public void testAPIProductGet() throws GovernanceException, APIManagementException {
    GenericArtifact artifact = PersistenceHelper.getSampleAPIProductArtifact();
    APIProduct apiProduct = RegistryPersistenceUtil.getAPIProduct(artifact, registry);
    Assert.assertEquals("Attibute overview_type does not match", artifact.getAttribute("overview_type"), apiProduct.getType());
    Assert.assertEquals("API product id does not match", artifact.getId(), apiProduct.getUuid());
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 47 with GovernanceException

use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.

the class RegistryPersistenceUtilTestCase method testGetAPIForSearch.

@Test
public void testGetAPIForSearch() throws APIPersistenceException, GovernanceException {
    GenericArtifact genericArtifact = PersistenceHelper.getSampleAPIArtifact();
    PublisherAPI api = RegistryPersistenceUtil.getAPIForSearch(genericArtifact);
    Assert.assertEquals("API name does not match", genericArtifact.getAttribute("overview_name"), api.getApiName());
    Assert.assertEquals("API version does not match", genericArtifact.getAttribute("overview_version"), api.getVersion());
    Assert.assertEquals("API provider does not match", genericArtifact.getAttribute("overview_provider"), api.getProviderName());
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 48 with GovernanceException

use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.

the class RegistryPersistenceUtilTestCase method testGetDevPortalAPIForSearch.

@Test
public void testGetDevPortalAPIForSearch() throws APIPersistenceException, GovernanceException {
    GenericArtifact genericArtifact = PersistenceHelper.getSampleAPIArtifact();
    DevPortalAPI api = RegistryPersistenceUtil.getDevPortalAPIForSearch(genericArtifact);
    Assert.assertEquals("API name does not match", genericArtifact.getAttribute("overview_name"), api.getApiName());
    Assert.assertEquals("API version does not match", genericArtifact.getAttribute("overview_version"), api.getVersion());
    Assert.assertEquals("API provider does not match", genericArtifact.getAttribute("overview_provider"), api.getProviderName());
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 49 with GovernanceException

use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.

the class RegistryPersistenceImpl method saveThumbnail.

@Override
public void saveThumbnail(Organization org, String apiId, ResourceFile resourceFile) throws ThumbnailPersistenceException {
    boolean isTenantFlowStarted = false;
    try {
        String tenantDomain = org.getName();
        RegistryHolder holder = getRegistry(tenantDomain);
        Registry registry = holder.getRegistry();
        isTenantFlowStarted = holder.isTenantFlowStarted();
        GenericArtifactManager apiArtifactManager = RegistryPersistenceUtil.getArtifactManager(registry, APIConstants.API_KEY);
        GenericArtifact apiArtifact = apiArtifactManager.getGenericArtifact(apiId);
        if (apiArtifact == null) {
            throw new ThumbnailPersistenceException("API not found. ", ExceptionCodes.API_NOT_FOUND);
        }
        String apiProviderName = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER);
        apiProviderName = RegistryPersistenceUtil.replaceEmailDomain(apiProviderName);
        String apiName = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_NAME);
        String apiVersion = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_VERSION);
        String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiProviderName + RegistryConstants.PATH_SEPARATOR + apiName + RegistryConstants.PATH_SEPARATOR + apiVersion;
        String filePath = artifactPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_ICON_IMAGE;
        String savedFilePath = addResourceFile(filePath, resourceFile, registry, tenantDomain);
        RegistryPersistenceUtil.setResourcePermissions(apiProviderName, null, null, filePath);
        apiArtifact.setAttribute(APIConstants.API_OVERVIEW_THUMBNAIL_URL, savedFilePath);
        apiArtifactManager.updateGenericArtifact(apiArtifact);
    } catch (APIPersistenceException | GovernanceException | PersistenceException | APIManagementException e) {
        throw new ThumbnailPersistenceException("Error while saving thumbnail for api " + apiId, e);
    } finally {
        if (isTenantFlowStarted) {
            PrivilegedCarbonContext.endTenantFlow();
        }
    }
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ThumbnailPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.ThumbnailPersistenceException) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) PersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.PersistenceException) GraphQLPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.GraphQLPersistenceException) MediationPolicyPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.MediationPolicyPersistenceException) ThumbnailPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.ThumbnailPersistenceException) WSDLPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.WSDLPersistenceException) OASPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.OASPersistenceException) AsyncSpecPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.AsyncSpecPersistenceException) DocumentationPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry)

Example 50 with GovernanceException

use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.

the class RegistryPersistenceImpl method getAPIArtifact.

protected GenericArtifact getAPIArtifact(String apiId, Registry registry) throws APIPersistenceException, GovernanceException {
    GenericArtifactManager artifactManager = RegistryPersistenceUtil.getArtifactManager(registry, APIConstants.API_KEY);
    GenericArtifact apiArtifact = artifactManager.getGenericArtifact(apiId);
    return apiArtifact;
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager)

Aggregations

GovernanceException (org.wso2.carbon.governance.api.exception.GovernanceException)42 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)32 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)29 API (org.wso2.carbon.apimgt.api.model.API)26 Test (org.junit.Test)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)18 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)17 ArrayList (java.util.ArrayList)15 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)15 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)14 Tier (org.wso2.carbon.apimgt.api.model.Tier)13 HashSet (java.util.HashSet)11 DevPortalAPI (org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI)10 UserStoreException (org.wso2.carbon.user.api.UserStoreException)10 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)9 Endpoint (org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)9 Resource (org.wso2.carbon.registry.core.Resource)9 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)9 LinkedHashSet (java.util.LinkedHashSet)8