如何通过JIRA插件中的电子邮件获取用户 [英] How to get a user by email in a JIRA plugin

查看:113
本文介绍了如何通过JIRA插件中的电子邮件获取用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为JIRA编写插件时,如何根据用户的电子邮件地址获取用户,或者仅仅是他们的用户名?

When writing a plugin for JIRA, how do you get a user, or just their username, given their email address?

似乎您应该在UserSearchService界面中使用findUsersByEmail方法

It seems that you're supposed to use the findUsersByEmail method in the UserSearchService interface

https://docs.atlassian.com/jira/7.0.2/com/atlassian/jira/bc/user/search/UserSearchService.html

但是如何获得此类的实例?还是单身?

But how do you get an instance of this class? Or a singleton of it?

推荐答案

JIRA中的组件系统基于Spring.因此,如果您正在处理的类是自动装配的(例如,像宏或Xwork操作之类的插件模块,则全部为servlet),请为UserSearchService创建一个实例变量并将其添加到构造函数中:

The component system in JIRA is built on Spring. Therefore, if the class you're working on is autowired (e.g. plugin module like a macro or a Xwork action, servlet all will be), create an instance variable for UserSearchService and add it to the constructor:

public MyServlet(UserSearchService userSearchService) {
    this.userSearchService = userSearchService;
}

或创建一个实例变量并为其添加一个setter:

OR create an instance variable and add a setter for it:

public void setUserSearchService(UserSearchService userSearchService) {
    this.userSearchService= userSearchService;
}

如果您正在处理的类未自动连线,则有时可以使用

If the class you're working on is not autowired, you can sometimes use the ComponentAccessor to access an instance statically but I can't see the UserSearchService in the list of methods.

这篇关于如何通过JIRA插件中的电子邮件获取用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆