use of org.wso2.carbon.apimgt.api.model.APIIdentifier in project carbon-apimgt by wso2.
the class AbstractAPIManager method getAllDocumentation.
public List<Documentation> getAllDocumentation(Identifier id) throws APIManagementException {
List<Documentation> documentationList = new ArrayList<Documentation>();
String docArtifactKeyType = StringUtils.EMPTY;
docArtifactKeyType = APIConstants.DOCUMENTATION_KEY;
String apiOrAPIProductDocPath;
APIRevision apiRevision = apiMgtDAO.checkAPIUUIDIsARevisionUUID(id.getUUID());
if (apiRevision != null && apiRevision.getApiUUID() != null) {
apiOrAPIProductDocPath = APIUtil.getAPIOrAPIProductRevisionDocPath(apiRevision.getApiUUID(), apiRevision.getId());
} else {
apiOrAPIProductDocPath = APIUtil.getAPIOrAPIProductDocPath(id);
}
String pathToContent = apiOrAPIProductDocPath + APIConstants.INLINE_DOCUMENT_CONTENT_DIR;
String pathToDocFile = apiOrAPIProductDocPath + APIConstants.DOCUMENT_FILE_DIR;
try {
if (registry.resourceExists(apiOrAPIProductDocPath)) {
Resource resource = registry.get(apiOrAPIProductDocPath);
if (resource instanceof org.wso2.carbon.registry.core.Collection) {
List<String> docPaths = getDocPaths((org.wso2.carbon.registry.core.Collection) resource, apiOrAPIProductDocPath);
for (String docPath : docPaths) {
if (!(docPath.equalsIgnoreCase(pathToContent) || docPath.equalsIgnoreCase(pathToDocFile))) {
Resource docResource = registry.get(docPath);
GenericArtifactManager artifactManager = getAPIGenericArtifactManager(registry, docArtifactKeyType);
GenericArtifact docArtifact = artifactManager.getGenericArtifact(docResource.getUUID());
Documentation doc = APIUtil.getDocumentation(docArtifact);
Date contentLastModifiedDate;
Date docLastModifiedDate = docResource.getLastModified();
if (Documentation.DocumentSourceType.INLINE.equals(doc.getSourceType()) || Documentation.DocumentSourceType.MARKDOWN.equals(doc.getSourceType())) {
String contentPath = StringUtils.EMPTY;
if (id instanceof APIIdentifier) {
contentPath = APIUtil.getAPIDocContentPath((APIIdentifier) id, doc.getName());
} else if (id instanceof APIProductIdentifier) {
contentPath = APIUtil.getProductDocContentPath((APIProductIdentifier) id, doc.getName());
}
contentLastModifiedDate = registry.get(contentPath).getLastModified();
doc.setLastUpdated((contentLastModifiedDate.after(docLastModifiedDate) ? contentLastModifiedDate : docLastModifiedDate));
} else {
doc.setLastUpdated(docLastModifiedDate);
}
documentationList.add(doc);
}
}
}
}
} catch (RegistryException e) {
String msg = "Failed to get documentations for api/product " + id.getName();
throw new APIManagementException(msg, e);
}
return documentationList;
}
use of org.wso2.carbon.apimgt.api.model.APIIdentifier in project carbon-apimgt by wso2.
the class AbstractAPIManager method getSwaggerDefinitionTimeStamps.
/**
* gets the swagger definition timestamps as a map
*
* @param apiIdentifier
* @return
* @throws APIManagementException
*/
public Map<String, String> getSwaggerDefinitionTimeStamps(APIIdentifier apiIdentifier) throws APIManagementException {
String apiTenantDomain = getTenantDomain(apiIdentifier);
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;
}
return OASParserUtil.getAPIOpenAPIDefinitionTimeStamps(apiIdentifier, registryType);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
log.error("Error while getting the lastUpdated time due to " + e.getMessage(), e);
} catch (RegistryException e) {
log.debug("Error while getting the lastUpdated time due to " + e.getMessage(), e);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.APIIdentifier in project carbon-apimgt by wso2.
the class AbstractAPIManager method getWSDL.
/**
* Returns the wsdl content in registry specified by the wsdl name
*
* @param apiId Api Identifier
* @return wsdl content matching name if exist else null
*/
@Override
public ResourceFile getWSDL(APIIdentifier apiId) throws APIManagementException {
String apiPath = APIUtil.getAPIPath(apiId);
int prependIndex = apiPath.indexOf(apiId.getVersion()) + apiId.getVersion().length();
String apiSourcePath = apiPath.substring(0, prependIndex);
String wsdlResourcePath = apiSourcePath + RegistryConstants.PATH_SEPARATOR + APIUtil.createWsdlFileName(apiId.getProviderName(), apiId.getApiName(), apiId.getVersion());
String wsdlResourcePathOld = APIConstants.API_WSDL_RESOURCE_LOCATION + APIUtil.createWsdlFileName(apiId.getProviderName(), apiId.getApiName(), apiId.getVersion());
String tenantDomain = getTenantDomain(apiId);
boolean isTenantFlowStarted = false;
try {
Registry registry;
if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
isTenantFlowStarted = true;
startTenantFlow(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(apiId.getProviderName(), MultitenantConstants.SUPER_TENANT_ID);
} else {
registry = this.registry;
}
}
if (registry.resourceExists(wsdlResourcePath)) {
Resource resource = registry.get(wsdlResourcePath);
return new ResourceFile(resource.getContentStream(), resource.getMediaType());
} else if (registry.resourceExists(wsdlResourcePathOld)) {
Resource resource = registry.get(wsdlResourcePathOld);
return new ResourceFile(resource.getContentStream(), resource.getMediaType());
} else {
wsdlResourcePath = apiSourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_WSDL_ARCHIVE_LOCATION + apiId.getProviderName() + APIConstants.WSDL_PROVIDER_SEPERATOR + apiId.getApiName() + apiId.getVersion() + APIConstants.ZIP_FILE_EXTENSION;
wsdlResourcePathOld = APIConstants.API_WSDL_RESOURCE_LOCATION + APIConstants.API_WSDL_ARCHIVE_LOCATION + apiId.getProviderName() + APIConstants.WSDL_PROVIDER_SEPERATOR + apiId.getApiName() + apiId.getVersion() + APIConstants.ZIP_FILE_EXTENSION;
if (registry.resourceExists(wsdlResourcePath)) {
Resource resource = registry.get(wsdlResourcePath);
return new ResourceFile(resource.getContentStream(), resource.getMediaType());
} else if (registry.resourceExists(wsdlResourcePathOld)) {
Resource resource = registry.get(wsdlResourcePathOld);
return new ResourceFile(resource.getContentStream(), resource.getMediaType());
} else {
throw new APIManagementException("No WSDL found for the API: " + apiId, ExceptionCodes.from(ExceptionCodes.NO_WSDL_AVAILABLE_FOR_API, apiId.getApiName(), apiId.getVersion()));
}
}
} catch (RegistryException | org.wso2.carbon.user.api.UserStoreException e) {
String msg = "Error while getting wsdl file from the registry for API: " + apiId.toString();
throw new APIManagementException(msg, e);
} finally {
if (isTenantFlowStarted) {
endTenantFlow();
}
}
}
use of org.wso2.carbon.apimgt.api.model.APIIdentifier 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.apimgt.api.model.APIIdentifier 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;
}
Aggregations