It's all about the answers!

Ask a question

How to identify the Associated work item type of a Change set using Event handler?


Muthukumar C (32712833) | asked Aug 23 '12, 1:18 a.m.
edited Aug 28 '12, 11:05 a.m. by Ralph Schoon (63.5k33646)
hi,

I need to restrict the Change set to be associated with ONE PARTICULAR WORK ITEM TYPE. Else, error message should be thrown.

I started to build event handler thru server side plugin project. But I don't know the exact APIs to be used.

Guide me with some samples or workshops for event handler.

Comments
Muthukumar C commented Aug 24 '12, 8:36 a.m.

I am using RTC 3.0.1.2 and hence I dont have the Predefined precondition in Deliever (Server) for querying work items.

4 answers



permanent link
Ralph Schoon (63.5k33646) | answered Oct 30 '12, 12:44 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Oct 30 '12, 12:46 p.m.
OK, here goes, I have taken an hour to get the answer for you guys. I shall make it a blog entry soon, but for now....

Please carefully look at

com.ibm.team.filesystem.service.internal.ServerRequireWorkItemAdvisor
com.ibm.team.filesystem.service.internal.ServerRequireWorkItemAdvisor.ServerRequireWorkItemAdvisor

You will notice the constructor that passes the providerfactory in the first advisor that instanciates the second one.

Please also note that the first extends AbstractScmService. Based on that and closely looking at what it does....

You need to extend AbstractScmService, then the code below gets you the work items.

        IRepositoryItemService itemService = getService(IRepositoryItemService.class);   
        ProviderFactory providerFactory = new ServerProviderFactory(this, itemService);
       
        for (IChangeSetHandle iChangeSetHandle : changeSetHandles) {
           
            List<ILink> links= ChangeSetLinks.findLinks(providerFactory, iChangeSetHandle, new String[] { ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID }, monitor);
            for (ILink link : links) {
                Object resolved = link.getTargetRef().resolve();
                if (resolved instanceof IWorkItemHandle) {
                    IWorkItemHandle wiHandle = (IWorkItemHandle) resolved;
                    IWorkItem workItem = (IWorkItem) workItemServer.getAuditableCommon().resolveAuditable(wiHandle, IWorkItem.FULL_PROFILE, monitor);
                    IWorkItem workingCopy= (IWorkItem) workItem.getWorkingCopy();
                    System.out.println(" Linked to: " + workItem.getId());
                }
            }

Please note you are calling internal API here!

I needed these prerequisites.

               <prerequisites>
                        <requiredService interface="com.ibm.team.workitem.service.IWorkItemServer" />
                          <requiredService interface="com.ibm.team.workitem.common.IWorkItemCommon" />
                          <requiredService interface="com.ibm.team.links.common.service.ILinkService" />
                          <requiredService interface="com.ibm.team.workitem.common.IAuditableCommon" />
                          <requiredService interface="com.ibm.team.repository.service.IRepositoryItemService" />   
                          <requiredService interface="com.ibm.team.scm.common.IScmService" />   
                          <requiredService interface="com.ibm.team.process.service.IProcessServerService" />   
                                
               </prerequisites>

This code is for an Advisor.



permanent link
Muthukumar C (32712833) | answered Aug 28 '12, 9:18 a.m.
edited Aug 28 '12, 9:19 a.m.
Hi,

I have developed a advisor for Source control Deliver (Server) operation.
I got the change set content. But I don't know the API to read associated work item details

Any clues now?


permanent link
Ralph Schoon (63.5k33646) | answered Aug 28 '12, 9:23 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I have posted a bunch of work item related api examples hrere: https://rsjazz.wordpress.com/

Comments
Muthukumar C commented Aug 28 '12, 9:26 a.m.

Many thanks ralph for starting this million dollar blog. But sorry what I am looking for is not in the page.


permanent link
Ralph Schoon (63.5k33646) | answered Aug 28 '12, 9:59 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I would assume you have to follow a link. https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ talks about links.

You are looking for a reference or related item at the change set with endpoint         IEndPointDescriptor changeSet= ILinkTypeRegistry.INSTANCE.getLinkType(WorkItemLinkTypes.CHANGE_SET).getTargetEndPointDescriptor();

instead of the parent. That's what I have to get you started at the moment. Maybe someone has more details.

Here is a post from recently that talks about creating that link. I assume you should be able to figure out how to detect there is one of this type from the change set.

Comments
Muthukumar C commented Aug 29 '12, 12:19 a.m.

Ralph, The above code is to get the Change Set from given work item. But what I want is the reverse. that is to get the associated work item from the given change set. so that I will verify the work item type of the associated work item during the Deliver operation.

Anybody?


Jamie Berry commented Oct 29 '12, 6:56 p.m.

I am looking for the same calls.  I need to enforce that the change set is linked (either directly or indirectly) to a particular work item type.  So far, I have not found a way to go from a change set to a work item.  Have you had any luck?

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.