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 } }
Community moderators have prevented the ability to post new answers.
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();
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 !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.