How to identify the Associated work item type of a Change set using Event handler?
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.
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.
4 answers
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.
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.
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.
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
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?
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?
Comments
Muthukumar C
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.