It's all about the answers!

Ask a question

RTC API: how to set a work item modification date to an arbitrary one?


Jerome De (184) | asked Jun 26 '17, 9:04 a.m.
edited Jun 26 '17, 11:34 a.m.

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:

IWorkItem wi;
Date d;
//...
d = wi.modified();

</pre>

It's all good, I can read when a work item has been updated.

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


permanent link
Geoffrey Clemm (29.4k23035) | answered Jun 26 '17, 5:06 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 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.

Jerome De selected this answer as the correct answer

Comments
Jerome De commented Jul 26 '17, 9:31 a.m.

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



permanent link
Sudipto Sarkar (63331) | answered Jun 26 '17, 9:19 a.m.

The return type of date field should be: timestamp. 


So, final return type should be :, 
return new Timestamp(date. GetTime());


Comments
Jerome De commented Jun 26 '17, 9:25 a.m.

Thanks, but it is not helping with my question.


permanent link
Ralph Schoon (56.6k23642) | answered Jun 26 '17, 9:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jun 26 '17, 9:37 a.m.

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
Jerome De commented Jun 26 '17, 9:44 a.m.

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... :-(


Ralph Schoon commented Jun 26 '17, 9:55 a.m. | edited Jun 26 '17, 9:55 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

That was my fear and my current experience as well. 

com.ibm.team.workitem.common.internal.model.WorkItem has the methods as well.

You can search for where the methods are used in the SDK and maybe find a way. I am not very optimistic though. 


Jerome De commented Jun 26 '17, 11:33 a.m.

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.

Your answer


Register or to post your answer.