It's all about the answers!

Ask a question

How an operation participant works?


0
1
Muthukumar C (32712833) | asked Jul 16 '12, 3:12 a.m.
edited Jul 16 '12, 12:59 p.m. by David Olsen (5237)
Hi all,

Question seems to be crazy. But I have a valid reason behind it.

Today, I tried to add a comment to a work item from a Operation Participant plugin.
But Nothing is happening when the plugin executes. Later I found that we should explicitly save the Workitem
using the statement workItemServer.saveWorkItem2(workItem, null, null);

But, is it logical to have this statement to confirm our transaction? Because, I am adding this plug-in in the Save Work item operation only,

Moreover, Operation Advisors that I I have already added also executing again during this explicit save operation again.

So the flow is like...
1. (Precondition) Advisors will execute --> Error in case of any validation vioaltion
2. Else continue with (Followup) Participants.
3. In case of any changes in the WI data, then we need to SAVE the WI using the saveWorkItem2 method
4. Again all the Advisors will execute and Participant will save the Workitem.

I am not sure whether is this right.. or I am misunderstanding some thing.

I really got confused between Advsior and Participant .

6 answers



permanent link
Ralph Schoon (63.1k33645) | answered Jul 17 '12, 5:44 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi Muthukumar,

I looked into the stale data. It appears you can't just modify the workingcopy in the participant. So I loaded the work item again and then I was able to save it in the participant.

wiServer = getService(IWorkItemServer.class);
IWorkItem wi = (IWorkItem)wiServer.getAuditableCommon().resolveAuditable(newState, IWorkItem.FULL_PROFILE, monitor).getWorkingCopy();

// Add a comment
IComments comments = newState.getComments();
IComment newComment = comments.createComment(this.getAuthenticatedContributor(),XMLString.createFromPlainText("Jazz note #2"));
wi.getComments().append(newComment);
                        wi.setHTMLDescription(XMLString.createFromPlainText(newState.getHTMLDescription().getPlainText()+"t"));
wiServer.saveWorkItem2(wi, null, null);


permanent link
Ralph Schoon (63.1k33645) | answered Jul 17 '12, 7:38 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi, not sure why this didn't post correctly. I assume you have solved it yourself, below is what to do in a participant to modify and save a work item avoiding the stale data.

Please be aware that this is a new save operation and your followup action triggers again. i found this with some hint on how to avoid it: https://jazz.net/forum/questions/49087/how-to-know-who-is-saving-the-wi-user-or-participant#52519

Hi Muthukumar,

I looked into the stale data. It appears you can't just modify the workingcopy in the participant. So I loaded the work item again and then I was able to save it in the participant.

wiServer = getService(IWorkItemServer.class);
IWorkItem wi = (IWorkItem)wiServer.getAuditableCommon().resolveAuditable(newState, IWorkItem.FULL_PROFILE, monitor).getWorkingCopy();

// Add a comment
IComments comments = newState.getComments();
IComment newComment = comments.createComment(this.getAuthenticatedContributor(),XMLString.createFromPlainText("Jazz note #2"));
wi.getComments().append(newComment);
                        wi.setHTMLDescription(XMLString.createFromPlainText(newState.getHTMLDescription().getPlainText()+"t"));
wiServer.saveWorkItem2(wi, null, null);

Comments
1
Ralph Schoon commented Jul 17 '12, 7:42 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

permanent link
Ralph Schoon (63.1k33645) | answered Jul 16 '12, 5:35 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jul 16 '12, 5:39 a.m.
Hi,

all preconditions and followup actions (advisors/participants) are triggered by operations such as work item save. That does not at all mean that they are actually doing things like saving or modifying work items.
A typical precondition for example checks if the save should happen based on some data. A follow up action might do something after an operation that is more or less unrelated to the data that triggered the save.

So if you want to modify data in such an operation you need to do the necessary steps to be able to.

By the way, this shows how to create a work item using an operation: https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation. You can also use it to modify work items.

I am not sure if it is possible to prevent the operations for the subsequent save you do. You could modify the work item in a way that prevents its save for example. In this case you would like the save to fail.

Comments
Muthukumar C commented Jul 16 '12, 5:42 a.m. | edited Jul 16 '12, 9:29 a.m.

hi ralph.

Thanks for the response.

I totally agree with you. My question is that, if I want to add a comment in a Work item using a Participant plug-in [which is added in the WorkItemSave], then I need to write the code for Adding the comment as well as code to Save the work item itself. In case of advisor it is not necessary. That is the point where I am getting deadlock.






Ralph Schoon commented Jul 16 '12, 6:49 a.m. | edited Jul 16 '12, 9:29 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Hi Mutukumar,

I have so far only created advisors or participants that acted on information. I never had to modify the information I was acting on.

As far as I understand, you need to have a working copy of a work item, in order to modify and save it. I was not aware what you get in an advisor or a participant. You can check what you have using the operation .isWorkingCopy().

If a follow up action creates a deadlock, because your save triggers a new run, I would try to use an advisor/preconditon.


permanent link
Muthukumar C (32712833) | answered Jul 16 '12, 9:37 a.m.
Dear Ralph,

I want to modify the Data of a work item from Followup condition. Lets say I want to add a Comment to the current WI (Which we are going to save) if the user has changed its Parent link.

I have tried by just adding the code for inserting comment in WI. But the comment not saved in WI. Then I add the code for Saving  the work item [saveworkitem2].
that code is working fine if user does'nt modify any data except the LINKS.
if any other modifications (State Change / Data change), Then I am getting Stale Data exception.

Guide me in this regards.

Thanks in advance



permanent link
Ralph Schoon (63.1k33645) | answered Jul 16 '12, 10:29 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi, Muthukumar,

please check these posts:

https://jazz.net/forum/questions/38138/stale-data-problem-in-plain-client
https://jazz.net/forum/questions/50984/sate-data-exception-on-bulkcocurrent-workitem-update

I haven't done something like this, and I am not sure what happens. One thing with stale data is reread the work item. The other thing is, that the code you use might just not be enough.

Currently, if creating or modifying a work item I use the WorkItemOperation from https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation where the operation does all that is needed to load and save.

This is code I used in the past to update code using a workingcopy:

        IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();        

        wcm.connect(workItem, IWorkItem.FULL_PROFILE, null);
       
        try {
            WorkItemWorkingCopy wc = wcm.getWorkingCopy(workItem);
           
            wc.getWorkItem().setHTMLSummary(XMLString.createFromPlainText(summary));
            IWorkItem wi = wc.getWorkItem();
            List <IAttributeHandle> attribs = wi.getCustomAttributes();
            for (Iterator iterator = attribs.iterator(); iterator.hasNext();) {
                IAttributeHandle iAttributeHandle = (IAttributeHandle) iterator
                        .next();
                IAttribute anAttribute = (IAttribute)auditableClient.resolveAuditable(iAttributeHandle, IAttribute.FULL_PROFILE, null);
                System.out.println("AttName:" + anAttribute.getDisplayName());               
            }
            IDetailedStatus s = wc.save(null);
            if (!s.isOK()) {
                throw new TeamRepositoryException("Error saving work item",
                        s.getException());
            }
        } finally {
            wcm.disconnect(workItem);
        }

        System.out.println("Modified work item: " + workItem.getId() + ".");

 


permanent link
Muthukumar C (32712833) | answered Jul 17 '12, 7:29 a.m.
Ralph, I agree with the approach.
I read a IBM article and understood that
1. Advisors are for checking the preconditions and Stop the save operation in case of any violation.
2. Participants should be used as followup conditions that is to modify the Other elements of the Artifacts based on the current work item.
3. If we want to change the attribute values of the Current Work item, then we need to add a Script based Calculated Values.

But, Instead of spending time in Scrip, As of now I added the Comment from the advisor plugin itself.

Thanks for your time.

Regards
Muthukumar

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.