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());
}
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());
}
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());
}
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();
}
}
}
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;
}
Aggregations