use of org.wso2.carbon.apimgt.api.model.Identifier 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.apimgt.api.model.Identifier 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;
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class AbstractAPIManager method getOpenAPIDefinition.
/**
* Returns the swagger 2.0 definition of the given API
*
* @param apiId id of the APIIdentifier
* @param organization identifier of the organization
* @return An String containing the swagger 2.0 definition
* @throws APIManagementException
*/
@Override
public String getOpenAPIDefinition(Identifier apiId, String organization) throws APIManagementException {
String definition = null;
String id;
if (apiId.getUUID() != null) {
id = apiId.getUUID();
} else {
id = apiMgtDAO.getUUIDFromIdentifier(apiId.getProviderName(), apiId.getName(), apiId.getVersion(), organization);
}
try {
definition = apiPersistenceInstance.getOASDefinition(new Organization(organization), id);
} catch (OASPersistenceException e) {
throw new APIManagementException("Error while retrieving OAS definition from the persistance location", e);
}
return definition;
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class AbstractAPIManager method isDocumentationExist.
/**
* Checks whether the given document already exists for the given api/product
*
* @param identifier API/Product Identifier
* @param docName Name of the document
* @return true if document already exists for the given api/product
* @throws APIManagementException if failed to check existence of the documentation
*/
public boolean isDocumentationExist(Identifier identifier, String docName) throws APIManagementException {
String docPath = "";
docPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion() + RegistryConstants.PATH_SEPARATOR + APIConstants.DOC_DIR + RegistryConstants.PATH_SEPARATOR + docName;
try {
return registry.resourceExists(docPath);
} catch (RegistryException e) {
String msg = "Failed to check existence of the document :" + docPath;
throw new APIManagementException(msg, e);
}
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class AbstractAPIManager method getCustomMediationResourceFromUuid.
/**
* Returns the mediation policy registry resource correspond to the given identifier
*
* @param mediationPolicyId uuid of the mediation resource
* @return Registry resource of given identifier or null
* @throws APIManagementException If failed to get the registry resource of given uuid
*/
@Override
public Resource getCustomMediationResourceFromUuid(String mediationPolicyId) throws APIManagementException {
String resourcePath = APIConstants.API_CUSTOM_SEQUENCE_LOCATION;
try {
Resource resource = registry.get(resourcePath);
// resource : customsequences
if (resource instanceof Collection) {
Collection typeCollection = (Collection) resource;
String[] typeArray = typeCollection.getChildren();
for (String type : typeArray) {
Resource typeResource = registry.get(type);
// typeResource: in/ out/ fault
if (typeResource instanceof Collection) {
String[] policyArray = ((Collection) typeResource).getChildren();
if (policyArray.length > 0) {
for (String policy : policyArray) {
Resource mediationResource = registry.get(policy);
// mediationResource: eg .log_in_msg.xml
String resourceId = mediationResource.getUUID();
if (resourceId.equals(mediationPolicyId)) {
// registry resource
return mediationResource;
}
}
}
}
}
}
} catch (RegistryException e) {
String msg = "Error while accessing registry objects";
throw new APIManagementException(msg, e);
}
return null;
}
Aggregations