Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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.
 
 

0 votes



4 answers

Permanent link
What does "This section does not work" mean? Have you looked into other examples e.g. https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ ?

0 votes

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

You save in the advisor, which triggers the advisor again and so on. Your server dies in the recursion. You have to make sure that you don't run the subscribe again after the first time. You can do that by passing additional parameters as described in the blog.


Permanent link
Not sure what is going on. I have done similar stuff here: https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/  and it works for me.
If you debug it with Jetty, what happens when the code runs? Is there a recursion?  

0 votes

Comments

Also look for the log files for stack traces. However, if you really want to do this kind of stuff familiarize yourself with using Jetty for debugging.


Permanent link

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.

0 votes


Permanent link

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.

0 votes

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

 

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 11,053

Question asked: May 12 '14, 11:21 a.m.

Question was seen: 6,898 times

Last updated: May 20 '14, 10:31 a.m.

Confirmation Cancel Confirm