RTC API: how to set a work item modification date to an arbitrary one?
Context: copying work item histories from one repository to another.
When reading a workitem state, I can read when it has been saved to the server:
It's all good, I can read when a work item has been updated.IWorkItem wi; Date d; //... d = wi.modified();</pre>
Now, I would like to write a new work item or update a work item and specify a timestamp for the update itself, a different one than the one automatically set by the server. How can I override the default timestamp put by the server and set an arbitrary modification date (my goal is to reflect the original history from the source repository)? Thanks!
EDIT: same thing for the user: I would like to change not only the timestamp of a change, but also the user who did it.
Accepted answer
I am merely speculating here, but I could imagine that lots of things that provide incremental updating and caching functionality depend on no games being played with the modification date, in which case even if you did find some way to do this, you wouldn't want to. I'd suggest storing some custom property like "original-mod-date" if this info is important to maintain.
Comments
Yes, I thought the same and it is what I did (https://github.com/jeromede/rtc.pa#workaround-for-work-items-history).
But this limitation makes it impossible to develop a rather exact migration tool using only the API :-(
Thanks!
2 other answers
I have tried that and have not been able to change the modified date so far in the Java API, as this seems to be encapsulated in the API and the modification date is set when performing the save operation based on the server system time. I was able to change the creation date and the creator, but not the modification date since IWorkItem does not expose methods to set the values. I looked again today and found some promising methods on the implementation classes for the IWorkItem interface. Any IWorkItem implements the implementation class com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl, so the cast should be ok. So you can try the following (No guarantee that the change does not get overwritten though. I don't have the time to try it out.):
((com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl)workItem).setModifiedBy(null);((com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl)workItem).setModified((Timestamp)calculateTimestamp(parameter));
Comments
Thanks a lot, Ralph! (And yes, there would also be the person who modifies to override). I tried your suggestion, but, unfortunately, it looks like the save() on the working copy sets the modification time back to the server time... :-(
That was my fear and my current experience as well.
Trying to tweak com.ibm.team.workitem.common.internal.model.WorkItem doesn't work either.
I guess the date/user is updated in the save() anyway...
Thanks again.