使用Atlassian API访问与项目角色关联的组

时间:2014-02-12 21:59:41

标签: jira jira-plugin jira-rest-java-api

我目前正在开发一个插件,允许项目管理员分组管理用户。我一直在梳理api参考文档,我似乎无法找到任何可以让我看到与特定项目相关联的组的调用。

我在与我搜索的内容相关的每个位置查看了API,但无效。

我目前有一个数据库查询,可以提供我正在寻找的内容。

SELECT ROLETYPEPARAMETER AS "Groups"

FROM projectrole PROJECT_ROLE,
projectroleactor PROJECT_ROLE_ACTOR

JOIN project PROJECT
    ON PROJECT.id = PROJECT_ROLE_ACTOR.PID
JOIN cwd_group
    ON group_name = roletypeparameter

WHERE PROJECT_ROLE_ACTOR.projectroleid = PROJECT_ROLE.id
AND PKEY = <projectkey>;

如果可能的话,我宁愿通过API操纵这些数据。

我可以使用所有其他部分来完成插件添加,从组中删除用户。

我知道我正在寻找的信息是可用的。如果您导航到角色页面,则您既有角色中的用户,也有角色中的组。我确信我忽略了API的一些小问题,以便为我提供与项目相关的组。

1 个答案:

答案 0 :(得分:0)

在实现我的数据库路由后,我回到了非数据库方法。这是解决问题的实现。

实现组的方式是作为角色扮演者作为项目角色下的一组。再下一级,你将组名作为角色扮演者的描述符。

//Create TreeMap to Store the Role-Group association.  Note a role can have more than one group
TreeMap<String,Collection<String>> projectGroups = new TreeMap<String,Collection<String>>();

//Get all the project roles
Collection<ProjectRole> projectRoles = projectRoleManager.getProjectRoles();

//Iterate through each role and get the groups associated with the role
for (ProjectRole projectRole : projectRoles)
{
    //Get the role actors for the project role 
    ProjectRoleActors roleActors = projectRoleManager.getProjectRoleActors(projectRole, project);

    //Create an iterator to grab all of the groups for this project role
    Iterator <RoleActor> roleActorIterator = roleActors.getRoleActors().iterator();

    //Create a collection of strings to store all of the group's roles to put in the map
    Collection <String> groupRoles = new ArrayList<String>();

    //Iterate the role actors to get the groups
    while (roleActorIterator.hasNext())
    {

        //Add the group by string name into collection
        groupRoles.add(roleActorIterator.next().getDescriptor());

    }//END While

    //Add that role, and the associated groups to that role into our map.
    projectGroups.put(projectRole.getName(), groupRoles);

}//END For

此输出与此

类似
{Administrators=[jira-administrators], Developers=[jira-developers, jira-users], Users=[jira-users]}