Stale data exception in an Operation Participant.
Hi,
I had face an issue with an operation participant.My operation participant
updates the workitem description,but when I was trying to save the workitem it gives stale data exception.
Here is my operation participant code.
Any help ??
Object data = operation.getOperationData();
if(data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable newState = saveParameter.getNewState();
if(newState instanceof IAuditable) {
IWorkItem workItemNewState = (IWorkItem) newState;
IWorkItem workingCopy = (IWorkItem) workItemNewState.getWorkingCopy();
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
IAttribute descAttribute =
workItemServer.findAttribute(workItemNewState.getProjectArea(), "description", null);
workingCopy.setValue(descAttribute, "This is description");
workItemServer.saveWorkItem2(workingCopy, null, null);
I had face an issue with an operation participant.My operation participant
updates the workitem description,but when I was trying to save the workitem it gives stale data exception.
Here is my operation participant code.
Any help ??
Object data = operation.getOperationData();
if(data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable newState = saveParameter.getNewState();
if(newState instanceof IAuditable) {
IWorkItem workItemNewState = (IWorkItem) newState;
IWorkItem workingCopy = (IWorkItem) workItemNewState.getWorkingCopy();
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
IAttribute descAttribute =
workItemServer.findAttribute(workItemNewState.getProjectArea(), "description", null);
workingCopy.setValue(descAttribute, "This is description");
workItemServer.saveWorkItem2(workingCopy, null, null);
Accepted answer
As far as I am aware this happens if you try to modify the save parameter directly.
http://www.google.de/search?q=stale+data+participant+site%3Ajazz.net has some hits and I have seen discussions and solutions to this in the forms.
I would suggest to try to fully resolve the new state, get a working copy on that and then save that.
IWorkItem workitem= (IWorkItem)workItemServer.getAuditableCommon().resolveAuditable(workItemNewState ,IWorkItem.FULL_PROFILE,monitor).getWorkingCopy();
http://www.google.de/search?q=stale+data+participant+site%3Ajazz.net has some hits and I have seen discussions and solutions to this in the forms.
I would suggest to try to fully resolve the new state, get a working copy on that and then save that.
IWorkItem workitem= (IWorkItem)workItemServer.getAuditableCommon().resolveAuditable(workItemNewState ,IWorkItem.FULL_PROFILE,monitor).getWorkingCopy();
Comments
1 vote
One other answer
you need to set a flag in the data that you can check when you are called a second time (recursion)
The saveWorkItem3() operation takes an additional parameter, a set of strings. This can be used to detect that a subsequent trigger of the participant was caused by this save operation. The following code inserted into the run() operation would allow to detect the recursion
to save the workitem and pass the parameter
<code>
additionalParams = new HashSet(); additionalParams.add(IExtensionsDefinitions.UPDATE_PARENT_DURATION_EXTENSION_ID);
</code>
.
.
.
<code>
workItemServer.saveWorkItem3(workingCopy, null, null, additionalParams);
</code>
to check for the parameter
<code>
if (saveParameter.getAdditionalSaveParameters().contains(
IExtensionsDefinitions.UPDATE_PARENT_DURATION_EXTENSION_ID))
return;
</code>
The saveWorkItem3() operation takes an additional parameter, a set of strings. This can be used to detect that a subsequent trigger of the participant was caused by this save operation. The following code inserted into the run() operation would allow to detect the recursion
to save the workitem and pass the parameter
<code>
additionalParams = new HashSet(); additionalParams.add(IExtensionsDefinitions.UPDATE_PARENT_DURATION_EXTENSION_ID);
</code>
.
.
.
<code>
workItemServer.saveWorkItem3(workingCopy, null, null, additionalParams);
</code>
to check for the parameter
<code>
if (saveParameter.getAdditionalSaveParameters().contains(
IExtensionsDefinitions.UPDATE_PARENT_DURATION_EXTENSION_ID))
return;
</code>