Search in sources :

Example 11 with Association

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;
    }
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) Association(org.wso2.carbon.registry.core.Association) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) API(org.wso2.carbon.apimgt.api.model.API) CommentList(org.wso2.carbon.apimgt.api.model.CommentList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 12 with Association

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);
    }
}
Also used : UserRealm(org.wso2.carbon.user.api.UserRealm) AuthenticationFailedException(org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) SMSOTPException(org.wso2.carbon.identity.authenticator.smsotp.exception.SMSOTPException) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager)

Aggregations

Association (org.wso2.carbon.registry.core.Association)10 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)8 Resource (org.wso2.carbon.registry.core.Resource)7 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)5 API (org.wso2.carbon.apimgt.api.model.API)4 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)4 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)4 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)4 UserStoreException (org.wso2.carbon.user.api.UserStoreException)4 ArrayList (java.util.ArrayList)3 DevPortalAPI (org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI)3 Registry (org.wso2.carbon.registry.core.Registry)3 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)3 List (java.util.List)2 QName (javax.xml.namespace.QName)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIResource (org.wso2.carbon.apimgt.api.doc.model.APIResource)2 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)2