Problems With Update WorkItem Subscribers PlugIn
Hi, i have a problem with my plugin .
A brief description how it works:
" When the workitem "defect" changes its state in "Closed", the members with a role equal to "subscriber" ( custom role ) and belonging to the Project Area are added as subscribers. "
The problem is :
Subscribers are properly added to the workitem working copy but the original workItem is not updated.
This is the plugin java code :
----------------------------------------------------------------------------------------------------------------------------------------------------------
public class SubscriberOnChange extends AbstractService implements IOperationParticipant {
// Stati WI
private static final String NAME_STATE_CHIUSO = "Chiuso";
// Role
private static final String ROLE_NAME_SUBSCRIBER = "subscriber";
// ID WI
private static final String WI_ID_DEF = "defect";
// Services we need
static private IWorkItemServer wiServer;
private IRepositoryItemService items;
private IContributorService contributorService;
@Override
public void run(AdvisableOperation operation,
IProcessConfigurationElement advisorConfiguration,
IParticipantInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {
// First check that the operation was a 'save' and get he operation data
Object opData = operation.getOperationData();
if(!(opData instanceof ISaveParameter)){
return;
}
// Check that this was a save operation on a work item
ISaveParameter data = (ISaveParameter)opData;
if(!(data.getNewState() instanceof IWorkItem)) {
return;
}
String wfAction = data.getWorkflowAction();
// Get the required service interfaces
wiServer = getService(IWorkItemServer.class);
items = getService(IRepositoryItemService.class);
contributorService = getService(IContributorService.class);
IWorkItem wi = (IWorkItem)data.getNewState();
IWorkItem workItemOld =(IWorkItem)data.getOldState();
if (!(wi.getWorkItemType().equals(WI_ID_DEF)) ){
return;
}
// Info workItem
Integer wiID = wi.getId();
XMLString wiSummary = wi.getHTMLSummary();
System.out.println("wiID : "+ wiID);
System.out.println("wiSummury : "+ wiSummary);
IWorkflowInfo wfInfo = wiServer.findWorkflowInfo(wi, monitor);
String nameStateNow = wfInfo.getStateName(wi.getState2());
String roleName;
if (nameStateNow.equalsIgnoreCase(NAME_STATE_CHIUSO)){
roleName = ROLE_NAME_SUBSCRIBER;
} else return;
System.out.println("RoleName :"+roleName);
// WorkItem Working Copy **************************************************************************************************
IWorkItem wiOnServer = wiServer.findWorkItemById(wiID,IWorkItem.FULL_PROFILE,null);
IWorkItem wiOnServerCopy = (IWorkItem)wiOnServer.getWorkingCopy();
//*********************************************************************************************************************************
if(workItemOld!=null){
System.out.println("Start Change subscriber section code.....");
ISubscriptions subscriptions= workItemOld.getSubscriptions();
System.out.println("Numero Subscriber WI-OLD :"+subscriptions.getContents().length);
//Contributors with a role equal to "subscriber" and belonging to the Project Area
//The method subscribersArrayByRoleName works
ArrayList<IContributor> subscribersArray =
subscribersArrayByRoleName(operation.getProcessArea(), wi, roleName, monitor);
if (subscribersArray==null) return;
if (subscribersArray.size()==0) {
//Tracciatura fine esecuzione plugin
System.out.println("END " + header);
return;
}
//Add new subscribers to the wi workingCopy*****************************************************************************
for (IContributor contr : subscribersArray){
IContributorHandle user = contributorService.fetchContributorByUserId(contr.getUserId());
wiOnServerCopy.getSubscriptions().add(user);
}
//*******************************************************************************************************************************
//Try to Save - This section code does not work; in the log file I only see the first sys.out
try{
System.out.println("Pre-Save......");
wiServer.saveWorkItem2(wiOnServerCopy, null, null); // ??? <------------
System.out.println("Post-Save.....");
}catch (Exception e) {;
System.out.println("ERRORE nel getService");
e.printStackTrace();
System.out.println(e.getMessage());
System.out.println(e.getStackTrace());
}}
}
Can you help me PLEASE???
Thanks.
Giuseppe Gravina.
4 answers
Comments
Hi Ralph,
This section does not work [ wiServer.saveWorkItem2(wiOnServerCopy, null, null);] means that I expect that with this line of code the subscribers added to the working copy, are added to the original wi too. So, the original wi is updated.
...when i change the wi state in Closed the Screen error is:
The server is not responding or a page navigation occurred before an operation completed. Check that your server connection is working and that the server is operational, then try the action again or refresh the page.
Guiseppe, I would suggest to
-
Read https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/
- Use saveWorkItem3() to save and communicate that the save does not trigger another run of your plugin
If you debug it with Jetty, what happens when the code runs? Is there a recursion?
Hi Ralph,
I read the article ( https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/) and I have some questions for you....Can you answer , please?
- How can I get the WI Working Copy?
1) **************************************************************** WAY 1 ********************************************************
Object opData = operation.getOperationData();
ISaveParameter data = (ISaveParameter)opData;
IWorkItemServer wiServer = getService(IWorkItemServer.class);
IWorkItem wi = (IWorkItem)data.getNewState();
IWorkItem wiOnServer = wiServer.findWorkItemById (wi.getId (),IWorkItem.FULL_PROFILE,null);
IWorkItem wiOnServerCopy = (IWorkItem)wiOnServer.getWorkingCopy();
2)**************************************************************** WAY 2*********************************************************
Object opData = operation.getOperationData();
ISaveParameter data = (ISaveParameter)opData;
IWorkItemServer wiServer = getService(IWorkItemServer.class);
IWorkItemHandle currentWIHandle =
(IWorkItemHandle)data.getNewState().getItemHandle();
IWorkItem workItem=(IWorkItem)wiServer.getAuditableCommon()
.resolveAuditable(currentWIHandle,IWorkItem.FULL_PROFILE,monitor)
.getWorkingCopy();
workItemCopy = (IWorkItem)workItem.getWorkingCopy();
3)*************************************************************** OTHER WAY ? ************************************************
???
- After working on WI Working Copy, how can i save changes?
IWorkItemServer wiServer = getService(IWorkItemServer.class);
wiServer.saveWorkItem2(workitemCopy, null, null);
Is this correct??
*************************************************************************************************************************************
Thanks,
Giuseppe.
Hi Ralph,
I read the article ( https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/) and I have some questions for you....Can you answer , please?
- How can I get the WI Working Copy?
1) **************************************************************** WAY 1 ********************************************************
Object opData = operation.getOperationData();
ISaveParameter data = (ISaveParameter)opData;
IWorkItemServer wiServer = getService(IWorkItemServer.class);
IWorkItem wi = (IWorkItem)data.getNewState();
IWorkItem wiOnServer = wiServer.findWorkItemById (wi.getId (),IWorkItem.FULL_PROFILE,null);
IWorkItem wiOnServerCopy = (IWorkItem)wiOnServer.getWorkingCopy();
2)**************************************************************** WAY 2*********************************************************
Object opData = operation.getOperationData();
ISaveParameter data = (ISaveParameter)opData;
IWorkItemServer wiServer = getService(IWorkItemServer.class);
IWorkItemHandle currentWIHandle =
(IWorkItemHandle)data.getNewState().getItemHandle();
IWorkItem workItem=(IWorkItem)wiServer.getAuditableCommon()
.resolveAuditable(currentWIHandle,IWorkItem.FULL_PROFILE,monitor)
.getWorkingCopy();
workItemCopy = (IWorkItem)workItem.getWorkingCopy();
3)*************************************************************** OTHER WAY ? ************************************************
???
- After working on WI Working Copy, how can i save changes?
IWorkItemServer wiServer = getService(IWorkItemServer.class);
wiServer.saveWorkItem2(workitemCopy, null, null);
Is this correct??
*************************************************************************************************************************************
Thanks,
Giuseppe.
Comments
Basically, how you get a working copy depends on what you have. If you have an ID, you can search for that. If you are in an advisor or follow up action you get parameters when being called. e.g. the old state of the work item and the new state. In other cases you get a work item handle and need to resolve that e.g. using a service, IAuditable or IItemManager.
You have saveWorkItem2() and saveWorkItem3, depending on what you need.
Thank You so much for your support Ralph.
I take one of your old question, that is : " what happens when the code runs? Is there a recursion? ".
So, from log files, i see that when the code runs all works correctly....subscribers are added to wi working copy, but when the code reaches the code line "saveWorkItem2(wiCopy,null,null)", the plug in restart more times and everytimes executes the commands until to save code line....
This behavior ends when appear the Screen error below:
"The server is not responding or a page navigation occurred before an operation completed. Check that your server connection is working and that the server is operational, then try the action again or refresh the page."
Is this recursion??
Thanks
Giuseppe.
Hi Ralph,
the plugin finally works :) .
The problem was recursion. I solved it by inserting the following lines of code:
" if (data.getAdditionalSaveParameters().contains("EXIT-NO-RECURSIVE- UPDATE")) { return; } "
+
" Set additionalParams = new HashSet();
additionalParams.add("EXIT-NO-RECURSIVE-UPDATE");
wiServer.saveWorkItem3(wiCopy, null, null,additionalParams); "
Thanks very much:)
ByeBye
Giuseppe.
if