Get a list of UserHistoryItem for a specific period of time

How can I get a list of UserHistoryItem for a specific period of time. Currently our plugin needs that functionality for internal business usage and what we have determined so far is we can call for example:
List<UserHistoryItem> issueHistoryItems = userHistoryManager.getHistory(UserHistoryItem.ISSUE, appUser);
to obtain a list of UserHistoryItem(s) but we can't find out how to restrict the period of time those changes occurred.

1 answer

1 accepted

User history does not contain data about the date it was created.

What do you exaclty want to achieve. Maybe there is a better approach which will allow you to filter by date.

Hi Boris,

I'd like to obtain user's activity for a specific timespan.

Any references to the API would be appreciated.

Many thanks

If by activity you mean any issue-related activity you can then use com.atlassian.jira.user.UserHistoryItem.getType() to filter out all items related to issues and the use com.atlassian.jira.user.UserHistoryItem.getEntityId() to collect all issue ids that were affected by a user action. Next use com.atlassian.jira.issue.changehistory.ChangeHistoryManager.getChangeHistoriesForUser(Iterable<Issue>, User) to get all com.atlassian.jira.issue.changehistory.ChangeHistory objects. The ChangeHistory has a getTimePerformed() method which you can use to apply filter by date/time period.

Thanks,

Have you got any idea why all the changeItems fields in the obtianed List<ChangeHistory> are null?

List&lt;UserHistoryItem&gt; issueHistoryItems = userHistoryManager.getHistory(UserHistoryItem.ISSUE, appUser);
        List&lt;Issue&gt; issuesUserActedOn = new ArrayList&lt;Issue&gt;();
        for(UserHistoryItem userHistoryItem : issueHistoryItems){
            Issue issueByString = issueManager.getIssueObject(userHistoryItem.getEntityId());
            Issue issueByLong = issueManager.getIssueObject(Long.parseLong(userHistoryItem.getEntityId()));
            issuesUserActedOn.add(issue);

        }

        List&lt;ChangeHistory&gt; changeHistories = changeHistoryManager.getChangeHistoriesForUser(issuesUserActedOn, ApplicationUsers.toDirectoryUser(appUser));

Output from the debugger:

  • [2] = {com.atlassian.jira.issue.changehistory.ChangeHistoryBatch$ChangeHistoryWithLazyLoadedChangeItems@27042}
  • this$0 = {com.atlassian.jira.issue.changehistory.ChangeHistoryBatch@26936}
  • changeHistory = {org.ofbiz.core.entity.GenericValue@27093} size = 4
  • [0] = {java.util.HashMap$Entry@27122}"id" -> "12871"
  • [1] = {java.util.HashMap$Entry@27124}"author" -> "svspkccjg"
  • [2] = {java.util.HashMap$Entry@27126}"created" -> "2013-11-19 13:36:07.0"
  • [3] = {java.util.HashMap$Entry@27128}"issue" -> "10274"
  • issueManager = {com.atlassian.jira.issue.managers.DefaultIssueManager@26937}
  • changeItems = null
  • user = null
  • userManager = {com.atlassian.jira.user.util.DefaultUserManager@26938}

... where you can see that changeItems = null;

The change items are lazy loaded so you should call some method and then check rather than just looking at the debugger

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,943 views 19 22
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you