use of org.wso2.carbon.registry.core.Association in project carbon-apimgt by wso2.
the class APIConsumerImpl method getPublishedAPIsByProvider.
@Override
public Set<API> getPublishedAPIsByProvider(String providerId, String loggedUsername, int limit, String apiOwner, String apiBizOwner) throws APIManagementException {
try {
Boolean allowMultipleVersions = APIUtil.isAllowDisplayMultipleVersions();
Boolean showAllAPIs = APIUtil.isAllowDisplayAPIsWithMultipleStatus();
String providerDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(providerId));
int tenantId = getTenantId(providerDomain);
final Registry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
GenericArtifactManager artifactManager = APIUtil.getArtifactManager(registry, APIConstants.API_KEY);
if (artifactManager == null) {
String errorMessage = "Artifact manager is null when retrieving all published APIs by provider ID " + providerId;
log.error(errorMessage);
throw new APIManagementException(errorMessage);
}
int publishedAPICount = 0;
Map<String, API> apiCollection = new HashMap<String, API>();
if (apiBizOwner != null && !apiBizOwner.isEmpty()) {
try {
final String bizOwner = apiBizOwner;
Map<String, List<String>> listMap = new HashMap<String, List<String>>();
listMap.put(APIConstants.API_OVERVIEW_BUSS_OWNER, new ArrayList<String>() {
{
add(bizOwner);
}
});
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(this.username);
GenericArtifact[] genericArtifacts = artifactManager.findGenericArtifacts(listMap);
if (genericArtifacts != null && genericArtifacts.length > 0) {
for (GenericArtifact artifact : genericArtifacts) {
if (publishedAPICount >= limit) {
break;
}
if (isCandidateAPI(artifact.getPath(), loggedUsername, artifactManager, tenantId, showAllAPIs, allowMultipleVersions, apiOwner, providerId, registry, apiCollection)) {
publishedAPICount += 1;
}
}
}
} catch (GovernanceException e) {
log.error("Error while finding APIs by business owner " + apiBizOwner, e);
return null;
}
} else {
String providerPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + providerId;
Association[] associations = registry.getAssociations(providerPath, APIConstants.PROVIDER_ASSOCIATION);
for (Association association : associations) {
if (publishedAPICount >= limit) {
break;
}
String apiPath = association.getDestinationPath();
if (isCandidateAPI(apiPath, loggedUsername, artifactManager, tenantId, showAllAPIs, allowMultipleVersions, apiOwner, providerId, registry, apiCollection)) {
publishedAPICount += 1;
}
}
}
return new HashSet<API>(apiCollection.values());
} catch (RegistryException e) {
handleException("Failed to get Published APIs for provider : " + providerId, e);
return null;
} catch (org.wso2.carbon.user.core.UserStoreException e) {
handleException("Failed to get Published APIs for provider : " + providerId, e);
return null;
} catch (UserStoreException e) {
handleException("Failed to get Published APIs for provider : " + providerId, e);
return null;
}
}
use of org.wso2.carbon.registry.core.Association in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPUtils method updateUserAttribute.
/**
* Update the mobile number (user attribute) in user's profile.
*
* @param username the Username
* @param attribute the Attribute
* @throws SMSOTPException
*/
public static void updateUserAttribute(String username, Map<String, String> attribute, String tenantDomain) throws SMSOTPException {
try {
// updating user attributes is independent from tenant association.not tenant association check needed here.
UserRealm userRealm;
// user is always in the super tenant.
userRealm = SMSOTPUtils.getUserRealm(tenantDomain);
if (userRealm == null) {
throw new SMSOTPException("The specified tenant domain " + tenantDomain + " does not exist.");
}
// check whether user already exists in the system.
SMSOTPUtils.verifyUserExists(username, tenantDomain);
UserStoreManager userStoreManager = userRealm.getUserStoreManager();
userStoreManager.setUserClaimValues(username, attribute, null);
} catch (UserStoreException | AuthenticationFailedException e) {
throw new SMSOTPException("Exception occurred while connecting to User Store: Authentication is failed. ", e);
}
}
Aggregations