Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

[closed] [EWM] add comments using API

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

0 votes


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

 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

0 votes

Comments

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.

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)

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?

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

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.

0 votes

Comments

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.

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:

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. 

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

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937

Question asked: Apr 18 '23, 3:14 a.m.

Question was seen: 1,088 times

Last updated: Apr 27 '23, 3:52 a.m.

Confirmation Cancel Confirm