Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Changelog history when importing from another issue-tracking software into JIRA

Saint Germain July 17, 2012

Having to import issue from another issue-tracking system, we must keep the transition history (i.e. when an issue went from 'Open' to 'In Progress' for instance).

It seems currently impossible through the "import CSV" from JIRA Importers Plugin.

As JIRA is currently used in production, we want to avoid changing the database directly (https://developer.atlassian.com/display/JIRADEV/Change+History) so I tried to develop a plugin using the official ChangeLogUtils.createChangeGroup API.

However it seems that even if I specify a timestamp when defining the transition (using ChangeItemBean), the current date/time is used instead of the specified timestamp.

In the following plugin code, I tried changing the TEST-1 issue and the registered changes is logged with the current time instead of the specified timestamp.

Tried with JIRA 5.0.6 installed on Windows and () with JIRA 5.1 installed on Linux.

Does anyone has managed to import issue changelog with the correct timestamp without messing directly with the database ?

Thanks for any help,

Here is the source code:

package com.user.jira.webwork;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.atlassian.jira.web.action.JiraWebActionSupport;

import com.atlassian.jira.ComponentManager;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.user.UserUtils;
import com.atlassian.jira.issue.IssueFieldConstants;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.history.ChangeLogUtils;
import org.ofbiz.core.entity.GenericValue;
import com.atlassian.jira.config.ConstantsManager;
import com.atlassian.jira.issue.status.Status;
import java.sql.Timestamp;

public class ForceTransition extends JiraWebActionSupport
{
    private static final Logger log = LoggerFactory.getLogger(ForceTransition.class);

    @Override
    public String execute() throws Exception {
	User user = null;
	Issue issue = null;
	IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
	ConstantsManager constantsManager = ComponentManager.getInstance().getConstantsManager(); 
	ChangeItemBean changeBean = null;
	IssueChangeHolder changeHolder = null;
	GenericValue changeLog = null;
	Status status_before = null;
	Status status_after = null;
	Timestamp created = new Timestamp(1);
	
	user = UserUtils.getUser("admin");
	issue = issueManager.getIssueObject( "TEST-1" );
	status_before = constantsManager.getStatusByName("Open");
	status_after = constantsManager.getStatusByName("In Progress");

	changeBean = new ChangeItemBean(ChangeItemBean.STATIC_FIELD, IssueFieldConstants.STATUS, status_before.getId(), status_before.getName(), status_after.getId(), status_after.getName(), created);

	changeHolder = new DefaultIssueChangeHolder();
	changeHolder.addChangeItem(changeBean);
	
	changeLog = ChangeLogUtils.createChangeGroup(user, issue, issue, changeHolder.getChangeItems(), true);

        return super.execute(); //returns SUCCESS
    }
}

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Dieter
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.
July 17, 2012

ChangeLogUtils.createChangeGroup always sets the created value to the current time.

You would have to add the following corrective code after

changeLog = ChangeLogUtils.createChangeGroup(user, issue, issue, changeHolder.getChangeItems(), true);

changeLog.set("created", created);
    	changeLog.store();

Saint Germain July 18, 2012

Thank you very much, it works perfectly.

changelog being a org.ofbiz.core.entity.GenericValue I had no idea that I could (and needed !) set or store anything (documentation is a bit lacking on that point).

Now we can import issues with changelog history, sweet !

0 votes
davidosteso November 16, 2016

Thanks Dieter,

It was really helpful!

 

 

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.
July 17, 2012

Yup, back in 4.2 I had to do it in a less elegant way with

GenericValue changeGroup = delegator.createValue("ChangeGroup", EasyMap.build("issue", issue.getId(), "author", (changeAuthor != null ? changeAuthor.getName() : null), "created", new java.sql.Timestamp(created.getTime())));
                    // TODO probably not needed since issue.store() does this?
                    cacheManager.flushChildren(CacheManager.ISSUE_CACHE, IssueRelationConstants.CHANGE_GROUPS, issue.getGenericValue());

TAGS
AUG Leaders

Atlassian Community Events