Best way for searching JIRA change history programmatically

Mário dos Santos _TOTVS_ June 7, 2017

Hi all,

I've to get data from issues transferred among projects during an interval of time.

What's the better method to do this in my Java plugin?

Keeping in mind performance, I think that executing SQL query directly is not a good idea (tables changegroup and changeitem).

This query returns exactly that I need.

 

 

SELECT project.pkey 
	,jiraissue.issuenum 
	,jiraissue.SUMMARY 
	,changegroup.CREATED 
	,changeitem.OLDSTRING 
	,changeitem.NEWSTRING 
	,cwd_user.display_name 
FROM changegroup 
	INNER JOIN changeitem 
		ON changeitem.groupid = changegroup.ID 
	INNER JOIN jiraissue 
		ON jiraissue.ID = changegroup.issueid 
	INNER JOIN project 
		ON project.ID = jiraissue.project 
	INNER JOIN cwd_user 
		ON cwd_user.user_name = changegroup.AUTHOR 
WHERE changeitem.FIELD = 'project' 
	AND changegroup.CREATED BETWEEN ' startDateTime ' AND ' finishDateTime ';

 

Somebody knows the correct way to do this?

Any sample piece of code will be appreciated.

 

Thanks in advance.

Mário dos Santos [TOTVS]

1 answer

0 votes
MattS
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.
June 7, 2017

Try https://docs.atlassian.com/jira/7.1.7/com/atlassian/jira/issue/changehistory/ChangeHistoryManager.html#getChangeHistoriesSince-com.atlassian.jira.issue.Issue-java.util.Date- for each issue in the proejct. But you may in fact get faster results using the lower-level APIs to execute the SQL you showed

Mário dos Santos _TOTVS_ June 8, 2017

Thank you very much for your reply Matt.

I've looked that interface before, but I've discarded it because I'd have to load all projects or issues to memory and iterate over them.
At this moment, we've 286008 issues in the instance which made me give up these interactions.
And what about the 'lower-level APIs' that you've mencioned, would you have any model or a path to them?

MattS
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.
June 8, 2017

Take a look at the implementation in 

jira-project/jira-components/jira-core/src/main/java/com/atlassian/jira/issue/changehistory/DefaultChangeHistoryManager.java

The same method and the ofBizDelegator part. You could create an EntityCondition for the project constraint

Suggest an answer

Log in or Sign up to answer