It's all about the answers!

Ask a question

Deletion of the Linked WI is not recognised on IWorkItemSave


vinitha dsouza (147223136) | asked Jan 09 '17, 9:41 a.m.

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");
          }
        }
       
    }






 

One answer



permanent link
Ralph Schoon (63.6k33647) | answered Jan 09 '17, 10:26 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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


Comments
vinitha dsouza commented Jan 09 '17, 11:02 p.m.


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 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.