It's all about the answers!

Ask a question

How to add and remove subscriber in a same Operation particpant?


Muthukumar C (32712833) | asked Oct 23 '12, 8:06 a.m.
Hai.

I have a peculiar requirement. I want to send alert notification mail to an user by adding him in the subscriber list based on a certain custom attribute and status of the Task.

Once the status change notification sent to the User, I want to unsubscribe him immediately. Because, other changes happening in the work item or not interested for them.

How to achieve this? Help appreciated.

Accepted answer


permanent link
sam detweiler (12.5k6195201) | answered Oct 23 '12, 8:27 a.m.
edited Apr 30 '13, 12:18 p.m.
at the time the participant is called, the workitem as been saved already.

so you will have to add the user as a subscriber, and save the workitem again,  which will call the participant again (so you need to set some flag to know this)
then you need to remove them as a subscriber, and save the workitem AGAIN.. which will call the participant again.

of course, I do not know if this will cause an email to be queued to send, as I don't know the internal timing of the calls.


Muthukumar C selected this answer as the correct answer

3 other answers



permanent link
Muthukumar C (32712833) | answered Oct 23 '12, 9:31 a.m.
edited Oct 23 '12, 9:32 a.m.
Thanks Sam.
I did the exact thing. I used SaveWorkitem3 method to send the additional parameter to avoid recursion.

But the thing is that the subscription is not happening. I removed the code for remove the subscriber and checked. user is not added as the Subscriber.

I am having the User ID as string. So I tried the following but no luck

sourceWorkItem = (IWorkItem) workItemServer.getAuditableCommon().resolveAuditable(sourceWorkItem ,IWorkItem.FULL_PROFILE,monitor).getWorkingCopy();
IContributor userIAG = (IContributor) IContributor.ITEM_TYPE.createItem();
userIAG.setUserId("myuserid");
ISubscriptions subscription= sourceWorkItem.getSubscriptions();
subscription.add(userIAG);
workItemServer.saveWorkItem3(sourceWorkItem, sourceWIRef, null, additionalParams);

   

                       

Comments
sam detweiler commented Oct 23 '12, 9:38 a.m.

you need to GET their contributor (user) record.
if they are not registered, you cannot add them to a workitem..


Muthukumar C commented Oct 23 '12, 9:44 a.m. | edited Oct 23 '12, 9:44 a.m.

I am doing that only.

IContributor userIAG = (IContributor) IContributor.ITEM_TYPE.createItem();
userIAG.setUserId("myuserid");

and adding that contributor to the subscriber.

Please let me know if I am doing some thing wron g


permanent link
sam detweiler (12.5k6195201) | answered Oct 24 '12, 9:40 p.m.
edited Apr 30 '13, 12:13 p.m.
U are creating a user entry in memory, not looking a user up in the system.

u need to use the IContributorManager class to find the user entry, from the javadoc

IContributorRecord fetchContributorRecordByUserId(IContributorUserId userId, org.eclipse.core.runtime.IProgressMonitor monitor)
          Fetches a contributor record by one of its user ids.



permanent link
Muthukumar C (32712833) | answered Oct 25 '12, 4:00 a.m.
Sam,

Thanks for guiding me in right direction.
As I am using the Server side plugin, I have achieved the functionality using

IContributorService#fetchContributorByUserId.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.