It's all about the answers!

Ask a question

How to programmatically add Related Change Request link?


Cecilia Lindgren (431213) | asked Jan 11 '11, 11:52 a.m.
I have created an operation Advisor that is communicating with an external system using OSLC interface. Now I need to save a link to the other system.
Is there any way to programmatically add a Related Change Request link to the workitem?

I am using RTC 2.0.02 iFix 5.

6 answers



permanent link
Bruno Braga (48013621) | answered May 06 '11, 7:42 p.m.
For advisors, the solutions above don't work to add link to current work item.

What you have to do in this case is only that:


Object data = operation.getOperationData();
ISaveParameter saveParameter = (ISaveParameter) data;

IWorkItemReferences references = saveParameter.getNewReferences();
Reference reference = (Reference)IReferenceFactory.INSTANCE.createReferenceToItem(wiParent);
references.add(WorkItemEndPoints.PARENT_WORK_ITEM, reference);


You don't need to save anything to edit the current work item because you are already in a save operation.

permanent link
Megan Katysovas (7665) | answered Apr 20 '11, 4:27 p.m.
Something like this may work, where you create a link of WorkItemLinkeTypes.RELATED_CHANGE_MANAGEMENT


ILinkManager linkManager= (ILinkManager) repo.getClientLibrary(ILinkManager.class);

IItemReference sourceRef= IReferenceFactory.INSTANCE.createReferenceToItem(source.getItemHandle());
IItemReference targetRef= IReferenceFactory.INSTANCE.createReferenceToItem(target.getItemHandle());
ILink link= ILinkFactory.INSTANCE.createLink(WorkItemLinkTypes.PARENT_WORK_ITEM, sourceRef, targetRef);


linkManager.saveLink(link, monitor);

permanent link
Nils Kronqvist (4162) | answered Jan 31 '11, 1:56 p.m.
JAZZ DEVELOPER
Follow up question from celin:
===
Now I had time to test your example and got it to work, but unfortunately it does not address the problem I have, I want to add a Change Management link to the current workitem.
I have not found how to create a IEndPointDescriptor of the type that the reference to MHWeb becomes, to use the code below.
I have resolved the references and see that id = "relatedChangeManagement" for this type EndPointDecsriptor when we sent the link to the RTC from Mhweb by passing the tag
<oslc_cm>

references.add(WorkItemEndPoints.PARENT_WORK_ITEM, WorkItemLinkTypes.createWorkItemReference(source));
===

So -- how to find the way of programmatically create a link of Change Management linktype?

/N

permanent link
Nils Kronqvist (4162) | answered Jan 20 '11, 4:04 p.m.
JAZZ DEVELOPER
No, all examples in the document references to code on client side. I need to be able create a link to the workitem in the save operation for the Operation Advisor on the server side.


OK -- might not be the best way, but code below is working (tried using RTC 3) .. and some lessons learned.

1. See https://jazz.net/wiki/bin/view/Main/RTCSDK20_ProcessPreConditionExample and the example https://jazz.net/wiki/pub/Main/RTCSDK20_ProcessPreConditionExample/advisor-example.zip
2. To get access to services for creating items etc - make your handler a subclass to the AbstractService. And to get access to services in the advisor you must ask for them as preconditions. See example below

<plugin>

<extension
point="com.ibm.team.process.service.operationAdvisors">
<operationAdvisor
class="com.ibm.ecat.exampleadvisor.LinkCreationTest"
id="com.ibm.ecat.exampleAdvisor.prohibitSave"
name="Creating Parent 2"
operationId="com.ibm.team.workitem.operation.workItemSave">
<extensionService
componentId="com.ibm.ecat.exampleAdvisor.linkCreationTest2"
implementationClass="com.ibm.ecat.exampleadvisor.LinkCreationTest">
<prerequisites>
<requiredService interface="com.ibm.team.workitem.service.IAuditableServer" />
<requiredService interface="com.ibm.team.workitem.service.IWorkItemServer" />
</prerequisites>
</extensionService>
</operationAdvisor>
</extension>

</plugin>


3. And a code snippet with an advisor that creates a Parent & and link to the new parent each time the item is saved (note: needs to turn off the FiledAgainst precondition for SaveItem to have this work)


package com.ibm.ecat.exampleadvisor;

import java.util.Collections;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;

import com.ibm.team.foundation.common.text.XMLString;
import com.ibm.team.process.common.IProcessArea;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.IProjectArea;
import com.ibm.team.process.common.IProjectAreaHandle;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.IAdvisorInfoCollector;
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.ISaveParameter;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.common.model.IWorkItemReferences;
import com.ibm.team.workitem.common.model.IWorkItemType;
import com.ibm.team.workitem.common.model.ItemProfile;
import com.ibm.team.workitem.common.model.WorkItemEndPoints;
import com.ibm.team.workitem.common.model.WorkItemLinkTypes;
import com.ibm.team.workitem.common.model.WorkItemTypes;
import com.ibm.team.workitem.service.IAuditableServer;
import com.ibm.team.workitem.service.IWorkItemServer;

public class LinkCreationTest extends AbstractService implements IOperationAdvisor {
public static final String PROBLEM_TYPE = " HelloWorldAdvisor.prohibitSave";

public void run(AdvisableOperation operation,
IProcessConfigurationElement advisorConfiguration,
IAdvisorInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {

Object data = operation.getOperationData();

if (data instanceof ISaveParameter) {
ISaveParameter param = (ISaveParameter) data;
IAuditable auditable = param.getNewState();
if (auditable instanceof IWorkItem) {
IWorkItem sourceworkItem = (IWorkItem) auditable;
if (sourceworkItem.isNewItem())
return;

IProcessArea processArea = operation.getProcessArea();
IProjectAreaHandle projectAreaHandle = processArea.getProjectArea();

IAuditableServer auditableServer= getService(IAuditableServer.class);
IProjectArea projectArea= auditableServer.resolveAuditable(
projectAreaHandle,
ItemProfile.<IProjectArea>createFullProfile(IProjectArea.ITEM_TYPE),
monitor);

createWorkItem(projectArea, "Parent to " + sourceworkItem.getId(), sourceworkItem);
}
}
}

private IWorkItem createWorkItem(IProjectArea projectArea, String summary, IWorkItem source) throws TeamRepositoryException {
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
IWorkItemType defectType = workItemServer.findWorkItemType(projectArea, WorkItemTypes.DEFECT, null);

IWorkItem workItem= workItemServer.createWorkItem2(defectType);
workItem.setHTMLSummary(XMLString.createFromPlainText(summary));

IWorkItemReferences references= workItemServer.resolveWorkItemReferences(workItem, null);
references.add(WorkItemEndPoints.PARENT_WORK_ITEM, WorkItemLinkTypes.createWorkItemReference(source));

System.out.println("Create work item " + summary + ": " + workItem.getItemId().getUuidValue());

long saveStart= System.currentTimeMillis();
IStatus status= workItemServer.saveWorkItem3(workItem, references, null, Collections.<String>emptySet());
System.out.println("Save total: "+ (System.currentTimeMillis() - saveStart));
if (status.matches(IStatus.ERROR)) {
throw new TeamRepositoryException(status.getMessage());
}

return workItem;
}

}


So in summary: Some snippets that might get you in the right direction.

permanent link
Cecilia Lindgren (431213) | answered Jan 13 '11, 10:43 a.m.
Hi,

Please look at https://jazz.net/wiki/bin/view/Main/ProgrammaticLinkCreation

Does that answer your question?

Rgs,

/N


No, all examples in the document references to code on client side. I need to be able create a link to the workitem in the save operation for the Operation Advisor on the server side.

permanent link
Nils Kronqvist (4162) | answered Jan 12 '11, 10:25 a.m.
JAZZ DEVELOPER
Hi,

Please look at https://jazz.net/wiki/bin/view/Main/ProgrammaticLinkCreation

Does that answer your question?

Rgs,

/N

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.