How to get a user by email in a JIRA plugin

非 Y 不嫁゛ 提交于 2020-01-06 03:20:10

问题


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

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?


回答1:


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;
}

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.



来源:https://stackoverflow.com/questions/35853662/how-to-get-a-user-by-email-in-a-jira-plugin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!