use of org.wso2.carbon.registry.core.exceptions.RegistryException in project carbon-apimgt by wso2.
the class AbstractAPIManager method getAPIorAPIProductByUUID.
/**
* Get API or APIProduct by registry artifact id
*
* @param uuid Registry artifact id
* @param requestedTenantDomain tenantDomain for the registry
* @return ApiTypeWrapper wrapping the API or APIProduct of the provided artifact id
* @throws APIManagementException
*/
public ApiTypeWrapper getAPIorAPIProductByUUID(String uuid, String requestedTenantDomain) throws APIManagementException {
boolean tenantFlowStarted = false;
try {
Registry registry;
if (requestedTenantDomain != null) {
int id = getTenantManager().getTenantId(requestedTenantDomain);
startTenantFlow(requestedTenantDomain);
tenantFlowStarted = true;
if (APIConstants.WSO2_ANONYMOUS_USER.equals(this.username)) {
registry = getRegistryService().getGovernanceUserRegistry(this.username, id);
} else if (this.tenantDomain != null && !this.tenantDomain.equals(requestedTenantDomain)) {
registry = getRegistryService().getGovernanceSystemRegistry(id);
} else {
registry = this.registry;
}
} else {
registry = this.registry;
}
GenericArtifactManager artifactManager = getAPIGenericArtifactManagerFromUtil(registry, APIConstants.API_KEY);
GenericArtifact apiArtifact = artifactManager.getGenericArtifact(uuid);
if (apiArtifact != null) {
String type = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_TYPE);
if (APIConstants.API_PRODUCT.equals(type)) {
APIProduct apiProduct = getApiProduct(registry, apiArtifact);
String productTenantDomain = getTenantDomain(apiProduct.getId());
if (APIConstants.API_GLOBAL_VISIBILITY.equals(apiProduct.getVisibility())) {
return new ApiTypeWrapper(apiProduct);
}
if (this.tenantDomain == null || !this.tenantDomain.equals(productTenantDomain)) {
throw new APIManagementException("User " + username + " does not have permission to view API Product : " + apiProduct.getId().getName());
}
return new ApiTypeWrapper(apiProduct);
} else {
API api = getApiForPublishing(registry, apiArtifact);
String apiTenantDomain = getTenantDomain(api.getId());
if (APIConstants.API_GLOBAL_VISIBILITY.equals(api.getVisibility())) {
return new ApiTypeWrapper(api);
}
if (this.tenantDomain == null || !this.tenantDomain.equals(apiTenantDomain)) {
throw new APIManagementException("User " + username + " does not have permission to view API : " + api.getId().getApiName());
}
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 (RegistryException | org.wso2.carbon.user.api.UserStoreException e) {
String msg = "Failed to get API";
throw new APIManagementException(msg, e);
} finally {
if (tenantFlowStarted) {
endTenantFlow();
}
}
}
use of org.wso2.carbon.registry.core.exceptions.RegistryException in project carbon-apimgt by wso2.
the class AbstractAPIManager method getThumbnailLastUpdatedTime.
/**
* get the thumbnailLastUpdatedTime for a thumbnail for a given api
*
* @param apiIdentifier
* @return
* @throws APIManagementException
*/
@Override
public String getThumbnailLastUpdatedTime(APIIdentifier apiIdentifier) throws APIManagementException {
String artifactPath = APIConstants.API_IMAGE_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
String thumbPath = artifactPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_ICON_IMAGE;
try {
if (registry.resourceExists(thumbPath)) {
Resource res = registry.get(thumbPath);
Date lastModifiedTime = res.getLastModified();
return lastModifiedTime == null ? String.valueOf(res.getCreatedTime().getTime()) : String.valueOf(lastModifiedTime.getTime());
}
} catch (RegistryException e) {
String msg = "Error while loading API icon from the registry";
throw new APIManagementException(msg, e);
}
return null;
}
use of org.wso2.carbon.registry.core.exceptions.RegistryException in project carbon-apimgt by wso2.
the class APIMConfigServiceImpl method updateWorkflowConfig.
@Override
public void updateWorkflowConfig(String organization, String workflowConfig) throws APIManagementException {
if (organization == null) {
organization = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(organization, true);
int tenantId = APIUtil.getTenantIdFromTenantDomain(organization);
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(organization)) {
APIUtil.loadTenantRegistry(tenantId);
}
UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
if (registry.resourceExists(APIConstants.WORKFLOW_EXECUTOR_LOCATION)) {
Resource resource = registry.get(APIConstants.WORKFLOW_EXECUTOR_LOCATION);
byte[] data = IOUtils.toByteArray(new StringReader(workflowConfig));
resource.setContent(data);
resource.setMediaType(APIConstants.WORKFLOW_MEDIA_TYPE);
registry.put(APIConstants.WORKFLOW_EXECUTOR_LOCATION, resource);
}
} catch (RegistryException | IOException e) {
String msg = "Error while retrieving External Stores Configuration from registry";
log.error(msg, e);
throw new APIManagementException(msg, e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.registry.core.exceptions.RegistryException in project carbon-apimgt by wso2.
the class APIMConfigServiceImpl method addSelfSighupConfig.
@Override
public void addSelfSighupConfig(String organization, String selfSignUpConfig) throws APIManagementException {
if (organization == null) {
organization = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(organization, true);
int tenantId = APIUtil.getTenantIdFromTenantDomain(organization);
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(organization)) {
APIUtil.loadTenantRegistry(tenantId);
}
UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
if (!registry.resourceExists(APIConstants.SELF_SIGN_UP_CONFIG_LOCATION)) {
byte[] data = IOUtils.toByteArray(new StringReader(selfSignUpConfig));
Resource resource = registry.newResource();
resource.setContent(data);
resource.setMediaType(APIConstants.SELF_SIGN_UP_CONFIG_MEDIA_TYPE);
registry.put(APIConstants.SELF_SIGN_UP_CONFIG_LOCATION, resource);
}
} catch (RegistryException | IOException e) {
String msg = "Error while adding Self-SignUp Configuration from registry";
log.error(msg, e);
throw new APIManagementException(msg, e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.registry.core.exceptions.RegistryException in project carbon-apimgt by wso2.
the class APIMConfigServiceImpl method getExternalStoreConfig.
@Override
public String getExternalStoreConfig(String organization) throws APIManagementException {
if (organization == null) {
organization = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(organization, true);
int tenantId = APIUtil.getTenantIdFromTenantDomain(organization);
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(organization)) {
APIUtil.loadTenantRegistry(tenantId);
}
UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
if (registry.resourceExists(APIConstants.EXTERNAL_API_STORES_LOCATION)) {
Resource resource = registry.get(APIConstants.EXTERNAL_API_STORES_LOCATION);
return new String((byte[]) resource.getContent(), Charset.defaultCharset());
} else {
return null;
}
} catch (RegistryException e) {
String msg = "Error while retrieving External Stores Configuration from registry";
log.error(msg, e);
throw new APIManagementException(msg, e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
Aggregations