It's all about the answers!

Ask a question

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


glory pugazhenthi (5699) | asked Mar 28 '12, 3:55 a.m.
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

2 answers



permanent link
Ralph Schoon (61.4k33643) | answered Mar 28 '12, 4:14 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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);


permanent link
glory pugazhenthi (5699) | answered Mar 28 '12, 7:04 a.m.
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

Your answer


Register or to post your answer.