It's all about the answers!

Ask a question

Why does a failed work item save in a participant cause the entire save operation to fail?


0
1
Jared Russell (1.3k12019) | asked Jul 31 '12, 6:32 a.m.
edited Aug 01 '12, 3:00 a.m. by David Olsen (5237)
I'm developing a work item participant that is designed to create a new work item in a different project area if certain conditions are met. One of the scenarios I need to deal with is if the user that triggers the participant does not have access/permissions to create the work item in the target project area, in which case I want my participant to do nothing and let the save operation proceed as normal.

I have two questions:

1) Is there any API to check if the user that triggered the participant has permissions to create a work item in the target project area? My approach so far has been to attempt the save and catch resulting TeamRepositoryException, which leads me to my next question...

2) I've wrapped the call to the IWorkItemServer#saveWorkItem2() call in a try/catch, with the catch block just silently ignoring the exception. Despite this, when I trigger the participant with a user that lacks permissions in the target project area, it causes the overall save operation to fail with an error message of "'Save Work Item' failed. Permission denied."

Things I've tried:
  • Surrounding the entire contents of the run() method in a try/catch(Throwable t) - no effect
  • Removed my participant from the process configuration - the save works fine

This behaviour seems to indicate that the failed attempt to save the work item in the other project causes some sort of global state to be set that prevents the operation from completing successfully. How can I prevent this failed save from causing the entire operation to fail?

Accepted answer


permanent link
Martha (Ruby) Andrews (3.0k44351) | answered Aug 01 '12, 4:31 p.m.
JAZZ DEVELOPER
Hello Jared,

com.ibm.team.process.service.IServerProcess#advise() returns a report that will tell you whether or not the user has permission to save. You must pass in the advisable operation. In your case, this would be the save on the work item you created.

Martha (Ruby) Andrews
Jazz L3 Developer
Ralph Schoon selected this answer as the correct answer

Comments
Nate Decker commented Jul 16 '14, 1:45 p.m.

How do you pass in the save on the work item as an advisable operation? Do you simply cast it? For example, would it look like this:

IServerProcess serverProcess = getService(IServerProcess.class);

IWorkItemServer service = getService(IWorkItemServer.class);

serverProcess.advise((AdvisableOperation) service.SaveWorkItem3(workItem, null, null, additionalParams));

I'm trying to test this via trial-and-error, but I'm experiencing issues with this because the server complains that com.ibm.team.process.service.IServerProcess service is not registered (causes an exception). Adding it to the plugin.xml doesn't seem to resolve the issue. Another forum posting seems to suggest that there may need to be a second prerequisite added to the plugin.xml and I'm investigating that (more trial-and-error). But if you can elaborate on what is required and thus save me time, I'd appreciate any further clarification.


Nate Decker commented Jul 16 '14, 4:00 p.m.

I tried to update the above comment, but evidently I don't have enough "reputation" for that. Instead, I'll post this follow up.

If anyone is using this thread to understand how to instantiate an IServerProcess instance, my example above is incorrect. It should look like this:

IProcessServerService pss = getService(IProcessServerService.class);
IServerProcess sp = pss.getServerProcess(operation.getProcessArea());

Of course this also requires that "com.ibm.team.process.service.IProcessServerService" also be added as a requiredService in the plugin.xml.

After that, I'm still not clear on how to use the IServerProcess object to do the advise operation. It takes an AdvisableOperation as its argument, but I'm not sure how to use my pending changes on the myWorkitem.getWorkingCopy() and convert it to an AdvisableOperation to pass to the advise function call.


sam detweiler commented Jul 16 '14, 4:18 p.m.

had to put my response in an answer below

2 other answers



permanent link
Ralph Schoon (63.4k33646) | answered Jul 31 '12, 7:58 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jul 31 '12, 7:58 a.m.
My take on it is, the check is done at a repository level. No matter how you wrap the operation, if the user has no permission - he has no permission. You can either give him permission or he chooses to save in a category where he has permissions.

It is probably very hard to check if the user has permission and the whole mechanism allows to create and edit. The permissions are checked when doing the save.

I also think it would be bad design if you could circumvent such basic permissions. 

Comments
Jared Russell commented Jul 31 '12, 9:02 a.m.

If the user has no permissions to create the work item then that's fine - as I mentioned I'm happy to not create the other work item and let the save operation continue. My question/problem is that RTC doesn't seem to let the save of the work item continue if the creation of the other work item fails. If I can't check the permissions that's also fine, I just need a way of allowing the save to continue and not throw an error message.


Ralph Schoon commented Jul 31 '12, 11:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Jared, are you sure you caught all exceptions? I assume if you fail to create the work item if you wrap that and catch everything you should be able to continue gracefully. I am wondering what you did not catch.


Jared Russell commented Jul 31 '12, 11:20 a.m. | edited Jul 31 '12, 11:21 a.m.

@rschoon 100% sure - as I mentioned in my original question I wrapped my entire run() method in a try/catch, and I can see in the debugger that the catch block is getting hit when the the attempt to create the other work item fails. Despite this the operation to save the work item that triggered the participant still fails with the permissions error.


Ralph Schoon commented Jul 31 '12, 11:22 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I will try to find some time to do the same stunt 8-)


Ralph Schoon commented Jul 31 '12, 11:23 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Um, I would not wrap the run() method, but the call to create/save the work item (maybe I am miss interpreting something) inside of the participants run() operation.


Jared Russell commented Jul 31 '12, 11:41 a.m.

@rschoon Wrapping the entirety of the run() method was done as an option of last resort to make sure there were no other exceptions being thrown - obviously for my production code I'd only catch the exception from the save operation

showing 5 of 6 show 1 more comments

permanent link
sam detweiler (12.5k6195201) | answered Jul 16 '14, 4:18 p.m.
AdvisableOperation is the parameter that gets passed to the advisor extensions.

the help for that datatype says (I have never built one to pass to advise)

Open Declaration com.ibm.team.process.common.advice.AdvisableOperation

An operation advisable by process. Advisable operations can be configured by end users with pre-condition checks (@see IOperationAdvisor ) and post-operation participation (@see IOperationParticipant ).

Advisable operations must be declared via extension so that clients can view the list of available operations to configure when authoring their process. Advisable operations are declared on the client as elements of the extension point com.ibm.team.process.client.configurationPoints . Operations are declared on the server as elements of the extension point com.ibm.team.process.service.configurationPoints .

For example:

     <extension
         point="com.ibm.team.process.client.configurationPoints">
         <operation
             id="com.ibm.example.operation"
             name="Example Operation">
                 <action id="foo">
                     <action id="bar"/>
                 </action>
                 <action id="foo2">
                     <action id="bar2"/>
                 </action>
         </operation>
     </extension>
 

Advisable operations may not be executed by clients directly. They should instead be passed to the advise and execute methods on the client or server process (@see com.ibm.team.process.client.IClientProcess and com.ibm.team.process.service.IServerProcess).

Since:
0.5


Comments
sam detweiler commented Jul 16 '14, 4:25 p.m.

>Advisable operations must be declared via extension so that clients can view the list of available operations to configure when authoring their process

this means to me that there must already be a workitem save operation that you should be able to locate in some other configuration. I haven't seen an example of that anywhere, and haven't done this myself.

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.