需要获取JIRA用户的工作日志条目

时间:2014-05-05 12:35:44

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

我有15个用户名,我需要提取这些用户的工作日志条目并从JAVA客户端操作它

以下是用于连接JIRA api和获取值的jar文件

enter image description here

代码粘贴在

下面
public class JiraConnector {

JiraRestClient jira;

public JiraConnector() throws URISyntaxException {
    String url = prop().getUrl();
    String userName = prop().getUser() ;
    String password = prop().getpwd() ;
    JerseyJiraRestClientFactory clientFactory = new JerseyJiraRestClientFactory();
    jira = clientFactory.createWithBasicHttpAuthentication(new URI(url),
            userName, password);
    System.out.println("Connection established to >> " + url);
}

public void printIssueDetails(String jiraNumber) {
    System.out.println("JiraNumber is " + jiraNumber);
    Issue issue = jira.getIssueClient().getIssue(jiraNumber, null);

    System.out.println(issue.getSummary());
    System.out.println(issue.getDescription());
}

public void printUserWorkLog(String userName) {
    System.out.println("user details invoked ... ");
    User user = jira.getUserClient().getUser(userName, null);
    System.out.println(user.getDisplayName());
    System.out.println(user.getEmailAddress());

}

对于任何给定的用户名,我可以打印他的displayName和emailAdress(所有这些基本信息)。

但我需要获取给定用户的工作日志列表。不知道如何继续

1 个答案:

答案 0 :(得分:2)

您可以找到所选问题的所有工作日志记录:

List<Worklog> worklogByIssue = ComponentAccessor.getWorklogManager().getByIssue(issue);

之后,您可以解析所有工作日志记录,以确定此记录创建的用户:

for (Worklog worklogByIssueItem : worklogByIssue)
{
   int timeSpent = worklogByIssueItem.getTimeSpent().intValue();
   String worklogAuthorName = worklogByIssueItem.getAuthorObject().getName();
   ...
}

最后一项任务是通过一些参数搜索问题:

public static List<Issue> searchIssues(SearchParametersAggregator searchParams)
{
    String jqlQuery = searchParams.getJqlQuery();
    String projectId = searchParams.getProjectId();
    String condition = createCondition(jqlQuery, projectId);

    JqlQueryBuilder jqlQueryBuilder = prepareJqlQueryBuilder(condition);

    return searchIssues(jqlQueryBuilder);
}

static List<Issue> searchIssues(JqlQueryBuilder jqlQueryBuilder)
{
    Query query = jqlQueryBuilder.buildQuery();
    SearchService searchService = ComponentAccessor.getComponent(SearchService.class);
    try
    {
        ApplicationUser applicationUser = ComponentAccessor.getJiraAuthenticationContext().getUser();
        User user = applicationUser.getDirectoryUser();
        SearchResults searchResults = searchService.search(user, query, PagerFilter.getUnlimitedFilter());
        List<Issue> issues = searchResults.getIssues();

        return issues;
    }
    catch (SearchException e)
    {
        LOGGER.error("Error occurs during search of issues");
        e.printStackTrace();
    }

    return new ArrayList<Issue>();
}

static JqlQueryBuilder prepareJqlQueryBuilder(String condition)
{
    try
    {
        Query query = jqlQueryParser.parseQuery(condition);
        JqlQueryBuilder builder = JqlQueryBuilder.newBuilder(query);

        return builder;
    }
    catch (JqlParseException e)
    {
        throw new RuntimeException("JqlParseException during parsing jqlQuery!");
    }
}