use of org.wso2.carbon.user.api.Tenant in project carbon-apimgt by wso2.
the class AbstractAPIManager method getGraphqlSchemaDefinition.
/**
* Returns the graphQL content in registry specified by the wsdl name
*
* @param apiId Api Identifier
* @return graphQL content matching name if exist else null
*/
@Override
public String getGraphqlSchemaDefinition(APIIdentifier apiId) throws APIManagementException {
String apiTenantDomain = getTenantDomain(apiId);
String schema;
try {
Registry registryType;
// Tenant store anonymous mode if current tenant and the required tenant is not matching
if (this.tenantDomain == null || isTenantDomainNotMatching(apiTenantDomain)) {
int tenantId = getTenantManager().getTenantId(apiTenantDomain);
registryType = getRegistryService().getGovernanceUserRegistry(CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME, tenantId);
} else {
registryType = registry;
}
schema = schemaDef.getGraphqlSchemaDefinition(apiId, registryType);
} catch (org.wso2.carbon.user.api.UserStoreException | RegistryException e) {
String msg = "Failed to get graphql schema definition of Graphql API : " + apiId;
throw new APIManagementException(msg, e);
}
return schema;
}
use of org.wso2.carbon.user.api.Tenant in project carbon-apimgt by wso2.
the class AbstractAPIManager method getApplicationByUUID.
/**
* Returns the corresponding application given the uuid with keys for a specific tenant.
*
* @param uuid uuid of the Application.
* @param tenantDomain domain of the accessed store.
* @return it will return Application corresponds to the uuid provided.
* @throws APIManagementException
*/
public Application getApplicationByUUID(String uuid, String tenantDomain) throws APIManagementException {
Application application = apiMgtDAO.getApplicationByUUID(uuid);
if (application != null) {
Set<APIKey> keys = getApplicationKeys(application.getId(), tenantDomain);
for (APIKey key : keys) {
if (APIConstants.JWT.equals(application.getTokenType())) {
key.setAccessToken("");
}
application.addKey(key);
}
int subscriptionCount = apiMgtDAO.getSubscriptionCountByApplicationId(application, tenantDomain);
application.setSubscriptionCount(subscriptionCount);
}
return application;
}
use of org.wso2.carbon.user.api.Tenant in project carbon-apimgt by wso2.
the class AbstractAPIManager method getIcon.
public ResourceFile getIcon(APIIdentifier identifier) throws APIManagementException {
String artifactOldPath = APIConstants.API_IMAGE_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion();
String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion();
String tenantDomain = getTenantDomain(identifier);
Registry registry;
boolean isTenantFlowStarted = false;
try {
if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
startTenantFlow(tenantDomain);
isTenantFlowStarted = true;
}
/* If the API provider is a tenant, load tenant registry*/
if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
int id = getTenantManager().getTenantId(tenantDomain);
registry = getRegistryService().getGovernanceSystemRegistry(id);
} else {
if (this.tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(this.tenantDomain)) {
registry = getRegistryService().getGovernanceUserRegistry(identifier.getProviderName(), MultitenantConstants.SUPER_TENANT_ID);
} else {
registry = this.registry;
}
}
String oldThumbPath = artifactOldPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_ICON_IMAGE;
String thumbPath = artifactPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_ICON_IMAGE;
if (registry.resourceExists(thumbPath)) {
Resource res = registry.get(thumbPath);
return new ResourceFile(res.getContentStream(), res.getMediaType());
} else if (registry.resourceExists(oldThumbPath)) {
Resource res = registry.get(oldThumbPath);
return new ResourceFile(res.getContentStream(), res.getMediaType());
}
} catch (RegistryException e) {
String msg = "Error while loading API icon of API " + identifier.getApiName() + ":" + identifier.getVersion() + " from the registry";
throw new APIManagementException(msg, e);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
String msg = "Error while loading API icon of API " + identifier.getApiName() + ":" + identifier.getVersion();
throw new APIManagementException(msg, e);
} finally {
if (isTenantFlowStarted) {
endTenantFlow();
}
}
return null;
}
use of org.wso2.carbon.user.api.Tenant in project carbon-apimgt by wso2.
the class AbstractAPIManager method getAPIProductbyUUID.
/**
* Get API Product by registry artifact id
*
* @param uuid Registry artifact id
* @param requestedTenantDomain tenantDomain for the registry
* @return API Product of the provided artifact id
* @throws APIManagementException
*/
public APIProduct getAPIProductbyUUID(String uuid, String requestedTenantDomain) throws APIManagementException {
try {
Registry registry;
if (requestedTenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(requestedTenantDomain)) {
int id = getTenantManager().getTenantId(requestedTenantDomain);
registry = getRegistryService().getGovernanceSystemRegistry(id);
} else {
if (this.tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(this.tenantDomain)) {
// at this point, requested tenant = carbon.super but logged in user is anonymous or tenant
registry = getRegistryService().getGovernanceSystemRegistry(MultitenantConstants.SUPER_TENANT_ID);
} else {
// both requested tenant and logged in user's tenant are carbon.super
registry = this.registry;
}
}
GenericArtifactManager artifactManager = getAPIGenericArtifactManagerFromUtil(registry, APIConstants.API_KEY);
GenericArtifact apiProductArtifact = artifactManager.getGenericArtifact(uuid);
if (apiProductArtifact != null) {
APIProduct apiProduct = getApiProduct(registry, apiProductArtifact);
WorkflowDTO workflowDTO = APIUtil.getAPIWorkflowStatus(apiProduct.getUuid(), WF_TYPE_AM_API_PRODUCT_STATE);
if (workflowDTO != null) {
WorkflowStatus status = workflowDTO.getStatus();
apiProduct.setWorkflowStatus(status.toString());
}
return apiProduct;
} else {
String msg = "Failed to get API Product. API Product artifact corresponding to artifactId " + uuid + " does not exist";
throw new APIMgtResourceNotFoundException(msg);
}
} catch (RegistryException e) {
String msg = "Failed to get API Product";
throw new APIManagementException(msg, e);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
String msg = "Failed to get API Product";
throw new APIManagementException(msg, e);
}
}
use of org.wso2.carbon.user.api.Tenant in project carbon-apimgt by wso2.
the class AbstractAPIManager method getDocumentationContent.
public String getDocumentationContent(Identifier identifier, String documentationName) throws APIManagementException {
String contentPath = StringUtils.EMPTY;
String identifierType = StringUtils.EMPTY;
if (identifier instanceof APIIdentifier) {
contentPath = APIUtil.getAPIDocPath((APIIdentifier) identifier) + APIConstants.INLINE_DOCUMENT_CONTENT_DIR + RegistryConstants.PATH_SEPARATOR + documentationName;
identifierType = APIConstants.API_IDENTIFIER_TYPE;
} else if (identifier instanceof APIProductIdentifier) {
contentPath = APIUtil.getProductDocPath((APIProductIdentifier) identifier) + APIConstants.INLINE_DOCUMENT_CONTENT_DIR + RegistryConstants.PATH_SEPARATOR + documentationName;
identifierType = APIConstants.API_PRODUCT_IDENTIFIER_TYPE;
}
String tenantDomain = getTenantDomain(identifier);
Registry registry;
boolean isTenantFlowStarted = false;
try {
if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
startTenantFlow(tenantDomain);
isTenantFlowStarted = true;
}
/* If the API provider is a tenant, load tenant registry*/
if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
int id = getTenantManager().getTenantId(tenantDomain);
registry = getRegistryService().getGovernanceSystemRegistry(id);
} else {
if (this.tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(this.tenantDomain)) {
registry = getRegistryService().getGovernanceUserRegistry(identifier.getProviderName(), MultitenantConstants.SUPER_TENANT_ID);
} else {
registry = this.registry;
}
}
if (registry.resourceExists(contentPath)) {
Resource docContent = registry.get(contentPath);
Object content = docContent.getContent();
if (content != null) {
return new String((byte[]) docContent.getContent(), Charset.defaultCharset());
}
}
} catch (RegistryException e) {
String msg = "No document content found for documentation: " + documentationName + " of " + identifierType + " : " + identifier.getName();
throw new APIManagementException(msg, e);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
String msg = "Failed to get document content found for documentation: " + documentationName + " of " + identifierType + " : " + identifier.getName();
throw new APIManagementException(msg, e);
} finally {
if (isTenantFlowStarted) {
endTenantFlow();
}
}
return null;
}
Aggregations