use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class APIUtil method clearResourcePermissions.
/**
* This function is to set resource permissions based on its visibility
*
* @param artifactPath API/Product resource path
* @throws APIManagementException Throwing exception
*/
public static void clearResourcePermissions(String artifactPath, Identifier id, int tenantId) throws APIManagementException {
try {
String resourcePath = RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + artifactPath);
String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(id.getProviderName()));
if (!org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
org.wso2.carbon.user.api.AuthorizationManager authManager = ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getAuthorizationManager();
authManager.clearResourceAuthorizations(resourcePath);
} else {
RegistryAuthorizationManager authorizationManager = new RegistryAuthorizationManager(ServiceReferenceHolder.getUserRealm());
authorizationManager.clearResourceAuthorizations(resourcePath);
}
} catch (UserStoreException e) {
handleException("Error while adding role permissions to API", e);
}
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class APIUtil method isPerAPISequence.
/**
* Returns true if the sequence is a per API one
*
* @param sequenceName
* @param tenantId
* @param identifier API identifier
* @param sequenceType in/out/fault
* @return true/false
* @throws APIManagementException
*/
public static boolean isPerAPISequence(String sequenceName, int tenantId, APIIdentifier identifier, String sequenceType) throws APIManagementException {
org.wso2.carbon.registry.api.Collection seqCollection = null;
try {
UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
if (registry.resourceExists(getSequencePath(identifier, sequenceType))) {
seqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(getSequencePath(identifier, sequenceType));
if (seqCollection != null) {
String[] childPaths = seqCollection.getChildren();
for (String childPath : childPaths) {
Resource sequence = registry.get(childPath);
OMElement seqElment = APIUtil.buildOMElement(sequence.getContentStream());
if (sequenceName.equals(seqElment.getAttributeValue(new QName("name")))) {
return true;
}
}
}
}
} catch (RegistryException e) {
String msg = "Error while retrieving registry for tenant " + tenantId;
log.error(msg);
throw new APIManagementException(msg, e);
} catch (org.wso2.carbon.registry.api.RegistryException e) {
String msg = "Error while processing the " + sequenceType + " sequences of " + identifier + " in the registry";
log.error(msg);
throw new APIManagementException(msg, e);
} catch (Exception e) {
throw new APIManagementException(e.getMessage(), e);
}
return false;
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class APIUtil method getAPIIdentifier.
/**
* Utility method to get api identifier from api path.
*
* @param apiPath Path of the API in registry
* @return relevant API Identifier
*/
public static APIIdentifier getAPIIdentifier(String apiPath) {
int length = (APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR).length();
if (!apiPath.contains(APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR)) {
length = (APIConstants.API_IMAGE_LOCATION + RegistryConstants.PATH_SEPARATOR).length();
}
if (length <= 0) {
length = (APIConstants.API_DOC_LOCATION + RegistryConstants.PATH_SEPARATOR).length();
}
String relativePath = apiPath.substring(length);
String[] values = relativePath.split(RegistryConstants.PATH_SEPARATOR);
if (values.length > 3) {
return new APIIdentifier(values[0], values[1], values[2]);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class APIAPIProductNameComparator method compare.
@Override
public int compare(Object o1, Object o2) {
Identifier identifier1;
Identifier identifier2;
if (o1 instanceof API) {
identifier1 = ((API) o1).getId();
} else {
identifier1 = ((APIProduct) o1).getId();
}
if (o2 instanceof API) {
identifier2 = ((API) o2).getId();
} else {
identifier2 = ((APIProduct) o2).getId();
}
Provider provider = new Provider(identifier1.getProviderName(), identifier2.getProviderName());
Name name = new Name(identifier1.getName(), identifier2.getName());
Version version = new Version(identifier1.getVersion(), identifier2.getVersion());
return compareFields(provider, name, version);
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class APIConsumerImpl method getLightweightAPI.
/**
* Get minimal details of API by API identifier
*
* @param identifier APIIdentifier object
* @return API of the provided APIIdentifier
* @throws APIManagementException
*/
public API getLightweightAPI(APIIdentifier identifier, String orgId) throws APIManagementException {
String uuid = null;
try {
Organization org = new Organization(orgId);
if (identifier.getUUID() != null) {
uuid = identifier.getUUID();
} else {
uuid = apiMgtDAO.getUUIDFromIdentifier(identifier.getProviderName(), identifier.getApiName(), identifier.getVersion(), orgId);
}
DevPortalAPI devPortalApi = apiPersistenceInstance.getDevPortalAPI(org, uuid);
if (devPortalApi != null) {
API api = APIMapper.INSTANCE.toApi(devPortalApi);
api.setOrganization(orgId);
return api;
} else {
String msg = "Failed to get API. API artifact corresponding to artifactId " + uuid + " does not exist";
throw new APIMgtResourceNotFoundException(msg);
}
} catch (APIPersistenceException e) {
String msg = "Failed to get API with uuid " + uuid;
throw new APIManagementException(msg, e);
}
}
Aggregations