use of org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI in project carbon-apimgt by wso2.
the class APIMapperTestCase method testAPItoDevPortalApiAndBack.
@Test
public void testAPItoDevPortalApiAndBack() throws GovernanceException, APIManagementException {
DevPortalAPI devAPI = APIMapper.INSTANCE.toDevPortalApi(api);
Assert.assertEquals("API name does not match", api.getId().getName(), devAPI.getApiName());
Assert.assertEquals("API uuid does not match", api.getUuid(), devAPI.getId());
Assert.assertTrue("Mapped api does not have status", devAPI.toString().contains(api.getStatus()));
API mappedAPI = APIMapper.INSTANCE.toApi(devAPI);
Assert.assertEquals("Mapped api name does not match", mappedAPI.getId().getName(), api.getId().getName());
}
use of org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI 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.apimgt.persistence.dto.DevPortalAPI in project carbon-apimgt by wso2.
the class RegistryPersistenceImpl method getDevPortalAPI.
@Override
public DevPortalAPI getDevPortalAPI(Organization org, String apiId) throws APIPersistenceException {
boolean tenantFlowStarted = false;
try {
String tenantDomain = org.getName();
RegistryHolder holder = getRegistry(tenantDomain);
Registry registry = holder.getRegistry();
tenantFlowStarted = holder.isTenantFlowStarted();
GenericArtifact apiArtifact = getAPIArtifact(apiId, registry);
if (apiArtifact != null) {
API api = RegistryPersistenceUtil.getApiForPublishing(registry, apiArtifact);
String definitionPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + RegistryPersistenceUtil.replaceEmailDomain(api.getId().getProviderName()) + RegistryConstants.PATH_SEPARATOR + api.getId().getName() + RegistryConstants.PATH_SEPARATOR + api.getId().getVersion() + RegistryConstants.PATH_SEPARATOR + APIConstants.API_OAS_DEFINITION_RESOURCE_NAME;
if (registry.resourceExists(definitionPath)) {
Resource apiDocResource = registry.get(definitionPath);
String apiDocContent = new String((byte[]) apiDocResource.getContent(), Charset.defaultCharset());
api.setSwaggerDefinition(apiDocContent);
}
String apiTenantDomain = MultitenantUtils.getTenantDomain(RegistryPersistenceUtil.replaceEmailDomainBack(api.getId().getProviderName()));
if (APIConstants.API_GLOBAL_VISIBILITY.equals(api.getVisibility())) {
// return new ApiTypeWrapper(api);
return APIMapper.INSTANCE.toDevPortalApi(api);
}
if (tenantDomain == null || !tenantDomain.equals(apiTenantDomain)) {
throw new APIPersistenceException("User does not have permission to view API : " + api.getId().getApiName());
}
return APIMapper.INSTANCE.toDevPortalApi(api);
} else {
return null;
}
} catch (RegistryException | APIManagementException e) {
String msg = "Failed to get API";
throw new APIPersistenceException(msg, e);
} finally {
if (tenantFlowStarted) {
RegistryPersistenceUtil.endTenantFlow();
}
}
}
use of org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI in project carbon-apimgt by wso2.
the class APIConsumerImpl method getAPIorAPIProductByUUID.
@Override
public ApiTypeWrapper getAPIorAPIProductByUUID(String uuid, String organization) throws APIManagementException {
try {
Organization org = new Organization(organization);
DevPortalAPI devPortalApi = apiPersistenceInstance.getDevPortalAPI(org, uuid);
if (devPortalApi != null) {
checkVisibilityPermission(userNameWithoutChange, devPortalApi.getVisibility(), devPortalApi.getVisibleRoles());
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);
populateAPIStatus(apiProduct);
apiProduct = addTiersToAPI(apiProduct, organization);
return new ApiTypeWrapper(apiProduct);
} else {
API api = APIMapper.INSTANCE.toApi(devPortalApi);
populateDevPortalAPIInformation(uuid, organization, api);
populateDefaultVersion(api);
populateAPIStatus(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);
}
}
use of org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI in project carbon-apimgt by wso2.
the class APIConsumerImpl method getLightweightAPIByUUID.
/**
* Get minimal details of API by registry artifact id
*
* @param uuid Registry artifact id
* @param organization identifier of the organization
* @return API of the provided artifact id
* @throws APIManagementException
*/
@Override
public API getLightweightAPIByUUID(String uuid, String organization) throws APIManagementException {
try {
Organization org = new Organization(organization);
DevPortalAPI devPortalApi = apiPersistenceInstance.getDevPortalAPI(org, uuid);
if (devPortalApi != null) {
checkVisibilityPermission(userNameWithoutChange, devPortalApi.getVisibility(), devPortalApi.getVisibleRoles());
API api = APIMapper.INSTANCE.toApi(devPortalApi);
// / populate relavant external info
// environment
String environmentString = null;
if (api.getEnvironments() != null) {
environmentString = String.join(",", api.getEnvironments());
}
api.setEnvironments(APIUtil.extractEnvironmentsForAPI(environmentString, organization));
// CORS . if null is returned, set default config from the configuration
if (api.getCorsConfiguration() == null) {
api.setCorsConfiguration(APIUtil.getDefaultCorsConfiguration());
}
return api;
} else {
String msg = "Failed to get API. API artifact corresponding to artifactId " + uuid + " does not exist";
throw new APIMgtResourceNotFoundException(msg);
}
} catch (APIPersistenceException e) {
String msg = "Failed to get API with uuid " + uuid;
throw new APIManagementException(msg, e);
}
}
Aggregations