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

Deletion of the Linked WI is not recognised on IWorkItemSave

Hello All,

Usecase: If Tracklinks is not present then do not allow the save operation.

i have followed the below article for creation of Advisor,
https://jazz.net/library/article/495

usecase works fine. But when i try to remove the tracks link manually and save , Advisor is not called at all.

If i change any field and remove the track links and save then Advisor is called.

Could you please help on this?

below is my code :
package operationadvisor;

import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;

import com.ibm.team.links.common.IReference;
import com.ibm.team.links.common.registry.IEndPointDescriptor;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.IAdvisorInfo;
import com.ibm.team.process.common.advice.IAdvisorInfoCollector;
import com.ibm.team.process.common.advice.IReportInfo;
import com.ibm.team.process.common.advice.runtime.IOperationAdvisor;
import com.ibm.team.repository.common.IAuditable;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.service.AbstractService;
import com.ibm.team.workitem.common.IAuditableCommon;
import com.ibm.team.workitem.common.ISaveParameter;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.common.model.IWorkItemHandle;
import com.ibm.team.workitem.common.model.IWorkItemReferences;
import com.ibm.team.workitem.common.model.Identifier;
import com.ibm.team.workitem.common.model.WorkItemEndPoints;
import com.ibm.team.workitem.service.IWorkItemServer;

public class Checktracklinksadvisor extends AbstractService implements IOperationAdvisor {

    @Override
    public void run(AdvisableOperation operation,
            IProcessConfigurationElement advisorConfiguration,
            IAdvisorInfoCollector collector, IProgressMonitor monitor)
            throws TeamRepositoryException {
       
          Object data = operation.getOperationData();
         
          if (!(data instanceof ISaveParameter)){
                       return;
          }
         
   
         
          ISaveParameter saveParameter = (ISaveParameter) data; 
          IAuditable auditable = saveParameter.getNewState();
         
                 
          if(!(auditable instanceof IWorkItem)) {
              System.out.println("auditable is not instance of workitem ....returning ...............");
              return;
          }
         
   
          IWorkItem workItem = (IWorkItem) auditable;
         
          System.out.println("testing.........link");
         
          IWorkItem newState = (IWorkItem)saveParameter.getNewState();
          Identifier newStateId = newState.getState2();
         
   
          if (newStateId != null ) {

                       String newType = newState.getWorkItemType();
                       //System.out.println("current WI" +newType);

                                  String state = newState.getState2().getStringIdentifier();
                                  System.out.println("state of the WI"+state);
                                  //if the WI type is story and the state is "Done"
                                  if (newType.equals("com.ibm.team.apt.workItemType.story")&&state.equals("com.ibm.team.apt.story.verified"))
                                  {
                                     
                                    IEndPointDescriptor linkDescriptor = WorkItemEndPoints.TRACKS_BY_ITEMS;
                                          IAuditableCommon iac = saveParameter.getSaveOperationParameter().getAuditableCommon();
                                    
                                    
                                      IWorkItemReferences ref = saveParameter.getNewReferences();
                                     
                                     
                                         // Get all workitem children or parent references.
                                         List<IReference> listReferences = ref.getReferences(linkDescriptor);
                                        
                                      
                                         int count=0;
                                         for (IReference reference : listReferences) {
                                         System.out.println("Refe"+reference.toString());
                                             count++;
                                        
                                         }  
                                     
                                      if(count<=0)
                                      {
                                          IReportInfo createProblemInfo = collector.createProblemInfo("New Method Please link the proper \"Defect\" workitem to the Problem.", "In order to ensure the work process, Do not add any other workitem to the problem using \"tracks\" link","error" );
                                           
                                            System.out
                                                    .println("createProblemInfo.setSeverity(IProcessReport.ERROR);" + createProblemInfo.getSummary() + " ... " + createProblemInfo.getSeverity());
                                         collector.addInfo(createProblemInfo);
                                       return; 
               
                                      }
                                     
                                      else
                                      {
                                          System.out.println("New Method:Done");
                                         
                                      }
                                     
                          
                                     
                                  }
                              
          }
          else
          {
              System.out.println("some state should be defined");
          }
        }
       
    }






 

0 votes



One answer

Permanent link

This, unfortunately, works as designed. These links that can go across server boundaries don't trigger behavior can not be intercepted or prevented. This was done to speed up the process and prevent complex error handling. See my request: 228421: Adding links of type "Tracks", "Contributes To" and "Related Change Request" does not trigger a work item save participant

1 vote

Comments


Hello Ralph,

I am creating the "tracks" link in the same project area.

foe eg.,  There is a Stroy WI which "tracks" Defect WI, both in the same project area.

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
× 10,941

Question asked: Jan 09 '17, 9:41 a.m.

Question was seen: 1,860 times

Last updated: Jan 09 '17, 11:02 p.m.

Confirmation Cancel Confirm