It's all about the answers!

Ask a question

[closed] [EWM] add comments using API


HIROAKI JOSAKO (47427) | asked Apr 18 '23, 3:14 a.m.
closed Apr 19 '23, 4:00 a.m. by David Honey (1.8k17)

I'm thinking of using OSLC (REST API) to add comments to my Workitem.
At this time, can I specify the comment user and the comment creation date?
Reference
https://jazz.net/wiki/bin/view/Main/WorkItemAPIsForOSLCCM20#Adding_comments

The question has been closed for the following reason: "The question is answered, right answer was accepted" by davidhoney Apr 19 '23, 4:00 a.m.

Accepted answer


permanent link
Ralph Schoon (63.2k33646) | answered Apr 18 '23, 5:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 As far as I can tell, I have to agree with David. 


See this citation from the API document you provided: 

As the creation date and the creator are automatically assigned, it is sufficient to POST the comment representation with just description in it to the collection url.

I am only aware of ways to set certain data such as creator, created using the Java APIs. I am not aware if you can also do this using OSLC. I actually did find that out pretty recently for the EWM Plain Java API.

HIROAKI JOSAKO selected this answer as the correct answer

Comments
HIROAKI JOSAKO commented Apr 18 '23, 8:24 p.m.

I see!

 it is sufficient to POST the comment


When I read the word "sufficient to", I mistakenly thought it could be further customized.

With EWM Plain Java, it's amazing what we can do.
On a different thing, when updating an RTC in TASKTOP, it seems we can change the commenter to the intended user.
It means that we may be updating using RTC Plain Java.


Ralph Schoon commented Apr 19 '23, 2:09 a.m. | edited Apr 19 '23, 2:10 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

For the Plain Java client Libraries, you can only set the creator using com.ibm.team.workitem.common.model.IWorkItem.setCreator(IContributorHandle).

You can only set the creation dates when the work item is not yet created using code like this:


    Timestamp cDate = getWorkItem().getCreationDate();
    if(cDate==null){ // CreationDate can only be set during work item creation.
        Object creationDate = calculateTimestamp(parameter);
        if(creationDate!=null){
            getWorkItem().setCreationDate((Timestamp) creationDate);
        }
    }

</pre>
<div>
    <br>
</div>
<div>
</div>
creation date when you create the item using com.ibm.team.workitem.common.model.IWorkItem.setCreationDate(Timestamp)

HIROAKI JOSAKO commented Apr 27 '23, 3:08 a.m.

That's right about the date of creation of work items.
When importing CSV with Eclipse, I use this omission.
I wish the comment date was the same, but what about it?


Ralph Schoon commented Apr 27 '23, 3:49 a.m. | edited Apr 27 '23, 3:52 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You should be able to look into the SDK as good as I can. 

com.ibm.team.workitem.common.model.IComments does not expose this.
The internal implementation com.ibm.team.workitem.common.internal.model.Comments does not expose this. But you can see the implementation of createComment.

Utils.initNew(comment); does not look promising.

ModelFactory.eINSTANCE.createComment()  ultimately calls 

com.ibm.team.workitem.common.internal.model.impl.CommentImpl.class 

which exposes all the details, but it is an internal class and you would use it unsupported.

Using the EMF capabilities should allow to do a lot more, but is also dangerous.

One other answer



permanent link
David Honey (1.8k17) | answered Apr 18 '23, 4:22 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I think it unlikely. I would expect the creator of the comment to be the current authenticated user, and the creation time to be the time it was added to a comment. In other words, I would expect that any dcterms:creator and dcterms:created included in the POST request JSON body would be ignored. Allowing the REST API to spoof another user would be a security issue.


Comments
HIROAKI JOSAKO commented Apr 18 '23, 4:54 a.m.

After all, yes.
It can also be a security breach such as impersonation.

But the page here seems to have descriptions that could be changed explicitly.

https://jazz.net/wiki/bin/view/Main/ResourceOrientedWorkItemAPIv2#Adding_a_Comment_to_a_Work_Item

If it is ignored, why are the procedures written separately?
I would like to change my username if possible.

The purpose is to move (copy) Workitems from the old RTC server to the new EWM server.
Moving comments is very difficult, so I am testing it in the hope that it can be done with the API.


David Honey commented Apr 18 '23, 5:20 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I don't think you will be able to do so using that API.

The page you reference shows the data that is available when you fetch the comments, but that does not imply or state that they are modifiable. That page also states:
As the creation date and the creator are automatically assigned, it is sufficient to post the description:

Ian Barnard commented Apr 18 '23, 5:21 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

The spec you link to says "the creation date and the creator are automatically assigned" which implies you can't set them in the content, i.e. the content for creator is ignored. 


HIROAKI JOSAKO commented Apr 18 '23, 8:12 p.m.

I see, I was mistaken.
Thank you!
That's how it was written!
I didn't understand the context.