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

How to set parent link when creating a work item java client

Hi,

i have created new workitem by plain java client.


But when i create workitem i want to add parent link from plain java client.



Thanks ,

Pugazh

0 votes



2 answers

Permanent link
Hi,

please see: https://jazz.net/forums/viewtopic.php?p=5489

There are several ways how to do it, important is the link type in WorkItemLinkTypes

The code below seems to work also.

ILinkManager linkManager= (ILinkManager)teamRepository.getClientLibrary(ILinkManager.class);
IItemReference source=IReferenceFactory.INSTANCE.createReferenceToItem(handle);
IItemReference target=IReferenceFactory.INSTANCE.createReferenceToItem(opposite);
ILink link=ILinkFactory.INSTANCE.createLink(WorkItemLinkTypes.BLOCKS_WORK_ITEM, source, target);
linkManager.saveLink(link, monitor);

0 votes


Permanent link
Hi,

Thanks for your response. I have found the solution.Check my code below.


public class WorkItemInitialization extends AbstractWorkItemOperation {

private String fSummary;
private ICategoryHandle fCategory;
private IAttribute iattribute;
IWorkItem iparent;
IWorkItemHandle target;

public WorkItemInitialization(String summary, ICategoryHandle category, IWorkItem parent, IWorkItemHandle parent2, IAttribute ia,IWorkItemClient workItemClient) {

super("Initializing Work Item");

fSummary = summary;
fCategory = category;
iattribute = ia;
iparent = parent;
target = parent2;
this.workItemClient = workItemClient;
}

protected void execute(WorkItemWorkingCopy workingCopy,IProgressMonitor monitor) throws TeamRepositoryException {



IWorkItem workItem = workingCopy.getWorkItem();
workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary));
java.util.Date date= new java.util.Date();

String str_date="08-05-2012";
DateFormat formatter ;
Date date1 = null ;
formatter = new SimpleDateFormat("dd-M-yy");
try {
date1 = (Date)formatter.parse(str_date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
java.sql.Timestamp timeStampDate = new Timestamp(date1.getTime());
System.out.println("Today is " +timeStampDate);

workItem.setCategory(fCategory);
workItem.setDueDate(timeStampDate);

IAttribute attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.Planned_Start_Date", monitor);
if (attr != null) {
workItem.setValue(attr,timeStampDate);
}

attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.Planned_Target_Date", monitor);
if (attr != null) {
workItem.setValue(attr,timeStampDate);
}


attr = workItemClient.findAttribute(workingCopy.getWorkItem().getProjectArea(),"Development.parent_dev", monitor);
System.out.println("------------------------------");
System.out.println(attr);
System.out.println("------------------------------");
if (attr != null) {
workItem.setValue(attr,iparent );
}



setParent(workingCopy,iparent);


}


private void setParent(WorkItemWorkingCopy wc, IWorkItem parent) {
IEndPointDescriptor referenceType= WorkItemEndPoints.PARENT_WORK_ITEM;
IReference reference= WorkItemLinkTypes.createWorkItemReference(parent);
wc.getReferences().add(referenceType, reference);
}


}

Thanks

Glory

0 votes

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,938

Question asked: Mar 28 '12, 3:55 a.m.

Question was seen: 5,571 times

Last updated: Mar 28 '12, 3:55 a.m.

Confirmation Cancel Confirm