It's all about the answers!

Ask a question

How to fetch userid of the modifier of Work Item usind a server side extension?


Harsh Vardhan Singh (32210) | asked Apr 22 '16, 6:47 a.m.
Hi,

I am working on creating a server-side plugin feature.

I have created a server- side  OperationPartcipant.

However, I am not able to get userid for the user who has modified the work item.

Currently I am using below code:

Object data = operation.getOperationData();
saveParameter = (ISaveParameter) data;
IWorkItem newState = (IWorkItem) saveParameter.getNewState();
String modified= newState.getModifiedBy().getItemId().getUuidValue();

Using above code I am getting a UUID value(maybe of user).

Is there a better way to do this?

Any suggestions/ tips would be helpful.

Thanks!

Accepted answer


permanent link
Ralph Schoon (58.7k23642) | answered Apr 22 '16, 7:20 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Apr 22 '16, 7:35 a.m.
If you want to do these kind of things it is critical to look at what Java Objects you receive and what you want and also  to try to find existing examples.

Start reading here: https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/

See https://rsjazz.wordpress.com/2014/05/26/only-owner-can-close-workitem-advisor/ it contains almost all the code you need.

The code would look similar to:

        IContributorHandle modifierHandle = workItem.getModifiedBy();
        IRepositoryItemService repositoryItemService=getService(IRepositoryItemService.class);
     IContributor modifier = (IContributor) repositoryItemService.fetchItem(modifierHandle , IRepositoryItemService.COMPLETE);

Harsh Vardhan Singh selected this answer as the correct answer

Comments
Harsh Vardhan Singh commented Jun 02 '16, 8:39 a.m.

Hi,

The code provided along with minor modifications worked.
However, when I save a Work Item in Web the value is returned as null for the "IContributor modifier" when workitem.getModifiedBy() is passed. While the same code works fine when workitem.getCreator() is passed.

The code is working fine when the changes in the Work Item are made in Eclipse Client.

Is this a known issue/limitation? Or am I doing something wrong?

I really don't like bothering you guys so much. So is there a documentation available which clearly mentions which services to call, when to call them and the dependencies which should be added to use them.

Blogs provided by you guys is very helpful! Real life like implementation and usage of the code really helps a lot.

Thanks


sam detweiler commented Jun 02 '16, 9:03 a.m.

there is no 'doc'. this is a long time problem.. there are tons of behaviors that you have to discover..

sounds like you  have found another bug.


Ralph Schoon commented Jun 02 '16, 9:05 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

All my server extensions so far have always worked in any UI. I would not expect any issues for server extensions. For attribute customization. You are limited to common API that should also work on client and server.


sam detweiler commented Jun 02 '16, 9:15 a.m. | edited Jun 02 '16, 9:25 a.m.

while I agree, I have had one experience where the data is not accurate unless I go get another copy from the system.  it is also in a participant.   my approval injector.

I shouldn't need to, but it doesn't work otherwise.

try this
// Get the full state of the parent work item so we can edit it
            IWorkItem cleancopy = (IWorkItem) fWorkItemServer.getAuditableCommon().resolveAuditable(workItem, IWorkItem.FULL_PROFILE, monitor);

and see if cleanCopy..getModifiedBy() works every time.. it should


Ralph Schoon commented Jun 02 '16, 10:48 a.m. | edited Jun 02 '16, 10:49 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

If this is in a participant or pre-condition the user in which this extension runs is the modifier of the workitem. This is how they work. So you can get the user context like in https://rsjazz.wordpress.com/2014/05/26/only-owner-can-close-workitem-advisor/  namely the loggedin contributor:

IContributorHandle loggedIn = this.getAuthenticatedContributor();

In the example above I have not even thought to use the modified by attribute. Otherwise I would have expected it to be in the newState.



One other answer



permanent link
sam detweiler (12.4k6182201) | answered Apr 22 '16, 8:32 a.m.
as often as this comes up, I think this is a failing of the documentation of the system design.

what is needed is a few sentences that describe the data model, using persistent identifiers (handles) in objects, and NOT object references themselves.

and this code needs to go away, and have a method on the base ITeamRepository class that does it
IRepositoryItemService repositoryItemService=getService(IRepositoryItemService.class);
   xxx= repositoryItemService.fetchItem(modifierHandle , IRepositoryItemService.COMPLETE);

everyone needs to do this and until you get the model and know the names, its impossible to get your head around it.



Your answer


Register or to post your answer.