Worklog entries of an JIRA-user needs to be fetched

梦想的初衷 提交于 2019-12-12 04:55:51

问题


I have 15 usernames with me, I need to pull worklog entries of these users and manipulate it from JAVA client

Below are the jar files am using to connect JIRA api and fetch values

The code is pasted below

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());

}

For any given username, am able to print his displayName and emailAdress (all those basic infos).

But I need to get the list of worklogs for the given user. Not sure how to proceed


回答1:


You can find all worklog records for selected issue:

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

After that you can parse all worklog records to determine for what user this record created:

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

And last task is search of issues by some params:

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!");
    }
}


来源:https://stackoverflow.com/questions/23472620/worklog-entries-of-an-jira-user-needs-to-be-fetched

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