0

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

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

在此处输入图像描述

代码粘贴在下面

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(所有这些基本信息)。

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

4

1 回答 1

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!");
    }
}
于 2014-07-09T12:33:45.477 回答