use of org.wso2.carbon.governance.api.generic.GenericArtifactManager in project carbon-apimgt by wso2.
the class AbstractAPIManager method getDocumentation.
public Documentation getDocumentation(APIIdentifier apiId, DocumentationType docType, String docName) throws APIManagementException {
Documentation documentation = null;
String docPath = APIUtil.getAPIDocPath(apiId) + docName;
GenericArtifactManager artifactManager = getAPIGenericArtifactManagerFromUtil(registry, APIConstants.DOCUMENTATION_KEY);
try {
Resource docResource = registry.get(docPath);
GenericArtifact artifact = artifactManager.getGenericArtifact(docResource.getUUID());
documentation = APIUtil.getDocumentation(artifact);
} catch (RegistryException e) {
String msg = "Failed to get documentation details";
throw new APIManagementException(msg, e);
}
return documentation;
}
use of org.wso2.carbon.governance.api.generic.GenericArtifactManager in project carbon-apimgt by wso2.
the class APIProviderImpl method updateWsdlFromUrl.
/**
* This method is used to save the wsdl file in the registry
* This is used when user starts api creation with a soap endpoint
*
* @param api api object
* @throws APIManagementException
* @throws RegistryException
*/
public void updateWsdlFromUrl(API api) throws APIManagementException {
boolean transactionCommitted = false;
try {
registry.beginTransaction();
String apiArtifactId = registry.get(APIUtil.getAPIPath(api.getId())).getUUID();
GenericArtifactManager artifactManager = APIUtil.getArtifactManager(registry, APIConstants.API_KEY);
if (artifactManager == null) {
String errorMessage = "Artifact manager is null when updating WSDL of API " + api.getId().getApiName();
log.error(errorMessage);
throw new APIManagementException(errorMessage);
}
GenericArtifact artifact = artifactManager.getGenericArtifact(apiArtifactId);
GenericArtifact apiArtifact = APIUtil.createAPIArtifactContent(artifact, api);
String artifactPath = GovernanceUtils.getArtifactPath(registry, apiArtifact.getId());
if (APIUtil.isValidWSDLURL(api.getWsdlUrl(), false)) {
String path = APIUtil.createWSDL(registry, api);
updateWSDLUriInAPIArtifact(path, artifactManager, apiArtifact, artifactPath);
}
registry.commitTransaction();
transactionCommitted = true;
} catch (RegistryException e) {
try {
registry.rollbackTransaction();
} catch (RegistryException ex) {
handleException("Error occurred while rolling back the transaction.", ex);
}
throw new APIManagementException("Error occurred while saving the wsdl in the registry.", e);
} finally {
try {
if (!transactionCommitted) {
registry.rollbackTransaction();
}
} catch (RegistryException ex) {
handleException("Error occurred while rolling back the transaction.", ex);
}
}
}
use of org.wso2.carbon.governance.api.generic.GenericArtifactManager in project carbon-apimgt by wso2.
the class APIProviderImpl method isAPIUpdateValid.
public boolean isAPIUpdateValid(API api) throws APIManagementException {
String apiSourcePath = APIUtil.getAPIPath(api.getId());
boolean isValid = false;
try {
Resource apiSourceArtifact = registry.get(apiSourcePath);
GenericArtifactManager artifactManager = APIUtil.getArtifactManager(registry, APIConstants.API_KEY);
if (artifactManager == null) {
String errorMessage = "Failed to retrieve artifact manager when checking validity of API update for " + api.getId().getApiName();
log.error(errorMessage);
throw new APIManagementException(errorMessage);
}
GenericArtifact artifact = artifactManager.getGenericArtifact(apiSourceArtifact.getUUID());
String status = APIUtil.getLcStateFromArtifact(artifact);
if (!APIConstants.CREATED.equals(status) && !APIConstants.PROTOTYPED.equals(status)) {
// api at least is in published status
if (APIUtil.hasPermission(getUserNameWithoutChange(), APIConstants.Permissions.API_PUBLISH)) {
// user has publish permission
isValid = true;
}
} else if (APIConstants.CREATED.equals(status) || APIConstants.PROTOTYPED.equals(status)) {
// api in create status
if (APIUtil.hasPermission(getUserNameWithoutChange(), APIConstants.Permissions.API_CREATE) || APIUtil.hasPermission(getUserNameWithoutChange(), APIConstants.Permissions.API_PUBLISH)) {
// user has creat or publish permission
isValid = true;
}
}
} catch (RegistryException ex) {
handleException("Error while validate user for API publishing", ex);
}
return isValid;
}
use of org.wso2.carbon.governance.api.generic.GenericArtifactManager in project carbon-apimgt by wso2.
the class AbstractAPIManager method getAPIProduct.
/**
* Get API Product by product identifier
*
* @param identifier APIProductIdentifier
* @return API product identified by provider identifier
* @throws APIManagementException
*/
public APIProduct getAPIProduct(APIProductIdentifier identifier) throws APIManagementException {
String apiProductPath = APIUtil.getAPIProductPath(identifier);
Registry registry;
try {
String productTenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(identifier.getProviderName()));
int productTenantId = getTenantManager().getTenantId(productTenantDomain);
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(productTenantDomain)) {
APIUtil.loadTenantRegistry(productTenantId);
}
if (this.tenantDomain == null || !this.tenantDomain.equals(productTenantDomain)) {
// cross tenant scenario
registry = getRegistryService().getGovernanceUserRegistry(getTenantAwareUsername(APIUtil.replaceEmailDomainBack(identifier.getProviderName())), productTenantId);
} else {
registry = this.registry;
}
GenericArtifactManager artifactManager = getAPIGenericArtifactManagerFromUtil(registry, APIConstants.API_KEY);
Resource productResource = registry.get(apiProductPath);
String artifactId = productResource.getUUID();
if (artifactId == null) {
throw new APIManagementException("artifact id is null for : " + apiProductPath);
}
GenericArtifact productArtifact = artifactManager.getGenericArtifact(artifactId);
APIProduct apiProduct = APIUtil.getAPIProduct(productArtifact, registry);
return apiProduct;
} catch (RegistryException e) {
String msg = "Failed to get API Product from : " + apiProductPath;
throw new APIManagementException(msg, e);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
String msg = "Failed to get API Product from : " + apiProductPath;
throw new APIManagementException(msg, e);
}
}
use of org.wso2.carbon.governance.api.generic.GenericArtifactManager in project carbon-apimgt by wso2.
the class APIProviderImpl method updateWsdlFromResourceFile.
public void updateWsdlFromResourceFile(API api) throws APIManagementException {
boolean transactionCommitted = false;
try {
registry.beginTransaction();
String apiArtifactId = registry.get(APIUtil.getAPIPath(api.getId())).getUUID();
GenericArtifactManager artifactManager = APIUtil.getArtifactManager(registry, APIConstants.API_KEY);
if (artifactManager == null) {
String errorMessage = "Artifact manager is null when updating WSDL of API " + api.getId().getApiName();
log.error(errorMessage);
throw new APIManagementException(errorMessage);
}
GenericArtifact artifact = artifactManager.getGenericArtifact(apiArtifactId);
GenericArtifact apiArtifact = APIUtil.createAPIArtifactContent(artifact, api);
String artifactPath = GovernanceUtils.getArtifactPath(registry, apiArtifact.getId());
if (api.getWsdlResource() != null) {
String path = APIUtil.saveWSDLResource(registry, api);
// reset the wsdl path
apiArtifact.setAttribute(APIConstants.API_OVERVIEW_WSDL, api.getWsdlUrl());
// update the artifact
artifactManager.updateGenericArtifact(apiArtifact);
registry.commitTransaction();
transactionCommitted = true;
}
} catch (RegistryException e) {
try {
registry.rollbackTransaction();
} catch (RegistryException ex) {
handleException("Error occurred while rolling back the transaction.", ex);
}
} finally {
try {
if (!transactionCommitted) {
registry.rollbackTransaction();
}
} catch (RegistryException ex) {
handleException("Error occurred while rolling back the transaction.", ex);
}
}
}
Aggregations