Get a list of UserHistoryItem for a specific period of time

todor kolev April 27, 2014

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

1 vote
Answer accepted
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 27, 2014

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.

todor kolev April 27, 2014

Hi Boris,

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

Any references to the API would be appreciated.

Many thanks

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 27, 2014

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.

todor kolev April 28, 2014

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;

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 28, 2014

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