当前位置:  开发笔记 > 编程语言 > 正文

JIRA SOAP API:获取用户列表

如何解决《JIRASOAPAPI:获取用户列表》经验,为你挑选了1个好方法。

我正在使用C#中的一个工具来连接JIRA SOAP API.我已经阅读了可以在这里找到的文档:http://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/index.html

有谁知道如何获得特定项目的所有可分配用户的列表?我还没找到怎么做......



1> PierrOz..:

好的,我今天必须处于更好的状态,所以这里是我的问题的解决方案

    /// 
    /// object interface to the JIRA API
    /// 
    private readonly JiraSoapServiceClient _JiraService;

    /// 
    /// authentication token returned by the login method 
    /// that can be used on all other SOAP methods
    /// 
    private readonly string _Token;

    /// 
    /// name of the RemoteProjectRole "Developers"
    /// 
    private const string DEVELOPER_ROLE = "Developers";

    /// 
    /// id of the RemoteProjectRole "Developers"
    /// 
    private static long? _DeveloperId;

    /// 
    /// return the list of the names of all the users who have
    /// the role "Developers" in a project
    /// 
    /// 
    /// 
    public List GetUsersForProject(string project)
    {
        List users = new List();
        try
        {
            // get the RemoteProject
            RemoteProject rp = _JiraService.getProjectByKey(_Token, project);

            // get the "Developers" Prject Role
            RemoteProjectRole developerRole = getDeveloperRole();

            if (developerRole != null)
            {
                // we can use this method only if the user logged in is an administrator
                RemoteRoleActors actors = _JiraService.getProjectRoleActors(_Token, developerRole, rp);
                foreach (RemoteRoleActor actor in actors.roleActors)
                {
                    foreach (RemoteUser user in actor.users)
                    {
                        users.Add(user.name);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            // TODO log the error

            users.Clear();
        }
        users.Sort();
        return users;
    }

    /// 
    /// return the RemoteProjectRole "Developers"
    /// 
    /// 
    private RemoteProjectRole getDeveloperRole()
    {
        RemoteProjectRole developerRole = null;
        if (_DeveloperId == null)
        {
            // the first time we call this function we don't know the id of this role
            // that's why we are obliged to find it with a foreach on all the project roles
            foreach (RemoteProjectRole role in _JiraService.getProjectRoles(_Token))
            {
                if (role.name == DEVELOPER_ROLE)
                {
                    developerRole = role;
                    _DeveloperId = role.id;
                    break;
                }
            }
        }
        else
        {
            // we have the id so we can get directly the RemoteProjectRole from the JIRA SOAP API
            developerRole = _JiraService.getProjectRole(_Token, (long)_DeveloperId);
        }

        return developerRole;
    }

欢迎评论.显然,我们可以以不同的角色使用相同的方式.只需要确保用户登录JIRA api有一些管理员权限

推荐阅读
殉情放开那只小兔子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有